diff --git a/packages/@steedos-widgets/steedos-lib/src/ui/tree.js b/packages/@steedos-widgets/steedos-lib/src/ui/tree.js index 166899fa1..43fe932ae 100644 --- a/packages/@steedos-widgets/steedos-lib/src/ui/tree.js +++ b/packages/@steedos-widgets/steedos-lib/src/ui/tree.js @@ -1,3 +1,9 @@ +/* + * @Author: 殷亮辉 yinlianghui@hotoa.com + * @Date: 2023-04-18 17:03:48 + * @LastEditors: 殷亮辉 yinlianghui@hotoa.com + * @LastEditTime: 2024-01-23 18:16:11 + */ /** * @@ -12,7 +18,11 @@ export function getTreeOptions(rows, options) { const unfoldedNum = options?.unfoldedNum || 1; const treeRecords = []; - const getChildren = (rows, childrenIds, childrenUnfoldedNum) => { + const getChildren = (currentRow, rows, childrenIds, childrenUnfoldedNum) => { + if (currentRow.children && typeof currentRow.children[0] === "object") { + // 考虑api配置了cache缓存的话,不会请求接口但是会重新进这个接收适配器脚本且payload.data.options返回的会是上一次计算结果,这里直接返回计算过的children + return currentRow.children; + } if (!childrenIds) { return; } @@ -23,11 +33,11 @@ export function getTreeOptions(rows, options) { if (childrenUnfoldedNum >= 1) { item.unfolded = true; if (item["children"]) { - item["children"] = getChildren(rows, item["children"], childrenUnfoldedNum - 1) + item["children"] = getChildren(item, rows, item["children"], childrenUnfoldedNum - 1) } } else { if (item["children"]) { - item["children"] = getChildren(rows, item["children"], childrenUnfoldedNum) + item["children"] = getChildren(item, rows, item["children"], childrenUnfoldedNum) } } @@ -55,9 +65,9 @@ export function getTreeOptions(rows, options) { if (row.noParent == 1) { if (unfoldedNum >= 1) { row.unfolded = true; - treeRecords.push(Object.assign({}, row, { children: getChildren(rows, row["children"], unfoldedNum - 1) })); + treeRecords.push(Object.assign({}, row, { children: getChildren(row, rows, row["children"], unfoldedNum - 1) })); }else{ - treeRecords.push(Object.assign({}, row, { children: getChildren(rows, row["children"], unfoldedNum) })); + treeRecords.push(Object.assign({}, row, { children: getChildren(row, rows, row["children"], unfoldedNum) })); } } });