From 09b45762cee2b5064d2b17df5c525b42552a41fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Fri, 6 Sep 2024 11:34:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E7=BD=91=E6=83=85?= =?UTF-8?q?=E5=86=B5=E5=88=97=E8=A1=A8=E4=BB=8D=E7=84=B6=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=92=8C=E9=95=BF=E6=97=B6=E9=97=B4loading=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/home/home.vue | 4 ++++ pages/keyList/keyList.vue | 37 ++++++++++++++++++++++++----- pages/passwordList/passwordList.vue | 33 +++++++++++++++++++++---- pages/userInfo/userInfo.vue | 9 ++++--- stores/lock.js | 18 ++++---------- utils/request.js | 15 ++++++++++-- 6 files changed, 86 insertions(+), 30 deletions(-) diff --git a/pages/home/home.vue b/pages/home/home.vue index ab414a2..8c4e93d 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -340,6 +340,10 @@ } const { code } = await this.getLockList(search) if(code !== 0) { + uni.showToast({ + title: message, + icon: 'none' + }) this.updateLockSearch(search) } } diff --git a/pages/keyList/keyList.vue b/pages/keyList/keyList.vue index b928042..4aa2274 100644 --- a/pages/keyList/keyList.vue +++ b/pages/keyList/keyList.vue @@ -96,13 +96,22 @@ export default { ...this.keySearch, lockId: this.currentLockInfo.lockId }) - const { code, meesage } = await this.getKeyList(this.keySearch) - this.requestFinished = true + const { code, message } = await this.getKeyList(this.keySearch) uni.hideLoading() + this.requestFinished = true + if(code !== 0) { + uni.showToast({ + title: message, + icon: 'none' + }) + } + }, + onUnload() { + this.clearList('key') }, methods: { ...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']), - ...mapActions(useLockStore, ['getKeyList', 'updateCurrentKeyInfo', 'updateKeySearch', 'getKeyStatus']), + ...mapActions(useLockStore, ['getKeyList', 'updateCurrentKeyInfo', 'updateKeySearch', 'getKeyStatus', 'clearList']), changeRadio() { this.checked = !this.checked }, @@ -239,12 +248,17 @@ export default { ...this.keySearch, pageNo: 1 }) - const { code, meesage } = await this.getKeyList(this.keySearch) + const { code, message } = await this.getKeyList(this.keySearch) if(code === 0) { uni.showToast({ title: '刷新成功', icon: 'none' }) + } else { + uni.showToast({ + title: message, + icon: 'none' + }) } this.refresherTriggered = false }, @@ -257,12 +271,17 @@ export default { ...this.keySearch, pageNo } - const { code, meesage } = await this.getKeyList(params) + const { code, message } = await this.getKeyList(params) if(code === 0) { this.updateKeySearch({ ...this.keySearch, pageNo }) + } else { + uni.showToast({ + title: message, + icon: 'none' + }) } }, async changeSearch(data) { @@ -270,7 +289,13 @@ export default { ...this.keySearch, searchStr: data }) - const { code, meesage } = await this.getKeyList(this.keySearch) + const { code, message } = await this.getKeyList(this.keySearch) + if(code !== 0) { + uni.showToast({ + title: message, + icon: 'none' + }) + } }, }, } diff --git a/pages/passwordList/passwordList.vue b/pages/passwordList/passwordList.vue index 32102fb..89410bb 100644 --- a/pages/passwordList/passwordList.vue +++ b/pages/passwordList/passwordList.vue @@ -80,9 +80,18 @@ export default { lockId: this.currentLockInfo.lockId, lockStatus: this.currentLockInfo.lockStatus }) - const { code, meesage } = await this.getPasswordList(this.passwordSearch) + const { code, message } = await this.getPasswordList(this.passwordSearch) this.requestFinished = true uni.hideLoading() + if(code !== 0) { + uni.showToast({ + title: message, + icon: 'none' + }) + } + }, + onUnload() { + this.clearList('password') }, methods: { ...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']), @@ -225,12 +234,17 @@ export default { ...this.passwordSearch, pageNo: 1 }) - const { code, meesage } = await this.getPasswordList(this.passwordSearch) + const { code, message } = await this.getPasswordList(this.passwordSearch) if(code === 0) { uni.showToast({ title: '刷新成功', icon: 'none' }) + } else { + uni.showToast({ + title: message, + icon: 'none' + }) } this.refresherTriggered = false }, @@ -243,12 +257,17 @@ export default { ...this.passwordSearch, pageNo } - const { code, meesage } = await this.getPasswordList(params) + const { code, message } = await this.getPasswordList(params) if(code === 0) { that.updatePasswordSearch({ ...that.passwordSearch, pageNo }) + } else { + uni.showToast({ + title: message, + icon: 'none' + }) } }, async changeSearch(data) { @@ -256,7 +275,13 @@ export default { ...this.passwordSearch, searchStr: data }) - const { code, meesage } = await this.getPasswordList(this.passwordSearch) + const { code, message } = await this.getPasswordList(this.passwordSearch) + if(code !== 0) { + uni.showToast({ + title: message, + icon: 'none' + }) + } }, }, } diff --git a/pages/userInfo/userInfo.vue b/pages/userInfo/userInfo.vue index 98926e7..cdd7952 100644 --- a/pages/userInfo/userInfo.vue +++ b/pages/userInfo/userInfo.vue @@ -81,9 +81,12 @@ export default { ...mapState(useUserStore, ['userInfo']) }, methods: { - ...mapActions(useBasicStore, ['routeJump']), + ...mapActions(useBasicStore, ['routeJump', 'getNetworkType']), ...mapActions(useUserStore, ['updateUserInfo', 'checkSession', 'getUserInfo']), async rebindPhone(detail) { + if(!(detail.detail.encryptedData && detail.detail.iv)) { + return + } if(detail.detail.errMsg === 'getPhoneNumber:fail user deny') { return } @@ -99,10 +102,6 @@ export default { }) if(code === 0) { this.getUserInfo() - // this.updateUserInfo({ - // ...this.userInfo, - // mobile: data.mobile - // }) uni.showToast({ title: '更换成功', icon: 'none' diff --git a/stores/lock.js b/stores/lock.js index c238b71..fc3aeaf 100644 --- a/stores/lock.js +++ b/stores/lock.js @@ -51,6 +51,10 @@ export const useLockStore = defineStore('lock', { } }, actions: { + // 清空列表 + clearList(type) { + this[type + 'List'] = [] + }, // 获取电量icon getPowerIcon(power) { if(power >= 80) { @@ -164,10 +168,6 @@ export const useLockStore = defineStore('lock', { } return { code } } else { - uni.showToast({ - title: message, - icon: 'none' - }) return { code, message } } }, @@ -220,19 +220,15 @@ export const useLockStore = defineStore('lock', { } return { code } } else { - uni.showToast({ - title: message, - icon: 'none' - }) return { code, message } } }, async getKeyList(params) { const { code, data, message } = await getKeyListRequest(params) + console.log(11111223, code, data, message) if(code === 0) { this.keyTotal = data.total for(let i = 0; i < data.list.length; i++) { - console.log(data.list[i].keyType) if(data.list[i].keyType === 1) { data.list[i].timeText = `${timeFormat(new Date(data.list[i].sendDate), 'yyyy-mm-dd h:M')} 永久` } else if(data.list[i].keyType === 2) { @@ -250,10 +246,6 @@ export const useLockStore = defineStore('lock', { } return { code } } else { - uni.showToast({ - title: message, - icon: 'none' - }) return { code, message } } } diff --git a/utils/request.js b/utils/request.js index 2e3539a..0937d71 100644 --- a/utils/request.js +++ b/utils/request.js @@ -11,6 +11,7 @@ import env from '@/config/env' * */ const request = (config) => { + let timer return new Promise((resolve) => { const baseConfig = env[getApp().globalData.getEnvConfig()] @@ -25,6 +26,9 @@ const request = (config) => { const header = config.header || headerDefault const data = config.data || {} const timestamp = new Date().getTime() + timer = setTimeout(() => { + resolve({ code: -1, message: '网络访问失败,请检查网络是否正常' }) + }, 8000) uni.request({ url: URL, method, @@ -33,6 +37,9 @@ const request = (config) => { timeout: 7000, async success(res) { const { statusCode, data } = res + if(timer) { + clearTimeout(timer) + } if (statusCode === 200) { const code = data.errorCode const message = data.errorMsg @@ -61,8 +68,12 @@ const request = (config) => { resolve({ code: -1, data, message: '网络访问失败,请检查网络是否正常' }) } }, - async fail() { - resolve({ code: -1, data, message: '网络访问失败,请检查网络是否正常' }) + async fail(res) { + console.log('网络访问失败', res) + if(timer) { + clearTimeout(timer) + } + resolve({ code: -1, message: '网络访问失败,请检查网络是否正常' }) }, async complete(res) { console.log(URL.substring(baseConfig.baseUrl.length + 1), {