From 2fc7ad7ed725531b1e6ae33d3ea39ce0d44fa98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Tue, 27 Aug 2024 10:12:56 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=AE=8C=E6=88=90=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E4=BF=AE=E6=94=B9=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=8A=9F=E8=83=BD=202.=20=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E8=B4=A6=E5=8F=B7=E7=BB=91=E5=AE=9A=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/user.js | 21 ++++- pages/home/home.vue | 17 +--- pages/mine/mine.vue | 30 +++---- pages/updatePassword/updatePassword.vue | 110 ++++++++++++++++++------ pages/userInfo/userInfo.vue | 60 ++++++++++--- stores/user.js | 40 ++++++--- 6 files changed, 195 insertions(+), 83 deletions(-) diff --git a/api/user.js b/api/user.js index 81e7b8f..f5f091a 100644 --- a/api/user.js +++ b/api/user.js @@ -68,8 +68,27 @@ export function loginRequest(data) { // 注册 export function phoneLoginRequest(data) { return request({ - url: '/wechat/mini/phone/login ', + url: '/wechat/mini/phone/login', method: 'POST', data }) } + +// 更换绑定手机号 +export function rebindPhoneRequest(data) { + return request({ + url: '/wechat/mini/rebindPhone', + method: 'POST', + data + }) +} + +// 验证码更换密码 +export function changePasswordRequest(data) { + return request({ + url: '/wechat/mini/changePassword', + method: 'POST', + data + }) +} + diff --git a/pages/home/home.vue b/pages/home/home.vue index 9254472..8fc9500 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -105,7 +105,7 @@ }, methods: { timeFormat, - ...mapActions(useUserStore, ['updateUserInfo', 'updateLoginStatus', 'getPhone']), + ...mapActions(useUserStore, ['updateUserInfo', 'updateLoginStatus', 'phoneLogin', 'getUserInfo']), ...mapActions(useLockStore, ['getLockList', 'getRole', 'getTimeLimit']), ...mapActions(useBluetoothStore, ['getBluetoothStatus', 'initAndListenBluetooth', 'updateCurrentLockInfo', 'checkSetting', 'updateKeyId']), @@ -153,14 +153,11 @@ if(data.detail.errMsg === 'getPhoneNumber:fail user deny') { return } - const result = await this.getPhone({ + const result = await this.phoneLogin({ encryptedData: data.detail.encryptedData, iv: data.detail.iv }) - if(result) { - this.getUserInfo() - this.getLockList(this.search) - } else { + if(!result) { uni.showToast({ title: '登录失败,请重试', icon: 'none' @@ -190,14 +187,6 @@ this.search.searchStr = data await this.getLockList(this.search) }, - async getUserInfo() { - const { code, data } = await getUserInfoRequest() - if(code === 0) { - this.updateUserInfo(data) - this.updateLoginStatus(true) - } - return code - }, getFocus() { this.focus = true }, diff --git a/pages/mine/mine.vue b/pages/mine/mine.vue index 7be172b..4961512 100644 --- a/pages/mine/mine.vue +++ b/pages/mine/mine.vue @@ -69,11 +69,19 @@ methods: { ...mapActions(useBasicStore, ['getButtonInfo', 'routeJump']), ...mapActions(useLockStore, ['getLockList']), - ...mapActions(useUserStore, ['updateLoginStatus', 'getPhone', 'updateUserInfo']), + ...mapActions(useUserStore, ['updateLoginStatus', 'phoneLogin', 'updateUserInfo', 'getUserInfo', 'checkSession']), async changePhone(res) { if(res.detail.errMsg === 'getPhoneNumber:fail user deny') { return } + const result = await this.checkSession() + if(!result) { + uni.showToast({ + title: '登录失败,请重试', + icon: 'none' + }) + return + } const openid = uni.getStorageSync('openid') const { code, data, message } = await phoneLoginRequest({ encryptedData: res.detail.encryptedData, @@ -83,8 +91,6 @@ }) if(code === 0) { uni.setStorageSync('token', data.accessToken) - console.log('token', data.accessToken,uni.getStorageSync('token')) - this.getUserInfo() this.getLockList({ pageNo: 1, pageSize: 50 @@ -104,31 +110,17 @@ if(data.detail.errMsg === 'getPhoneNumber:fail user deny') { return } - const result = await this.getPhone({ + const result = await this.phoneLogin({ encryptedData: data.detail.encryptedData, iv: data.detail.iv }) - if(result) { - this.getUserInfo() - this.getLockList({ - pageNo: 1, - pageSize: 50 - }) - } else { + if(!result) { uni.showToast({ title: '登录失败,请重试', icon: 'none' }) } }, - async getUserInfo() { - const { code, data } = await getUserInfoRequest() - if(code === 0) { - this.updateUserInfo(data) - this.updateLoginStatus(true) - } - return code - }, toUsereInfo() { this.routeJump({ name: 'userInfo' diff --git a/pages/updatePassword/updatePassword.vue b/pages/updatePassword/updatePassword.vue index 11462b3..e07943e 100644 --- a/pages/updatePassword/updatePassword.vue +++ b/pages/updatePassword/updatePassword.vue @@ -1,11 +1,12 @@