树形转数组
/** 属性结构添加路径 */
export const addPathKey = (list: (DemandProps.TreeNodeData & { pathKey?: string })[], parentKey?: string) => {
list.forEach((item) => {
const pathKey = parentKey ? `${parentKey}-${item.value}` : item.value;
item.value = pathKey;
if (Array.isArray(item.children) && item.children.length > 0) {
addPathKey(item.children, pathKey);
}
});
return list;
};
export const addClueKey = (list: any[], parentKey = '') => {
list.flatMap(item => {
const pathKey = parentKey ? `${parentKey}-${item.value}` : item.value;
item.value = pathKey;
if (item.children) {
return addClueKey(item.children, pathKey)
}
return item;
})
return list;
}