|
@@ -46,10 +46,43 @@ const mutations = {
|
|
|
state.permission = permission
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+function getFirstMenu(routes) {
|
|
|
+ let firstMenu = null
|
|
|
+ routes.forEach(item => {
|
|
|
+ if(item.children?.length > 0 && !item.hidden) {
|
|
|
+ firstMenu = pathErgodic(item)
|
|
|
+ item.redirect = firstMenu
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return routes
|
|
|
+}
|
|
|
+
|
|
|
+function pathErgodic(item) {
|
|
|
+ let firstMenu = null
|
|
|
+ item.children.forEach(i => {
|
|
|
+ if(!firstMenu && i.children?.length > 0) {
|
|
|
+ firstMenu = pathErgodic(i)
|
|
|
+ } else {
|
|
|
+ if(!firstMenu && checkPathUrl(i.path)) {
|
|
|
+ firstMenu = i.path
|
|
|
+ } else {
|
|
|
+ if(!firstMenu && !i.hidden) {
|
|
|
+ firstMenu = item.path + '/' + i.path
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return firstMenu
|
|
|
+}
|
|
|
+// 判断path有没有带/,并且是第一个位置
|
|
|
+function checkPathUrl(path) {
|
|
|
+ return path.indexOf('/') === 0 ? true : false
|
|
|
+}
|
|
|
// 路由
|
|
|
+
|
|
|
// 递归遍历数组
|
|
|
function recursionRouter (arr) {
|
|
|
-
|
|
|
if (arr.length > 0) {
|
|
|
let newArr = [];
|
|
|
for (let i = 0; i < arr.length; i++) {
|
|
@@ -66,9 +99,8 @@ function recursionRouter (arr) {
|
|
|
// }
|
|
|
arr[i].hid == 0 ? obj.hidden = false : obj.hidden = true
|
|
|
// console.log('高亮标签'+arr[i].parentPermission,'普通路径'+arr[i].path)
|
|
|
-
|
|
|
obj.path = arr[i].path;
|
|
|
- obj.meta = { 'title': arr[i].name, 'icon': arr[i].icon, 'noCache': arr[i].keepAlive, 'activeMenu': arr[i].parentPermission }
|
|
|
+ obj.meta = { 'title': arr[i].name, 'icon': arr[i].icon, 'noCache': arr[i].keepAlive, 'activeMenu': arr[i].parentPermission, 'belongTopMenu': arr[i].belongTopMenu }
|
|
|
if (arr[i].sysMenus && arr[i].sysMenus.length > 0) {
|
|
|
obj.children = recursionRouter(arr[i].sysMenus);
|
|
|
}
|
|
@@ -78,6 +110,42 @@ function recursionRouter (arr) {
|
|
|
return newArr
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// 设置 belongTopMenu, 顶部菜单
|
|
|
+function addTopMenu(arr) {
|
|
|
+ if(arr.length > 0) {
|
|
|
+ let newArr = [];
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ if (arr[i].type == 1) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ let obj = arr[i]
|
|
|
+ obj.belongTopMenu = obj.path
|
|
|
+
|
|
|
+ if (arr[i].sysMenus && arr[i].sysMenus.length > 0) {
|
|
|
+ obj.sysMenus = setTopMenu(arr[i].sysMenus, obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ newArr.push(obj)
|
|
|
+ }
|
|
|
+ return newArr
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function setTopMenu(arr, topParentArr) {
|
|
|
+ let newArr = [];
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ let obj = arr[i]
|
|
|
+ obj.belongTopMenu = topParentArr.path
|
|
|
+ if (arr[i].sysMenus && arr[i].sysMenus.length > 0) {
|
|
|
+ obj.sysMenus = setTopMenu(arr[i].sysMenus, topParentArr);
|
|
|
+ }
|
|
|
+
|
|
|
+ newArr.push(obj)
|
|
|
+ }
|
|
|
+ return newArr
|
|
|
+}
|
|
|
+
|
|
|
// 权限
|
|
|
// 递归遍历数组
|
|
|
let tempArr = []
|
|
@@ -95,7 +163,10 @@ const actions = {
|
|
|
// 获取接口返回的权限菜单
|
|
|
getSilder().then(res => {
|
|
|
if (res.code == 200) {
|
|
|
- let newData = recursionRouter(res.data);
|
|
|
+ let result = addTopMenu(res.data)
|
|
|
+ let newData = recursionRouter(result);
|
|
|
+ newData = getFirstMenu(newData)
|
|
|
+ // console.log((newData))
|
|
|
recursionPermission(res.data)
|
|
|
let accessedRoutes
|
|
|
|