菜单配置
This commit is contained in:
parent
a9855f5d72
commit
ada7408941
|
|
@ -8,120 +8,120 @@ import InnerLink from '@/layout/components/InnerLink'
|
|||
// 匹配views里面所有的.vue文件
|
||||
const modules = import.meta.glob('./../../views/**/*.vue')
|
||||
|
||||
const usePermissionStore = defineStore(
|
||||
'permission',
|
||||
{
|
||||
const usePermissionStore = defineStore('permission', {
|
||||
state: () => ({
|
||||
routes: [],
|
||||
addRoutes: [],
|
||||
defaultRoutes: [],
|
||||
topbarRouters: [],
|
||||
sidebarRouters: []
|
||||
routes: [],
|
||||
addRoutes: [],
|
||||
defaultRoutes: [],
|
||||
topbarRouters: [],
|
||||
sidebarRouters: [],
|
||||
}),
|
||||
actions: {
|
||||
setRoutes(routes) {
|
||||
this.addRoutes = routes
|
||||
this.routes = constantRoutes.concat(routes)
|
||||
},
|
||||
setDefaultRoutes(routes) {
|
||||
this.defaultRoutes = constantRoutes.concat(routes)
|
||||
},
|
||||
setTopbarRoutes(routes) {
|
||||
this.topbarRouters = routes
|
||||
},
|
||||
setSidebarRouters(routes) {
|
||||
this.sidebarRouters = routes
|
||||
},
|
||||
generateRoutes(roles) {
|
||||
return new Promise(resolve => {
|
||||
// 向后端请求路由数据
|
||||
getRouters().then(res => {
|
||||
const sdata = JSON.parse(JSON.stringify(res.data))
|
||||
const rdata = JSON.parse(JSON.stringify(res.data))
|
||||
const defaultData = JSON.parse(JSON.stringify(res.data))
|
||||
const sidebarRoutes = filterAsyncRouter(sdata)
|
||||
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
|
||||
const defaultRoutes = filterAsyncRouter(defaultData)
|
||||
const asyncRoutes = filterDynamicRoutes(dynamicRoutes)
|
||||
asyncRoutes.forEach(route => { router.addRoute(route) })
|
||||
this.setRoutes(rewriteRoutes)
|
||||
this.setSidebarRouters(constantRoutes.concat(sidebarRoutes))
|
||||
this.setDefaultRoutes(sidebarRoutes)
|
||||
this.setTopbarRoutes(defaultRoutes)
|
||||
resolve(rewriteRoutes)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
setRoutes(routes) {
|
||||
this.addRoutes = routes
|
||||
this.routes = constantRoutes.concat(routes)
|
||||
},
|
||||
setDefaultRoutes(routes) {
|
||||
this.defaultRoutes = constantRoutes.concat(routes)
|
||||
},
|
||||
setTopbarRoutes(routes) {
|
||||
this.topbarRouters = routes
|
||||
},
|
||||
setSidebarRouters(routes) {
|
||||
this.sidebarRouters = routes
|
||||
},
|
||||
generateRoutes(roles) {
|
||||
return new Promise((resolve) => {
|
||||
// 向后端请求路由数据
|
||||
getRouters().then((res) => {
|
||||
const sdata = JSON.parse(JSON.stringify(res.data))
|
||||
const rdata = JSON.parse(JSON.stringify(res.data))
|
||||
const defaultData = JSON.parse(JSON.stringify(res.data))
|
||||
const sidebarRoutes = filterAsyncRouter(sdata)
|
||||
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
|
||||
const defaultRoutes = filterAsyncRouter(defaultData)
|
||||
const asyncRoutes = filterDynamicRoutes(dynamicRoutes)
|
||||
asyncRoutes.forEach((route) => {
|
||||
router.addRoute(route)
|
||||
})
|
||||
this.setRoutes(rewriteRoutes)
|
||||
this.setSidebarRouters(constantRoutes.concat(sidebarRoutes))
|
||||
this.setDefaultRoutes(sidebarRoutes)
|
||||
this.setTopbarRoutes(defaultRoutes)
|
||||
resolve(rewriteRoutes)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// 遍历后台传来的路由字符串,转换为组件对象
|
||||
function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
|
||||
return asyncRouterMap.filter(route => {
|
||||
if (type && route.children) {
|
||||
route.children = filterChildren(route.children)
|
||||
}
|
||||
if (route.component) {
|
||||
// Layout ParentView 组件特殊处理
|
||||
if (route.component === 'Layout') {
|
||||
route.component = Layout
|
||||
} else if (route.component === 'ParentView') {
|
||||
route.component = ParentView
|
||||
} else if (route.component === 'InnerLink') {
|
||||
route.component = InnerLink
|
||||
} else {
|
||||
route.component = loadView(route.component)
|
||||
}
|
||||
}
|
||||
if (route.children != null && route.children && route.children.length) {
|
||||
route.children = filterAsyncRouter(route.children, route, type)
|
||||
} else {
|
||||
delete route['children']
|
||||
delete route['redirect']
|
||||
}
|
||||
return true
|
||||
})
|
||||
return asyncRouterMap.filter((route) => {
|
||||
if (type && route.children) {
|
||||
route.children = filterChildren(route.children)
|
||||
}
|
||||
if (route.component) {
|
||||
// Layout ParentView 组件特殊处理
|
||||
if (route.component === 'Layout') {
|
||||
route.component = Layout
|
||||
} else if (route.component === 'ParentView') {
|
||||
route.component = ParentView
|
||||
} else if (route.component === 'InnerLink') {
|
||||
route.component = InnerLink
|
||||
} else {
|
||||
route.component = loadView(route.component)
|
||||
}
|
||||
}
|
||||
if (route.children != null && route.children && route.children.length) {
|
||||
route.children = filterAsyncRouter(route.children, route, type)
|
||||
} else {
|
||||
delete route['children']
|
||||
delete route['redirect']
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
function filterChildren(childrenMap, lastRouter = false) {
|
||||
var children = []
|
||||
childrenMap.forEach(el => {
|
||||
el.path = lastRouter ? lastRouter.path + '/' + el.path : el.path
|
||||
if (el.children && el.children.length && el.component === 'ParentView') {
|
||||
children = children.concat(filterChildren(el.children, el))
|
||||
} else {
|
||||
children.push(el)
|
||||
}
|
||||
})
|
||||
return children
|
||||
var children = []
|
||||
childrenMap.forEach((el) => {
|
||||
el.path = lastRouter ? lastRouter.path + '/' + el.path : el.path
|
||||
if (el.children && el.children.length && el.component === 'ParentView') {
|
||||
children = children.concat(filterChildren(el.children, el))
|
||||
} else {
|
||||
children.push(el)
|
||||
}
|
||||
})
|
||||
return children
|
||||
}
|
||||
|
||||
// 动态路由遍历,验证是否具备权限
|
||||
export function filterDynamicRoutes(routes) {
|
||||
const res = []
|
||||
routes.forEach(route => {
|
||||
if (route.permissions) {
|
||||
if (auth.hasPermiOr(route.permissions)) {
|
||||
res.push(route)
|
||||
}
|
||||
} else if (route.roles) {
|
||||
if (auth.hasRoleOr(route.roles)) {
|
||||
res.push(route)
|
||||
}
|
||||
}
|
||||
})
|
||||
return res
|
||||
const res = []
|
||||
routes.forEach((route) => {
|
||||
if (route.permissions) {
|
||||
if (auth.hasPermiOr(route.permissions)) {
|
||||
res.push(route)
|
||||
}
|
||||
} else if (route.roles) {
|
||||
if (auth.hasRoleOr(route.roles)) {
|
||||
res.push(route)
|
||||
}
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
export const loadView = (view) => {
|
||||
let res
|
||||
for (const path in modules) {
|
||||
const dir = path.split('views/')[1].split('.vue')[0]
|
||||
if (dir === view) {
|
||||
res = () => modules[path]()
|
||||
let res
|
||||
for (const path in modules) {
|
||||
const dir = path.split('views/')[1].split('.vue')[0]
|
||||
if (dir === view) {
|
||||
res = () => modules[path]()
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
return res
|
||||
}
|
||||
|
||||
export default usePermissionStore
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>业务类型管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="BusinessType"></script>
|
||||
|
||||
<style></style>
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>运检站管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="InspectionStation"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>人员分类管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="PersonCategory"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>人员性质管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="PersonNature"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>计划类别管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="PlanCategory"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>计划专业管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="PlanProfessional"></script>
|
||||
|
||||
<style></style>
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>岗位管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Position"></script>
|
||||
|
||||
<style></style>
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>项目部管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="ProjectDept"></script>
|
||||
|
||||
<style></style>
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>工作量类别管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="WorkloadCategory"></script>
|
||||
|
||||
<style></style>
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>月报管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="monthlyReport"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>人员管理123</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Person"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>日计划填报管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="DailyPlan"></script>
|
||||
|
||||
<style></style>
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>月计划填报管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="MonthlyPlan"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>计划管理</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Plan"></script>
|
||||
|
||||
<style></style>
|
||||
|
||||
Loading…
Reference in New Issue