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-07-08 16:55:04 +08:00
|
|
|
import { useUserStore } from '@/stores/modules/user';
|
|
|
|
|
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
|
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-07-08 16:55:04 +08:00
|
|
|
enterpriseInfo: (glsWithCatch('enterpriseInfo') && JSON.parse(glsWithCatch('enterpriseInfo') as string)) || null,
|
2025-06-20 16:16:17 +08:00
|
|
|
}),
|
|
|
|
|
actions: {
|
|
|
|
|
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
|
|
|
|
|
this.enterpriseInfo = enterpriseInfo;
|
2025-07-08 16:55:04 +08:00
|
|
|
slsWithCatch('enterpriseInfo', JSON.stringify(enterpriseInfo));
|
2025-06-23 22:03:57 -04:00
|
|
|
},
|
2025-07-08 16:55:04 +08:00
|
|
|
clearUserEnterpriseInfo() {
|
2025-06-23 22:03:57 -04:00
|
|
|
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-07-09 15:27:28 +08:00
|
|
|
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);
|
|
|
|
|
}
|
2025-06-23 05:58:04 -04:00
|
|
|
}
|
|
|
|
|
},
|
2025-06-20 16:16:17 +08:00
|
|
|
},
|
|
|
|
|
});
|