1. 锁列表用户信息添加缓存

This commit is contained in:
范鹏 2024-09-06 14:07:13 +08:00
parent 95ec088d54
commit 23dc17aacb
5 changed files with 34 additions and 11 deletions

View File

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

View File

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

View File

@ -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++) {

View File

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

View File

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