2024-08-22 16:37:15 +08:00

39 lines
881 B
JavaScript

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