You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.0 KiB
50 lines
1.0 KiB
import {acceptHMRUpdate, createPinia, defineStore} from 'pinia';
|
|
|
|
type menu = 'light' | 'dark'
|
|
export interface UserState {
|
|
token: string;
|
|
info: any;
|
|
loginVisible: boolean;
|
|
}
|
|
const useUserInfo = defineStore('user', {
|
|
state: (): UserState => ({
|
|
token: '',
|
|
info: {},
|
|
loginVisible: false,
|
|
}),
|
|
|
|
actions: {
|
|
setToken(token: string):void {
|
|
this.token = token;
|
|
},
|
|
setInfo(info: any):void {
|
|
this.info = info;
|
|
},
|
|
setLoginVisible(val: boolean):void {
|
|
this.loginVisible = val;
|
|
},
|
|
|
|
async login(data: any){
|
|
const { commonApi } = useApi()
|
|
const res = await commonApi.login(data);
|
|
// if (res.data)
|
|
console.log('login>>>>', res)
|
|
|
|
return res;
|
|
}
|
|
|
|
},
|
|
getters:{
|
|
getLoginVisible:(state)=> state.loginVisible,
|
|
},
|
|
persist: process.client && {
|
|
storage: localStorage,
|
|
paths: ['info', 'token']
|
|
}
|
|
|
|
})
|
|
export default useUserInfo;
|
|
if (import.meta.hot) {
|
|
import.meta.hot.accept(acceptHMRUpdate(useUserInfo, import.meta.hot))
|
|
}
|