diff --git a/pages/home/home.vue b/pages/home/home.vue index 3202af0..67f8fca 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -447,16 +447,34 @@ if (data.detail.errMsg === 'getPhoneNumber:fail user deny') { return } - const result = await this.phoneLogin({ - encryptedData: data.detail.encryptedData, - iv: data.detail.iv + + const that = this + uni.showLoading({ + title: '登录中' + }) + uni.login({ + provider: 'weixin', + async success(loginRes) { + const result = await that.phoneLogin({ + encryptedData: data.detail.encryptedData, + iv: data.detail.iv, + code: loginRes.code + }) + uni.hideLoading() + if (!result) { + uni.showToast({ + title: result.message, + icon: 'none' + }) + } + }, + fail() { + uni.hideLoading() + uni.showToast({ + title: '登录失败,请重试' + }) + } }) - if (!result) { - uni.showToast({ - title: '登录失败,请重试', - icon: 'none' - }) - } }, async nextPage() { if (this.lockList.length < this.lockTotal) { diff --git a/pages/mine/mine.vue b/pages/mine/mine.vue index 82bb33e..3f52956 100644 --- a/pages/mine/mine.vue +++ b/pages/mine/mine.vue @@ -143,62 +143,90 @@ if (res.detail.errMsg === 'getPhoneNumber:fail user deny') { return } - const result = await this.checkSession() - if (!result) { - uni.showToast({ - title: '登录失败,请重试', - icon: 'none' - }) - return - } - const openid = getStorage('openid') - const { code, data, message } = await phoneLoginRequest({ - encryptedData: res.detail.encryptedData, - iv: res.detail.iv, - rebind: true, - openid + + const that = this + uni.showLoading({ + title: '登录中' + }) + uni.login({ + provider: 'weixin', + async success(loginRes) { + const openid = getStorage('openid') + const { code, data, message } = await phoneLoginRequest({ + encryptedData: res.detail.encryptedData, + iv: res.detail.iv, + rebind: true, + openid, + js_code: loginRes.code + }) + uni.hideLoading() + if (code === 0) { + removeStorage('userInfo') + removeStorage('lockList') + setStorage('token', data.accessToken) + that.updateLockSearch({ + ...that.lockSearch, + pageNo: 1 + }) + that.getUserInfo() + that.getLockList(that.lockSearch) + that.updateNotificationSearch({ + pageNo: 1 + }) + that.getNotificationList(that.notificationSearch) + uni.showToast({ + title: '账号切换成功', + icon: 'none' + }) + } else if (code === 438) { + /* empty */ + } else { + uni.showToast({ + title: message, + icon: 'none' + }) + } + }, + fail() { + uni.hideLoading() + uni.showToast({ + title: '登录失败,请重试' + }) + } }) - if (code === 0) { - removeStorage('userInfo') - removeStorage('lockList') - setStorage('token', data.accessToken) - this.updateLockSearch({ - ...this.lockSearch, - pageNo: 1 - }) - this.getUserInfo() - this.getLockList(this.lockSearch) - this.updateNotificationSearch({ - pageNo: 1 - }) - this.getNotificationList(this.notificationSearch) - uni.showToast({ - title: '账号切换成功', - icon: 'none' - }) - } else if (code === 438) { - /* empty */ - } else { - uni.showToast({ - title: message, - icon: 'none' - }) - } }, async getphonenumber(data) { if (data.detail.errMsg === 'getPhoneNumber:fail user deny') { return } - const result = await this.phoneLogin({ - encryptedData: data.detail.encryptedData, - iv: data.detail.iv + + const that = this + uni.showLoading({ + title: '登录中' + }) + uni.login({ + provider: 'weixin', + async success(loginRes) { + const result = await that.phoneLogin({ + encryptedData: data.detail.encryptedData, + iv: data.detail.iv, + code: loginRes.code + }) + uni.hideLoading() + if (!result) { + uni.showToast({ + title: result.message, + icon: 'none' + }) + } + }, + fail() { + uni.hideLoading() + uni.showToast({ + title: '登录失败,请重试' + }) + } }) - if (!result) { - uni.showToast({ - title: '登录失败,请重试', - icon: 'none' - }) - } }, toUsereInfo() { this.routeJump({ diff --git a/pages/notificationList/notificationList.vue b/pages/notificationList/notificationList.vue index 87c2ed4..62fb13b 100644 --- a/pages/notificationList/notificationList.vue +++ b/pages/notificationList/notificationList.vue @@ -157,16 +157,34 @@ if (data.detail.errMsg === 'getPhoneNumber:fail user deny') { return } - const result = await this.phoneLogin({ - encryptedData: data.detail.encryptedData, - iv: data.detail.iv + + const that = this + uni.showLoading({ + title: '登录中' + }) + uni.login({ + provider: 'weixin', + async success(loginRes) { + const result = await that.phoneLogin({ + encryptedData: data.detail.encryptedData, + iv: data.detail.iv, + code: loginRes.code + }) + uni.hideLoading() + if (!result) { + uni.showToast({ + title: result.message, + icon: 'none' + }) + } + }, + fail() { + uni.hideLoading() + uni.showToast({ + title: '登录失败,请重试' + }) + } }) - if (!result) { - uni.showToast({ - title: '登录失败,请重试', - icon: 'none' - }) - } }, scroll() { this.$refs.swipeItem.forEach(item => { diff --git a/stores/user.js b/stores/user.js index ee28624..8675e85 100644 --- a/stores/user.js +++ b/stores/user.js @@ -35,12 +35,12 @@ export const useUserStore = defineStore('user', { return code }, async phoneLogin(params) { - const { iv, encryptedData } = params + const { iv, encryptedData, code: js_code } = params const openid = await getStorage('openid') if (!openid) { return false } - const { code, data } = await phoneLoginRequest({ iv, encryptedData, openid }) + const { code, data } = await phoneLoginRequest({ iv, encryptedData, openid, js_code }) if (code === 0) { setStorage('token', data.accessToken) this.getUserInfo()