ant-design-vue/components/vc-menu/util.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-12-08 06:31:53 +00:00
export function noop () {
}
export function getKeyFromChildrenIndex (child, menuEventKey, index) {
const prefix = menuEventKey || ''
return child.key || `${prefix}item_${index}`
}
export function loopMenuItem (children, cb) {
2018-01-02 11:05:02 +00:00
let index = -1
children.forEach((c) => {
index++
if (c && c.type && c.type.isMenuItemGroup) {
c.$slots.default.forEach((c2) => {
index++
2018-01-16 11:15:07 +00:00
c.componentOptions && cb(c2, index)
2018-01-02 11:05:02 +00:00
})
} else {
2018-01-16 11:15:07 +00:00
c.componentOptions && cb(c, index)
2018-01-02 11:05:02 +00:00
}
})
2017-12-08 06:31:53 +00:00
}
export function loopMenuItemRecusively (children, keys, ret) {
if (!children || ret.find) {
return
}
2018-01-02 11:05:02 +00:00
children.forEach((c) => {
2017-12-08 06:31:53 +00:00
if (ret.find) {
return
}
2018-01-04 11:06:54 +00:00
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)) {
2017-12-08 06:31:53 +00:00
return
}
if (keys.indexOf(c.key) !== -1) {
ret.find = true
2018-01-04 11:06:54 +00:00
} else if (c.componentOptions.children) {
loopMenuItemRecusively(c.componentOptions.children, keys, ret)
2017-12-08 06:31:53 +00:00
}
}
})
}