- 移除各 API函数中的重复 headers 设置 - 在全局请求拦截器中添加企业 ID 头部信息 - 优化企业信息状态管理,确保信息不为空时才进行更新 -调整 API 调用方式,统一使用新格式
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
interface EnterpriseInfo {
|
||
id: number;
|
||
name: string;
|
||
update_name_quota: number;
|
||
used_update_name_count: number;
|
||
sub_account_quota: number;
|
||
used_sub_account_count: number;
|
||
}
|
||
|
||
interface EnterpriseState {
|
||
enterpriseInfo: EnterpriseInfo | null;
|
||
}
|
||
|
||
export const useEnterpriseStore = defineStore('enterprise', {
|
||
state: (): EnterpriseState => ({
|
||
// todo 暂时写死,登录功能完成后记得重置为null哦
|
||
enterpriseInfo: {
|
||
id: 1,
|
||
name: '企业1',
|
||
update_name_quota: 2,
|
||
used_update_name_count: 1,
|
||
sub_account_quota: 2,
|
||
used_sub_account_count: 2,
|
||
},
|
||
}),
|
||
actions: {
|
||
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
|
||
this.enterpriseInfo = 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++;
|
||
}
|
||
},
|
||
getEnterpriseInfo(): EnterpriseInfo | null {
|
||
return this.enterpriseInfo;
|
||
},
|
||
},
|
||
});
|