feat: 产品菜单路由权限

This commit is contained in:
rd
2025-07-08 16:55:04 +08:00
parent ead209da4d
commit f87e5ff020
26 changed files with 263 additions and 102 deletions

View File

@ -1,5 +1,7 @@
import { fetchEnterpriseInfo } from '@/api/all/login';
import { useSidebarStore } from '@/stores/modules/side-bar';
import { useUserStore } from '@/stores/modules/user';
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
interface EnterpriseInfo {
id: number;
@ -17,24 +19,14 @@ interface EnterpriseState {
export const useEnterpriseStore = defineStore('enterprise', {
state: (): EnterpriseState => ({
enterpriseInfo: (() => {
const stored = localStorage.getItem('enterpriseInfo');
if (stored) {
try {
return JSON.parse(stored) as EnterpriseInfo;
} catch {
return null;
}
}
return null;
})(),
enterpriseInfo: (glsWithCatch('enterpriseInfo') && JSON.parse(glsWithCatch('enterpriseInfo') as string)) || null,
}),
actions: {
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
this.enterpriseInfo = enterpriseInfo;
localStorage.setItem('enterpriseInfo', JSON.stringify(enterpriseInfo));
slsWithCatch('enterpriseInfo', JSON.stringify(enterpriseInfo));
},
clearEnterpriseInfo() {
clearUserEnterpriseInfo() {
this.enterpriseInfo = null;
localStorage.removeItem('enterpriseInfo');
},
@ -53,17 +45,12 @@ export const useEnterpriseStore = defineStore('enterprise', {
this.enterpriseInfo.used_sub_account_count++;
}
},
getEnterpriseInfo(): EnterpriseInfo | null {
return this.enterpriseInfo;
},
async updateEnterpriseInfo() {
const sidebarStore = useSidebarStore();
const res = await fetchEnterpriseInfo(this.enterpriseInfo!.id);
const { code, data } = res;
if (code === 200) {
this.setEnterpriseInfo(data);
sidebarStore.getNavbarMenuList();
async getUserEnterpriseInfo() {
if (this.enterpriseInfo) {
const { code, data } = await fetchEnterpriseInfo(this.enterpriseInfo!.id);
if (code === 200) {
this.setEnterpriseInfo(data);
}
}
},
},