-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae61a5d
commit 0c76fb8
Showing
1 changed file
with
15 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
|
||
/** | ||
* | ||
|
@@ -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) })); | ||
} | ||
} | ||
}); | ||
|