fix: 🐛 获取当前选择节点的工具,未能定位到唯一元素

This commit is contained in:
“chenhuachun”
2026-04-13 14:47:13 +08:00
parent a03be8d6ec
commit 2eba0b916c
4 changed files with 26 additions and 4 deletions

View File

@@ -486,4 +486,11 @@ export class NodeModel {
}
return match;
}
findChildIndex(child: NodeModel) {
if (Array.isArray(this.children)) {
return this.children.findIndex((n) => n === child || n.id === child.id);
}
return -1;
}
}

View File

@@ -55,6 +55,7 @@ export interface DesignHelper {
rect: DOMRect;
type?: DropPosition;
path?: Array<NodeModel | BlockModel>;
indexes?: number[];
}
export class Designer {
@@ -377,6 +378,16 @@ export class Designer {
return [...nodePath, root];
}
private getNodePathIndex(nodePath: Array<BlockModel | NodeModel>) {
return nodePath.map((n) => {
if (isBlock(n)) {
return 0;
} else {
return n.parent?.findChildIndex(n) || 0;
}
});
}
private setDslFrom(dsl: NodeSchema) {
const desc = this.engine.assets.componentMap.get(dsl.name);
dsl.from = dsl.from || desc?.package;
@@ -435,12 +446,14 @@ export class Designer {
const rect = el.getBoundingClientRect();
const type = this.getDropType(rect, e.clientX, e.clientY);
const path = this.getNodePath(targets);
const indexes = this.getNodePathIndex(path);
return {
el,
model,
rect,
type,
path
path,
indexes
};
}

View File

@@ -1139,10 +1139,12 @@ const getSelectedPath: ToolConfig = {
async () => {
const designer = engine.simulator.designer.value;
if (!designer) return null;
const path = designer.selected.value?.path;
const { path, indexes = [] } = designer.selected.value || {};
if (!path) return null;
return path
.map((n) => n.name)
.map((n, i) => {
return `${n.name}[${indexes[i]}]`;
})
.reverse()
.join('>');
}

View File

@@ -69,7 +69,7 @@
},
"vtj": {
"name": "VTJ.PRO",
"platform": "uniapp",
"platform": "web",
"remote": "https://app.vtj.pro",
"__ACCESS__": {
"auth": "https://app.vtj.pro/#/login",