Commit a680eb0bfbae5eb0135f2995f44e1e88589427fb

Authored by fengtao
1 parent 19f336fc

feat:新增全局变量存储openid

1 <script> 1 <script>
2 - import base from "@/config/baseUrl";  
3 - import store from "@/store";  
4 - // #ifdef APP-PLUS  
5 - import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';  
6 - // #endif  
7 -  
8 - import { mpUpData,scene } from '@/config/common';  
9 - export default {  
10 - onLaunch(e) {  
11 - //取出缓存数据  
12 - store.commit('setCacheData');  
13 - //获取二维码信息  
14 - scene(e)  
15 - // #ifdef APP-PLUS  
16 - APPUpdate() //检测app更新  
17 - // #endif  
18 - },  
19 - onShow(e) {  
20 - // #ifdef MP  
21 - mpUpData() //检测小程序更新  
22 - // #endif  
23 - },  
24 - onHide() {  
25 - console.log('App Hide')  
26 - } 2 +import base from '@/config/baseUrl';
  3 +import store from '@/store';
  4 +// #ifdef APP-PLUS
  5 +import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
  6 +// #endif
  7 +
  8 +import { mpUpData, scene } from '@/config/common';
  9 +export default {
  10 + //设置全局变量,解绑时从这里取
  11 + globalData: {
  12 + openId: ''
  13 + },
  14 + onLaunch(e) {
  15 + //取出缓存数据
  16 + store.commit('setCacheData');
  17 + //获取二维码信息
  18 + scene(e);
  19 + // #ifdef APP-PLUS
  20 + APPUpdate(); //检测app更新
  21 + // #endif
  22 + },
  23 + onShow(e) {
  24 + // #ifdef MP
  25 + mpUpData(); //检测小程序更新
  26 + // #endif
  27 + },
  28 + onHide() {
  29 + console.log('App Hide');
27 } 30 }
  31 +};
28 </script> 32 </script>
29 33
30 <style lang="scss"> 34 <style lang="scss">
31 /* #ifndef APP-NVUE */ 35 /* #ifndef APP-NVUE */
32 -@import "@/uni_modules/uview-ui/index.scss"; 36 +@import '@/uni_modules/uview-ui/index.scss';
33 @import './style/iconfont.scss'; 37 @import './style/iconfont.scss';
34 -@import "./style/common.scss"; 38 +@import './style/common.scss';
35 page { 39 page {
36 - background-color: #f5f5f5; 40 + background-color: #f5f5f5;
37 } 41 }
38 // 隐藏滚动条 42 // 隐藏滚动条
39 ::-webkit-scrollbar { 43 ::-webkit-scrollbar {
40 - width: 0;  
41 - height: 0;  
42 - color: transparent; 44 + width: 0;
  45 + height: 0;
  46 + color: transparent;
43 } 47 }
44 /* #endif */ 48 /* #endif */
45 </style> 49 </style>
@@ -69,6 +69,8 @@ export default { @@ -69,6 +69,8 @@ export default {
69 if (res.statusCode == 200) { 69 if (res.statusCode == 200) {
70 this.openid = res.data.openid; 70 this.openid = res.data.openid;
71 this.session_key = res.data.session_key; 71 this.session_key = res.data.session_key;
  72 + //设置全局变量openId
  73 + getApp().globalData.openId = res.data.openid;
72 } 74 }
73 }, 75 },
74 complete: e => { 76 complete: e => {
@@ -88,8 +90,8 @@ export default { @@ -88,8 +90,8 @@ export default {
88 ...mapMutations(['setUserInfo']), 90 ...mapMutations(['setUserInfo']),
89 ...mapActions(['updateBadgeTotal']), 91 ...mapActions(['updateBadgeTotal']),
90 //微信授权登录 92 //微信授权登录
91 - //#ifdef MP  
92 - onAuthorization(e) { 93 + //#ifdef MP-WEIXIN
  94 + onAuthorization() {
93 /** 95 /**
94 * 注意:通过wx.getUserProfile并不能获取用户的openid,openid是唯一识别用户的标识, 96 * 注意:通过wx.getUserProfile并不能获取用户的openid,openid是唯一识别用户的标识,
95 * 所以最好在用户授权登录时就获取。调用wx.login()获取 97 * 所以最好在用户授权登录时就获取。调用wx.login()获取
@@ -113,8 +115,12 @@ export default { @@ -113,8 +115,12 @@ export default {
113 if (res.token == '' || res.token == null) { 115 if (res.token == '' || res.token == null) {
114 //需要绑定,跳转我的页面进行绑定,显示绑定按钮 116 //需要绑定,跳转我的页面进行绑定,显示绑定按钮
115 uni.reLaunch({ 117 uni.reLaunch({
116 - url: '/pages/personal/personal' 118 + url: '../../pages/personal/personal'
117 }); 119 });
  120 + let userInfo = {
  121 + isThirdLogin: true //token用于判断是否登录
  122 + };
  123 + this.setUserInfo(userInfo);
118 } else { 124 } else {
119 // 不需要绑定 125 // 不需要绑定
120 // 储存登录信息 126 // 储存登录信息
@@ -135,6 +141,9 @@ export default { @@ -135,6 +141,9 @@ export default {
135 }); 141 });
136 this.saveUserInfo(); 142 this.saveUserInfo();
137 this.getAlarmTotalData(); 143 this.getAlarmTotalData();
  144 + uni.reLaunch({
  145 + url: '../../pages/personal/personal'
  146 + });
138 } 147 }
139 }) 148 })
140 .catch(e => { 149 .catch(e => {
@@ -147,7 +156,7 @@ export default { @@ -147,7 +156,7 @@ export default {
147 // #ifdef MP 156 // #ifdef MP
148 setTimeout(() => { 157 setTimeout(() => {
149 uni.reLaunch({ 158 uni.reLaunch({
150 - url: '/pages/personal/personal?obj=' + encodeURIComponent(JSON.stringify(obj)) 159 + url: '../../pages/personal/personal?obj=' + encodeURIComponent(JSON.stringify(obj))
151 }); 160 });
152 }, 500); 161 }, 500);
153 // #endif 162 // #endif
@@ -202,7 +211,8 @@ export default { @@ -202,7 +211,8 @@ export default {
202 }; 211 };
203 let userInfo = { 212 let userInfo = {
204 ...resObj, 213 ...resObj,
205 - token: true //token用于判断是否登录 214 + token: true, //token用于判断是否登录
  215 + isThirdLogin: false
206 }; 216 };
207 if (userInfo.token) { 217 if (userInfo.token) {
208 this.setUserInfo(userInfo); 218 this.setUserInfo(userInfo);