From 3ba6a9caa8cf3e5ab33fd360228aadb183007253 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 9 Aug 2022 18:56:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E9=A6=96=E9=A1=B5=E7=9A=84=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1008972 --user=李玉号 【项目设置】支持二级菜单的权限管控 https://www.tapd.cn/55049933/s/1221291 --- backend/src/main/resources/permission.json | 27 ++++++++++ .../components/api/head/ApiHeaderMenus.vue | 2 +- .../components/common/router/router.js | 49 ++++++++++++++++++- .../head/PerformanceHeaderMenus.vue | 2 +- .../settings/system/group/EditPermission.vue | 4 +- .../track/head/TrackHeaderMenus.vue | 2 +- frontend/src/common/js/constants.js | 23 +++++++++ frontend/src/i18n/en-US.js | 6 +++ frontend/src/i18n/zh-CN.js | 6 +++ frontend/src/i18n/zh-TW.js | 6 +++ 10 files changed, 120 insertions(+), 7 deletions(-) diff --git a/backend/src/main/resources/permission.json b/backend/src/main/resources/permission.json index abbe290a54..d3962a1dc0 100644 --- a/backend/src/main/resources/permission.json +++ b/backend/src/main/resources/permission.json @@ -457,6 +457,11 @@ "name": "permission.project_custom_code.copy", "resourceId": "PROJECT_CUSTOM_CODE" }, + { + "id": "PROJECT_TRACK_HOME:READ", + "name": "permission.common.read", + "resourceId": "PROJECT_TRACK_HOME" + }, { "id": "PROJECT_TRACK_CASE:READ", "name": "permission.project_track_case.read", @@ -664,6 +669,11 @@ "name": "permission.project_track_report.export", "resourceId": "PROJECT_TRACK_REPORT" }, + { + "id": "PROJECT_API_HOME:READ", + "name": "permission.common.read", + "resourceId": "PROJECT_API_HOME" + }, { "id": "PROJECT_API_DEFINITION:READ", "name": "permission.project_api_definition.read", @@ -937,6 +947,11 @@ "resourceId": "PROJECT_UI_REPORT", "license": true }, + { + "id": "PROJECT_PERFORMANCE_HOME:READ", + "name": "permission.common.read", + "resourceId": "PROJECT_PERFORMANCE_HOME" + }, { "id": "PROJECT_PERFORMANCE_TEST:READ", "name": "permission.project_performance_test.read", @@ -1256,6 +1271,10 @@ "id": "PROJECT_APP_MANAGER", "name": "permission.project_app_manager.name" }, + { + "id": "PROJECT_TRACK_HOME", + "name": "permission.common.home" + }, { "id": "PROJECT_TRACK_CASE", "name": "permission.project_track_case.name" @@ -1276,6 +1295,10 @@ "id": "PROJECT_TRACK_REPORT", "name": "permission.project_track_report.name" }, + { + "id": "PROJECT_API_HOME", + "name": "permission.common.home" + }, { "id": "PROJECT_API_DEFINITION", "name": "permission.project_api_definition.name" @@ -1303,6 +1326,10 @@ "name": "permission.project_ui_report.name", "license": true }, + { + "id": "PROJECT_PERFORMANCE_HOME", + "name": "permission.common.home" + }, { "id": "PROJECT_PERFORMANCE_TEST", "name": "permission.project_performance_test.name" diff --git a/frontend/src/business/components/api/head/ApiHeaderMenus.vue b/frontend/src/business/components/api/head/ApiHeaderMenus.vue index 64fc0c39f1..10b27a62b4 100644 --- a/frontend/src/business/components/api/head/ApiHeaderMenus.vue +++ b/frontend/src/business/components/api/head/ApiHeaderMenus.vue @@ -5,7 +5,7 @@ - + {{ $t("i18n.home") }} diff --git a/frontend/src/business/components/common/router/router.js b/frontend/src/business/components/common/router/router.js index 675a46442a..4c3d574071 100644 --- a/frontend/src/business/components/common/router/router.js +++ b/frontend/src/business/components/common/router/router.js @@ -8,6 +8,7 @@ import Track from "@/business/components/track/router"; import ReportStatistics from "@/business/components/reportstatistics/router"; import Project from "@/business/components/project/router"; import {getCurrentUser, getCurrentUserId, hasPermissions} from "@/common/js/utils"; +import {SECOND_LEVEL_ROUTE_PERMISSION_MAP} from "@/common/js/constants"; Vue.use(VueRouter); const requireContext = require.context('@/business/components/xpack/', true, /router\.js$/); @@ -66,15 +67,59 @@ function redirectLoginPath(originPath, next) { sessionStorage.setItem('lastUser', getCurrentUserId()); sessionStorage.setItem('redirectUrl', originPath); sessionStorage.removeItem('loginSuccess'); + let defaultMenuRoute = sessionStorage.getItem('defaultMenuRoute'); if (redirectUrl && loginSuccess) { + // 登录后只执行一次 sessionStorage.removeItem('loginSuccess'); - // router.push(redirectUrl); + redirectUrl = getDefaultSecondLevelMenu(redirectUrl); next({path: redirectUrl}); } else { - next(); + if (!defaultMenuRoute) { + // 记录标识,防止死循环 + sessionStorage.setItem('defaultMenuRoute', 'sign'); + originPath = getDefaultSecondLevelMenu(originPath); + next({path: originPath}); + if (router.currentRoute.fullPath === originPath) { + sessionStorage.setItem('redirectUrl', originPath); + // 路径相同时,移除标识 + sessionStorage.removeItem("defaultMenuRoute"); + } + } else { + sessionStorage.setItem('redirectUrl', originPath); + sessionStorage.removeItem("defaultMenuRoute"); + next(); + } } } +function getDefaultSecondLevelMenu(toPath) { + let {TRACK: tracks, API: apis, LOAD: loads} = SECOND_LEVEL_ROUTE_PERMISSION_MAP; + if (tracks.map(r => r.router).indexOf(toPath) > -1) { + return _getDefaultSecondLevelMenu(tracks, toPath); + } else if (apis.map(r => r.router).indexOf(toPath) > -1) { + return _getDefaultSecondLevelMenu(apis, toPath); + } else if (loads.map(r => r.router).indexOf(toPath) > -1) { + return _getDefaultSecondLevelMenu(loads, toPath); + } else { + return toPath; + } +} + +function _getDefaultSecondLevelMenu(secondLevelRouters, toPath) { + let toRouter = secondLevelRouters.find(r => r['router'] === toPath); + if (toRouter && hasPermissions(...toRouter['permission'])) { + // 将要跳转的路由有权限则放行 + return toPath; + } + for (let router of secondLevelRouters) { + if (hasPermissions(...router['permission'])) { + // 返回第一个有权限的路由路径 + return router['router']; + } + } + return '/'; +} + export default router; diff --git a/frontend/src/business/components/performance/head/PerformanceHeaderMenus.vue b/frontend/src/business/components/performance/head/PerformanceHeaderMenus.vue index 7e6966c94e..baa4693317 100644 --- a/frontend/src/business/components/performance/head/PerformanceHeaderMenus.vue +++ b/frontend/src/business/components/performance/head/PerformanceHeaderMenus.vue @@ -4,7 +4,7 @@ - + {{ $t("i18n.home") }} diff --git a/frontend/src/business/components/settings/system/group/EditPermission.vue b/frontend/src/business/components/settings/system/group/EditPermission.vue index 0d37a76aa5..847b682d86 100644 --- a/frontend/src/business/components/settings/system/group/EditPermission.vue +++ b/frontend/src/business/components/settings/system/group/EditPermission.vue @@ -14,7 +14,7 @@ style="width: 100%">