-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathRoutesMeta.vue
101 lines (98 loc) · 2.4 KB
/
RoutesMeta.vue
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
<template>
<scroll-pane>
<div
v-if="activeRouteChange"
slot="scroll"
>
<state-inspector :state="{ options }" />
</div>
<div
v-else
slot="scroll"
class="no-route-data"
>
No route selected
</div>
</scroll-pane>
</template>
<script>
import StateInspector from '@front/components/StateInspector.vue'
import ScrollPane from '@front/components/ScrollPane.vue'
import { mapGetters } from 'vuex'
import { UNDEFINED } from '@utils/util'
export default {
components: {
ScrollPane,
StateInspector
},
computed: {
...mapGetters('routes', [
'activeRouteChange'
]),
options () {
return this.sanitizeRouteData(this.activeRouteChange)
},
to () {
return this.sanitizeRouteData(this.activeRouteChange.to)
},
from () {
return this.sanitizeRouteData(this.activeRouteChange.from)
}
},
methods: {
sanitizeRouteData (routeData) {
console.log(routeData)
const data = {
path: routeData.path
}
if (routeData.redirect) {
data.redirect = routeData.redirect
}
if (routeData.alias) {
data.alias = routeData.alias
}
if (!this.isEmptyObject(routeData.props)) {
data.props = routeData.props
}
if (routeData.name && routeData.name !== UNDEFINED) {
data.name = routeData.name
}
if (routeData.meta && !this.isEmptyObject(routeData.meta)) {
data.meta = routeData.meta
}
if (routeData.component) {
const component = {}
// if (routeData.component.__file) {
// component.file = routeData.component.__file
// }
if (routeData.component.template) {
component.template = routeData.component.template
}
if (routeData.component.props) {
component.props = routeData.component.props
}
if (!this.isEmptyObject(component)) {
data.component = component
}
}
if (routeData.children) {
data.children = []
routeData.children.forEach((item) => {
data.children.push(this.sanitizeRouteData(item))
})
}
return data
},
isEmptyObject (obj) {
return obj === UNDEFINED || !obj || Object.keys(obj).length === 0
}
}
}
</script>
<style lang="stylus" scoped>
.no-route-data
color: #ccc
text-align: center
margin-top: 50px
line-height: 30px
</style>