/** * @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') this.isLogin = true const { code, data } = await getUserInfoRequest() useLockStore().getLockList({ pageNo: 1, pageSize: 50 }) if(code === 0) { this.updateUserInfo(data) } return this.isLogin } } })