perf: 去掉产品权限控制相关逻辑

This commit is contained in:
rd
2025-08-22 09:51:32 +08:00
parent 322101164b
commit f53b697df1
7 changed files with 230 additions and 233 deletions

View File

@ -1,116 +1,116 @@
import { MENU_GROUP_IDS } from '@/router/constants';
export const MENU_LIST = [
{
id: MENU_GROUP_IDS.WORK_BENCH_ID,
name: '工作台',
routeName: 'Home',
includeRouteNames: ['Home'],
requiresAuth: false,
permissionKey: '', // 权限key如果为空则表示该菜单不需要权限与后端约定
},
{
id: MENU_GROUP_IDS.DATA_ENGINE_ID,
name: '全域数据分析',
permissionKey: 'data_analysis',
requiresAuth: true,
children: [
{
name: '行业热门话题洞察',
routeName: 'DataEngineHotTranslation',
includeRouteNames: ['DataEngineHotTranslation'],
},
{
name: '行业词云',
routeName: 'DataEngineHotCloud',
includeRouteNames: ['DataEngineHotCloud'],
},
{
name: '行业关键词动向',
routeName: 'DataEngineKeyWord',
includeRouteNames: ['DataEngineKeyWord'],
},
{
name: '用户痛点观察',
routeName: 'DataEngineUserPainPoints',
includeRouteNames: ['DataEngineUserPainPoints'],
},
{
name: '重点品牌动向',
routeName: 'DataEngineKeyBrandMovement',
includeRouteNames: ['DataEngineKeyBrandMovement'],
},
{
name: '用户画像',
routeName: 'DataEngineUserPersona',
includeRouteNames: ['DataEngineUserPersona'],
},
],
},
{
id: MENU_GROUP_IDS.CREATIVE_GENERATION_WORKSHOP_ID,
name: '创意生成工坊',
permissionKey: '',
requiresAuth: true,
children: [
{
name: '内容稿件',
routeName: 'ManuscriptList',
includeRouteNames: [
'ManuscriptList',
'ManuscriptUpload',
'ManuscriptEdit',
'ManuscriptDetail',
'ManuscriptCheckList',
'ManuscriptCheckListDetail',
'ManuscriptCheck',
],
},
],
},
{
id: MENU_GROUP_IDS.PROPERTY_ID,
name: '营销资产中台',
permissionKey: 'marketing_asset',
requiresAuth: true,
children: [
{
name: '品牌资产管理',
routeName: 'RepositoryBrandMaterials',
includeRouteNames: ['RepositoryBrandMaterials'],
},
{
name: '账号资源中心',
routeName: 'MediaAccountAccountManagement',
includeRouteNames: [
'MediaAccountAccountManagement',
'MediaAccountAccountDashboard',
'MediaAccountAccountDetails',
],
},
{
name: '投放资源中心',
routeName: 'PutAccountAccountManagement',
includeRouteNames: [
'PutAccountAccountManagement',
'PutAccountAccountData',
'PutAccountAccountDashboard',
'PutAccountInvestmentGuidelines',
'PutAccountInvestmentGuidelinesDetail',
],
},
// {
// name: '智能方案管理',
// routeName: 'IntelligentSolutionBusinessAnalysisReport',
// includeRouteNames: [
// 'IntelligentSolutionBusinessAnalysisReport',
// 'IntelligentSolutionCompetitiveProductAnalysisReport',
// ],
// },
{
name: '项目管理',
routeName: 'ProjectList',
includeRouteNames: ['ProjectList'],
},
],
},
];
// import { MENU_GROUP_IDS } from '@/router/constants';
// export const MENU_LIST = [
// {
// id: MENU_GROUP_IDS.WORK_BENCH_ID,
// name: '工作台',
// routeName: 'Home',
// includeRouteNames: ['Home'],
// requiresAuth: false,
// permissionKey: '', // 权限key如果为空则表示该菜单不需要权限与后端约定
// },
// {
// id: MENU_GROUP_IDS.DATA_ENGINE_ID,
// name: '全域数据分析',
// permissionKey: 'data_analysis',
// requiresAuth: true,
// children: [
// {
// name: '行业热门话题洞察',
// routeName: 'DataEngineHotTranslation',
// includeRouteNames: ['DataEngineHotTranslation'],
// },
// {
// name: '行业词云',
// routeName: 'DataEngineHotCloud',
// includeRouteNames: ['DataEngineHotCloud'],
// },
// {
// name: '行业关键词动向',
// routeName: 'DataEngineKeyWord',
// includeRouteNames: ['DataEngineKeyWord'],
// },
// {
// name: '用户痛点观察',
// routeName: 'DataEngineUserPainPoints',
// includeRouteNames: ['DataEngineUserPainPoints'],
// },
// {
// name: '重点品牌动向',
// routeName: 'DataEngineKeyBrandMovement',
// includeRouteNames: ['DataEngineKeyBrandMovement'],
// },
// {
// name: '用户画像',
// routeName: 'DataEngineUserPersona',
// includeRouteNames: ['DataEngineUserPersona'],
// },
// ],
// },
// {
// id: MENU_GROUP_IDS.CREATIVE_GENERATION_WORKSHOP_ID,
// name: '创意生成工坊',
// permissionKey: '',
// requiresAuth: true,
// children: [
// {
// name: '内容稿件',
// routeName: 'ManuscriptList',
// includeRouteNames: [
// 'ManuscriptList',
// 'ManuscriptUpload',
// 'ManuscriptEdit',
// 'ManuscriptDetail',
// 'ManuscriptCheckList',
// 'ManuscriptCheckListDetail',
// 'ManuscriptCheck',
// ],
// },
// ],
// },
// {
// id: MENU_GROUP_IDS.PROPERTY_ID,
// name: '营销资产中台',
// permissionKey: 'marketing_asset',
// requiresAuth: true,
// children: [
// {
// name: '品牌资产管理',
// routeName: 'RepositoryBrandMaterials',
// includeRouteNames: ['RepositoryBrandMaterials'],
// },
// {
// name: '账号资源中心',
// routeName: 'MediaAccountAccountManagement',
// includeRouteNames: [
// 'MediaAccountAccountManagement',
// 'MediaAccountAccountDashboard',
// 'MediaAccountAccountDetails',
// ],
// },
// {
// name: '投放资源中心',
// routeName: 'PutAccountAccountManagement',
// includeRouteNames: [
// 'PutAccountAccountManagement',
// 'PutAccountAccountData',
// 'PutAccountAccountDashboard',
// 'PutAccountInvestmentGuidelines',
// 'PutAccountInvestmentGuidelinesDetail',
// ],
// },
// // {
// // name: '智能方案管理',
// // routeName: 'IntelligentSolutionBusinessAnalysisReport',
// // includeRouteNames: [
// // 'IntelligentSolutionBusinessAnalysisReport',
// // 'IntelligentSolutionCompetitiveProductAnalysisReport',
// // ],
// // },
// {
// name: '项目管理',
// routeName: 'ProjectList',
// includeRouteNames: ['ProjectList'],
// },
// ],
// },
// ];

View File

@ -5,14 +5,13 @@
import { defineStore } from 'pinia';
import router from '@/router';
import type { RouteLocationNormalized } from 'vue-router';
import { MENU_LIST } from './constants';
// import { MENU_LIST } from './constants';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
import { getTaskUnread, patchTaskRead } from '@/api/all/common';
interface sidebarState {
activeMenuKey: string | number | null;
menuList: any[];
allowAccessRoutes: any[];
// menuList: any[];
unreadInfo: number[];
menuCollapse: boolean;
}
@ -22,9 +21,8 @@ let unreadInfoTimer: number | null = null;
export const useSidebarStore = defineStore('sidebar', {
state: (): sidebarState => ({
activeMenuKey: null, // 激活的菜单id
menuList: [], // 菜单信息
// menuList: [], // 菜单信息
unreadInfo: [], // 未读消息
allowAccessRoutes: [], // 允许访问的路由列表
menuCollapse: false, // 菜单是否折叠
}),
getters: {
@ -45,16 +43,16 @@ export const useSidebarStore = defineStore('sidebar', {
clearMenuCollapse() {
this.menuCollapse = false;
},
clearUserNavbarMenuList() {
this.menuList = [];
},
// clearUserNavbarMenuList() {
// this.menuList = [];
// },
// navbar菜单列表由企业对应权限决定
getUserNavbarMenuList() {
const enterpriseStore = useEnterpriseStore();
this.menuList = MENU_LIST.filter(
(item) => !item.permissionKey || enterpriseStore.enterpriseInfo?.permissions?.includes(item.permissionKey),
);
},
// getUserNavbarMenuList() {
// const enterpriseStore = useEnterpriseStore();
// this.menuList = MENU_LIST.filter(
// (item) => !item.permissionKey || enterpriseStore.enterpriseInfo?.permissions?.includes(item.permissionKey),
// );
// },
// 根据当前路由自动设置 activeMenuKey
setActiveMenuKeyByRoute(route: RouteLocationNormalized) {
const appRoutes = router.options?.routes ?? [];

View File

@ -16,7 +16,7 @@ interface UserInfo {
interface UserState {
token: string;
userInfo: UserInfo | null;
allowAccessRoutes: string[];
// allowAccessRoutes: string[];
// isLogin: boolean;
}
@ -30,8 +30,8 @@ export const useUserStore = defineStore('user', {
state: (): UserState => ({
token: glsWithCatch('accessToken') || '',
userInfo: (glsWithCatch('userInfo') && JSON.parse(glsWithCatch('userInfo') as string)) || null,
allowAccessRoutes:
(glsWithCatch('allowAccessRoutes') && JSON.parse(glsWithCatch('allowAccessRoutes') as string)) || [], // 允许访问的路由列表
// allowAccessRoutes:
// (glsWithCatch('allowAccessRoutes') && JSON.parse(glsWithCatch('allowAccessRoutes') as string)) || [], // 允许访问的路由列表
}),
getters: {
isLogin(): boolean {
@ -72,40 +72,40 @@ export const useUserStore = defineStore('user', {
this.setUserInfo(data);
}
},
clearUserAllowAccessRoutes() {
this.allowAccessRoutes = [];
rlsWithCatch('allowAccessRoutes');
},
getUserAllowAccessRoutes() {
const sidebarStore = useSidebarStore();
const menuList = sidebarStore.menuList;
const appRoutes = router.getRoutes();
// clearUserAllowAccessRoutes() {
// this.allowAccessRoutes = [];
// rlsWithCatch('allowAccessRoutes');
// },
// getUserAllowAccessRoutes() {
// const sidebarStore = useSidebarStore();
// const menuList = sidebarStore.menuList;
// const appRoutes = router.getRoutes();
appRoutes.forEach((route: any) => {
if (!route.meta?.requiresAuth) {
this.allowAccessRoutes.push(route.name);
}
});
// appRoutes.forEach((route: any) => {
// if (!route.meta?.requiresAuth) {
// this.allowAccessRoutes.push(route.name);
// }
// });
const pushAllowAccessRoutes = (includeRouteNames: string[]) => {
const matchedRoute = appRoutes
.filter((route: any) => includeRouteNames.includes(route.name))
.map((route: any) => route.name);
this.allowAccessRoutes.push(...matchedRoute);
};
// const pushAllowAccessRoutes = (includeRouteNames: string[]) => {
// const matchedRoute = appRoutes
// .filter((route: any) => includeRouteNames.includes(route.name))
// .map((route: any) => route.name);
// this.allowAccessRoutes.push(...matchedRoute);
// };
menuList.forEach((item) => {
if (item.children && item.children.length > 0) {
item.children.forEach((child: any) => {
pushAllowAccessRoutes(child.includeRouteNames);
});
} else {
pushAllowAccessRoutes(item.includeRouteNames);
}
});
// menuList.forEach((item) => {
// if (item.children && item.children.length > 0) {
// item.children.forEach((child: any) => {
// pushAllowAccessRoutes(child.includeRouteNames);
// });
// } else {
// pushAllowAccessRoutes(item.includeRouteNames);
// }
// });
this.allowAccessRoutes = uniq(this.allowAccessRoutes);
slsWithCatch('allowAccessRoutes', JSON.stringify(this.allowAccessRoutes));
},
// this.allowAccessRoutes = uniq(this.allowAccessRoutes);
// slsWithCatch('allowAccessRoutes', JSON.stringify(this.allowAccessRoutes));
// },
},
});