feat(系统设置): 模块首页的权限控制
--story=1008972 --user=李玉号 【项目设置】支持二级菜单的权限管控 https://www.tapd.cn/55049933/s/1221291
This commit is contained in:
parent
f7d26d4e24
commit
3ba6a9caa8
|
@ -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"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<el-col :span="14">
|
||||
<el-menu class="header-menu" :unique-opened="true" mode="horizontal" router :default-active='currentPath'>
|
||||
|
||||
<el-menu-item :index="'/api/home'">
|
||||
<el-menu-item :index="'/api/home'" v-permission="['PROJECT_API_HOME:READ']">
|
||||
{{ $t("i18n.home") }}
|
||||
</el-menu-item>
|
||||
<el-menu-item :index="'/api/definition'" v-permission="['PROJECT_API_DEFINITION:READ']">
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<project-change :project-name="currentProject"/>
|
||||
<el-col :span="14">
|
||||
<el-menu class="header-menu" :unique-opened="true" mode="horizontal" router :default-active="pathName">
|
||||
<el-menu-item :index="'/performance/home'">
|
||||
<el-menu-item :index="'/performance/home'" v-permission="['PROJECT_PERFORMANCE_HOME:READ']">
|
||||
{{ $t("i18n.home") }}
|
||||
</el-menu-item>
|
||||
<el-menu-item :index="'/performance/test/all'" v-permission="['PROJECT_PERFORMANCE_TEST:READ']">
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
style="width: 100%">
|
||||
<el-table-column
|
||||
prop="type"
|
||||
:label="$t('group.functional_menu')"
|
||||
:label="$t('permission.common.first_level_menu')"
|
||||
width="180">
|
||||
<template v-slot:default="scope">
|
||||
<span v-if="scope.row.type !== 'PROJECT'">
|
||||
|
@ -25,7 +25,7 @@
|
|||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="resource"
|
||||
:label="$t('group.operation_object')"
|
||||
:label="$t('permission.common.second_level_menu')"
|
||||
width="180">
|
||||
<template v-slot:default="scope">
|
||||
{{ $t(scope.row.resource.name) }}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<el-col :span="14">
|
||||
<el-menu class="header-menu" :unique-opened="true" mode="horizontal" router
|
||||
:default-active="pathName">
|
||||
<el-menu-item :index="'/track/home'">
|
||||
<el-menu-item :index="'/track/home'" v-permission="['PROJECT_TRACK_HOME:READ']">
|
||||
{{ $t("i18n.home") }}
|
||||
</el-menu-item>
|
||||
<el-menu-item :index="'/track/case/all'" v-permission="['PROJECT_TRACK_CASE:READ']">
|
||||
|
|
|
@ -205,3 +205,26 @@ export const ENV_TYPE = {
|
|||
}
|
||||
|
||||
export const DEFAULT_XSS_ATTR = ['style', 'class'];
|
||||
|
||||
|
||||
export const SECOND_LEVEL_ROUTE_PERMISSION_MAP = {
|
||||
API: [
|
||||
{router: '/api/home', permission: ['PROJECT_API_HOME:READ']},
|
||||
{router: '/api/definition', permission: ['PROJECT_API_DEFINITION:READ']},
|
||||
{router: '/api/automation', permission: ['PROJECT_API_SCENARIO:READ']},
|
||||
{router: '/api/automation/report', permission: ['PROJECT_API_REPORT:READ']},
|
||||
],
|
||||
TRACK: [
|
||||
{router: '/track/home', permission: ['PROJECT_TRACK_HOME:READ']},
|
||||
{router: '/track/case/all', permission: ['PROJECT_TRACK_CASE:READ']},
|
||||
{router: '/track/review/all', permission: ['PROJECT_TRACK_REVIEW:READ']},
|
||||
{router: '/track/plan/all', permission: ['PROJECT_TRACK_PLAN:READ']},
|
||||
{router: '/track/issue', permission: ['PROJECT_TRACK_ISSUE:READ']},
|
||||
{router: '/track/testPlan/reportList', permission: ['PROJECT_TRACK_REPORT:READ']},
|
||||
],
|
||||
LOAD: [
|
||||
{router: '/performance/home', permission: ['PROJECT_PERFORMANCE_HOME:READ']},
|
||||
{router: '/performance/test/all', permission: ['PROJECT_PERFORMANCE_TEST:READ']},
|
||||
{router: '/performance/report/all', permission: ['PROJECT_PERFORMANCE_REPORT:READ']},
|
||||
]
|
||||
}
|
||||
|
|
|
@ -2921,6 +2921,12 @@ export default {
|
|||
api_case: 'API Case',
|
||||
},
|
||||
permission: {
|
||||
common: {
|
||||
home: "HOME",
|
||||
read: "READ",
|
||||
first_level_menu: "First Level Menu",
|
||||
second_level_menu: "Second Level Menu",
|
||||
},
|
||||
project_error_report_library: {
|
||||
name: "Error report library",
|
||||
read: "READ",
|
||||
|
|
|
@ -2930,6 +2930,12 @@ export default {
|
|||
api_case: '接口用例'
|
||||
},
|
||||
permission: {
|
||||
common: {
|
||||
home: "首页",
|
||||
read: "查看",
|
||||
first_level_menu: "一级菜单",
|
||||
second_level_menu: "二级菜单",
|
||||
},
|
||||
project_error_report_library: {
|
||||
name: "误报库",
|
||||
read: "查看误报",
|
||||
|
|
|
@ -2924,6 +2924,12 @@ export default {
|
|||
api_case: '接口用例'
|
||||
},
|
||||
permission: {
|
||||
common: {
|
||||
home: "首頁",
|
||||
read: "查看",
|
||||
first_level_menu: "一級菜單",
|
||||
second_level_menu: "二級菜單",
|
||||
},
|
||||
project_error_report_library: {
|
||||
name: "誤報庫",
|
||||
read: "查看誤報",
|
||||
|
|
Loading…
Reference in New Issue