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 @@