App.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script>
  2. import Vue from 'vue'
  3. import BASE_URL from './config.js'
  4. import {mapActions} from 'vuex'
  5. export default {
  6. onLaunch: function() {
  7. uni.getSystemInfo({
  8. success: function(e) {
  9. // #ifndef MP
  10. Vue.prototype.StatusBar = e.statusBarHeight;
  11. if (e.platform == 'android') {
  12. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  13. } else {
  14. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  15. };
  16. // #endif
  17. // #ifdef MP-WEIXIN
  18. Vue.prototype.StatusBar = e.statusBarHeight;
  19. let custom = wx.getMenuButtonBoundingClientRect();
  20. Vue.prototype.Custom = custom;
  21. Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
  22. // #endif
  23. // #ifdef MP-ALIPAY
  24. Vue.prototype.StatusBar = e.statusBarHeight;
  25. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  26. // #endif
  27. }
  28. })
  29. Vue.prototype.ColorList = [{
  30. title: '嫣红',
  31. name: 'red',
  32. color: '#e54d42'
  33. },
  34. {
  35. title: '桔橙',
  36. name: 'orange',
  37. color: '#f37b1d'
  38. },
  39. {
  40. title: '明黄',
  41. name: 'yellow',
  42. color: '#fbbd08'
  43. },
  44. {
  45. title: '橄榄',
  46. name: 'olive',
  47. color: '#8dc63f'
  48. },
  49. {
  50. title: '森绿',
  51. name: 'green',
  52. color: '#39b54a'
  53. },
  54. {
  55. title: '天青',
  56. name: 'cyan',
  57. color: '#1cbbb4'
  58. },
  59. {
  60. title: '海蓝',
  61. name: 'blue',
  62. color: '#0081ff'
  63. },
  64. {
  65. title: '姹紫',
  66. name: 'purple',
  67. color: '#6739b6'
  68. },
  69. {
  70. title: '木槿',
  71. name: 'mauve',
  72. color: '#9c26b0'
  73. },
  74. {
  75. title: '桃粉',
  76. name: 'pink',
  77. color: '#e03997'
  78. },
  79. {
  80. title: '棕褐',
  81. name: 'brown',
  82. color: '#a5673f'
  83. },
  84. {
  85. title: '玄灰',
  86. name: 'grey',
  87. color: '#8799a3'
  88. },
  89. {
  90. title: '草灰',
  91. name: 'gray',
  92. color: '#aaaaaa'
  93. },
  94. {
  95. title: '墨黑',
  96. name: 'black',
  97. color: '#333333'
  98. },
  99. {
  100. title: '雅白',
  101. name: 'white',
  102. color: '#ffffff'
  103. },
  104. ]
  105. },
  106. onShow: function() {
  107. console.log('App Show')
  108. },
  109. onHide: function() {
  110. console.log('App Hide')
  111. },
  112. created: async function() {
  113. // 获取 URL 中的 code 参数
  114. const urlParams = new URLSearchParams(window.location.search);
  115. const code = urlParams.get('code');
  116. console.log('传入 code -------');
  117. console.log(code);
  118. if (code) {
  119. try {
  120. // 发起请求获取用户信息
  121. const [err, res] = await uni.request({
  122. url: BASE_URL + `/flowable-server/app/proxy?appid=wxa79f618dcaf992f7&secret=24f99f0d9ed67b9078cd545be50f9ccb&code=` + code,
  123. method: 'GET'
  124. });
  125. if (res && res.statusCode === 200) {
  126. console.log('用户信息获取成功-----------');
  127. const data = res.data;
  128. console.log(data);
  129. console.log(data.openId);
  130. // 将微信用户的 openId 存到本地
  131. uni.setStorageSync('openId', data.openId);
  132. console.log('getStorageSync-> ', uni.getStorageSync('openId'));
  133. } else {
  134. console.error('获取用户信息失败:', res.data);
  135. }
  136. } catch (err) {
  137. console.error('请求失败:', err);
  138. }
  139. }
  140. // 判断当前微信号的openId 是否已经存入到数据库了,如果存入了,那么就直接通过openId匹配登录,否则就进入登录页面
  141. const flag = true;
  142. const localOpenId = uni.getStorageSync('openId');
  143. if (localOpenId) {
  144. try {
  145. // 发起请求获取库中的openId
  146. const [err, res] = await uni.request({
  147. url: BASE_URL + `/system-server/sys/user/allOpenIds`,
  148. method: 'GET'
  149. });
  150. if (res && res.statusCode === 200) {
  151. const data = res.data;
  152. console.log('allOpenIds:', data);
  153. // 确保 data 是数组
  154. if (Array.isArray(data) && data.includes(localOpenId)) {
  155. // 包含的话,则直接根据 openId来实现登录
  156. console.log(`data 包含 openId: ${localOpenId}`);
  157. const [err, res] = await uni.request({
  158. url: BASE_URL + `/auth-server/user/sys/wxLogin`,
  159. method: 'POST',
  160. data: { openId: localOpenId },
  161. header: {
  162. 'domain': 'ydddl'
  163. }
  164. });
  165. if (res && res.statusCode === 200) {
  166. this.$store.commit('SET_TOKEN',res.data.token);
  167. await this.refreshUserInfo();
  168. uni.reLaunch({
  169. url: '../index/index',
  170. });
  171. }
  172. }
  173. }
  174. } catch (err) {
  175. console.error('请求失败:', err);
  176. }
  177. }
  178. if (flag) {
  179. console.log('进来了');
  180. }
  181. },
  182. methods: {
  183. ...mapActions(['refreshUserInfo']),
  184. }
  185. }
  186. </script>
  187. <style lang="scss">
  188. /*每个页面公共css */
  189. @import "@/uni_modules/uview-ui/index.scss";
  190. @import "static/css/jeeplus.scss";
  191. /* @import 'jeeplus-flowable/lib/jeeplus-flowable.css'; */
  192. @import "static/css/main.css";
  193. @import "static/css/icon.css";
  194. /*每个页面公共css */
  195. </style>