Authored by QC-L

添加登录相关 review by 黄敬囿

@@ -49,6 +49,7 @@ export const getUserInfo = async (e) => { @@ -49,6 +49,7 @@ export const getUserInfo = async (e) => {
49 49
50 export const getPhoneNumber = async (e) => { 50 export const getPhoneNumber = async (e) => {
51 const event = global.event; 51 const event = global.event;
  52 + const app = getApp();
52 try { 53 try {
53 if (e.detail.errMsg === 'getPhoneNumber:ok') { 54 if (e.detail.errMsg === 'getPhoneNumber:ok') {
54 const srd_session = wx.getStorageSync('srd_session') || ''; 55 const srd_session = wx.getStorageSync('srd_session') || '';
@@ -60,11 +61,54 @@ export const getPhoneNumber = async (e) => { @@ -60,11 +61,54 @@ export const getPhoneNumber = async (e) => {
60 } 61 }
61 const bindResult = await login.bindMiniAppByAuto(union_id, phoneNumber, countryCode); 62 const bindResult = await login.bindMiniAppByAuto(union_id, phoneNumber, countryCode);
62 console.log(bindResult); 63 console.log(bindResult);
  64 + if (bindResult && bindResult.is_register === 0) {
  65 + const newUserInfo = {
  66 + is_bind: bindResult.is_bind,
  67 + mobile: bindResult.profile,
  68 + session_key: bindResult.session_key,
  69 + uid: bindResult.uid,
  70 + ssouid: bindResult.ssouid,
  71 + union_id: union_id,
  72 + vip: bindResult.vip
  73 + };
  74 +
  75 + let userInfo = wx.getStorageSync('userInfo');
  76 + userInfo = Object.assign(userInfo, newUserInfo);
  77 + await setStorageWithValueForKey('userInfo', userInfo);
  78 + await setStorageWithValueForKey('sessionkey', result.session_key);
  79 +
  80 + app.globalData.userInfo = userInfo;
  81 + event.emit('wechat-login-success');
  82 + event.emit('user-login-success', newUserInfo);
  83 + wx.showToast({
  84 + icon: 'none',
  85 + title: '手机号授权成功!\r\n为享受更多权益,已为您注册有货会员!',
  86 + duration: 3000
  87 + });
  88 + } else if (bindResult && bindResult.is_register === 2) {
  89 + const newUserInfo = {
  90 + is_bind: bindResult.is_bind,
  91 + mobile: bindResult.profile,
  92 + session_key: bindResult.session_key,
  93 + uid: bindResult.uid,
  94 + ssouid: bindResult.ssouid,
  95 + union_id: union_id,
  96 + vip: bindResult.vip
  97 + };
  98 +
  99 + let userInfo = wx.getStorageSync('userInfo');
  100 + userInfo = Object.assign(userInfo, newUserInfo);
  101 + await setStorageWithValueForKey('userInfo', userInfo);
  102 + await setStorageWithValueForKey('sessionkey', result.session_key);
  103 +
  104 + app.globalData.userInfo = userInfo;
  105 + event.emit('wechat-login-success');
  106 + event.emit('user-login-success', newUserInfo);
  107 + }
63 } else { 108 } else {
64 throw new Error('手机号获取失败,请使用手机号登录'); 109 throw new Error('手机号获取失败,请使用手机号登录');
65 } 110 }
66 } catch (error) { 111 } catch (error) {
67 - console.log(error);  
68 event.emit('wechat-login-error', error); 112 event.emit('wechat-login-error', error);
69 } 113 }
70 } 114 }
@@ -86,10 +130,10 @@ const wechatUnionIdIsBind = async (union_id, userInfo) => { @@ -86,10 +130,10 @@ const wechatUnionIdIsBind = async (union_id, userInfo) => {
86 const newUserInfo = Object.assign(userInfo, { mobile, session_key, uid, ssouid }); 130 const newUserInfo = Object.assign(userInfo, { mobile, session_key, uid, ssouid });
87 await setStorageValueForKey('userInfo', newUserInfo); 131 await setStorageValueForKey('userInfo', newUserInfo);
88 await setStorageValueForKey('sessionkey', session_key); 132 await setStorageValueForKey('sessionkey', session_key);
  133 +
  134 + // 赋值全局变量
89 globalData.sessionkey = session_key; 135 globalData.sessionkey = session_key;
90 globalData.userInfo = userInfo; 136 globalData.userInfo = userInfo;
91 - // 赋值全局变量  
92 -  
93 // 上传保存头像 137 // 上传保存头像
94 login.sendWeChatUserData(uid, userInfo.nickName, userInfo.avatarUrl).catch(error => {}); 138 login.sendWeChatUserData(uid, userInfo.nickName, userInfo.avatarUrl).catch(error => {});
95 // 触发事件登录成功 139 // 触发事件登录成功
@@ -21,6 +21,8 @@ export default class BaseService { @@ -21,6 +21,8 @@ export default class BaseService {
21 }).then(res => { 21 }).then(res => {
22 if (res.code === 200) { 22 if (res.code === 200) {
23 return res.data 23 return res.data
  24 + } else {
  25 + throw res
24 } 26 }
25 }) 27 })
26 } 28 }
@@ -80,7 +80,7 @@ Page(Object.assign({ @@ -80,7 +80,7 @@ Page(Object.assign({
80 80
81 if (options && options.tabIndex) { 81 if (options && options.tabIndex) {
82 this.setData({ 82 this.setData({
83 - tabIndex: options.tabIndex 83 + tabIndex: Number(options.tabIndex)
84 }) 84 })
85 this._init(options.tabIndex); 85 this._init(options.tabIndex);
86 } else { 86 } else {
@@ -134,13 +134,11 @@ Page(Object.assign({ @@ -134,13 +134,11 @@ Page(Object.assign({
134 [pageKey]: page + 1, 134 [pageKey]: page + 1,
135 }) 135 })
136 } 136 }
137 -  
138 this.setData({ 137 this.setData({
139 footText: '暂无更多内容' 138 footText: '暂无更多内容'
140 }); 139 });
141 }) 140 })
142 } else { 141 } else {
143 - console.log('++++++++++++++++++++');  
144 this._getReleaseData(); 142 this._getReleaseData();
145 } 143 }
146 }, 144 },
@@ -164,10 +162,8 @@ Page(Object.assign({ @@ -164,10 +162,8 @@ Page(Object.assign({
164 this.setData({ 162 this.setData({
165 footText: '内容加载中...' 163 footText: '内容加载中...'
166 }) 164 })
167 -  
168 this._getProceedingData(); 165 this._getProceedingData();
169 this._getReleaseData(1); 166 this._getReleaseData(1);
170 -  
171 return this._getPage(page).then(list => { 167 return this._getPage(page).then(list => {
172 if (list.length === 0) { 168 if (list.length === 0) {
173 this.setData({ 169 this.setData({
@@ -279,9 +275,6 @@ Page(Object.assign({ @@ -279,9 +275,6 @@ Page(Object.assign({
279 [key]: oldData.concat(data), 275 [key]: oldData.concat(data),
280 [keyPage]: ++page 276 [keyPage]: ++page
281 }) 277 })
282 - this.setData({  
283 - footText: ''  
284 - })  
285 if (data.length === 0) { 278 if (data.length === 0) {
286 this.setData({ 279 this.setData({
287 footText: '暂无更多内容' 280 footText: '暂无更多内容'
@@ -298,14 +291,14 @@ Page(Object.assign({ @@ -298,14 +291,14 @@ Page(Object.assign({
298 }, 291 },
299 292
300 onTabChange({detail}) { 293 onTabChange({detail}) {
301 - if (detail === 3 && !this.data.isLogin) {  
302 - return;  
303 - }  
304 this.setData({ 294 this.setData({
305 tabIndex: detail, 295 tabIndex: detail,
306 [`list[${detail}].page`]: 1 296 [`list[${detail}].page`]: 1
307 }); 297 });
308 298
  299 + if (detail === 3 && !this.data.isLogin) {
  300 + return;
  301 + }
309 this._init(); 302 this._init();
310 }, 303 },
311 304
@@ -52,7 +52,7 @@ @@ -52,7 +52,7 @@
52 </block> 52 </block>
53 </view> --> 53 </view> -->
54 </tabs-pane> 54 </tabs-pane>
55 - <block wx:if="{{isLogin}}"> 55 + <block wx:if="{{tabIndex !== 3}}">
56 <view class="list-foot-blank">{{footText}}</view> 56 <view class="list-foot-blank">{{footText}}</view>
57 </block> 57 </block>
58 </tabs> 58 </tabs>