setMenuMark.js
3.36 KB
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
import { getColumnLayoutList } from '@/api/portal.js'
import { validArray, nest2tile } from '@/utils/array.js'
export default {
data() {
return {
newRoutes: [],
indexLayoutConfig: {},
}
},
computed: {
indexRoutesIndex() {
return this.routes.findIndex(
(item) =>
item.path === '/' &&
item.name === '首页' &&
item.meta.title === '首页'
)
},
indexRoutesChildren() {
let indexChildren = []
if (
this.routes[this.indexRoutesIndex] &&
this.routes[this.indexRoutesIndex].children
) {
indexChildren = this.routes[this.indexRoutesIndex].children
}
return indexChildren
},
},
mounted() {
this.newRoutes = this.routes
this.getLayoutListByAlias()
this.$baseEventBus.$on('get-layout-config', () => {
this.getLayoutListByAlias()
})
},
methods: {
getLayoutListByAlias() {
if (this.routes && this.routes.length) {
const routeList = nest2tile(this.routes)
const columnLayoutRoute = routeList.filter((item) => {
const itemRouteExtend =
item.routeExtend && JSON.parse(item.routeExtend)
return (
(item.meta && item.meta.index) ||
(itemRouteExtend &&
itemRouteExtend.component == '@/views/home/index') ||
item.alias === 'Index'
)
})
const columnAlias = columnLayoutRoute.map((item) => {
const itemRouteExtend =
item.routeExtend && JSON.parse(item.routeExtend)
return (
item.meta.alias ||
((itemRouteExtend &&
itemRouteExtend.component == '@/views/home/index') ||
item.alias === 'Index'
? 'default_front'
: '')
)
})
getColumnLayoutList(
validArray(columnAlias).join(',') || 'default_front'
).then((res) => {
if (res && res.length > 0) {
this.indexLayoutConfig = res.reduce((pre, cur) => {
pre[cur.alias] = cur.identifyChange === 2
return pre
}, {})
this.getRoutes()
}
})
}
},
getRoutes() {
let routeList = _.cloneDeep(this.routes)
routeList.forEach((item) => {
if (item.children && item.children.length) {
item.children.forEach((child) => {
const itemRouteExtend =
child.routeExtend && JSON.parse(child.routeExtend)
if (
(child.meta && child.meta.index) ||
child.alias === 'Index' ||
(itemRouteExtend &&
itemRouteExtend.component == '@/views/home/index')
) {
child.meta.isNew =
(itemRouteExtend &&
itemRouteExtend.component == '@/views/home/index') ||
child.alias === 'Index'
? this.indexLayoutConfig['default_front']
: this.indexLayoutConfig[child.meta && child.meta.alias]
}
})
if (item.type && item.type === 'catalog' && item.meta) {
item.meta.isNew = this.hasLeastOneNew(item.children)
}
}
})
this.newRoutes = routeList
},
hasLeastOneNew(data) {
return (
data && data.length && data.some((item) => item.meta && item.meta.isNew)
)
},
},
}