You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.4 KiB
JavaScript
89 lines
2.4 KiB
JavaScript
import Layout from '@/layouts'
|
|
/**
|
|
* @description all模式渲染后端返回路由
|
|
* @param constantRoutes
|
|
* @returns {*}
|
|
*/
|
|
export function convertRouter(asyncRoutes) {
|
|
const tempRouters = []
|
|
asyncRoutes.forEach((route) => {
|
|
if (route.component && route.menuType !== 'F') {
|
|
if (route.component === '#' || route.component === '/' || route.path === '/') {
|
|
route.component = Layout
|
|
} else if (route.component === 'EmptyLayout') {
|
|
route.component = (resolve) =>
|
|
require(['@/layouts/EmptyLayout'], resolve)
|
|
} else {
|
|
const index = route.component.indexOf('views')
|
|
const path =
|
|
index > 0 ? route.component.slice(index) : `views${route.component}`
|
|
route.component = (resolve) => require([`@/${path}`], resolve)
|
|
}
|
|
route.hidden = !(route.hidden === '1')
|
|
route.meta = {
|
|
title: route.title,
|
|
subtitle: route.subtitle,
|
|
icon: route.icon,
|
|
activeMenu: route.activeMenu,
|
|
rootPaths: route.rootPaths
|
|
}
|
|
if (route.children && route.children.length) { route.children = convertRouter(route.children) }
|
|
if (route.children && route.children.length === 0) delete route.children
|
|
tempRouters.push(route)
|
|
}
|
|
})
|
|
return tempRouters
|
|
}
|
|
/**
|
|
* @description 获取按钮权限列表
|
|
* @param asyncRoutes
|
|
* @returns [*]
|
|
*/
|
|
|
|
export function convertPermission(asyncRoutes, that) {
|
|
if (that === undefined) that = []
|
|
asyncRoutes.forEach(route => {
|
|
if (route.menuType === 'F') {
|
|
that.push(route.perm)
|
|
}
|
|
if (route.children && route.children.length) {
|
|
convertPermission(route.children, that)
|
|
}
|
|
})
|
|
return that
|
|
}
|
|
|
|
/**
|
|
* @description 判断当前路由是否包含权限
|
|
* @param permissions
|
|
* @param route
|
|
* @returns {boolean|*}
|
|
*/
|
|
function hasPermission(permissions, route) {
|
|
if (route && route.permission) {
|
|
return permissions.some((role) => route.permission.includes(role))
|
|
} else {
|
|
return true
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @description intelligence模式根据permissions数组拦截路由
|
|
* @param routes
|
|
* @param permissions
|
|
* @returns {[]}
|
|
*/
|
|
export function filterAsyncRoutes(routes, permissions) {
|
|
const finallyRoutes = []
|
|
routes.forEach((route) => {
|
|
const item = { ...route }
|
|
if (hasPermission(permissions, item)) {
|
|
if (item.children) {
|
|
item.children = filterAsyncRoutes(item.children, permissions)
|
|
}
|
|
finallyRoutes.push(item)
|
|
}
|
|
})
|
|
return finallyRoutes
|
|
}
|