forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppMenu.js
More file actions
133 lines (111 loc) · 3 KB
/
AppMenu.js
File metadata and controls
133 lines (111 loc) · 3 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {
QExpansionItem,
QList,
QItem,
QItemSection,
QIcon,
QBadge,
Ripple
} from 'quasar'
import { mdiArrowDownThinCircleOutline } from '@quasar/extras/mdi-v6'
import { h, ref, watch, onBeforeUpdate, withDirectives } from 'vue'
import { useRoute } from 'vue-router'
import Menu from 'assets/menu.js'
import './AppMenu.sass'
function getParentVm (vm) {
if (vm.$parent !== void 0 && vm.$parent !== null) {
return vm.$parent
}
vm = vm.$.parent
while (vm !== void 0 && vm !== null) {
if (vm.proxy !== void 0 && vm.proxy !== null) {
return vm.proxy
}
vm = vm.parent
}
}
export default {
name: 'AppMenu',
setup () {
const $route = useRoute()
const routePath = $route.path
const rootRef = ref(null)
watch(() => $route.path, val => {
showMenu(childRefs[ val ])
})
let childRefs = []
onBeforeUpdate(() => {
childRefs = []
})
function showMenu (vm) {
if (vm !== void 0 && vm !== rootRef.value) {
vm.show !== void 0 && vm.show()
const parent = getParentVm(vm)
if (parent !== void 0) {
showMenu(parent)
}
}
}
function getDrawerMenu (menu, path, level) {
if (menu.children !== void 0) {
return h(
QExpansionItem,
{
class: 'non-selectable',
ref: vm => { if (vm) { childRefs[ path ] = vm } },
key: `${menu.name}-${path}`,
label: menu.name,
dense: true,
icon: menu.icon,
expandIcon: mdiArrowDownThinCircleOutline,
defaultOpened: menu.opened || routePath.startsWith(path),
expandSeparator: true,
switchToggleSide: level > 0,
denseToggle: level > 0
},
() => menu.children.map(item => getDrawerMenu(
item,
path + (item.path !== void 0 ? '/' + item.path : ''),
level + 1
))
)
}
const props = {
ref: vm => { if (vm) { childRefs[ path ] = vm } },
key: path,
class: 'app-menu-entry non-selectable',
to: path,
dense: level > 0,
insetLevel: level > 1 ? 1.2 : level
}
menu.external === true && Object.assign(props, {
to: void 0,
clickable: true,
tag: 'a',
href: menu.path,
target: '_blank'
})
const child = []
menu.icon !== void 0 && child.push(
h(QItemSection, {
avatar: true
}, () => h(QIcon, { name: menu.icon }))
)
child.push(
h(QItemSection, () => menu.name)
)
menu.badge !== void 0 && child.push(
h(QItemSection, {
side: true
}, () => h(QBadge, { label: menu.badge, color: 'brand-primary' }))
)
return withDirectives(
h(QItem, props, () => child),
[[Ripple]]
)
}
return () => h(QList, { ref: rootRef, class: 'app-menu', dense: true }, () => Menu.map(
item => getDrawerMenu(item, '/' + item.path, 0)
))
}
}