From 23dc17aacb043ab9cb5fe96ebc65d62357d03e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Fri, 6 Sep 2024 14:07:13 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E9=94=81=E5=88=97=E8=A1=A8=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E6=B7=BB=E5=8A=A0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/home/home.vue | 30 ++++++++++++++++++++++-------- pages/mine/mine.vue | 4 ++++ stores/lock.js | 6 +++++- stores/user.js | 1 + utils/request.js | 4 ++-- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/pages/home/home.vue b/pages/home/home.vue index c2532b1..b8ec76c 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -128,25 +128,39 @@ mask: true }) const accountInfo = uni.getAccountInfoSync() - console.log(accountInfo) getApp().globalData.appid = accountInfo.miniProgram.appId getApp().globalData.envVersion = accountInfo.miniProgram.envVersion this.deviceInfo = await this.getDeviceInfo() - const token = uni.getStorageSync('token') if(token) { - this.getLockList(this.lockSearch) - await this.getUserInfo() + await Promise.all([ + this.getLockList(this.lockSearch), + this.getUserInfo() + ]).then((res) => { + this.penging = false + uni.hideLoading() + const list = uni.getStorageSync('lockList') + const userInfo = uni.getStorageSync('userInfo') + if(res[0].code === -1 && res[1] === -1 && list && userInfo) { + uni.showToast({ + title: '网络访问失败,请检查网络是否正常', + icon: 'none' + }) + this.updateLockList(list) + this.updateUserInfo(userInfo) + this.updateLoginStatus(true) + } + }) } else { await this.homeLogin() + this.penging = false + uni.hideLoading() } - this.penging = false - uni.hideLoading() }, methods: { timeFormat, ...mapActions(useUserStore, ['updateUserInfo', 'updateLoginStatus', 'phoneLogin', 'getUserInfo']), - ...mapActions(useLockStore, ['getLockList', 'getRole', 'getTimeLimit', 'updateLockSearch', 'getPowerIcon']), + ...mapActions(useLockStore, ['getLockList', 'updateLockList', 'getRole', 'getTimeLimit', 'updateLockSearch', 'getPowerIcon']), ...mapActions(useBluetoothStore, ['getBluetoothStatus', 'initAndListenBluetooth', 'updateCurrentLockInfo', 'checkSetting', 'updateKeyId', 'resetDevice']), ...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']), @@ -400,7 +414,7 @@ } }, async toLockDeatil(lock) { - if(this.bluetoothStatus !== 0) { + if(!(this.bluetoothStatus === 0 || this.bluetoothStatus === -1)) { this.getBluetoothStatus() return } diff --git a/pages/mine/mine.vue b/pages/mine/mine.vue index e350449..263cc71 100644 --- a/pages/mine/mine.vue +++ b/pages/mine/mine.vue @@ -102,6 +102,8 @@ uni.setStorageSync('envVersion', env.key) uni.removeStorageSync('token') uni.removeStorageSync('openid') + uni.removeStorageSync('userInfo') + uni.removeStorageSync('lockList') uni.reLaunch({ url: '/pages/home/home' }) @@ -126,6 +128,8 @@ openid }) if(code === 0) { + uni.removeStorageSync('userInfo') + uni.removeStorageSync('lockList') uni.setStorageSync('token', data.accessToken) this.updateLockSearch({ ...this.lockSearch, diff --git a/stores/lock.js b/stores/lock.js index fc3aeaf..fbdd324 100644 --- a/stores/lock.js +++ b/stores/lock.js @@ -51,6 +51,10 @@ export const useLockStore = defineStore('lock', { } }, actions: { + // 更新锁列表 + updateLockList(list) { + this.lockList = list + }, // 清空列表 clearList(type) { this[type + 'List'] = [] @@ -166,6 +170,7 @@ export const useLockStore = defineStore('lock', { } else { this.lockList = this.lockList.concat(data.groupList) } + uni.setStorageSync('lockList', this.lockList) return { code } } else { return { code, message } @@ -225,7 +230,6 @@ export const useLockStore = defineStore('lock', { }, 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++) { diff --git a/stores/user.js b/stores/user.js index c074d18..529a734 100644 --- a/stores/user.js +++ b/stores/user.js @@ -25,6 +25,7 @@ export const useUserStore = defineStore('user', { async getUserInfo() { const { code, data } = await getUserInfoRequest() if(code === 0) { + uni.setStorageSync('userInfo', data) this.updateUserInfo(data) this.updateLoginStatus(true) } diff --git a/utils/request.js b/utils/request.js index b5abd2c..f769bbb 100644 --- a/utils/request.js +++ b/utils/request.js @@ -28,13 +28,13 @@ const request = (config) => { const timestamp = new Date().getTime() timer = setTimeout(() => { resolve({ code: -1, message: '网络访问失败,请检查网络是否正常' }) - }, 5000) + }, 3200) uni.request({ url: URL, method, header, data, - timeout: 4000, + timeout: 3000, async success(res) { const { statusCode, data } = res if(timer) {