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,62 +1,62 @@
/* // /*
* @Author: RenXiaoDong // * @Author: RenXiaoDong
* @Date: 2025-06-19 01:45:53 // * @Date: 2025-06-19 01:45:53
*/ // */
import type { RouteRecordRaw, RouteRecordNormalized } from 'vue-router'; // import type { RouteRecordRaw, RouteRecordNormalized } from 'vue-router';
import { useRouter } from 'vue-router'; // import { useRouter } from 'vue-router';
import { useSidebarStore } from '@/stores/modules/side-bar'; // import { useSidebarStore } from '@/stores/modules/side-bar';
export default function useMenuTree() { // export default function useMenuTree() {
const router = useRouter(); // const router = useRouter();
const appRoutes = router.options?.routes ?? []; // const appRoutes = router.options?.routes ?? [];
const sidebarStore = useSidebarStore(); // const sidebarStore = useSidebarStore();
const appRoute = computed(() => { // const appRoute = computed(() => {
const _filterRoutes = appRoutes.filter((v) => v.meta?.id === sidebarStore.activeMenuKey); // const _filterRoutes = appRoutes.filter((v) => v.meta?.id === sidebarStore.activeMenuKey);
return _filterRoutes; // return _filterRoutes;
}); // });
const menuTree = computed(() => { // const menuTree = computed(() => {
const copyRouter = cloneDeep(appRoute.value) as RouteRecordNormalized[]; // const copyRouter = cloneDeep(appRoute.value) as RouteRecordNormalized[];
copyRouter.sort((a: RouteRecordNormalized, b: RouteRecordNormalized) => { // copyRouter.sort((a: RouteRecordNormalized, b: RouteRecordNormalized) => {
return (a.meta.order || 0) - (b.meta.order || 0); // return (a.meta.order || 0) - (b.meta.order || 0);
}); // });
function travel(_routes: RouteRecordRaw[], layer: number) { // function travel(_routes: RouteRecordRaw[], layer: number) {
if (!_routes) return null; // if (!_routes) return null;
const collector: any = _routes.map((element) => { // const collector: any = _routes.map((element) => {
// leaf node // // leaf node
if (element.meta?.hideChildrenInMenu || !element.children) { // if (element.meta?.hideChildrenInMenu || !element.children) {
element.children = []; // element.children = [];
return element; // return element;
} // }
// route filter hideInMenu true // // route filter hideInMenu true
element.children = element.children.filter((x) => x.meta?.hideInMenu !== true); // element.children = element.children.filter((x) => x.meta?.hideInMenu !== true);
// Associated child node // // Associated child node
const subItem = travel(element.children, layer + 1); // const subItem = travel(element.children, layer + 1);
if (subItem.length) { // if (subItem.length) {
element.children = subItem; // element.children = subItem;
return element; // return element;
} // }
// the else logic // // the else logic
if (layer > 1) { // if (layer > 1) {
element.children = subItem; // element.children = subItem;
return element; // return element;
} // }
if (element.meta?.hideInMenu === false) { // if (element.meta?.hideInMenu === false) {
return element; // return element;
} // }
return null; // return null;
}); // });
return collector.filter(Boolean); // return collector.filter(Boolean);
} // }
return travel(copyRouter, 0); // return travel(copyRouter, 0);
}); // });
return { // return {
menuTree, // menuTree,
}; // };
} // }

View File

@ -1,9 +1,9 @@
import { useUserStore } from '@/stores/modules/user'; // import { useUserStore } from '@/stores/modules/user';
export function checkRoutePermission(routeName: string) { // export function checkRoutePermission(routeName: string) {
const userStore = useUserStore(); // // const userStore = useUserStore();
const allowAccessRoutes = userStore.allowAccessRoutes; // // const allowAccessRoutes = userStore.allowAccessRoutes;
if (!routeName) return false; // // if (!routeName) return false;
return allowAccessRoutes.includes(routeName); // // return allowAccessRoutes.includes(routeName);
} // }

View File

@ -6,7 +6,7 @@ import type { Router } from 'vue-router';
import NProgress from 'nprogress'; import NProgress from 'nprogress';
import { goUserLogin } from '@/utils/user'; import { goUserLogin } from '@/utils/user';
// import router from '@/router'; // import router from '@/router';
import { checkRoutePermission } from '@/permission/permission'; // import { checkRoutePermission } from '@/permission/permission';
import { useUserStore } from '@/stores/modules/user'; import { useUserStore } from '@/stores/modules/user';

View File

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

View File

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

View File

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

View File

@ -15,12 +15,12 @@ export function goUserLogin(query?: any) {
export const getUserEnterpriseInfo = async () => { export const getUserEnterpriseInfo = async () => {
const enterpriseStore = useEnterpriseStore(); const enterpriseStore = useEnterpriseStore();
const sidebarStore = useSidebarStore(); // const sidebarStore = useSidebarStore();
const userStore = useUserStore(); const userStore = useUserStore();
await enterpriseStore.getEnterpriseInfo(); // 初始化企业信息 await enterpriseStore.getEnterpriseInfo(); // 初始化企业信息
sidebarStore.getUserNavbarMenuList(); // 初始化navbar菜单 // sidebarStore.getUserNavbarMenuList(); // 初始化navbar菜单
userStore.getUserAllowAccessRoutes(); // 初始化允许访问的路由 // userStore.getUserAllowAccessRoutes(); // 初始化允许访问的路由
}; };
// 登录处理 // 登录处理
@ -37,8 +37,7 @@ export async function handleUserLogin() {
// 首页 // 首页
export function handleUserHome(params?: any) { export function handleUserHome(params?: any) {
router.push({ name: 'Home', params });
router.push({ name: 'Home' });
} }
// 登出处理 // 登出处理
@ -50,8 +49,8 @@ export function handleUserLogout() {
userStore.clearUserInfo(); // 清除用户信息 userStore.clearUserInfo(); // 清除用户信息
userStore.clearToken(); // 清除token userStore.clearToken(); // 清除token
enterpriseStore.clearUserEnterpriseInfo(); // 清除企业信息 enterpriseStore.clearUserEnterpriseInfo(); // 清除企业信息
sidebarStore.clearUserNavbarMenuList(); // 清除navbar菜单信息 // sidebarStore.clearUserNavbarMenuList(); // 清除navbar菜单信息
userStore.clearUserAllowAccessRoutes(); // 清除权限路由列表 // userStore.clearUserAllowAccessRoutes(); // 清除权限路由列表
sidebarStore.stopUnreadInfoPolling(); // 清除未读消息 sidebarStore.stopUnreadInfoPolling(); // 清除未读消息
sidebarStore.clearActiveMenuKey(); // 清除active菜单id sidebarStore.clearActiveMenuKey(); // 清除active菜单id
sidebarStore.clearMenuCollapse(); // 清除active菜单id sidebarStore.clearMenuCollapse(); // 清除active菜单id