Authored by QC-L

添加登录相关 review by 黄敬囿

... ... @@ -49,6 +49,7 @@ export const getUserInfo = async (e) => {
export const getPhoneNumber = async (e) => {
const event = global.event;
const app = getApp();
try {
if (e.detail.errMsg === 'getPhoneNumber:ok') {
const srd_session = wx.getStorageSync('srd_session') || '';
... ... @@ -60,11 +61,54 @@ export const getPhoneNumber = async (e) => {
}
const bindResult = await login.bindMiniAppByAuto(union_id, phoneNumber, countryCode);
console.log(bindResult);
if (bindResult && bindResult.is_register === 0) {
const newUserInfo = {
is_bind: bindResult.is_bind,
mobile: bindResult.profile,
session_key: bindResult.session_key,
uid: bindResult.uid,
ssouid: bindResult.ssouid,
union_id: union_id,
vip: bindResult.vip
};
let userInfo = wx.getStorageSync('userInfo');
userInfo = Object.assign(userInfo, newUserInfo);
await setStorageWithValueForKey('userInfo', userInfo);
await setStorageWithValueForKey('sessionkey', result.session_key);
app.globalData.userInfo = userInfo;
event.emit('wechat-login-success');
event.emit('user-login-success', newUserInfo);
wx.showToast({
icon: 'none',
title: '手机号授权成功!\r\n为享受更多权益,已为您注册有货会员!',
duration: 3000
});
} else if (bindResult && bindResult.is_register === 2) {
const newUserInfo = {
is_bind: bindResult.is_bind,
mobile: bindResult.profile,
session_key: bindResult.session_key,
uid: bindResult.uid,
ssouid: bindResult.ssouid,
union_id: union_id,
vip: bindResult.vip
};
let userInfo = wx.getStorageSync('userInfo');
userInfo = Object.assign(userInfo, newUserInfo);
await setStorageWithValueForKey('userInfo', userInfo);
await setStorageWithValueForKey('sessionkey', result.session_key);
app.globalData.userInfo = userInfo;
event.emit('wechat-login-success');
event.emit('user-login-success', newUserInfo);
}
} else {
throw new Error('手机号获取失败,请使用手机号登录');
}
} catch (error) {
console.log(error);
event.emit('wechat-login-error', error);
}
}
... ... @@ -86,10 +130,10 @@ const wechatUnionIdIsBind = async (union_id, userInfo) => {
const newUserInfo = Object.assign(userInfo, { mobile, session_key, uid, ssouid });
await setStorageValueForKey('userInfo', newUserInfo);
await setStorageValueForKey('sessionkey', session_key);
// 赋值全局变量
globalData.sessionkey = session_key;
globalData.userInfo = userInfo;
// 赋值全局变量
// 上传保存头像
login.sendWeChatUserData(uid, userInfo.nickName, userInfo.avatarUrl).catch(error => {});
// 触发事件登录成功
... ...
... ... @@ -21,6 +21,8 @@ export default class BaseService {
}).then(res => {
if (res.code === 200) {
return res.data
} else {
throw res
}
})
}
... ...
... ... @@ -80,7 +80,7 @@ Page(Object.assign({
if (options && options.tabIndex) {
this.setData({
tabIndex: options.tabIndex
tabIndex: Number(options.tabIndex)
})
this._init(options.tabIndex);
} else {
... ... @@ -134,13 +134,11 @@ Page(Object.assign({
[pageKey]: page + 1,
})
}
this.setData({
footText: '暂无更多内容'
});
})
} else {
console.log('++++++++++++++++++++');
this._getReleaseData();
}
},
... ... @@ -164,10 +162,8 @@ Page(Object.assign({
this.setData({
footText: '内容加载中...'
})
this._getProceedingData();
this._getReleaseData(1);
return this._getPage(page).then(list => {
if (list.length === 0) {
this.setData({
... ... @@ -279,9 +275,6 @@ Page(Object.assign({
[key]: oldData.concat(data),
[keyPage]: ++page
})
this.setData({
footText: ''
})
if (data.length === 0) {
this.setData({
footText: '暂无更多内容'
... ... @@ -298,14 +291,14 @@ Page(Object.assign({
},
onTabChange({detail}) {
if (detail === 3 && !this.data.isLogin) {
return;
}
this.setData({
tabIndex: detail,
[`list[${detail}].page`]: 1
});
if (detail === 3 && !this.data.isLogin) {
return;
}
this._init();
},
... ...
... ... @@ -52,7 +52,7 @@
</block>
</view> -->
</tabs-pane>
<block wx:if="{{isLogin}}">
<block wx:if="{{tabIndex !== 3}}">
<view class="list-foot-blank">{{footText}}</view>
</block>
</tabs>
... ...