App.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <script>
  2. export default {
  3. globalData: {
  4. winHeight: "",
  5. is_auth: '',
  6. baseUrl: 'http://admin.l4j.cn/api', //线上地址
  7. product: '',
  8. code_no: '',
  9. code: '',
  10. latitude: '',
  11. longitude: '',
  12. subscribe: '',
  13. },
  14. onLaunch: function(e) {
  15. let that = this
  16. let code_no = e.query.no
  17. let code = e.query.code
  18. let code_num = e.query.state
  19. uni.setStorageSync('code_no', e.query.no)
  20. let location_url = window.location.href
  21. let skip_url = 'http://l4j.cn/pages/statistics'
  22. let skip_url1 = `http://l4j.cn/pages/statistics?code=${code}&state=state`
  23. //登陆方法线上需要谢在下方else位置
  24. if (location_url !== skip_url && location_url !== skip_url1) {
  25. let token = uni.getStorageSync('token')
  26. if (token) return
  27. if (!e.query.code) {
  28. that.globalData.code_no = e.query.no
  29. //线上解开此处
  30. window.location.replace(
  31. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx22dc4d8cbc0a192d&redirect_uri=http://l4j.cn&response_type=code&scope=snsapi_base&state=${code_no}#wechat_redirect`
  32. )
  33. return
  34. } else {
  35. // 此处写登陆方法
  36. uni.showLoading({
  37. mask: true
  38. })
  39. uni.request({
  40. url: that.globalData.baseUrl + '/auth/wechat-login',
  41. method: 'POST',
  42. header: {
  43. 'content-type': 'application/json',
  44. 'Accept': 'application/json',
  45. },
  46. data: {
  47. code: e.query.code,
  48. //code: 'mead',
  49. appId: 'wx22dc4d8cbc0a192d',
  50. },
  51. success(res) {
  52. console.log(res, 'huoqutoken')
  53. if (res.data.message == "授权失败") {
  54. console.log(code_num, '红包码')
  55. uni.showModal({
  56. title: '提示',
  57. content: '授权失败是否重试',
  58. confirmText: '重试',
  59. showCancel: false,
  60. success: (res) => {
  61. if (res.confirm) {
  62. window.location.replace('http://l4j.cn/?no=' +
  63. code_num)
  64. }
  65. }
  66. })
  67. } else {
  68. uni.setStorageSync('token', res.data.data.token),
  69. uni.setStorageSync('is_auth', res.data.data.is_auth),
  70. uni.setStorageSync('subscribe', res.data.data.subscribe)
  71. that.globalData.subscribe = res.data.data.subscribe
  72. // uni.hideLoading()
  73. }
  74. },
  75. catch: (err => {
  76. uni.showToast({
  77. title: '授权失败',
  78. icon: 'none'
  79. })
  80. })
  81. })
  82. }
  83. } else {
  84. return;
  85. }
  86. uni.getSystemInfo({
  87. success(res) {
  88. console.log(res, '系统信息')
  89. that.globalData.winHeight = res.windowHeight
  90. console.log(that.globalData.winHeight, '系统信息')
  91. }
  92. })
  93. },
  94. onShow: function() {
  95. console.log('App Show')
  96. },
  97. onHide: function() {
  98. console.log('App Hide')
  99. },
  100. methods: {
  101. request(api, params, method) {
  102. var that = this;
  103. return new Promise((resolve, reject) => {
  104. uni.request({
  105. url: that.globalData.baseUrl + api,
  106. data: params,
  107. header: {
  108. 'content-type': 'application/json',
  109. 'Accept': 'application/json',
  110. 'Authorization': uni.getStorageSync('token'),
  111. },
  112. method: method,
  113. success: (res) => {
  114. resolve(res.data)
  115. console.log(res, '请求结果----------------------')
  116. if (res.statusCode == 450) {
  117. return;
  118. }
  119. if (res.statusCode == 401) {
  120. uni.clearStorageSync('token')
  121. location.reload()
  122. } else if (res.statusCode != 200) {
  123. if (res.message != undefined) {
  124. uni.showToast({
  125. title: res.message,
  126. icon: 'none',
  127. duration: 3000,
  128. mask: true
  129. })
  130. } else if (res.data.message != undefined) {
  131. uni.showToast({
  132. title: res.data.message,
  133. icon: 'none',
  134. duration: 3000,
  135. mask: true
  136. })
  137. }
  138. }
  139. if (res.statusCode == 429) {
  140. uni.showToast({
  141. title: "操作频繁请稍后再试",
  142. icon: 'none',
  143. duration: 3000,
  144. mask: true
  145. })
  146. uni.navigateBack({
  147. })
  148. }
  149. },
  150. fail: (err) => {
  151. // console.log('请求失败')
  152. resolve(err)
  153. // reject("请求失败")
  154. }
  155. })
  156. })
  157. },
  158. }
  159. }
  160. </script>
  161. <style>
  162. /*每个页面公共css */
  163. </style>