diff --git a/src/layouts/components/siderBar/use-menu-tree.ts b/src/layouts/components/siderBar/use-menu-tree.ts index ef371e8..b6d44a5 100644 --- a/src/layouts/components/siderBar/use-menu-tree.ts +++ b/src/layouts/components/siderBar/use-menu-tree.ts @@ -1,62 +1,62 @@ -/* - * @Author: RenXiaoDong - * @Date: 2025-06-19 01:45:53 - */ -import type { RouteRecordRaw, RouteRecordNormalized } from 'vue-router'; -import { useRouter } from 'vue-router'; -import { useSidebarStore } from '@/stores/modules/side-bar'; +// /* +// * @Author: RenXiaoDong +// * @Date: 2025-06-19 01:45:53 +// */ +// import type { RouteRecordRaw, RouteRecordNormalized } from 'vue-router'; +// import { useRouter } from 'vue-router'; +// import { useSidebarStore } from '@/stores/modules/side-bar'; -export default function useMenuTree() { - const router = useRouter(); - const appRoutes = router.options?.routes ?? []; - const sidebarStore = useSidebarStore(); - const appRoute = computed(() => { - const _filterRoutes = appRoutes.filter((v) => v.meta?.id === sidebarStore.activeMenuKey); - return _filterRoutes; - }); - const menuTree = computed(() => { - const copyRouter = cloneDeep(appRoute.value) as RouteRecordNormalized[]; - copyRouter.sort((a: RouteRecordNormalized, b: RouteRecordNormalized) => { - return (a.meta.order || 0) - (b.meta.order || 0); - }); - function travel(_routes: RouteRecordRaw[], layer: number) { - if (!_routes) return null; +// export default function useMenuTree() { +// const router = useRouter(); +// const appRoutes = router.options?.routes ?? []; +// const sidebarStore = useSidebarStore(); +// const appRoute = computed(() => { +// const _filterRoutes = appRoutes.filter((v) => v.meta?.id === sidebarStore.activeMenuKey); +// return _filterRoutes; +// }); +// const menuTree = computed(() => { +// const copyRouter = cloneDeep(appRoute.value) as RouteRecordNormalized[]; +// copyRouter.sort((a: RouteRecordNormalized, b: RouteRecordNormalized) => { +// return (a.meta.order || 0) - (b.meta.order || 0); +// }); +// function travel(_routes: RouteRecordRaw[], layer: number) { +// if (!_routes) return null; - const collector: any = _routes.map((element) => { - // leaf node - if (element.meta?.hideChildrenInMenu || !element.children) { - element.children = []; - return element; - } +// const collector: any = _routes.map((element) => { +// // leaf node +// if (element.meta?.hideChildrenInMenu || !element.children) { +// element.children = []; +// return element; +// } - // route filter hideInMenu true - element.children = element.children.filter((x) => x.meta?.hideInMenu !== true); +// // route filter hideInMenu true +// element.children = element.children.filter((x) => x.meta?.hideInMenu !== true); - // Associated child node - const subItem = travel(element.children, layer + 1); +// // Associated child node +// const subItem = travel(element.children, layer + 1); - if (subItem.length) { - element.children = subItem; - return element; - } - // the else logic - if (layer > 1) { - element.children = subItem; - return element; - } +// if (subItem.length) { +// element.children = subItem; +// return element; +// } +// // the else logic +// if (layer > 1) { +// element.children = subItem; +// return element; +// } - if (element.meta?.hideInMenu === false) { - return element; - } +// if (element.meta?.hideInMenu === false) { +// return element; +// } - return null; - }); - return collector.filter(Boolean); - } - return travel(copyRouter, 0); - }); +// return null; +// }); +// return collector.filter(Boolean); +// } +// return travel(copyRouter, 0); +// }); - return { - menuTree, - }; -} +// return { +// menuTree, +// }; +// } diff --git a/src/permission/permission.ts b/src/permission/permission.ts index 27ddd3d..9fe2112 100644 --- a/src/permission/permission.ts +++ b/src/permission/permission.ts @@ -1,9 +1,9 @@ -import { useUserStore } from '@/stores/modules/user'; +// import { useUserStore } from '@/stores/modules/user'; -export function checkRoutePermission(routeName: string) { - const userStore = useUserStore(); - const allowAccessRoutes = userStore.allowAccessRoutes; +// export function checkRoutePermission(routeName: string) { +// // const userStore = useUserStore(); +// // const allowAccessRoutes = userStore.allowAccessRoutes; - if (!routeName) return false; - return allowAccessRoutes.includes(routeName); -} +// // if (!routeName) return false; +// // return allowAccessRoutes.includes(routeName); +// } diff --git a/src/router copy/guard/userLoginInfo.ts b/src/router copy/guard/userLoginInfo.ts index 2d83b6b..729750c 100644 --- a/src/router copy/guard/userLoginInfo.ts +++ b/src/router copy/guard/userLoginInfo.ts @@ -6,7 +6,7 @@ import type { Router } from 'vue-router'; import NProgress from 'nprogress'; import { goUserLogin } from '@/utils/user'; // import router from '@/router'; -import { checkRoutePermission } from '@/permission/permission'; +// import { checkRoutePermission } from '@/permission/permission'; import { useUserStore } from '@/stores/modules/user'; diff --git a/src/stores/modules/side-bar/constants.ts b/src/stores/modules/side-bar/constants.ts index e0615c3..2769953 100644 --- a/src/stores/modules/side-bar/constants.ts +++ b/src/stores/modules/side-bar/constants.ts @@ -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'], +// }, +// ], +// }, +// ]; diff --git a/src/stores/modules/side-bar/index.ts b/src/stores/modules/side-bar/index.ts index e367122..c97a386 100644 --- a/src/stores/modules/side-bar/index.ts +++ b/src/stores/modules/side-bar/index.ts @@ -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 ?? []; diff --git a/src/stores/modules/user/index.ts b/src/stores/modules/user/index.ts index 972eda7..fb2ed6a 100644 --- a/src/stores/modules/user/index.ts +++ b/src/stores/modules/user/index.ts @@ -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)); + // }, }, }); diff --git a/src/utils/user.ts b/src/utils/user.ts index 19a360d..b75d9d6 100644 --- a/src/utils/user.ts +++ b/src/utils/user.ts @@ -15,12 +15,12 @@ export function goUserLogin(query?: any) { export const getUserEnterpriseInfo = async () => { const enterpriseStore = useEnterpriseStore(); - const sidebarStore = useSidebarStore(); + // const sidebarStore = useSidebarStore(); const userStore = useUserStore(); await enterpriseStore.getEnterpriseInfo(); // 初始化企业信息 - sidebarStore.getUserNavbarMenuList(); // 初始化navbar菜单 - userStore.getUserAllowAccessRoutes(); // 初始化允许访问的路由 + // sidebarStore.getUserNavbarMenuList(); // 初始化navbar菜单 + // userStore.getUserAllowAccessRoutes(); // 初始化允许访问的路由 }; // 登录处理 @@ -37,8 +37,7 @@ export async function handleUserLogin() { // 首页 export function handleUserHome(params?: any) { - - router.push({ name: 'Home' }); + router.push({ name: 'Home', params }); } // 登出处理 @@ -50,8 +49,8 @@ export function handleUserLogout() { userStore.clearUserInfo(); // 清除用户信息 userStore.clearToken(); // 清除token enterpriseStore.clearUserEnterpriseInfo(); // 清除企业信息 - sidebarStore.clearUserNavbarMenuList(); // 清除navbar菜单信息 - userStore.clearUserAllowAccessRoutes(); // 清除权限路由列表 + // sidebarStore.clearUserNavbarMenuList(); // 清除navbar菜单信息 + // userStore.clearUserAllowAccessRoutes(); // 清除权限路由列表 sidebarStore.stopUnreadInfoPolling(); // 清除未读消息 sidebarStore.clearActiveMenuKey(); // 清除active菜单id sidebarStore.clearMenuCollapse(); // 清除active菜单id