From 053d14db4702ec01a289a21e4b75a70061b38f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Thu, 29 Aug 2024 17:40:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=89=E5=8D=93=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=9B=9E=E9=80=80toast=E6=97=A0=E6=B3=95=E6=98=BE?= =?UTF-8?q?=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/bindLock/bindLock.vue | 20 +++--------- pages/createKey/createKey.vue | 11 ++----- pages/createPassword/createPassword.vue | 12 ++----- pages/keyDetail/keyDetail.vue | 11 ++----- pages/mine/mine.vue | 8 +++-- pages/passwordDetail/passwordDetail.vue | 13 +++----- pages/setting/setting.vue | 22 +++---------- pages/updateEmail/updateEmail.vue | 11 ++----- pages/updateName/updateName.vue | 11 ++----- pages/updatePassword/updatePassword.vue | 15 ++------- .../updateSafeQuestion/updateSafeQuestion.vue | 11 ++----- pages/userInfo/userInfo.vue | 20 ++++++------ pages/verifyEmail/verifyEmail.vue | 31 ------------------- stores/basic.js | 15 +++++++++ 14 files changed, 60 insertions(+), 151 deletions(-) diff --git a/pages/bindLock/bindLock.vue b/pages/bindLock/bindLock.vue index 9565c4b..c8232df 100644 --- a/pages/bindLock/bindLock.vue +++ b/pages/bindLock/bindLock.vue @@ -14,6 +14,7 @@ import { useUserStore } from '@/stores/user' import { mapActions, mapState } from 'pinia' import { bindLockAdmin } from '@/api/lock' import { useLockStore } from '@/stores/lock' +import { useBasicStore } from '@/stores/basic' export default { data () { @@ -34,6 +35,7 @@ export default { methods: { ...mapActions(useBluetoothStore, ['addLockUser']), ...mapActions(useLockStore, ['getLockList', 'updateLockSearch']), + ...mapActions(useBasicStore, ['backAndToast']), uopdateName(data) { this.name = data.detail.value }, @@ -71,15 +73,8 @@ export default { password }) if(addUserCode !== 0) { - uni.navigateBack({ - complete() { - uni.showToast({ - title: '添加失败,请重试', - icon: 'none' - }) - } - }) uni.hideLoading() + this.backAndToast('添加失败,请重试') return } const params = { @@ -122,14 +117,7 @@ export default { }) this.getLockList(this.lockSearch) uni.hideLoading() - uni.navigateBack({ - complete() { - uni.showToast({ - title: '添加成功', - icon: 'none' - }) - } - }) + this.backAndToast('添加成功') } else { uni.hideLoading() uni.showToast({ diff --git a/pages/createKey/createKey.vue b/pages/createKey/createKey.vue index 382e175..fc327aa 100644 --- a/pages/createKey/createKey.vue +++ b/pages/createKey/createKey.vue @@ -80,7 +80,7 @@ export default { this.temporaryInvalidTime = this.setTime() }, methods: { - ...mapActions(useBasicStore, ['getDeviceInfo']), + ...mapActions(useBasicStore, ['getDeviceInfo', 'backAndToast']), ...mapActions(useLockStore, ['getKeyList', 'updateKeySearch']), setTime () { const now = new Date() @@ -154,14 +154,7 @@ export default { pageNo: 1 }) this.getKeyList(this.keySearch) - uni.navigateBack({ - complete: () => { - uni.showToast({ - title: '钥匙已发送', - icon: 'none' - }) - } - }) + this.backAndToast('钥匙已发送') } else if(code === 425) { this.pending = false await this.createKey(type, true) diff --git a/pages/createPassword/createPassword.vue b/pages/createPassword/createPassword.vue index 414a987..dd1dfad 100644 --- a/pages/createPassword/createPassword.vue +++ b/pages/createPassword/createPassword.vue @@ -70,7 +70,7 @@ export default { this.temporaryTime = this.setTime() }, methods: { - ...mapActions(useBasicStore, ['getDeviceInfo']), + ...mapActions(useBasicStore, ['getDeviceInfo', 'backAndToast']), ...mapActions(useLockStore, ['getPasswordList', 'updatePasswordSearch']), setTime() { const now = new Date() @@ -80,6 +80,7 @@ export default { return now.getTime() }, async createPassword(type) { + const that = this if((type === 'temporary' && this.temporaryName === '') || (type === 'permanent' && this.permanentName === '')) { uni.showToast({ title: '名称不能为空', @@ -131,14 +132,7 @@ export default { uni.setClipboardData({ data: data.keyboardPwd, success: () => { - uni.navigateBack({ - complete: () => { - uni.showToast({ - title: '复制成功', - icon: 'none' - }) - } - }) + that.backAndToast('复制成功') } }) } diff --git a/pages/keyDetail/keyDetail.vue b/pages/keyDetail/keyDetail.vue index 4aaf07f..aa9aa4a 100644 --- a/pages/keyDetail/keyDetail.vue +++ b/pages/keyDetail/keyDetail.vue @@ -33,6 +33,7 @@ import { mapActions, mapState } from 'pinia' import { useLockStore } from '@/stores/lock' import { timeFormat } from 'uview-plus' import { deleteKeyRequest } from '@/api/key' +import { useBasicStore } from '@/stores/basic' export default { data () { @@ -44,6 +45,7 @@ export default { methods: { timeFormat, ...mapActions(useLockStore, ['updateKeySearch', 'getKeyList']), + ...mapActions(useBasicStore, ['backAndToast']), async deleteKey () { const that = this uni.showModal({ @@ -65,14 +67,7 @@ export default { pageNo: 1 }) await that.getKeyList(that.keySearch) - uni.navigateBack({ - complete: () => { - uni.showToast({ - title: '删除成功', - icon: 'none' - }) - } - }) + that.backAndToast('删除成功') } else { uni.hideLoading() uni.showToast({ diff --git a/pages/mine/mine.vue b/pages/mine/mine.vue index 33b64d3..a1fbc73 100644 --- a/pages/mine/mine.vue +++ b/pages/mine/mine.vue @@ -52,7 +52,7 @@ import { useUserStore } from '@/stores/user' import { useLockStore } from '@/stores/lock' import { mapState, mapActions } from 'pinia' - import { getUserInfoRequest, phoneLoginRequest } from '@/api/user' + import { phoneLoginRequest } from '@/api/user' export default { data() { @@ -70,7 +70,8 @@ methods: { ...mapActions(useBasicStore, ['getButtonInfo', 'routeJump']), ...mapActions(useLockStore, ['getLockList', 'updateLockSearch']), - ...mapActions(useUserStore, ['updateLoginStatus', 'phoneLogin', 'updateUserInfo', 'getUserInfo', 'checkSession']), + ...mapActions(useUserStore, ['updateLoginStatus', 'phoneLogin', 'updateUserInfo', 'getUserInfo', + 'checkSession']), async changePhone(res) { if(res.detail.errMsg === 'getPhoneNumber:fail user deny') { return @@ -93,9 +94,10 @@ if(code === 0) { uni.setStorageSync('token', data.accessToken) this.updateLockSearch({ - ...that.lockSearch, + ...this.lockSearch, pageNo: 1 }) + this.getUserInfo() this.getLockList(this.lockSearch) uni.showToast({ title: '账号切换成功', diff --git a/pages/passwordDetail/passwordDetail.vue b/pages/passwordDetail/passwordDetail.vue index 7cdc813..abfd8bc 100644 --- a/pages/passwordDetail/passwordDetail.vue +++ b/pages/passwordDetail/passwordDetail.vue @@ -36,6 +36,7 @@ import { timeFormat } from 'uview-plus' import { deletePsaawordRequest } from '@/api/keyboardPwd' import { useBluetoothStore } from '@/stores/bluetooth' import { useUserStore } from '@/stores/user' +import { useBasicStore } from '@/stores/basic' export default { data () { @@ -44,12 +45,13 @@ export default { computed: { ...mapState(useLockStore, ['currentPasswordInfo', 'passwordSearch']), ...mapState(useBluetoothStore, ['currentLockInfo', 'keyId']), - ...mapState(useUserStore, ['userInfo']), + ...mapState(useUserStore, ['userInfo']) }, methods: { timeFormat, ...mapActions(useBluetoothStore, ['setLockPassword']), ...mapActions(useLockStore, ['updatePasswordSearch', 'getPasswordList']), + ...mapActions(useBasicStore, ['backAndToast']), async deletePassword () { const that = this uni.showModal({ @@ -86,14 +88,7 @@ export default { pageNo: 1 }) that.getPasswordList(that.passwordSearch) - uni.navigateBack({ - complete: () => { - uni.showToast({ - title: '删除成功', - icon: 'none' - }) - } - }) + that.backAndToast('删除成功') } else { uni.hideLoading() uni.showToast({ diff --git a/pages/setting/setting.vue b/pages/setting/setting.vue index 3b6b6d1..dd5b8f6 100644 --- a/pages/setting/setting.vue +++ b/pages/setting/setting.vue @@ -49,6 +49,7 @@ import { deleteLockRequest } from '@/api/lock' import { useLockStore } from '@/stores/lock' import { updateLockSettingRequest } from '@/api/lockSetting' import { deleteKeyRequest } from '@/api/key' +import { useBasicStore } from '@/stores/basic' export default { data () { @@ -67,6 +68,7 @@ export default { methods: { ...mapActions(useBluetoothStore, ['resetDevice', 'updateCurrentLockInfo']), ...mapActions(useLockStore, ['getLockList', 'updateLockSearch']), + ...mapActions(useBasicStore, ['backAndToast']), async changeUnlockApp(value) { uni.showLoading({ title: '更新中', @@ -122,15 +124,7 @@ export default { pageNo: 1 }) that.getLockList(that.lockSearch) - uni.navigateBack({ - delta: 2, - complete: () => { - uni.showToast({ - title: '删除成功', - icon: 'none' - }) - } - }) + that.backAndToast('删除成功', 2) uni.navigateBack() } else { uni.hideLoading() @@ -157,15 +151,7 @@ export default { pageNo: 1 }) that.getLockList(that.lockSearch) - uni.navigateBack({ - delta: 2, - complete: () => { - uni.showToast({ - title: '删除成功', - icon: 'none' - }) - } - }) + that.backAndToast('删除成功', 2) uni.navigateBack() } else { uni.hideLoading() diff --git a/pages/updateEmail/updateEmail.vue b/pages/updateEmail/updateEmail.vue index cc45226..59136d1 100644 --- a/pages/updateEmail/updateEmail.vue +++ b/pages/updateEmail/updateEmail.vue @@ -42,7 +42,7 @@ export default { }, methods: { ...mapActions(useUserStore, ['updateUserInfo']), - ...mapActions(useBasicStore, ['routeJump']), + ...mapActions(useBasicStore, ['routeJump', 'backAndToast']), updateInputEmail(data) { this.email = data.detail.value }, @@ -100,14 +100,7 @@ export default { ...this.userInfo, email: this.email }) - uni.navigateBack({ - complete () { - uni.showToast({ - title: '邮箱更新成功', - icon: 'none' - }) - } - }) + this.backAndToast('邮箱绑定成功') } else { uni.showToast({ title: message, diff --git a/pages/updateName/updateName.vue b/pages/updateName/updateName.vue index 97f7538..572c12b 100644 --- a/pages/updateName/updateName.vue +++ b/pages/updateName/updateName.vue @@ -10,6 +10,7 @@ import { mapActions, mapState } from 'pinia' import { useUserStore } from '@/stores/user' import { updateUserInfoRequest } from '@/api/user' +import { useBasicStore } from '@/stores/basic' export default { data() { @@ -26,6 +27,7 @@ export default { }, methods: { ...mapActions(useUserStore, ['updateUserInfo']), + ...mapActions(useBasicStore, ['backAndToast']), updateInput(data) { this.nickname = data.detail.value console.log(data) @@ -50,14 +52,7 @@ export default { ...this.userInfo, nickname: this.nickname }) - uni.navigateBack({ - complete() { - uni.showToast({ - title: '昵称更新成功', - icon: 'none' - }) - } - }) + this.backAndToast('昵称更新成功') } else { uni.showToast({ title: '昵称更新失败', diff --git a/pages/updatePassword/updatePassword.vue b/pages/updatePassword/updatePassword.vue index e07943e..87e9317 100644 --- a/pages/updatePassword/updatePassword.vue +++ b/pages/updatePassword/updatePassword.vue @@ -17,6 +17,7 @@ import { mapActions, mapState } from 'pinia' import { useUserStore } from '@/stores/user' import { changePasswordRequest, getEmailCodeRequest, updatePasswordRequest } from '@/api/user' import { test } from 'uview-plus' +import { useBasicStore } from '@/stores/basic' export default { data () { @@ -32,6 +33,7 @@ export default { }, methods: { ...mapActions(useUserStore, ['updateUserInfo']), + ...mapActions(useBasicStore, ['backAndToast']), updateNewPassword (data) { this.password = data.detail.value }, @@ -100,18 +102,7 @@ export default { channel: '1' }) if (code === 0) { - this.updateUserInfo({ - ...this.userInfo, - nickname: this.nickname - }) - uni.navigateBack({ - complete () { - uni.showToast({ - title: '密码重置成功', - icon: 'none' - }) - } - }) + this.backAndToast('密码重置成功') } else { uni.showToast({ title: message, diff --git a/pages/updateSafeQuestion/updateSafeQuestion.vue b/pages/updateSafeQuestion/updateSafeQuestion.vue index 53d323f..40bbf71 100644 --- a/pages/updateSafeQuestion/updateSafeQuestion.vue +++ b/pages/updateSafeQuestion/updateSafeQuestion.vue @@ -46,6 +46,7 @@ import { getQuestionAnswerRequest, getQuestionListRequest, updateQuestionAnswerRequest } from '@/api/safeAnswer' import { mapActions, mapState } from 'pinia' import { useUserStore } from '@/stores/user' +import { useBasicStore } from '@/stores/basic' export default { data() { @@ -75,6 +76,7 @@ export default { }, methods: { ...mapActions(useUserStore, ['updateUserInfo']), + ...mapActions(useBasicStore, ['backAndToast']), async updateAnswer() { console.log('答案', this.answer) for(let i = 0; i < this.answer.length; i++) { @@ -107,14 +109,7 @@ export default { ...this.userInfo, haveSafeAnswer: 1 }) - uni.navigateBack({ - complete() { - uni.showToast({ - title: '安全问题设置成功', - icon: 'none' - }) - } - }) + this.backAndToast('设置成功') } else { uni.showToast({ title: message, diff --git a/pages/userInfo/userInfo.vue b/pages/userInfo/userInfo.vue index dcda414..2d9e32b 100644 --- a/pages/userInfo/userInfo.vue +++ b/pages/userInfo/userInfo.vue @@ -82,9 +82,9 @@ export default { }, methods: { ...mapActions(useBasicStore, ['routeJump']), - ...mapActions(useUserStore, ['updateUserInfo', 'checkSession']), + ...mapActions(useUserStore, ['updateUserInfo', 'checkSession', 'getUserInfo']), async rebindPhone(detail) { - if(data.detail.errMsg === 'getPhoneNumber:fail user deny') { + if(detail.detail.errMsg === 'getPhoneNumber:fail user deny') { return } if(this.pending) { @@ -98,12 +98,13 @@ export default { iv: detail.detail.iv }) if(code === 0) { - this.updateUserInfo({ - ...this.userInfo, - mobile: data.mobile - }) + this.getUserInfo() + // this.updateUserInfo({ + // ...this.userInfo, + // mobile: data.mobile + // }) uni.showToast({ - title: '手机号换绑成功', + title: '更换成功', icon: 'none' }) } else { @@ -113,10 +114,7 @@ export default { }) } } else { - uni.showToast({ - title: '手机号换绑失败,请重试', - icon: 'none' - }) + this.rebindPhone() } this.pending = false }, diff --git a/pages/verifyEmail/verifyEmail.vue b/pages/verifyEmail/verifyEmail.vue index d041c40..4a86fb4 100644 --- a/pages/verifyEmail/verifyEmail.vue +++ b/pages/verifyEmail/verifyEmail.vue @@ -87,37 +87,6 @@ export default { }, updateInput(data) { this.verificationCode = data.detail.value - }, - async updateName() { - if(this.nickname === '') { - uni.showToast({ - title: '昵称不能为空', - icon: 'none' - }) - return - } - const { code } = await updateUserInfoRequest({ - nickname: this.nickname - }) - if(code === 0) { - this.updateUserInfo({ - ...this.userInfo, - nickname: this.nickname - }) - uni.navigateBack({ - complete() { - uni.showToast({ - title: '昵称更新成功', - icon: 'none' - }) - } - }) - } else { - uni.showToast({ - title: '昵称更新失败', - icon: 'none' - }) - } } } } diff --git a/stores/basic.js b/stores/basic.js index b2e34b6..628309e 100644 --- a/stores/basic.js +++ b/stores/basic.js @@ -181,6 +181,21 @@ export const useBasicStore = defineStore('basic', { } } return totalWidth + }, + // 回退页面并弹出toast提示 + backAndToast(message, delta = 1) { + const that = this + uni.navigateBack({ + delta: delta, + complete: function () { + setTimeout(() => { + uni.showToast({ + title: message, + icon: 'none' + }) + }, 200) + } + }) } } })