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

64 lines
1.7 KiB
TypeScript
Raw Normal View History

import { fetchEnterpriseInfo } from '@/api/all/login';
2025-09-18 18:05:17 +08:00
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
interface EnterpriseInfo {
2025-08-25 11:49:58 +08:00
id: number | string;
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-09-11 12:04:54 +08:00
[key: string]: any;
}
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,
}),
2025-09-11 12:04:54 +08:00
getters: {
// 企业已开通/试用中
isOpenEnterprise(): boolean {
return [1, 2].includes(this.enterpriseInfo?.subscribe_status);
},
},
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;
2025-09-18 18:05:17 +08:00
rlsWithCatch('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);
}
}
},
},
});