Skip to content

Commit

Permalink
普通的树对象计算树结点时按人员字段左侧树一样处理
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlianghui committed Jan 23, 2024
1 parent ae61a5d commit 0c76fb8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/@steedos-widgets/steedos-lib/src/ui/tree.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* @Author: 殷亮辉 [email protected]
* @Date: 2023-04-18 17:03:48
* @LastEditors: 殷亮辉 [email protected]
* @LastEditTime: 2024-01-23 18:16:11
*/

/**
*
Expand All @@ -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;
}
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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) }));
}
}
});
Expand Down

0 comments on commit 0c76fb8

Please sign in to comment.