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

58 lines
1.7 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';
2025-07-08 16:55:04 +08:00
import { useUserStore } from '@/stores/modules/user';
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
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 => ({
2025-07-08 16:55:04 +08:00
enterpriseInfo: (glsWithCatch('enterpriseInfo') && JSON.parse(glsWithCatch('enterpriseInfo') as string)) || null,
}),
actions: {
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
this.enterpriseInfo = enterpriseInfo;
2025-07-08 16:55:04 +08:00
slsWithCatch('enterpriseInfo', JSON.stringify(enterpriseInfo));
},
2025-07-08 16:55:04 +08:00
clearUserEnterpriseInfo() {
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++;
}
},
async getEnterpriseInfo() {
2025-07-08 16:55:04 +08:00
if (this.enterpriseInfo) {
const { code, data } = await fetchEnterpriseInfo(this.enterpriseInfo!.id);
if (code === 200) {
this.setEnterpriseInfo(data);
}
}
},
},
});