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%">