Skip to content

Commit

Permalink
fix: optimize maxDepth algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling committed Feb 6, 2025
1 parent a0c74da commit 87d776b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions packages/plugins/tree/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export default {
const filterSchema = (data) => {
maxDepth.value = 0
const translateChild = (data, depth = 0) => {
let tempMaxDepth = depth
if (depth > maxDepth.value) {
maxDepth.value = depth
}
data.forEach((item) => {
item.show = pageState.nodesStatus[item.id] !== false
item.showEye = !item.show
Expand All @@ -97,22 +100,15 @@ export default {
delete item.children
} else {
if (item.children.length) {
const { maxDepth: curDepth } = translateChild(item.children, depth + 1)
if (curDepth > maxDepth.value) {
maxDepth.value = curDepth
}
translateChild(item.children, depth + 1)
}
}
})
return {
data,
maxDepth: tempMaxDepth
}
return data
}
return [{ ...translateChild([extend(true, {}, data)]).data[0], componentName: 'body' }]
return [{ ...translateChild([extend(true, {}, data)])[0], componentName: 'body' }]
}
const state = reactive({
pageSchema: [],
Expand Down

0 comments on commit 87d776b

Please sign in to comment.