-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
47 lines (44 loc) · 1.16 KB
/
util.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
export function noop () {
}
export function getKeyFromChildrenIndex (child, menuEventKey, index) {
const prefix = menuEventKey || ''
return child.key || `${prefix}item_${index}`
}
export function loopMenuItem (children, cb) {
let index = -1
children.forEach((c) => {
index++
if (c && c.type && c.type.isMenuItemGroup) {
c.$slots.default.forEach((c2) => {
index++
c.componentOptions && cb(c2, index)
})
} else {
c.componentOptions && cb(c, index)
}
})
}
export function loopMenuItemRecusively (children, keys, ret) {
if (!children || ret.find) {
return
}
children.forEach((c) => {
if (ret.find) {
return
}
if (c.data && c.data.slot && c.data.slot !== 'default') {
return
}
if (c && c.componentOptions) {
const options = c.componentOptions.Ctor.options
if (!options || !(options.isSubMenu || options.isMenuItem || options.isMenuItemGroup)) {
return
}
if (keys.indexOf(c.key) !== -1) {
ret.find = true
} else if (c.componentOptions.children) {
loopMenuItemRecusively(c.componentOptions.children, keys, ret)
}
}
})
}