ant-design-vue/components/vc-cascader/hooks/useEntities.ts
tangjinzhou f0385d7c24
Refactor cascader (#5192)
* 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
2022-01-21 21:58:10 +08:00

37 lines
1.3 KiB
TypeScript

import { convertDataToEntities } from '../../vc-tree/utils/treeUtil';
import type { DataEntity } from '../../vc-tree/interface';
import type { DefaultOptionType, InternalFieldNames } from '../Cascader';
import { VALUE_SPLIT } from '../utils/commonUtil';
import type { Ref } from 'vue';
import { computed } from 'vue';
export interface OptionsInfo {
keyEntities: Record<string, DataEntity>;
pathKeyEntities: Record<string, DataEntity>;
}
/** Lazy parse options data into conduct-able info to avoid perf issue in single mode */
export default (options: Ref<DefaultOptionType[]>, fieldNames: Ref<InternalFieldNames>) => {
const entities = computed(() => {
return (
convertDataToEntities(options.value as any, {
fieldNames: fieldNames.value,
initWrapper: wrapper => ({
...wrapper,
pathKeyEntities: {},
}),
processEntity: (entity, wrapper: any) => {
const pathKey = entity.nodes.map(node => node[fieldNames.value.value]).join(VALUE_SPLIT);
wrapper.pathKeyEntities[pathKey] = entity;
// Overwrite origin key.
// this is very hack but we need let conduct logic work with connect path
entity.key = pathKey;
},
}) as any
).pathKeyEntities;
});
return entities;
};