Skip to content

Commit 09174a6

Browse files
authored
Fix route empty children (#322)
* fix(route):修复路由配置中children为空的情况 * fix: 修复路由sharking逻辑 * fix: remove debug info
1 parent 142f5e5 commit 09174a6

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

src/component/layout/breadcrumb.vue

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ export default {
2121
return this.stageInfo.map(item => item.title).filter(item => !!item)
2222
},
2323
},
24-
// created() {},
25-
// mounted() {},
26-
// watch: {},
27-
// components: {},
2824
}
2925
</script>
3026

src/component/layout/menu-tab.vue

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default {
2929
}
3030
const father = this.stageInfo[this.stageInfo.length - 2]
3131
if (father.type === 'tab') {
32-
console.log(father.children)
3332
const menus = []
3433
father.children.forEach(item => {
3534
if (item.inNav) {

src/lin/util/sse.js

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default class Sse {
1515
*/
1616
constructor(url, events) {
1717
/* eslint-disable no-undef */
18-
console.log(url, events)
1918
this.source = new EventSourcePolyfill(url, {
2019
headers: {
2120
Authorization: getToken('access_token'),

src/plugin/custom/stage-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const CustomRouter = {
1212
title: 'upload 图像上传',
1313
type: 'view',
1414
name: 'ImgsUploadDemo',
15-
route: '/upload-image/stage1',
15+
route: '/custom/upload-image',
1616
filePath: 'plugin/custom/view/upload-image.vue',
1717
inNav: true,
1818
icon: 'iconfont icon-zidingyi',

src/router/home-router.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function deepTravel(config, fuc) {
66
config.forEach(subConfig => {
77
deepTravel(subConfig, fuc)
88
})
9-
} else if (config.children) {
9+
} else if (config.children && config.children.length) {
1010
config.children.forEach(subConfig => {
1111
deepTravel(subConfig, fuc)
1212
})

src/store/getter.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,34 @@ export const readedMessages = state => state.readedMessages
2727

2828
export const unreadMessages = state => state.unreadMessages
2929

30+
/**
31+
* 在侧边栏展示时,如果当前路由 children 属性为空,则删除该路由
32+
* @param {*} arr 路由配置项数据
33+
*/
3034
function IterationDelateMenuChildren(arr) {
3135
if (arr.length) {
3236
for (const i in arr) {
3337
if (arr[i].children && !arr[i].children.length) {
34-
delete arr[i] // eslint-disable-line
35-
} else if (arr[i].children && !arr[i].children.length) {
38+
delete arr[i]
39+
} else if (arr[i].children && arr[i].children.length) {
3640
IterationDelateMenuChildren(arr[i].children)
3741
}
3842
}
3943
}
4044
return arr
4145
}
4246

47+
/**
48+
* Shaking 掉无限制路由
49+
* @param {array} stageConfig 路由配置项数据
50+
* @param {array} permissions 当前登录管理员所拥有的权限集合
51+
* @param {object} currentUser 当前登录管理员
52+
*/
4353
function permissionShaking(stageConfig, permissions, currentUser) {
44-
// eslint-disable-line
4554
const shookConfig = stageConfig.filter(route => {
4655
if (Util.hasPermission(permissions, route, currentUser)) {
4756
if (route.children && route.children.length) {
48-
route.children = permissionShaking(route.children, permissions, currentUser) // eslint-disable-line
57+
route.children = permissionShaking(route.children, permissions, currentUser)
4958
}
5059
return true
5160
}
@@ -176,7 +185,7 @@ export const getStageInfo = state => {
176185
return result
177186
}
178187

179-
if (stages.children) {
188+
if (stages.children && stages.children.length) {
180189
result = findStage(stages.children, name)
181190
if (result) {
182191
result.unshift(stages)

0 commit comments

Comments
 (0)