feat: 全局获取userinfo、数据持久化、store处理
This commit is contained in:
@ -15,12 +15,26 @@ interface EnterpriseState {
|
||||
|
||||
export const useEnterpriseStore = defineStore('enterprise', {
|
||||
state: (): EnterpriseState => ({
|
||||
enterpriseInfo: null,
|
||||
enterpriseInfo: (() => {
|
||||
const stored = localStorage.getItem('enterpriseInfo');
|
||||
if (stored) {
|
||||
try {
|
||||
return JSON.parse(stored) as EnterpriseInfo;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
})(),
|
||||
}),
|
||||
actions: {
|
||||
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
|
||||
console.log('setEnterpriseInfo', enterpriseInfo);
|
||||
this.enterpriseInfo = enterpriseInfo;
|
||||
localStorage.setItem('enterpriseInfo', JSON.stringify(enterpriseInfo));
|
||||
},
|
||||
clearEnterpriseInfo() {
|
||||
this.enterpriseInfo = null;
|
||||
localStorage.removeItem('enterpriseInfo');
|
||||
},
|
||||
setEnterpriseName(name: string) {
|
||||
if (this.enterpriseInfo) {
|
||||
|
||||
Reference in New Issue
Block a user