范鹏 0b595ed01c 1. 添加全局登录状态
2. 完成修改安全问题
3. 优化请求处理
2024-08-21 16:20:11 +08:00

34 lines
746 B
JavaScript

/**
* @description 用户信息数据持久化
*/
import { defineStore } from 'pinia'
import { getUserInfoRequest } from '@/api/user'
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', '1041|9UcJSZO3C1uuDnIgG8jXTxNXDIiCrvvIhdj7bFF8c1c07b2d')
this.isLogin = true
const { code, data } = await getUserInfoRequest()
if(code === 0) {
this.updateUserInfo(data)
}
return this.isLogin
}
}
})