|
|
|
@ -29,12 +29,16 @@ |
|
|
|
|
openid: '', |
|
|
|
|
unionid: '', |
|
|
|
|
submiting: false, |
|
|
|
|
token: '', |
|
|
|
|
isBind: false, |
|
|
|
|
accounts: [], |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onShow() { |
|
|
|
|
// uni.setStorageSync('token', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjM5NTc2LCJyblN0ciI6IjZXZUtCNTdOMU9ubGhBSG53RmJwMWN0c3VuVWlyR2l5IiwiYWNjb3VudElkIjozOTU3NiwidXNlcklkIjozOTU3NSwic2Nob29sSWQiOjI4NDYsInVzZXJOYW1lIjoiYWMiLCJwbGF0Zm9ybUlkIjoiMSJ9.hYkjwTUdMMYQLXJVRmqnw3tqRvGndNAzUiVh1ClyCec') |
|
|
|
|
const pages = getCurrentPages() |
|
|
|
|
const { options } = pages[pages.length - 1] |
|
|
|
|
this.fromLogout = options.logout || 0 |
|
|
|
|
|
|
|
|
|
this.checkLogin() |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
@ -44,6 +48,8 @@ |
|
|
|
|
this.toIndex() |
|
|
|
|
} else { |
|
|
|
|
uni.clearStorageSync() |
|
|
|
|
this.token = '' |
|
|
|
|
this.isBind = false |
|
|
|
|
this.submiting = false |
|
|
|
|
this.autoLogin() |
|
|
|
|
} |
|
|
|
@ -53,8 +59,6 @@ |
|
|
|
|
uni.login({ |
|
|
|
|
success: async ({ code }) => { |
|
|
|
|
if (code) { |
|
|
|
|
this.submiting = true |
|
|
|
|
|
|
|
|
|
// 微信小程序登录 |
|
|
|
|
try { |
|
|
|
|
const res = await studentWeChatAppletCallback({ |
|
|
|
@ -62,7 +66,6 @@ |
|
|
|
|
avatarUrl: '' |
|
|
|
|
}) |
|
|
|
|
const { data } = res |
|
|
|
|
this.submiting = false |
|
|
|
|
const e = data.sessionKey |
|
|
|
|
this.sessionKey = e.session_key |
|
|
|
|
this.openid = e.openid |
|
|
|
@ -70,8 +73,7 @@ |
|
|
|
|
uni.setStorageSync('openid', e.openid) |
|
|
|
|
// 如果没有绑定手机号,则显示绑定按钮,引导用户绑定,否则,直接跳到首页 |
|
|
|
|
if (data.state === 'login') { |
|
|
|
|
uni.setStorageSync('token', data.token) |
|
|
|
|
this.toIndex() |
|
|
|
|
this.token = data.token |
|
|
|
|
} else if (data.state === 'bind') { |
|
|
|
|
// 注册 |
|
|
|
|
this.isBind = true |
|
|
|
@ -79,50 +81,43 @@ |
|
|
|
|
// 多个账号 |
|
|
|
|
this.accounts = JSON.stringify(data.data.userAccounts) |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
} |
|
|
|
|
} catch (e) {} |
|
|
|
|
} else { |
|
|
|
|
this.submiting = false |
|
|
|
|
that.$util.errMsg('登录失败!') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
async toAccounts() { |
|
|
|
|
uni.setStorageSync('accounts', this.accounts) |
|
|
|
|
this.$util.to(`/user/selectAccount/selectAccount?openid=${this.openid}`) |
|
|
|
|
}, |
|
|
|
|
// 绑定手机号 |
|
|
|
|
async onGetPhoneNumber(e){ |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const { encryptedData, iv } = e.detail |
|
|
|
|
const appId = uni.getAccountInfoSync().miniProgram.appId |
|
|
|
|
const pc = new WXBizDataCrypt(appId , this.sessionKey) |
|
|
|
|
const decData = pc.decryptData(encryptedData , iv) |
|
|
|
|
this.submiting = true |
|
|
|
|
const phone = decData.phoneNumber |
|
|
|
|
uni.setStorageSync('phone', phone) |
|
|
|
|
const { data } = await studentBinding({ |
|
|
|
|
openid: this.openid, |
|
|
|
|
phone, |
|
|
|
|
platformId: 1 |
|
|
|
|
}) |
|
|
|
|
if (data) { |
|
|
|
|
const accounts = data.userAccounts |
|
|
|
|
if (accounts) { |
|
|
|
|
// 多个账号则前往选择账号 |
|
|
|
|
uni.setStorageSync('accounts', JSON.stringify(accounts)) |
|
|
|
|
this.$util.to(`/user/selectAccount/selectAccount?openid=${this.openid}&phone=${phone}`) |
|
|
|
|
if (this.agree.length) { |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
this.submiting = true |
|
|
|
|
if (!this.token) { |
|
|
|
|
uni.setStorageSync('accounts', this.accounts) |
|
|
|
|
this.$util.to(`/user/selectAccount/selectAccount?openid=${this.openid}`) |
|
|
|
|
} else { |
|
|
|
|
uni.setStorageSync('token', data.token) |
|
|
|
|
uni.switchTab({ |
|
|
|
|
url: '/pages/index/index' |
|
|
|
|
}) |
|
|
|
|
uni.setStorageSync('token', this.token) |
|
|
|
|
this.toIndex() |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.$util.errMsg('请先阅读勾选协议!') |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 绑定手机号 |
|
|
|
|
async onGetPhoneNumber(e){ |
|
|
|
|
if (this.agree.length) { |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const { encryptedData, iv } = e.detail |
|
|
|
|
const appId = uni.getAccountInfoSync().miniProgram.appId |
|
|
|
|
const pc = new WXBizDataCrypt(appId , this.sessionKey) |
|
|
|
|
const decData = pc.decryptData(encryptedData , iv) |
|
|
|
|
this.submiting = true |
|
|
|
|
const phone = decData.phoneNumber |
|
|
|
|
uni.setStorageSync('phone', phone) |
|
|
|
|
// 新用户则前往绑定账号 |
|
|
|
|
this.$util.to(`/user/reg/reg?openid=${this.openid}&phone=${phone}`) |
|
|
|
|
} else { |
|
|
|
|
this.$util.errMsg('请先阅读勾选协议!') |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
toAgreement(id) { |
|
|
|
|