mirror of
https://gitee.com/newgateway/vtj.git
synced 2026-05-07 01:10:03 +08:00
fix: 🐛 获取当前选择节点的工具,未能定位到唯一元素
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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('>');
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
},
|
||||
"vtj": {
|
||||
"name": "VTJ.PRO",
|
||||
"platform": "uniapp",
|
||||
"platform": "web",
|
||||
"remote": "https://app.vtj.pro",
|
||||
"__ACCESS__": {
|
||||
"auth": "https://app.vtj.pro/#/login",
|
||||
|
||||
Reference in New Issue
Block a user