Files
lingji-work-fe/src/stores/modules/enterprise/index.ts

71 lines
1.8 KiB
TypeScript
Raw Normal View History

import { fetchEnterpriseInfo } from '@/api/all/login';
2025-07-07 18:17:31 +08:00
import { useSidebarStore } from '@/stores/modules/side-bar';
interface EnterpriseInfo {
id: number;
name: string;
update_name_quota: number;
used_update_name_count: number;
sub_account_quota: number;
used_sub_account_count: number;
2025-07-07 18:17:31 +08:00
permissions: string[];
}
interface EnterpriseState {
enterpriseInfo: EnterpriseInfo | null;
}
export const useEnterpriseStore = defineStore('enterprise', {
state: (): EnterpriseState => ({
enterpriseInfo: (() => {
const stored = localStorage.getItem('enterpriseInfo');
if (stored) {
try {
return JSON.parse(stored) as EnterpriseInfo;
} catch {
return null;
}
}
return null;
})(),
}),
actions: {
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
this.enterpriseInfo = enterpriseInfo;
localStorage.setItem('enterpriseInfo', JSON.stringify(enterpriseInfo));
},
clearEnterpriseInfo() {
this.enterpriseInfo = null;
localStorage.removeItem('enterpriseInfo');
},
setEnterpriseName(name: string) {
if (this.enterpriseInfo) {
this.enterpriseInfo.name = name;
}
},
incUsedUpdateNameCount() {
if (this.enterpriseInfo) {
this.enterpriseInfo.used_update_name_count++;
}
},
incUsedSubAccountCount() {
if (this.enterpriseInfo) {
this.enterpriseInfo.used_sub_account_count++;
}
},
getEnterpriseInfo(): EnterpriseInfo | null {
return this.enterpriseInfo;
},
async updateEnterpriseInfo() {
2025-07-07 18:17:31 +08:00
const sidebarStore = useSidebarStore();
const res = await fetchEnterpriseInfo(this.enterpriseInfo!.id);
const { code, data } = res;
if (code === 200) {
this.setEnterpriseInfo(data);
2025-07-07 18:17:31 +08:00
sidebarStore.getNavbarMenuList();
}
},
},
});