Files
lingji-work-fe/src/stores/modules/enterprise/index.ts
2025-09-18 18:05:17 +08:00

64 lines
1.7 KiB
TypeScript

import { fetchEnterpriseInfo } from '@/api/all/login';
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
interface EnterpriseInfo {
id: number | string;
name: string;
update_name_quota: number;
used_update_name_count: number;
sub_account_quota: number;
used_sub_account_count: number;
permissions: string[];
[key: string]: any;
}
interface EnterpriseState {
enterpriseInfo: EnterpriseInfo | null;
}
export const useEnterpriseStore = defineStore('enterprise', {
state: (): EnterpriseState => ({
enterpriseInfo: (glsWithCatch('enterpriseInfo') && JSON.parse(glsWithCatch('enterpriseInfo') as string)) || null,
}),
getters: {
// 企业已开通/试用中
isOpenEnterprise(): boolean {
return [1, 2].includes(this.enterpriseInfo?.subscribe_status);
},
},
actions: {
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
this.enterpriseInfo = enterpriseInfo;
slsWithCatch('enterpriseInfo', JSON.stringify(enterpriseInfo));
},
clearUserEnterpriseInfo() {
this.enterpriseInfo = null;
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() {
if (this.enterpriseInfo) {
const { code, data } = await fetchEnterpriseInfo(this.enterpriseInfo!.id);
if (code === 200) {
this.setEnterpriseInfo(data);
}
}
},
},
});