🐛 fix(connectionStore): 修复分组连接时树节点的更新逻辑
确保连接到分组中的连接时,原地更新现有节点属性,避免添加重复的根节点。 使用 findNode 递归搜索替代 findIndex 只搜索根级别。原地修改节点属性而非替换整个对象,保留父子引用关系。
This commit is contained in:
2 files changed
+112
-12
No files matched your search
@@ -759,19 +759,21 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
clearConnectionError(config.id);
|
||||
if (id !== config.id) clearConnectionError(id);
|
||||
|
||||
const node: TreeNode = {
|
||||
id,
|
||||
label: config.name,
|
||||
type: "connection",
|
||||
connectionId: id,
|
||||
isExpanded: false,
|
||||
children: [],
|
||||
};
|
||||
const existing = treeNodes.value.findIndex((n) => n.id === id);
|
||||
if (existing >= 0) {
|
||||
treeNodes.value[existing] = node;
|
||||
const existing = findNode(treeNodes.value, id);
|
||||
if (existing) {
|
||||
existing.label = config.name;
|
||||
existing.type = "connection";
|
||||
existing.connectionId = id;
|
||||
existing.children = existing.children || [];
|
||||
} else {
|
||||
treeNodes.value.push(node);
|
||||
treeNodes.value.push({
|
||||
id,
|
||||
label: config.name,
|
||||
type: "connection",
|
||||
connectionId: id,
|
||||
isExpanded: false,
|
||||
children: [],
|
||||
});
|
||||
}
|
||||
return id;
|
||||
} catch (e) {
|
||||
|
||||
Reference in new issue
Block a user