import { getComponentFromProp } from '../_util/props-util' import PropTypes from '../_util/vue-types' import arrayTreeFilter from 'array-tree-filter' import BaseMixin from '../_util/BaseMixin' export default { name: 'CascaderMenus', mixins: [BaseMixin], props: { value: PropTypes.array.def([]), activeValue: PropTypes.array.def([]), options: PropTypes.array.isRequired, prefixCls: PropTypes.string.def('rc-cascader-menus'), expandTrigger: PropTypes.string.def('click'), // onSelect: PropTypes.func, visible: PropTypes.bool.def(false), dropdownMenuColumnStyle: PropTypes.object, defaultFieldNames: PropTypes.object, fieldNames: PropTypes.object, expandIcon: PropTypes.any, loadingIcon: PropTypes.any, }, data () { this.menuItems = {} return {} }, mounted () { this.$nextTick(() => { this.scrollActiveItemToView() }) }, watch: { visible (val) { if (val) { this.$nextTick(() => { this.scrollActiveItemToView() }) } }, }, methods: { getFieldName (name) { const { fieldNames, defaultFieldNames } = this.$props // 防止只设置单个属性的名字 return fieldNames[name] || defaultFieldNames[name] }, getOption (option, menuIndex) { const { prefixCls, expandTrigger } = this const loadingIcon = getComponentFromProp(this, 'loadingIcon') const expandIcon = getComponentFromProp(this, 'expandIcon') const onSelect = (e) => { this.__emit('select', option, menuIndex, e) } const key = option[this.getFieldName('value')] const expandProps = { attrs: { }, on: { click: onSelect, }, key: Array.isArray(key) ? key.join('__ant__') : key, } let menuItemCls = `${prefixCls}-menu-item` let expandIconNode = null const hasChildren = option[this.getFieldName('children')] && option[this.getFieldName('children')].length > 0 if (hasChildren || option.isLeaf === false) { menuItemCls += ` ${prefixCls}-menu-item-expand` if (!option.loading) { expandIconNode = (
) } } if (expandTrigger === 'hover' && hasChildren) { expandProps.on = { mouseenter: this.delayOnSelect.bind(this, onSelect), mouseleave: this.delayOnSelect.bind(this), click: onSelect, } } if (this.isActiveOption(option, menuIndex)) { menuItemCls += ` ${prefixCls}-menu-item-active` expandProps.ref = this.getMenuItemRef(menuIndex) } if (option.disabled) { menuItemCls += ` ${prefixCls}-menu-item-disabled` } let loadingIconNode = null if (option.loading) { menuItemCls += ` ${prefixCls}-menu-item-loading` loadingIconNode = loadingIcon || null } let title = '' if (option.title) { title = option.title } else if (typeof option[this.getFieldName('label')] === 'string') { title = option[this.getFieldName('label')] } expandProps.attrs.title = title expandProps.class = menuItemCls return (