perf: update tree-select

pull/2682/head
tangjinzhou 2020-08-12 21:35:45 +08:00
parent e03d442542
commit 8cea617319
6 changed files with 35 additions and 28 deletions

@ -1 +1 @@
Subproject commit 13d33537f288296fed2de511882f74be15dd4981 Subproject commit 747488ec6b7df7cb3f7fd2a3c15c16e4368a79ec

View File

@ -61,10 +61,18 @@ const TreeSelect = {
} }
return <CaretDownOutlined class={`${prefixCls}-switcher-icon`} />; return <CaretDownOutlined class={`${prefixCls}-switcher-icon`} />;
}, },
onChange(...args) { handleChange(...args) {
this.$emit('update:value', args[0]); this.$emit('update:value', args[0]);
this.$emit('change', ...args); this.$emit('change', ...args);
}, },
handleTreeExpand(...args) {
this.$emit('update:treeExpandedKeys', args[0]);
this.$emit('treeExpand', ...args);
},
handleSearch(...args) {
this.$emit('update:searchValue', args[0]);
this.$emit('search', ...args);
},
updateTreeData(treeData) { updateTreeData(treeData) {
const { $slots } = this; const { $slots } = this;
const defaultFields = { const defaultFields = {
@ -163,8 +171,6 @@ const TreeSelect = {
); );
const VcTreeSelectProps = { const VcTreeSelectProps = {
...this.$attrs, ...this.$attrs,
...Object.assign(
{
switcherIcon: nodeProps => this.renderSwitcherIcon(prefixCls, nodeProps), switcherIcon: nodeProps => this.renderSwitcherIcon(prefixCls, nodeProps),
inputIcon, inputIcon,
removeIcon: finalRemoveIcon, removeIcon: finalRemoveIcon,
@ -177,11 +183,11 @@ const TreeSelect = {
dropdownStyle: { maxHeight: '100vh', overflow: 'auto', ...dropdownStyle }, dropdownStyle: { maxHeight: '100vh', overflow: 'auto', ...dropdownStyle },
treeCheckable: checkable, treeCheckable: checkable,
notFoundContent: notFoundContent || renderEmpty('Select'), notFoundContent: notFoundContent || renderEmpty('Select'),
}, ...(treeData ? { treeData } : {}),
treeData ? { treeData } : {},
),
class: cls, class: cls,
onChange: this.onChange, onChange: this.handleChange,
onSearch: this.handleSearch,
onTreeExpand: this.handleTreeExpand,
ref: this.saveTreeSelect, ref: this.saveTreeSelect,
children: getSlot(this), children: getSlot(this),
}; };

View File

@ -33,9 +33,6 @@ export const TreeSelectProps = () => ({
]), ]),
multiple: PropTypes.bool, multiple: PropTypes.bool,
notFoundContent: PropTypes.any, notFoundContent: PropTypes.any,
// onSelect: (value: any) => void,
// onChange: (value: any, label: any) => void,
// onSearch: (value: any) => void,
searchPlaceholder: PropTypes.string, searchPlaceholder: PropTypes.string,
searchValue: PropTypes.string, searchValue: PropTypes.string,
showCheckedStrategy: PropTypes.oneOf(['SHOW_ALL', 'SHOW_PARENT', 'SHOW_CHILD']), showCheckedStrategy: PropTypes.oneOf(['SHOW_ALL', 'SHOW_PARENT', 'SHOW_CHILD']),
@ -56,4 +53,12 @@ export const TreeSelectProps = () => ({
replaceFields: PropTypes.object.def({}), replaceFields: PropTypes.object.def({}),
clearIcon: PropTypes.any, clearIcon: PropTypes.any,
removeIcon: PropTypes.any, removeIcon: PropTypes.any,
onSelect: PropTypes.func,
onChange: PropTypes.func,
onSearch: PropTypes.func,
onTreeExpand: PropTypes.func,
'onUpdate:treeExpandedKeys': PropTypes.func,
'onUpdate:searchValue': PropTypes.func,
'onUpdate:value': PropTypes.func,
}); });

View File

@ -148,7 +148,6 @@ const BasePopup = {
this.__emit('treeExpanded'); this.__emit('treeExpanded');
}); });
} }
this.__emit('update:treeExpandedKeys', expandedKeyList);
this.__emit('treeExpand', expandedKeyList); this.__emit('treeExpand', expandedKeyList);
}, },

View File

@ -707,7 +707,6 @@ const Select = {
// We should also trigger onSearch with empty string here // We should also trigger onSearch with empty string here
// since if user use `treeExpandedKeys`, it need user have the ability to reset it. // since if user use `treeExpandedKeys`, it need user have the ability to reset it.
if (searchValue && searchValue.length) { if (searchValue && searchValue.length) {
this.__emit('update:searchValue', '');
this.__emit('search', ''); this.__emit('search', '');
} }
} }
@ -834,7 +833,6 @@ const Select = {
const value = event.target.value; const value = event.target.value;
const { _treeNodes: treeNodes, _valueEntities: valueEntities } = this.$data; const { _treeNodes: treeNodes, _valueEntities: valueEntities } = this.$data;
const { filterTreeNode, treeNodeFilterProp } = this.$props; const { filterTreeNode, treeNodeFilterProp } = this.$props;
this.__emit('update:searchValue', value);
this.__emit('search', value); this.__emit('search', value);
let isSet = false; let isSet = false;
@ -1031,7 +1029,6 @@ const Select = {
if (!this.isMultiple()) { if (!this.isMultiple()) {
returnValue = returnValue[0]; returnValue = returnValue[0];
} }
// this.__emit('update:value', returnValue);
this.__emit('change', returnValue, labelList, extra); this.__emit('change', returnValue, labelList, extra);
} }
}, },

View File

@ -4,7 +4,7 @@
</div> </div>
</template> </template>
<script> <script>
import demo from '../antdv-demo/docs/tree/demo/index'; import demo from '../antdv-demo/docs/tree-select/demo/index';
export default { export default {
components: { components: {