1. 锁列表用户信息添加缓存
This commit is contained in:
parent
95ec088d54
commit
23dc17aacb
@ -128,25 +128,39 @@
|
|||||||
mask: true
|
mask: true
|
||||||
})
|
})
|
||||||
const accountInfo = uni.getAccountInfoSync()
|
const accountInfo = uni.getAccountInfoSync()
|
||||||
console.log(accountInfo)
|
|
||||||
getApp().globalData.appid = accountInfo.miniProgram.appId
|
getApp().globalData.appid = accountInfo.miniProgram.appId
|
||||||
getApp().globalData.envVersion = accountInfo.miniProgram.envVersion
|
getApp().globalData.envVersion = accountInfo.miniProgram.envVersion
|
||||||
this.deviceInfo = await this.getDeviceInfo()
|
this.deviceInfo = await this.getDeviceInfo()
|
||||||
|
|
||||||
const token = uni.getStorageSync('token')
|
const token = uni.getStorageSync('token')
|
||||||
if(token) {
|
if(token) {
|
||||||
this.getLockList(this.lockSearch)
|
await Promise.all([
|
||||||
await this.getUserInfo()
|
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 {
|
} else {
|
||||||
await this.homeLogin()
|
await this.homeLogin()
|
||||||
|
this.penging = false
|
||||||
|
uni.hideLoading()
|
||||||
}
|
}
|
||||||
this.penging = false
|
|
||||||
uni.hideLoading()
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
timeFormat,
|
timeFormat,
|
||||||
...mapActions(useUserStore, ['updateUserInfo', 'updateLoginStatus', 'phoneLogin', 'getUserInfo']),
|
...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',
|
...mapActions(useBluetoothStore, ['getBluetoothStatus', 'initAndListenBluetooth', 'updateCurrentLockInfo',
|
||||||
'checkSetting', 'updateKeyId', 'resetDevice']),
|
'checkSetting', 'updateKeyId', 'resetDevice']),
|
||||||
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']),
|
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']),
|
||||||
@ -400,7 +414,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async toLockDeatil(lock) {
|
async toLockDeatil(lock) {
|
||||||
if(this.bluetoothStatus !== 0) {
|
if(!(this.bluetoothStatus === 0 || this.bluetoothStatus === -1)) {
|
||||||
this.getBluetoothStatus()
|
this.getBluetoothStatus()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,6 +102,8 @@
|
|||||||
uni.setStorageSync('envVersion', env.key)
|
uni.setStorageSync('envVersion', env.key)
|
||||||
uni.removeStorageSync('token')
|
uni.removeStorageSync('token')
|
||||||
uni.removeStorageSync('openid')
|
uni.removeStorageSync('openid')
|
||||||
|
uni.removeStorageSync('userInfo')
|
||||||
|
uni.removeStorageSync('lockList')
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pages/home/home'
|
url: '/pages/home/home'
|
||||||
})
|
})
|
||||||
@ -126,6 +128,8 @@
|
|||||||
openid
|
openid
|
||||||
})
|
})
|
||||||
if(code === 0) {
|
if(code === 0) {
|
||||||
|
uni.removeStorageSync('userInfo')
|
||||||
|
uni.removeStorageSync('lockList')
|
||||||
uni.setStorageSync('token', data.accessToken)
|
uni.setStorageSync('token', data.accessToken)
|
||||||
this.updateLockSearch({
|
this.updateLockSearch({
|
||||||
...this.lockSearch,
|
...this.lockSearch,
|
||||||
|
|||||||
@ -51,6 +51,10 @@ export const useLockStore = defineStore('lock', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
// 更新锁列表
|
||||||
|
updateLockList(list) {
|
||||||
|
this.lockList = list
|
||||||
|
},
|
||||||
// 清空列表
|
// 清空列表
|
||||||
clearList(type) {
|
clearList(type) {
|
||||||
this[type + 'List'] = []
|
this[type + 'List'] = []
|
||||||
@ -166,6 +170,7 @@ export const useLockStore = defineStore('lock', {
|
|||||||
} else {
|
} else {
|
||||||
this.lockList = this.lockList.concat(data.groupList)
|
this.lockList = this.lockList.concat(data.groupList)
|
||||||
}
|
}
|
||||||
|
uni.setStorageSync('lockList', this.lockList)
|
||||||
return { code }
|
return { code }
|
||||||
} else {
|
} else {
|
||||||
return { code, message }
|
return { code, message }
|
||||||
@ -225,7 +230,6 @@ export const useLockStore = defineStore('lock', {
|
|||||||
},
|
},
|
||||||
async getKeyList(params) {
|
async getKeyList(params) {
|
||||||
const { code, data, message } = await getKeyListRequest(params)
|
const { code, data, message } = await getKeyListRequest(params)
|
||||||
console.log(11111223, code, data, message)
|
|
||||||
if(code === 0) {
|
if(code === 0) {
|
||||||
this.keyTotal = data.total
|
this.keyTotal = data.total
|
||||||
for(let i = 0; i < data.list.length; i++) {
|
for(let i = 0; i < data.list.length; i++) {
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export const useUserStore = defineStore('user', {
|
|||||||
async getUserInfo() {
|
async getUserInfo() {
|
||||||
const { code, data } = await getUserInfoRequest()
|
const { code, data } = await getUserInfoRequest()
|
||||||
if(code === 0) {
|
if(code === 0) {
|
||||||
|
uni.setStorageSync('userInfo', data)
|
||||||
this.updateUserInfo(data)
|
this.updateUserInfo(data)
|
||||||
this.updateLoginStatus(true)
|
this.updateLoginStatus(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,13 +28,13 @@ const request = (config) => {
|
|||||||
const timestamp = new Date().getTime()
|
const timestamp = new Date().getTime()
|
||||||
timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
resolve({ code: -1, message: '网络访问失败,请检查网络是否正常' })
|
resolve({ code: -1, message: '网络访问失败,请检查网络是否正常' })
|
||||||
}, 5000)
|
}, 3200)
|
||||||
uni.request({
|
uni.request({
|
||||||
url: URL,
|
url: URL,
|
||||||
method,
|
method,
|
||||||
header,
|
header,
|
||||||
data,
|
data,
|
||||||
timeout: 4000,
|
timeout: 3000,
|
||||||
async success(res) {
|
async success(res) {
|
||||||
const { statusCode, data } = res
|
const { statusCode, data } = res
|
||||||
if(timer) {
|
if(timer) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user