diff --git a/data/magic-api/api/系统管理/菜单管理/当前用户菜单.ms b/data/magic-api/api/系统管理/菜单管理/当前用户菜单.ms index b8fac54..a4830a0 100644 --- a/data/magic-api/api/系统管理/菜单管理/当前用户菜单.ms +++ b/data/magic-api/api/系统管理/菜单管理/当前用户菜单.ms @@ -573,7 +573,7 @@ var menus = db.select(""" select role_id from sys_user_role where user_id = #{userId} ) ) - } and sm.is_del = '0' and (sm.is_show = 1 or (sm.component_name is not null and sm.component_name != '')) order by sm.sort + } and sm.is_del = '0' and sm.is_show = 1 order by sm.sort """) for(menu in menus){ @@ -611,4 +611,4 @@ nodes.each((key, node) => { } }) -return treeNodes \ No newline at end of file +return treeNodes diff --git a/data/magic-api/api/系统管理/菜单管理/当前用户隐藏菜单路由.ms b/data/magic-api/api/系统管理/菜单管理/当前用户隐藏菜单路由.ms new file mode 100644 index 0000000..6247dce --- /dev/null +++ b/data/magic-api/api/系统管理/菜单管理/当前用户隐藏菜单路由.ms @@ -0,0 +1,203 @@ +{ + "properties" : { }, + "id" : "2da55da9c28c441ebfdef412e7004cd0", + "script" : null, + "groupId" : "67b2ce258e24491194b74992958c74aa", + "name" : "当前用户隐藏菜单路由", + "createTime" : null, + "updateTime" : 1660381679813, + "lock" : null, + "createBy" : null, + "updateBy" : "guyi", + "path" : "/current/hidden/menus", + "method" : "POST", + "parameters" : [ ], + "options" : [ ], + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [{\n \"componentName\": \"\",\n \"name\": \"创建售后单\",\n \"path\": \"order/aftersales/after-sales\",\n \"subCount\": 0,\n \"keepAlive\": 1,\n \"openMode\": \"0\"\n }],\n \"timestamp\": 1660381448247,\n \"executeTime\": 41\n}", + "description" : null, + "requestBodyDefinition" : null, + "responseBodyDefinition" : { + "name" : "", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "code", + "value" : "200", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "message", + "value" : "success", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "data", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Array", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "componentName", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "name", + "value" : "创建售后单", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "path", + "value" : "order/aftersales/after-sales", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "subCount", + "value" : "0", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "keepAlive", + "value" : "1", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "openMode", + "value" : "0", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } ] + }, { + "name" : "timestamp", + "value" : "1660381448247", + "description" : "", + "required" : false, + "dataType" : "Long", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "executeTime", + "value" : "41", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } +} +================================ +import cn.dev33.satoken.stp.StpUtil + +var userId = StpUtil.getLoginId() +return db.select(""" + select * from ( + select + component_name, + name, + url as path, + (select count(1) from sys_menu where is_del = 0 and pid = sm.id) sub_count, + sm.keep_alive + from sys_menu sm + where ((component_name is not null and component_name != '') or (url is not null and url != '')) + and is_show = 0 and is_del = 0 + ?{userId != '1', + and sm.id in ( + select menu_id from sys_role_menu where role_id in ( + select role_id from sys_user_role where user_id = #{userId} + ) + ) + } + ) sm where sub_count = 0 +""") \ No newline at end of file diff --git a/magic-boot-ui/src/permission.js b/magic-boot-ui/src/permission.js index 4f140f6..f7da8fc 100644 --- a/magic-boot-ui/src/permission.js +++ b/magic-boot-ui/src/permission.js @@ -6,7 +6,7 @@ import 'nprogress/nprogress.css' // progress bar style import { getToken } from '@/scripts/auth' // get token from cookie import global from '@/scripts/global' import common from '@/scripts/common' -import { generateRoutes } from '@/scripts/routerPermission' +import { generateRoutes, generateHiddenRoutes } from '@/scripts/routerPermission' NProgress.configure({ showSpinner: false }) // NProgress Configuration @@ -43,6 +43,11 @@ router.beforeEach(async(to, from, next) => { router.addRoute(it) }) }) + await generateHiddenRoutes().then(accessRoutes => { + accessRoutes.forEach(it => { + router.addRoute(it) + }) + }) // dynamically add accessible routes // hack method to ensure that addRoutes is complete // set the replace: true, so the navigation will not leave a history record diff --git a/magic-boot-ui/src/scripts/routerPermission.js b/magic-boot-ui/src/scripts/routerPermission.js index b44d5e6..bc6c0fd 100644 --- a/magic-boot-ui/src/scripts/routerPermission.js +++ b/magic-boot-ui/src/scripts/routerPermission.js @@ -14,10 +14,6 @@ export const filterAsyncRouter = (routers, level) => { router.props = { url: router.url } router.path = "/" + sha256(router.url) } - var setLayout = () => { - router.path = "/" + common.uuid() - router.component = level > 0 ? layoutModules[`../layout/none.vue`] : loadLayoutView() - } if(router.url && router.url.startsWith('http')){ if(router.openMode == '0'){ setIframe() @@ -34,30 +30,16 @@ export const filterAsyncRouter = (routers, level) => { } else if (router.component) { const component = router.component if (component === 'Layout') { - if (router.children && router.children.length > 0) { - const children = filterAsyncRouter(router.children, level + 1); - if(children.some(it => it.isShow == 1)){ - router.children = children - setLayout() - }else{ - router.children = undefined - router.alwaysShow = false - router.redirect = '' - router.path = router.path.startsWith('/') ? router.path : '/' + router.path - router.component = loadView(router.path) || layoutModules[`../layout/empty.vue`] - } - }else{ - setLayout() - } + router.path = "/" + common.uuid() + router.component = level > 0 ? layoutModules[`../layout/none.vue`] : loadLayoutView(component) } else { router.path = router.path.startsWith('/') ? router.path : '/' + router.path router.component = loadView(component) || layoutModules[`../layout/empty.vue`] } } - return true - } else if (router.componentName) { - router.component = loadView(`/common/show-component`) - router.props = { name: router.componentName } + if (router.children && router.children.length) { + router.children = filterAsyncRouter(router.children, level + 1) + } return true } return false @@ -74,6 +56,34 @@ export const loadView = (view) => { return viewModules[`../views${view}.vue`] } +function loadComponent(router){ + var result = { + path: router.path, + meta: { + title: router.name, + keepAlive: router.keepAlive + } + } + if(router.componentName){ + result.component = loadView(`/common/show-component`) + result.props = { name: router.componentName } + }else if(router.path){ + result.component = loadView(router.path) || layoutModules[`../layout/empty.vue`] + } + return result +} + +export function loadHiddenRouter(routers){ + return routers.filter(router => { + router.path = router.path.startsWith('/') ? router.path : '/' + router.path + router.redirect = router.path + router.component = loadLayoutView() + router.hidden = true + router.children = [loadComponent(router)] + return true + }) +} + export function generateRoutes(){ return new Promise((resolve, reject) => { request({ @@ -86,3 +96,16 @@ export function generateRoutes(){ }) }) } + +export function generateHiddenRoutes(){ + return new Promise((resolve, reject) => { + request({ + url: '/system/menu/current/hidden/menus', + method: 'post' + }).then(response => { + const { data } = response + const asyncRouter = loadHiddenRouter(data) + resolve(asyncRouter) + }) + }) +}