feat: 全局获取userinfo、数据持久化、store处理

This commit is contained in:
renxiaodong
2025-06-23 22:03:57 -04:00
parent 55198613a8
commit 59dac3bb13
10 changed files with 104 additions and 75 deletions

View File

@ -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) {