-
Notifications
You must be signed in to change notification settings - Fork 655
/
Copy pathindex.js
116 lines (109 loc) · 2.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import Utils from '@/lin/util/util'
import adminConfig from './admin'
import bookConfig from './book' // 引入图书管理路由文件
import pluginsConfig from './plugin'
// eslint-disable-next-line import/no-mutable-exports
let homeRouter = [
{
title: '林间有风',
type: 'view',
name: Symbol('about'),
route: '/about',
filePath: 'view/about/about.vue',
inNav: true,
icon: 'iconfont icon-iconset0103',
isElementIcon: false,
order: 1,
},
{
title: '日志管理',
type: 'view',
name: Symbol('log'),
route: '/log',
filePath: 'view/log/log.vue',
inNav: true,
icon: 'iconfont icon-rizhiguanli',
isElementIcon: false,
order: 2,
permission: ['查询所有日志'],
},
{
title: '个人中心',
type: 'view',
name: Symbol('center'),
route: '/center',
filePath: 'view/center/center.vue',
inNav: false,
icon: 'iconfont icon-rizhiguanli',
isElementIcon: false,
},
{
title: '404',
type: 'view',
name: Symbol('404'),
route: '/404',
filePath: 'view/error-page/404.vue',
inNav: false,
icon: 'iconfont icon-rizhiguanli',
isElementIcon: false,
},
bookConfig,
adminConfig,
]
// 接入插件
const plugins = [...pluginsConfig]
filterPlugin(homeRouter)
homeRouter = homeRouter.concat(plugins)
// 处理顺序
homeRouter = Utils.sortByOrder(homeRouter)
deepReduceName(homeRouter)
export default homeRouter
/**
* 筛除已经被添加的插件
*/
function filterPlugin(data) {
if (plugins.length === 0) {
return
}
if (Array.isArray(data)) {
data.forEach(item => {
filterPlugin(item)
})
} else {
const findResult = plugins.findIndex(item => data === item)
if (findResult >= 0) {
plugins.splice(findResult, 1)
}
if (data.children) {
filterPlugin(data.children)
}
}
}
/**
* 使用 Symbol 处理 name 字段, 保证唯一性
*/
function deepReduceName(target) {
if (Array.isArray(target)) {
target.forEach(item => {
if (typeof item !== 'object') {
return
}
deepReduceName(item)
})
return
}
if (typeof target === 'object') {
if (typeof target.name !== 'symbol') {
target.name = target.name || Utils.getRandomStr()
target.name = Symbol(target.name)
}
if (Array.isArray(target.children)) {
target.children.forEach(item => {
if (typeof item !== 'object') {
return
}
deepReduceName(item)
})
}
}
}