ant-design-vue/components/vc-tree-select/utils/valueUtil.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

51 lines
1.2 KiB
TypeScript

import type { Key, DataNode, FieldNames } from '../interface';
import type { DefaultOptionType, InternalFieldName } from '../TreeSelect';
export function toArray<T>(value: T | T[]): T[] {
if (Array.isArray(value)) {
return value;
}
return value !== undefined ? [value] : [];
}
export function fillFieldNames(fieldNames?: FieldNames) {
const { label, value, children } = fieldNames || {};
const mergedValue = value || 'value';
return {
_title: label ? [label] : ['title', 'label'],
value: mergedValue,
key: mergedValue,
children: children || 'children',
};
}
export function isCheckDisabled(node: DataNode) {
return node.disabled || node.disableCheckbox || node.checkable === false;
}
/** Loop fetch all the keys exist in the tree */
export function getAllKeys(treeData: DefaultOptionType[], fieldNames: InternalFieldName) {
const keys: Key[] = [];
function dig(list: DefaultOptionType[]) {
list.forEach(item => {
keys.push(item[fieldNames.value]);
const children = item[fieldNames.children];
if (children) {
dig(children);
}
});
}
dig(treeData);
return keys;
}
export function isNil(val: any) {
return val === null || val === undefined;
}