summaryrefslogtreecommitdiff
path: root/UI source code/dns_mapping_ui-master/src/store/modules/permission.js
diff options
context:
space:
mode:
Diffstat (limited to 'UI source code/dns_mapping_ui-master/src/store/modules/permission.js')
-rw-r--r--UI source code/dns_mapping_ui-master/src/store/modules/permission.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/UI source code/dns_mapping_ui-master/src/store/modules/permission.js b/UI source code/dns_mapping_ui-master/src/store/modules/permission.js
new file mode 100644
index 0000000..513e259
--- /dev/null
+++ b/UI source code/dns_mapping_ui-master/src/store/modules/permission.js
@@ -0,0 +1,83 @@
+import { constantRouterMap } from '@/router/routers'
+import Layout from '@/layout/index'
+import ParentView from '@/components/ParentView'
+
+const permission = {
+ state: {
+ routers: constantRouterMap,
+ addRouters: [],
+ sidebarRouters: []
+ },
+ mutations: {
+ SET_ROUTERS: (state, routers) => {
+ state.addRouters = routers
+ state.routers = constantRouterMap.concat(routers)
+ },
+ SET_SIDEBAR_ROUTERS: (state, routers) => {
+ state.sidebarRouters = constantRouterMap.concat(routers)
+ }
+ },
+ actions: {
+ GenerateRoutes({ commit }, asyncRouter) {
+ commit('SET_ROUTERS', asyncRouter)
+ },
+ SetSidebarRouters({ commit }, sidebarRouter) {
+ commit('SET_SIDEBAR_ROUTERS', sidebarRouter)
+ }
+ }
+}
+
+export const filterAsyncRouter = (routers, lastRouter = false, type = false) => { // 遍历后台传来的路由字符串,转换为组件对象
+ return routers.filter(router => {
+ if (type && router.children) {
+ router.children = filterChildren(router.children)
+ }
+ if (router.component) {
+ if (router.component === 'Layout') { // Layout组件特殊处理
+ router.component = Layout
+ } else if (router.component === 'ParentView') {
+ router.component = ParentView
+ } else {
+ const component = router.component
+ router.component = loadView(component)
+ }
+ }
+ if (router.children != null && router.children && router.children.length) {
+ router.children = filterAsyncRouter(router.children, router, type)
+ } else {
+ delete router['children']
+ delete router['redirect']
+ }
+ return true
+ })
+}
+
+function filterChildren(childrenMap, lastRouter = false) {
+ var children = []
+ childrenMap.forEach((el, index) => {
+ if (el.children && el.children.length) {
+ if (el.component === 'ParentView') {
+ el.children.forEach(c => {
+ c.path = el.path + '/' + c.path
+ if (c.children && c.children.length) {
+ children = children.concat(filterChildren(c.children, c))
+ return
+ }
+ children.push(c)
+ })
+ return
+ }
+ }
+ if (lastRouter) {
+ el.path = lastRouter.path + '/' + el.path
+ }
+ children = children.concat(el)
+ })
+ return children
+}
+
+export const loadView = (view) => {
+ return (resolve) => require([`@/views/${view}`], resolve)
+}
+
+export default permission