mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2025-02-07 20:32:49 +08:00
支持 配置路由地址 但菜单隐藏 仍加载路由
This commit is contained in:
parent
1012c419ac
commit
accbc2890b
@ -573,7 +573,7 @@ var menus = db.select("""
|
|||||||
select role_id from sys_user_role where user_id = #{userId}
|
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){
|
for(menu in menus){
|
||||||
|
203
data/magic-api/api/系统管理/菜单管理/当前用户隐藏菜单路由.ms
Normal file
203
data/magic-api/api/系统管理/菜单管理/当前用户隐藏菜单路由.ms
Normal file
@ -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
|
||||||
|
""")
|
@ -6,7 +6,7 @@ import 'nprogress/nprogress.css' // progress bar style
|
|||||||
import { getToken } from '@/scripts/auth' // get token from cookie
|
import { getToken } from '@/scripts/auth' // get token from cookie
|
||||||
import global from '@/scripts/global'
|
import global from '@/scripts/global'
|
||||||
import common from '@/scripts/common'
|
import common from '@/scripts/common'
|
||||||
import { generateRoutes } from '@/scripts/routerPermission'
|
import { generateRoutes, generateHiddenRoutes } from '@/scripts/routerPermission'
|
||||||
|
|
||||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||||
|
|
||||||
@ -43,6 +43,11 @@ router.beforeEach(async(to, from, next) => {
|
|||||||
router.addRoute(it)
|
router.addRoute(it)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
await generateHiddenRoutes().then(accessRoutes => {
|
||||||
|
accessRoutes.forEach(it => {
|
||||||
|
router.addRoute(it)
|
||||||
|
})
|
||||||
|
})
|
||||||
// dynamically add accessible routes
|
// dynamically add accessible routes
|
||||||
// hack method to ensure that addRoutes is complete
|
// hack method to ensure that addRoutes is complete
|
||||||
// set the replace: true, so the navigation will not leave a history record
|
// set the replace: true, so the navigation will not leave a history record
|
||||||
|
@ -14,10 +14,6 @@ export const filterAsyncRouter = (routers, level) => {
|
|||||||
router.props = { url: router.url }
|
router.props = { url: router.url }
|
||||||
router.path = "/" + sha256(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.url && router.url.startsWith('http')){
|
||||||
if(router.openMode == '0'){
|
if(router.openMode == '0'){
|
||||||
setIframe()
|
setIframe()
|
||||||
@ -34,30 +30,16 @@ export const filterAsyncRouter = (routers, level) => {
|
|||||||
} else if (router.component) {
|
} else if (router.component) {
|
||||||
const component = router.component
|
const component = router.component
|
||||||
if (component === 'Layout') {
|
if (component === 'Layout') {
|
||||||
if (router.children && router.children.length > 0) {
|
router.path = "/" + common.uuid()
|
||||||
const children = filterAsyncRouter(router.children, level + 1);
|
router.component = level > 0 ? layoutModules[`../layout/none.vue`] : loadLayoutView(component)
|
||||||
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()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
router.path = router.path.startsWith('/') ? router.path : '/' + router.path
|
router.path = router.path.startsWith('/') ? router.path : '/' + router.path
|
||||||
router.component = loadView(component) || layoutModules[`../layout/empty.vue`]
|
router.component = loadView(component) || layoutModules[`../layout/empty.vue`]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
if (router.children && router.children.length) {
|
||||||
} else if (router.componentName) {
|
router.children = filterAsyncRouter(router.children, level + 1)
|
||||||
router.component = loadView(`/common/show-component`)
|
}
|
||||||
router.props = { name: router.componentName }
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -74,6 +56,34 @@ export const loadView = (view) => {
|
|||||||
return viewModules[`../views${view}.vue`]
|
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(){
|
export function generateRoutes(){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
request({
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user