mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2026-05-15 00:00:02 +08:00
支持 配置路由地址 但菜单隐藏 仍加载路由
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user