ant-design-vue/components/vc-cascader/Menus.jsx

182 lines
5.5 KiB
Vue
Raw Normal View History

2019-01-12 11:33:27 +08:00
import { getComponentFromProp } from '../_util/props-util';
import PropTypes from '../_util/vue-types';
import arrayTreeFilter from 'array-tree-filter';
import BaseMixin from '../_util/BaseMixin';
2018-03-02 22:12:52 +08:00
export default {
2018-10-12 19:22:01 +08:00
name: 'CascaderMenus',
2018-03-02 22:12:52 +08:00
mixins: [BaseMixin],
props: {
value: PropTypes.array.def([]),
activeValue: PropTypes.array.def([]),
2019-02-18 22:13:29 +08:00
options: PropTypes.array,
2018-03-02 22:12:52 +08:00
prefixCls: PropTypes.string.def('rc-cascader-menus'),
expandTrigger: PropTypes.string.def('click'),
// onSelect: PropTypes.func,
visible: PropTypes.bool.def(false),
dropdownMenuColumnStyle: PropTypes.object,
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
defaultFieldNames: PropTypes.object,
fieldNames: PropTypes.object,
expandIcon: PropTypes.any,
loadingIcon: PropTypes.any,
2018-03-02 22:12:52 +08:00
},
2019-01-12 11:33:27 +08:00
data() {
this.menuItems = {};
return {};
2018-03-02 22:12:52 +08:00
},
watch: {
2019-01-12 11:33:27 +08:00
visible(val) {
2018-03-02 22:12:52 +08:00
if (val) {
this.$nextTick(() => {
2019-01-12 11:33:27 +08:00
this.scrollActiveItemToView();
});
2018-03-02 16:54:22 +08:00
}
2018-03-02 22:12:52 +08:00
},
},
2019-02-01 17:23:00 +08:00
mounted() {
this.$nextTick(() => {
this.scrollActiveItemToView();
});
},
2018-03-02 22:12:52 +08:00
methods: {
2019-01-12 11:33:27 +08:00
getFieldName(name) {
const { fieldNames, defaultFieldNames } = this.$props;
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
// 防止只设置单个属性的名字
2019-01-12 11:33:27 +08:00
return fieldNames[name] || defaultFieldNames[name];
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
},
2019-01-12 11:33:27 +08:00
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);
};
2019-02-18 22:13:29 +08:00
const onItemDoubleClick = e => {
this.__emit('itemDoubleClick', option, menuIndex, e);
};
2019-01-12 11:33:27 +08:00
const key = option[this.getFieldName('value')];
2018-03-02 22:12:52 +08:00
const expandProps = {
2019-09-02 22:49:34 +08:00
attrs: {
2019-09-11 22:35:25 +08:00
role: 'menuitem',
2019-09-02 22:49:34 +08:00
},
2018-03-02 22:12:52 +08:00
on: {
click: onSelect,
2019-11-20 15:49:31 +08:00
dblclick: onItemDoubleClick,
2019-09-02 22:49:34 +08:00
mousedown: e => e.preventDefault(),
2018-03-02 22:12:52 +08:00
},
2018-10-12 19:22:01 +08:00
key: Array.isArray(key) ? key.join('__ant__') : key,
2019-01-12 11:33:27 +08:00
};
let menuItemCls = `${prefixCls}-menu-item`;
let expandIconNode = null;
const hasChildren =
option[this.getFieldName('children')] && option[this.getFieldName('children')].length > 0;
2018-03-02 22:12:52 +08:00
if (hasChildren || option.isLeaf === false) {
2019-01-12 11:33:27 +08:00
menuItemCls += ` ${prefixCls}-menu-item-expand`;
if (!option.loading) {
2019-01-12 11:33:27 +08:00
expandIconNode = <span class={`${prefixCls}-menu-item-expand-icon`}>{expandIcon}</span>;
}
2018-03-02 22:12:52 +08:00
}
2019-09-02 22:49:34 +08:00
if (expandTrigger === 'hover' && (hasChildren || option.isLeaf === false)) {
2018-03-02 22:12:52 +08:00
expandProps.on = {
mouseenter: this.delayOnSelect.bind(this, onSelect),
mouseleave: this.delayOnSelect.bind(this),
click: onSelect,
2019-01-12 11:33:27 +08:00
};
2018-03-02 22:12:52 +08:00
}
if (this.isActiveOption(option, menuIndex)) {
2019-01-12 11:33:27 +08:00
menuItemCls += ` ${prefixCls}-menu-item-active`;
expandProps.ref = this.getMenuItemRef(menuIndex);
2018-03-02 22:12:52 +08:00
}
if (option.disabled) {
2019-01-12 11:33:27 +08:00
menuItemCls += ` ${prefixCls}-menu-item-disabled`;
2018-03-02 22:12:52 +08:00
}
2019-01-12 11:33:27 +08:00
let loadingIconNode = null;
2018-03-02 22:12:52 +08:00
if (option.loading) {
2019-01-12 11:33:27 +08:00
menuItemCls += ` ${prefixCls}-menu-item-loading`;
loadingIconNode = loadingIcon || null;
2018-03-02 22:12:52 +08:00
}
2019-01-12 11:33:27 +08:00
let title = '';
2018-03-02 22:12:52 +08:00
if (option.title) {
2019-01-12 11:33:27 +08:00
title = option.title;
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
} else if (typeof option[this.getFieldName('label')] === 'string') {
2019-01-12 11:33:27 +08:00
title = option[this.getFieldName('label')];
2018-03-02 22:12:52 +08:00
}
2019-01-12 11:33:27 +08:00
expandProps.attrs.title = title;
expandProps.class = menuItemCls;
2018-03-02 22:12:52 +08:00
return (
<li {...expandProps}>
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
{option[this.getFieldName('label')]}
{expandIconNode}
{loadingIconNode}
2018-03-02 22:12:52 +08:00
</li>
2019-01-12 11:33:27 +08:00
);
2018-03-02 22:12:52 +08:00
},
2019-01-12 11:33:27 +08:00
getActiveOptions(values) {
const activeValue = values || this.activeValue;
const options = this.options;
return arrayTreeFilter(
options,
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
(o, level) => o[this.getFieldName('value')] === activeValue[level],
2019-01-12 11:33:27 +08:00
{ childrenKeyName: this.getFieldName('children') },
);
2018-03-02 22:12:52 +08:00
},
2019-01-12 11:33:27 +08:00
getShowOptions() {
const { options } = this;
2018-03-02 22:12:52 +08:00
const result = this.getActiveOptions()
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
.map(activeOption => activeOption[this.getFieldName('children')])
2019-01-12 11:33:27 +08:00
.filter(activeOption => !!activeOption);
result.unshift(options);
return result;
2018-03-02 22:12:52 +08:00
},
2019-01-12 11:33:27 +08:00
delayOnSelect(onSelect, ...args) {
2018-03-02 22:12:52 +08:00
if (this.delayTimer) {
2019-01-12 11:33:27 +08:00
clearTimeout(this.delayTimer);
this.delayTimer = null;
2018-03-02 22:12:52 +08:00
}
if (typeof onSelect === 'function') {
this.delayTimer = setTimeout(() => {
2019-01-12 11:33:27 +08:00
onSelect(args);
this.delayTimer = null;
}, 150);
2018-03-02 22:12:52 +08:00
}
},
2018-03-02 16:54:22 +08:00
2019-01-12 11:33:27 +08:00
scrollActiveItemToView() {
// scroll into view
const optionsLength = this.getShowOptions().length;
2018-03-02 22:12:52 +08:00
for (let i = 0; i < optionsLength; i++) {
2019-01-12 11:33:27 +08:00
const itemComponent = this.$refs[`menuItems_${i}`];
2018-03-02 22:12:52 +08:00
if (itemComponent) {
2019-01-12 11:33:27 +08:00
const target = itemComponent;
target.parentNode.scrollTop = target.offsetTop;
2018-03-02 22:12:52 +08:00
}
2018-03-02 16:54:22 +08:00
}
2018-03-02 22:12:52 +08:00
},
2018-03-02 16:54:22 +08:00
2019-01-12 11:33:27 +08:00
isActiveOption(option, menuIndex) {
const { activeValue = [] } = this;
return activeValue[menuIndex] === option[this.getFieldName('value')];
2018-03-02 22:12:52 +08:00
},
2018-03-02 16:54:22 +08:00
2019-01-12 11:33:27 +08:00
getMenuItemRef(index) {
return `menuItems_${index}`;
2018-03-02 22:12:52 +08:00
},
},
2018-03-02 16:54:22 +08:00
2019-01-12 11:33:27 +08:00
render() {
const { prefixCls, dropdownMenuColumnStyle } = this;
2018-03-02 16:54:22 +08:00
return (
<div>
2019-01-12 11:33:27 +08:00
{this.getShowOptions().map((options, menuIndex) => (
2018-03-02 22:12:52 +08:00
<ul class={`${prefixCls}-menu`} key={menuIndex} style={dropdownMenuColumnStyle}>
2018-03-02 16:54:22 +08:00
{options.map(option => this.getOption(option, menuIndex))}
</ul>
2019-01-12 11:33:27 +08:00
))}
2018-03-02 16:54:22 +08:00
</div>
2019-01-12 11:33:27 +08:00
);
2018-03-02 22:12:52 +08:00
},
2019-01-12 11:33:27 +08:00
};