20260728173026
This commit is contained in:
1 parent
63588bd217
commit
5ec7aadef9
25 files changed
+627
-462
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
hasChanges,
|
||||
} from "@/utils/dataChanges";
|
||||
import { createTempId } from "@/utils/tempId";
|
||||
import { buildTree } from "@/utils/tree";
|
||||
|
||||
const props = defineProps({
|
||||
visible: { type: Boolean, default: false },
|
||||
@@ -33,35 +34,15 @@ watch(
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const treeData = computed(() => {
|
||||
return buildTreeData(localGroups.value);
|
||||
});
|
||||
|
||||
function buildTreeData(items) {
|
||||
const nodes = new Map();
|
||||
const roots = [];
|
||||
|
||||
for (const item of items) {
|
||||
const key = String(item.b_id);
|
||||
nodes.set(key, {
|
||||
key,
|
||||
const treeData = computed(() =>
|
||||
buildTree(localGroups.value, {
|
||||
mapNode: (item) => ({
|
||||
key: String(item.b_id),
|
||||
title: item.b_title || `分组-${item.b_id}`,
|
||||
children: [],
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of items) {
|
||||
const node = nodes.get(String(item.b_id));
|
||||
const parent = item.b_parent_id ? nodes.get(String(item.b_parent_id)) : null;
|
||||
if (parent && parent !== node) {
|
||||
parent.children.push(node);
|
||||
} else {
|
||||
roots.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
return roots;
|
||||
}
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
const selectedGroup = computed(() =>
|
||||
localGroups.value.find((g) => String(g.b_id) === selectedGroupId.value),
|
||||
@@ -151,7 +132,6 @@ function onClose() {
|
||||
v-if="treeData.length > 0"
|
||||
class="group-tree"
|
||||
:tree-data="treeData"
|
||||
:field-names="{ title: 'title', key: 'key', children: 'children' }"
|
||||
:selected-keys="selectedGroupId ? [selectedGroupId] : []"
|
||||
@select="onTreeSelect"
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user