39 lines
881 B
JavaScript
Raw Normal View History

2024-08-06 10:20:56 +08:00
/**
* @description 用户信息数据持久化
*/
import { defineStore } from 'pinia'
import { getUserInfoRequest } from '@/api/user'
2024-08-22 15:03:30 +08:00
import { useLockStore } from '@/stores/lock'
2024-08-06 10:20:56 +08:00
export const useUserStore = defineStore('user', {
state() {
return {
// 用户信息
userInfo: {},
// 登录状态
isLogin: false
2024-08-06 10:20:56 +08:00
}
},
actions: {
updateUserInfo(data) {
this.userInfo = data
},
updateLoginStatus(status) {
this.isLogin = status
},
async login() {
2024-08-22 15:03:30 +08:00
uni.setStorageSync('token', '3021|MZv7iEf0NwjCPSGx4QWs37zOjeVN3GrSJ2v7D56L7db1fcc5')
const { code, data } = await getUserInfoRequest()
2024-08-22 16:37:15 +08:00
await useLockStore().getLockList({
2024-08-22 15:03:30 +08:00
pageNo: 1,
pageSize: 50
})
if(code === 0) {
this.updateUserInfo(data)
}
2024-08-22 16:37:15 +08:00
this.isLogin = true
return this.isLogin
2024-08-06 10:20:56 +08:00
}
}
})