From 625d832310b24ef0f8b9a9a4b1e6c98180091357 Mon Sep 17 00:00:00 2001 From: "xinxin.wu" Date: Mon, 8 Apr 2024 15:04:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E9=A1=B6=E9=83=A8=E8=8F=9C=E5=8D=95=E4=B8=8D?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/ms-common-script/utils.ts | 11 ++++++----- .../components/business/ms-top-menu/index.vue | 10 +--------- frontend/src/hooks/usePermission.ts | 2 +- frontend/src/store/modules/app/index.ts | 16 ++++++++++++++++ frontend/src/utils/permission.ts | 8 ++++++-- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/business/ms-common-script/utils.ts b/frontend/src/components/business/ms-common-script/utils.ts index 992bf593b2..5629ca6153 100644 --- a/frontend/src/components/business/ms-common-script/utils.ts +++ b/frontend/src/components/business/ms-common-script/utils.ts @@ -22,11 +22,12 @@ function getInsertCommonScript() { } export const SCRIPT_MENU: CommonScriptMenu[] = [ - { - title: t('project.code_segment.importApiTest'), - value: 'api_definition', - command: 'api_definition', - }, + // TODO 这个版本不上 + // { + // title: t('project.code_segment.importApiTest'), + // value: 'api_definition', + // command: 'api_definition', + // }, { title: t('project.code_segment.newApiTest'), value: 'new_api_request', diff --git a/frontend/src/components/business/ms-top-menu/index.vue b/frontend/src/components/business/ms-top-menu/index.vue index 7b7fa5a150..c3ec55d11e 100644 --- a/frontend/src/components/business/ms-top-menu/index.vue +++ b/frontend/src/components/business/ms-top-menu/index.vue @@ -95,15 +95,7 @@ } const filterMenuTopRouter = - currentParent?.children?.filter((item: any) => { - if (permission.accessRouter(item) && item.meta?.isTopMenu) { - // if (item.name === RouteEnum.SETTING_SYSTEM_AUTHORIZED_MANAGEMENT) { - // return appStore.packageType === 'enterprise'; - // } - return true; - } - return false; - }) || []; + currentParent?.children?.filter((item: any) => permission.accessRouter(item) && item.meta?.isTopMenu) || []; appStore.setTopMenus(filterMenuTopRouter); setCurrentTopMenu(name as string); diff --git a/frontend/src/hooks/usePermission.ts b/frontend/src/hooks/usePermission.ts index ea47f6a184..c2c704d16a 100644 --- a/frontend/src/hooks/usePermission.ts +++ b/frontend/src/hooks/usePermission.ts @@ -16,7 +16,7 @@ export default function usePermission() { * @returns 是否 */ accessRouter(route: RouteLocationNormalized | RouteRecordRaw) { - if (includes(firstLevelMenu, route.name)) { + if (firstLevelMenu.includes(route.name as string)) { // 一级菜单: 创建项目时 被勾选的模块 return topLevelMenuHasPermission(route); } diff --git a/frontend/src/store/modules/app/index.ts b/frontend/src/store/modules/app/index.ts index a68ddb1377..f5c33fdf24 100644 --- a/frontend/src/store/modules/app/index.ts +++ b/frontend/src/store/modules/app/index.ts @@ -272,6 +272,22 @@ const useAppStore = defineStore('app', { return false; } }, + async getProjectInfos() { + try { + const res = await getProjectInfo(this.currentProjectId); + if (!res || res.deleted) { + const router = useRouter(); + router.push({ + name: NO_PROJECT_ROUTE_NAME, + }); + } + if (res) { + this.setCurrentMenuConfig(res?.moduleIds || []); + } + } catch (error) { + console.log(error); + } + }, /** * 初始化页面配置 */ diff --git a/frontend/src/utils/permission.ts b/frontend/src/utils/permission.ts index 5594d34013..30f48b19d8 100644 --- a/frontend/src/utils/permission.ts +++ b/frontend/src/utils/permission.ts @@ -82,11 +82,15 @@ export function composePermissions(userRoleRelations: UserRoleRelation[], type: } // 判断当前一级菜单是否有权限 -export function topLevelMenuHasPermission(route: RouteLocationNormalized | RouteRecordRaw) { +export async function topLevelMenuHasPermission(route: RouteLocationNormalized | RouteRecordRaw) { const userStore = useUserStore(); const appStore = useAppStore(); const { currentMenuConfig } = appStore; - if (!currentMenuConfig.includes(route.name as string)) { + if (!currentMenuConfig.length) { + await appStore.getProjectInfos(); + } + + if (currentMenuConfig.length && !currentMenuConfig.includes(route.name as string)) { // 没有配置的菜单不显示 return false; }