From 1f2fa5c2afe52f5db538371fdf96b0de59d343a9 Mon Sep 17 00:00:00 2001 From: xy <271556543@qq.com> Date: Fri, 2 Jun 2023 14:54:11 +0800 Subject: [PATCH] 2023-6-2 --- src/store/modules/permission.js | 53 ++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index 9254dfa..2c6773b 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -6,6 +6,28 @@ import Layout from '@/layout' import { getAuthMenu } from '@/api/user.js' +const pathHandler = (item) => { + if(!item.path || item.path?.includes('#') || item.path == ''){ + return item.id + '_key' + } + if(/^\^/.test(item.path)){ + return item.path.replace(/^\^+/g,"") + } + if(/^\$/.test(item.path)){ + return item.path.replace(/^\$+/g,"") + } + return item.path + // if(path.includes('$')){ + // return path.replace(/^\$+/g,"") + // } + // if(path.includes('^')){ + // return path.replace(/^\^+/g,"") + // } + // if(path.includes('#') || path == ''){ + // return id + '_key' + // } + // return path +} const componentHandler = (path) => { //return path === '#'|| path == '' ? Layout : loadView(path) if(path === '#' || path === ''){ @@ -109,6 +131,29 @@ export function generaMenu(routes, data) { } }] }) + }else if(/^\^/.test(item.path)){ + const menu = { + path: pathHandler(item), + component: Layout, + children: [{ + path: "", + name: 'menu_' + item.id, + component: (item.url.includes('#')||item.path == '') ? Layout : loadView(item.url), + meta: { + title: item.name, + id: item.id, + roles: ['admin'], + auths:item.has_auth_node_tags, + params, + + icon: item.icon + } + }, ] + } + if (item.children) { + generaMenu(menu.children, item.children) + } + routes.push(menu) } else { var path = item.url; if (item.path != "null" && item.path != null && item.path != "") { @@ -132,6 +177,7 @@ export function generaMenu(routes, data) { if (item.children) { generaMenu(menu.children, item.children) } + routes.push(menu) } }) @@ -167,8 +213,8 @@ const actions = { commit('SET_ROOTMENU',data) - let routes = data.find(item => item.path === '/contract').children - let root = data.map(item => { + let routes = data?.find(item => item.path === '/contract').children + let root = data?.map(item => { let menu = [] generaMenu(menu,item.children) commit('SET_SIDEBARMENUMAP', { k: item.path, v: menu }) @@ -176,7 +222,7 @@ const actions = { item.redirect = item.children[0]?.path } if(item.path === '/contract') { - item.redirect = '/contract/contract/contractList' + item.redirect = '/contract/dashboard' } item.hidden = true return item @@ -188,7 +234,6 @@ const actions = { console.log(asyncRoutes) let accessedRoutes if (roles.includes('admin')) { - // alert(JSON.stringify(asyncRoutes)) accessedRoutes = asyncRoutes || [] } else { accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)