mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-02 12:07:54 +08:00
f0385d7c24
* feat: tree * refactor: select * refactor: select * refactor: select * refactor: vc-tree-select * refactor: tree-select * refactor: tree-select * feat: add showLeafIcon * refactor: remove lod vc-tree-select * feat: tree-select add tag-render * refactor: cascader * refactor: cascader * refactor: cascader * refactor: cascader * fix: maxTagmaxTagPlaceholder not work
42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
import { convertDataToEntities } from '../../vc-tree/utils/treeUtil';
|
|
import type { DataEntity } from '../../vc-tree/interface';
|
|
import type { FieldNames, RawValueType } from '../TreeSelect';
|
|
|
|
import { isNil } from '../utils/valueUtil';
|
|
import type { Ref } from 'vue';
|
|
import { ref, watchEffect } from 'vue';
|
|
import { warning } from '../../vc-util/warning';
|
|
|
|
export default (treeData: Ref<any>, fieldNames: Ref<FieldNames>) => {
|
|
const valueEntities = ref<Map<RawValueType, DataEntity>>(new Map());
|
|
const keyEntities = ref<Record<string, DataEntity>>({});
|
|
watchEffect(() => {
|
|
const collection = convertDataToEntities(treeData.value, {
|
|
fieldNames: fieldNames.value,
|
|
initWrapper: wrapper => ({
|
|
...wrapper,
|
|
valueEntities: new Map(),
|
|
}),
|
|
processEntity: (entity, wrapper: any) => {
|
|
const val = entity.node[fieldNames.value.value];
|
|
|
|
// Check if exist same value
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
const key = entity.node.key;
|
|
|
|
warning(!isNil(val), 'TreeNode `value` is invalidate: undefined');
|
|
warning(!wrapper.valueEntities.has(val), `Same \`value\` exist in the tree: ${val}`);
|
|
warning(
|
|
!key || String(key) === String(val),
|
|
`\`key\` or \`value\` with TreeNode must be the same or you can remove one of them. key: ${key}, value: ${val}.`,
|
|
);
|
|
}
|
|
wrapper.valueEntities.set(val, entity);
|
|
},
|
|
}) as any;
|
|
valueEntities.value = collection.valueEntities;
|
|
keyEntities.value = collection.keyEntities;
|
|
});
|
|
return { valueEntities, keyEntities };
|
|
};
|