2025-06-23 05:58:04 -04:00
|
|
|
import { fetchEnterpriseInfo } from '@/api/all/login';
|
2025-07-07 18:17:31 +08:00
|
|
|
import { useSidebarStore } from '@/stores/modules/side-bar';
|
2025-06-23 05:58:04 -04:00
|
|
|
|
2025-06-20 16:16:17 +08:00
|
|
|
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[];
|
2025-06-20 16:16:17 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-20 16:58:03 +08:00
|
|
|
interface EnterpriseState {
|
|
|
|
|
enterpriseInfo: EnterpriseInfo | null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 16:16:17 +08:00
|
|
|
export const useEnterpriseStore = defineStore('enterprise', {
|
2025-06-20 16:58:03 +08:00
|
|
|
state: (): EnterpriseState => ({
|
2025-06-23 22:03:57 -04:00
|
|
|
enterpriseInfo: (() => {
|
|
|
|
|
const stored = localStorage.getItem('enterpriseInfo');
|
|
|
|
|
if (stored) {
|
|
|
|
|
try {
|
|
|
|
|
return JSON.parse(stored) as EnterpriseInfo;
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
})(),
|
2025-06-20 16:16:17 +08:00
|
|
|
}),
|
|
|
|
|
actions: {
|
|
|
|
|
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
|
|
|
|
|
this.enterpriseInfo = enterpriseInfo;
|
2025-06-23 22:03:57 -04:00
|
|
|
localStorage.setItem('enterpriseInfo', JSON.stringify(enterpriseInfo));
|
|
|
|
|
},
|
|
|
|
|
clearEnterpriseInfo() {
|
|
|
|
|
this.enterpriseInfo = null;
|
|
|
|
|
localStorage.removeItem('enterpriseInfo');
|
2025-06-20 16:16:17 +08:00
|
|
|
},
|
|
|
|
|
setEnterpriseName(name: string) {
|
2025-06-20 16:58:03 +08:00
|
|
|
if (this.enterpriseInfo) {
|
|
|
|
|
this.enterpriseInfo.name = name;
|
|
|
|
|
}
|
2025-06-20 16:16:17 +08:00
|
|
|
},
|
|
|
|
|
incUsedUpdateNameCount() {
|
2025-06-20 16:58:03 +08:00
|
|
|
if (this.enterpriseInfo) {
|
|
|
|
|
this.enterpriseInfo.used_update_name_count++;
|
|
|
|
|
}
|
2025-06-20 16:16:17 +08:00
|
|
|
},
|
|
|
|
|
incUsedSubAccountCount() {
|
2025-06-20 16:58:03 +08:00
|
|
|
if (this.enterpriseInfo) {
|
|
|
|
|
this.enterpriseInfo.used_sub_account_count++;
|
|
|
|
|
}
|
2025-06-20 16:16:17 +08:00
|
|
|
},
|
2025-06-20 16:58:03 +08:00
|
|
|
getEnterpriseInfo(): EnterpriseInfo | null {
|
2025-06-20 16:16:17 +08:00
|
|
|
return this.enterpriseInfo;
|
|
|
|
|
},
|
2025-06-23 05:58:04 -04:00
|
|
|
async updateEnterpriseInfo() {
|
2025-07-07 18:17:31 +08:00
|
|
|
const sidebarStore = useSidebarStore();
|
|
|
|
|
|
2025-06-23 05:58:04 -04:00
|
|
|
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();
|
2025-06-23 05:58:04 -04:00
|
|
|
}
|
|
|
|
|
},
|
2025-06-20 16:16:17 +08:00
|
|
|
},
|
|
|
|
|
});
|