mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-02 03:58:05 +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
51 lines
1.2 KiB
TypeScript
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;
|
|
}
|