You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
import { CascaderOptionType } from 'antd/lib/cascader';
|
|
import { DataNode } from 'antd/lib/tree';
|
|
|
|
// 将设备分类列表转换为树形选择器数据
|
|
export const generateCategoryOptions = (
|
|
categories: defs.MajorCategory[],
|
|
disableLevel?: boolean,
|
|
): DataNode[] => {
|
|
const dataNodeList: DataNode[] = (categories || []).map((category: defs.MajorCategory) => {
|
|
return {
|
|
title: category.name || '',
|
|
key: category.id || '',
|
|
children: generateCategoryOptions(category.children || [], false),
|
|
value: category.id,
|
|
selectable: !disableLevel,
|
|
};
|
|
});
|
|
|
|
return dataNodeList;
|
|
};
|
|
|
|
// 将设备分类列表转换为级联选择器选项
|
|
export const mapToCategoryCascaderOptions = (
|
|
categories: defs.MajorCategory[],
|
|
): CascaderOptionType[] => {
|
|
const options: CascaderOptionType[] = (categories || []).map((category: defs.MajorCategory) => {
|
|
const option: CascaderOptionType = {
|
|
label: category.name || '',
|
|
key: category.id || '',
|
|
value: category.id,
|
|
};
|
|
|
|
if (category && Array.isArray(category.children) && category.children.length > 0) {
|
|
option.children = mapToCategoryCascaderOptions(category.children);
|
|
}
|
|
|
|
return option;
|
|
});
|
|
|
|
return options;
|
|
};
|
|
|