将直接获取modeljson改为通过回调函数

This commit is contained in:
猴赛雷 2024-10-09 10:30:16 +08:00
parent aa802ad524
commit 66261878b6
8 changed files with 156 additions and 103 deletions

12
package-lock.json generated
View File

@ -1,15 +1,15 @@
{ {
"name": "ddei-editor", "name": "ddei-editor",
"version": "1.2.41-121", "version": "1.2.41-127",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ddei-editor", "name": "ddei-editor",
"version": "1.2.41-121", "version": "1.2.41-127",
"license": "Apache License 2.0", "license": "Apache License 2.0",
"dependencies": { "dependencies": {
"ddei-framework": "file:///Users/hoslay/work/ddei/ddei-framework/ddei-framework-1.2.41-121.tgz" "ddei-framework": "file:///Users/hoslay/work/ddei/ddei-framework/ddei-framework-1.2.41-127.tgz"
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node18": "^18.2.0", "@tsconfig/node18": "^18.2.0",
@ -518,9 +518,9 @@
"integrity": "sha512-tdMuLdcJyreope1BWfnYqTQaIkSIrU/KtY9yX5mNGd+tYeJ0Y99ARHDuYnEABPX/8yh/r0Kl169v5ODg2vr98g==" "integrity": "sha512-tdMuLdcJyreope1BWfnYqTQaIkSIrU/KtY9yX5mNGd+tYeJ0Y99ARHDuYnEABPX/8yh/r0Kl169v5ODg2vr98g=="
}, },
"node_modules/ddei-framework": { "node_modules/ddei-framework": {
"version": "1.2.41-121", "version": "1.2.41-127",
"resolved": "file:../ddei-framework/ddei-framework-1.2.41-121.tgz", "resolved": "file:../ddei-framework/ddei-framework-1.2.41-127.tgz",
"integrity": "sha512-M7/2QFzEjt1m4HUusaagSL17/G4UUT9ks75Cs4UXB5/SPls9xMqZCRu29Wb1kTQ4M9Z7xlO0ArcOju6dsvY/+w==", "integrity": "sha512-SDIJ1vG6k1rTD1xXZI08zwbzgsnPB4JnMgUudT3chRTccxI9qsAhpgfUXuTazha1moYxB9VVAlJTirc56zo8lw==",
"license": "Apache License 2.0", "license": "Apache License 2.0",
"dependencies": { "dependencies": {
"ddei-autolink": "^1.1.1", "ddei-autolink": "^1.1.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "ddei-editor", "name": "ddei-editor",
"version": "1.2.41-122", "version": "1.2.41-128",
"private": false, "private": false,
"type": "module", "type": "module",
"author": "hoslay <3697355039@qq.com>", "author": "hoslay <3697355039@qq.com>",
@ -49,7 +49,7 @@
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false" "type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false"
}, },
"dependencies": { "dependencies": {
"ddei-framework": "file:///Users/hoslay/work/ddei/ddei-framework/ddei-framework-1.2.41-121.tgz" "ddei-framework": "file:///Users/hoslay/work/ddei/ddei-framework/ddei-framework-1.2.41-128.tgz"
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node18": "^18.2.0", "@tsconfig/node18": "^18.2.0",

View File

@ -12,7 +12,7 @@ import {DDeiEnumOperateType} from "ddei-framework";
import {DDeiPolygon} from "ddei-framework"; import {DDeiPolygon} from "ddei-framework";
import {DDeiLink} from "ddei-framework"; import {DDeiLink} from "ddei-framework";
import {DDeiLineLink} from "ddei-framework"; import {DDeiLineLink} from "ddei-framework";
import {DDeiEditorState} from "ddei-framework"; import { DDeiEditorState, DDeiEditorUtil } from "ddei-framework";
/** /**
* 键行为:粘贴 * 键行为:粘贴
* *
@ -390,6 +390,11 @@ class DDeiKeyActionPaste extends DDeiKeyAction {
DDeiUtil.convertChildrenJsonUnit(model, stage, unit); DDeiUtil.convertChildrenJsonUnit(model, stage, unit);
}); });
} }
//创建并初始化控件以及关系
let controlInitJSON = DDeiEditorUtil.getModelInitJSON(stage.ddInstance, null, jsonArray)
if (!controlInitJSON) {
return;
}
//当前选中控件是否为1且有表格且选中表格的单元格则作为表格单元格的内容粘贴 //当前选中控件是否为1且有表格且选中表格的单元格则作为表格单元格的内容粘贴
let createControl = true; let createControl = true;
@ -400,7 +405,7 @@ class DDeiKeyActionPaste extends DDeiKeyAction {
let cells = model.getSelectedCells(); let cells = model.getSelectedCells();
if (cells.length > 0) { if (cells.length > 0) {
cells.forEach(cell => { cells.forEach(cell => {
this.createControl(jsonArray, jsonLinkArray, offsetX, offsetY, stage, cell, mode, evt) this.createControl(controlInitJSON, jsonLinkArray, offsetX, offsetY, stage, cell, mode, evt)
}) })
hasChange = true; hasChange = true;
createControl = false createControl = false
@ -408,14 +413,14 @@ class DDeiKeyActionPaste extends DDeiKeyAction {
} }
//添加到容器 //添加到容器
else if (model.baseModelType == 'DDeiContainer') { else if (model.baseModelType == 'DDeiContainer') {
this.createControl(jsonArray, jsonLinkArray, offsetX, offsetY, stage, model, mode, evt) this.createControl(controlInitJSON, jsonLinkArray, offsetX, offsetY, stage, model, mode, evt)
createControl = false createControl = false
hasChange = true; hasChange = true;
} }
} }
//如果没有粘贴到表格在最外层容器的鼠标位置反序列化控件重新设置ID其他信息保留 //如果没有粘贴到表格在最外层容器的鼠标位置反序列化控件重新设置ID其他信息保留
if (createControl) { if (createControl) {
this.createControl(jsonArray, jsonLinkArray, offsetX, offsetY, stage, layer, mode, evt) this.createControl(controlInitJSON, jsonLinkArray, offsetX, offsetY, stage, layer, mode, evt)
hasChange = true; hasChange = true;
} }
if (hasChange) { if (hasChange) {

View File

@ -257,7 +257,11 @@ export default {
if(control){ if(control){
if (editMode != 4){ if (editMode != 4){
// //
let models = DDeiEditorUtil.createControl(control, this.editor) let controlInitJSON = DDeiEditorUtil.getModelInitJSON(this.editor.ddInstance, null, [control])
if (!controlInitJSON) {
return;
}
let models = DDeiEditorUtil.createControl(controlInitJSON[0], this.editor)
// //
let rsState = DDeiUtil.invokeCallbackFunc("EVENT_CONTROL_CREATE_BEFORE", DDeiEnumOperateType.CREATE, { models: models }, ddInstance, e) let rsState = DDeiUtil.invokeCallbackFunc("EVENT_CONTROL_CREATE_BEFORE", DDeiEnumOperateType.CREATE, { models: models }, ddInstance, e)
@ -458,17 +462,20 @@ export default {
} }
let rsState = DDeiUtil.invokeCallbackFunc("EVENT_CONTROL_CREATE_BEFORE", DDeiEnumOperateType.CREATE, { controls: [control] }, ddInstance, e) let rsState = DDeiUtil.invokeCallbackFunc("EVENT_CONTROL_CREATE_BEFORE", DDeiEnumOperateType.CREATE, { controls: [control] }, ddInstance, e)
if (rsState == 0 || rsState == 1) { if (rsState == 0 || rsState == 1) {
let models = this.editor.addControls([{model:control.id}]) let controlInitJSON = DDeiEditorUtil.getModelInitJSON(this.editor.ddInstance, null, [{ model: control.id }])
let pushDatas = [] if (controlInitJSON){
models.forEach((model, key) => { let models = this.editor.addControls(controlInitJSON)
pushDatas.push({ id: model.id, value: DDeiEnumControlState.SELECTED }); let pushDatas = []
}); models.forEach((model, key) => {
this.editor.ddInstance?.bus?.push(DDeiEnumBusCommandType.CancelCurLevelSelectedModels, null, e); pushDatas.push({ id: model.id, value: DDeiEnumControlState.SELECTED });
this.editor.ddInstance?.bus?.push(DDeiEnumBusCommandType.ModelChangeSelect, pushDatas, e); });
this.editor.ddInstance?.bus?.push(DDeiEnumBusCommandType.StageChangeSelectModels); this.editor.ddInstance?.bus?.push(DDeiEnumBusCommandType.CancelCurLevelSelectedModels, null, e);
this.editor.bus.executeAll() this.editor.ddInstance?.bus?.push(DDeiEnumBusCommandType.ModelChangeSelect, pushDatas, e);
this.editor.changeState(DDeiEditorState.DESIGNING); this.editor.ddInstance?.bus?.push(DDeiEnumBusCommandType.StageChangeSelectModels);
DDeiUtil.invokeCallbackFunc("EVENT_CONTROL_CREATE_AFTER", DDeiEnumOperateType.CREATE, { models: models }, ddInstance, e) this.editor.bus.executeAll()
this.editor.changeState(DDeiEditorState.DESIGNING);
DDeiUtil.invokeCallbackFunc("EVENT_CONTROL_CREATE_AFTER", DDeiEnumOperateType.CREATE, { models: models }, ddInstance, e)
}
} }
} }

View File

@ -331,9 +331,12 @@ export default {
if ((layer.display == 0 && !layer.tempDisplay) || layer.lock) { if ((layer.display == 0 && !layer.tempDisplay) || layer.lock) {
return; return;
} }
let controlInitJSON = DDeiEditorUtil.getModelInitJSON(this.editor.ddInstance, null, [control])
if (!controlInitJSON) {
return;
}
// //
let models = DDeiEditorUtil.createControl(control,this.editor) let models = DDeiEditorUtil.createControl(controlInitJSON[0],this.editor)
// //
let rsState = DDeiUtil.invokeCallbackFunc("EVENT_CONTROL_CREATE_BEFORE", DDeiEnumOperateType.CREATE, { models: models }, ddInstance, e) let rsState = DDeiUtil.invokeCallbackFunc("EVENT_CONTROL_CREATE_BEFORE", DDeiEnumOperateType.CREATE, { models: models }, ddInstance, e)

View File

@ -18,6 +18,7 @@
<script lang="ts"> <script lang="ts">
import { DDeiAbstractShape } from "ddei-framework"; import { DDeiAbstractShape } from "ddei-framework";
import { DDeiEditorUtil } from "ddei-framework"; import { DDeiEditorUtil } from "ddei-framework";
import { clone } from "lodash"
import DialogBase from "./dialog" import DialogBase from "./dialog"
export default { export default {
@ -143,69 +144,87 @@ export default {
let type = this.editor.tempPopData['ddei-ext-dialog-quickchoosecontrol'].type let type = this.editor.tempPopData['ddei-ext-dialog-quickchoosecontrol'].type
if (model){ if (model){
let outRect = DDeiAbstractShape.getOutRectByPV([model]) let outRect = DDeiAbstractShape.getOutRectByPV([model])
let controls = this.editor.addControls([ let controlInitJSON = DDeiEditorUtil.getModelInitJSON(this.editor.ddInstance, model, [
{ {
model: controlId model: controlId
}, },
],true,false) ])
// if (controlInitJSON){
let outRect1 = DDeiAbstractShape.getOutRectByPV(controls) let controls = this.editor.addControls(controlInitJSON,true,false)
let x,y,sx,sy,ex,ey //
let startSita, endSita let outRect1 = DDeiAbstractShape.getOutRectByPV(controls)
let weight = 60 let x,y,sx,sy,ex,ey
// let startSita, endSita
if(type == 1){ let weight = 60
x = (outRect.x+outRect.x1)/2 //
y = outRect.y - weight - outRect1.height / 2 if(type == 1){
sx = x x = (outRect.x+outRect.x1)/2
sy = outRect.y y = outRect.y - weight - outRect1.height / 2
ex = x sx = x
ey = y + outRect1.height / 2 sy = outRect.y
startSita = -90 ex = x
endSita = 90 ey = y + outRect1.height / 2
} else if (type == 2) { startSita = -90
x = outRect.x1 + weight + outRect1.width/2, endSita = 90
y =(outRect.y1 + outRect.y) / 2 } else if (type == 2) {
sx = outRect.x1 x = outRect.x1 + weight + outRect1.width/2,
sy = y y =(outRect.y1 + outRect.y) / 2
ex = x - outRect1.width / 2 sx = outRect.x1
ey = y sy = y
startSita = 0 ex = x - outRect1.width / 2
endSita = 180 ey = y
} else if (type == 3) { startSita = 0
x = (outRect.x + outRect.x1) / 2, endSita = 180
y = outRect.y1 + weight + outRect1.height / 2 } else if (type == 3) {
sx = x x = (outRect.x + outRect.x1) / 2,
sy = outRect.y1 y = outRect.y1 + weight + outRect1.height / 2
ex = x sx = x
ey = y - outRect1.height / 2 sy = outRect.y1
startSita = 90 ex = x
endSita = -90 ey = y - outRect1.height / 2
} else if (type == 4) { startSita = 90
x = outRect.x - weight -outRect1.width/2 endSita = -90
y = (outRect.y1 + outRect.y) / 2 } else if (type == 4) {
sx = outRect.x x = outRect.x - weight -outRect1.width/2
sy = y y = (outRect.y1 + outRect.y) / 2
ex = x+outRect1.width / 2 sx = outRect.x
ey = y sy = y
startSita = 180 ex = x+outRect1.width / 2
endSita = 0 ey = y
startSita = 180
endSita = 0
}
controls[0].setPosition({x:x,y:y})
//线
let smodel ={ id: model.id, x: sx, y: sy, rate: 0.5, sita: startSita }
let emodel = { id: controls[0].id, x: ex, y: ey, rate: 0.5, sita: endSita }
let initLine = DDeiEditorUtil.getLineInitJSON(this.editor.ddInstance,smodel,emodel)
if (initLine){
let initJson = clone(initLine)
initJson.model = initLine.modelCode ? initLine.modelCode : initLine.model ? initLine.model : initLine.id ? initLine.id : '100401'
if (!initJson.type) {
initJson.type = 2
}
if (!initJson.startPoint) {
initJson.startPoint = { x: sx, y: sy }
}
if (!initJson.endPoint) {
initJson.endPoint = { x: ex, y: ey }
}
if (!initJson.smodel) {
initJson.smodel = smodel
}
if (!initJson.emodel) {
initJson.emodel = emodel
}
this.editor.addLines([
initJson
],true,true,false)
this.editor.ddInstance.stage.makeSelectModels(controls);
this.editor.ddInstance.stage.notifyChange()
}
} }
controls[0].setPosition({x:x,y:y})
//线
let initLine = DDeiEditorUtil.getLineInitJSON()
this.editor.addLines([
{
model: initLine.modelCode ? initLine.modelCode : initLine.model ? initLine.model : initLine.id ? initLine.id : '100401',
type:2,
startPoint: {x:sx,y:sy},
endPoint: {x:ex,y:ey},
smodel: { id: model.id,x:sx,y:sy ,rate:0.5,sita:startSita},
emodel:{id:controls[0].id,x:ex,y:ey,rate:0.5,sita:endSita}
},
],true,true,false)
this.editor.ddInstance.stage.makeSelectModels(controls);
this.editor.ddInstance.stage.notifyChange()
} }
} }
} }

View File

@ -34,7 +34,7 @@
import { DDeiEditor, DDeiEnumControlState, DDeiUtil } from "ddei-framework"; import { DDeiEditor, DDeiEnumControlState, DDeiUtil } from "ddei-framework";
import {DDeiEditorUtil} from "ddei-framework"; import {DDeiEditorUtil} from "ddei-framework";
import { DDeiAbstractShape } from "ddei-framework"; import { DDeiAbstractShape } from "ddei-framework";
import {DDeiEditorState} from "ddei-framework"; import { clone } from "lodash";
import { DDeiEnumBusCommandType } from "ddei-framework"; import { DDeiEnumBusCommandType } from "ddei-framework";
export default { export default {
@ -243,22 +243,38 @@ export default {
endSita = 0 endSita = 0
} }
//线 //线
let initLine = DDeiEditorUtil.getLineInitJSON() let smodel = { id: model.id, x: sx, y: sy, rate: 0.5, sita: startSita }
let lines = this.editor.addLines([ let emodel = { id: existsControl.id, x: ex, y: ey, rate: 0.5, sita: endSita }
{ let initLine = DDeiEditorUtil.getLineInitJSON(this.editor.ddInstance,smodel, emodel)
model: initLine.modelCode ? initLine.modelCode : initLine.model ? initLine.model : initLine.id ? initLine.id : '100401', if (initLine){
type: 2, let initJson = clone(initLine)
dash:[10,5], initJson.model = initLine.modelCode ? initLine.modelCode : initLine.model ? initLine.model : initLine.id ? initLine.id : '100401'
startPoint: { x: sx, y: sy }, if (!initJson.type) {
endPoint: { x: ex, y: ey }, initJson.type = 2
smodel: { id: model.id, x: sx, y: sy, rate: 0.5, sita: startSita }, }
emodel: { id: existsControl.id, x: ex, y: ey, rate: 0.5, sita: endSita } if (!initJson.dash) {
}, initJson.dash = [10, 5]
],true,true,false) }
this.editor.tempLineModel = lines[0]; if (!initJson.startPoint) {
DDeiEditorUtil.closeDialog(this.editor, 'ddei-ext-dialog-quickchoosecontrol', true) initJson.startPoint = { x: sx, y: sy }
this.editor.bus.push(DDeiEnumBusCommandType.RefreshShape); }
this.editor.bus.executeAll(); if (!initJson.endPoint) {
initJson.endPoint = { x: ex, y: ey }
}
if (!initJson.smodel) {
initJson.smodel = smodel
}
if (!initJson.emodel) {
initJson.emodel = emodel
}
let lines = this.editor.addLines([
initJson
],true,true,false)
this.editor.tempLineModel = lines[0];
DDeiEditorUtil.closeDialog(this.editor, 'ddei-ext-dialog-quickchoosecontrol', true)
this.editor.bus.push(DDeiEnumBusCommandType.RefreshShape);
this.editor.bus.executeAll();
}
} }
} }
} }

View File

@ -198,7 +198,10 @@ export default {
converters?.forEach(converter => { converters?.forEach(converter => {
initData = converter.input(initData) initData = converter.input(initData)
}); });
this.editor.addControls(initData.controls) let controlInitJSON = DDeiEditorUtil.getModelInitJSON(this.editor.ddInstance, null, initData.controls)
if (controlInitJSON){
this.editor.addControls(controlInitJSON)
}
} }
if (options?.config?.access){ if (options?.config?.access){