Skip to content

DDeiEditor

  DDeiEditor是DDei设计器的核心类,每当使用DDeiEditorViewer都会生成一个组件实例,其中的editor属性类型为DDeiEditor

  DDeiEditor实例包含了组件的所有数据,在获取后可以通过它访问其他内容。DDeiEditor中维护了一个实例池,可以根据名称得到任意实例。

  一个DDeiEditor实例至少包含一个DDeiFile实例和一个DDei实例。

  本篇最后提供的示例可以在文档中直接预览。

属性

属性名说明数据类型静态默认值备注
ididstring
containerid所属容器IDstring
files文件列表DDeiFile[][]
currentFileIndex当前文件下标number-1
state状态DDeiEditorStateDESIGNING
modelType模型名称stringDDeiEditor
ddInstanceDDei内部对象stringDDeiEditor
editMode编辑模式number11指针/2手/3文本创建/4线段创建
INSTANCE_POOL实例池Map以key-value的形式维护了所有DDeiEditor实例
width画布宽度number仅用于初始化
height画布高度number仅用于初始化
ratio缩放比率number1.0仅用于初始化
mark水印string/object/null1.0仅用于初始化 查看详情
ruler标尺number1.0仅用于初始化 查看详情
grid网格number/null1仅用于初始化 查看详情
paper纸张string/object/null仅用于初始化 查看详情
background背景string/object/null仅用于初始化 查看详情
EXT_STAGE_WIDTH自动扩展宽度boolean
EXT_STAGE_HEIGHT自动扩展宽度boolean
GLOBAL_ALLOW_STAGE_RATIO开启全局缩放booleantrue
GLOBAL_ADV_WEIGHT吸附区域尺寸number5大于0时拖拽时会有吸附效果,小于0时没有效果
GLOBAL_HELP_LINE_ENABLE显示对齐辅助线booleantrue
EVENT_LOAD_FILE加载文件Function/null回调函数
EVENT_SAVE_FILE保存文件Function/null回调函数
EVENT_CONTROL_SELECT_BEFORE控件选择前Function/null回调函数
EVENT_CONTROL_SELECT_AFTER控件选择后Function/null回调函数
EVENT_CONTROL_SELECT_CREATE控件创建前Function/null回调函数
EVENT_MOUSE_OPERATING鼠标操作中Function/null回调函数
EVENT_CONTROL_DRAG_BEFORE拖拽前Function/null回调函数
EVENT_CONTROL_DRAG_AFTER拖拽后Function/null回调函数
EVENT_LINE_DRAG_BEFORE线拖拽前Function/null回调函数
EVENT_LINE_DRAG_AFTER线拖砖后Function/null回调函数
EVENT_CONTROL_DEL_BEFORE控件删除前Function/null回调函数
EVENT_CONTROL_DEL_AFTER控件删除后Function/null回调函数
EVENT_CONTROL_EDIT_BEFORE控件编辑前Function/null回调函数
EVENT_CONTROL_EDIT_AFTER控件编辑后Function/null回调函数
EVENT_CONTROL_EDIT_BEFORE控件编辑前Function/null回调函数
EVENT_CONTROL_EDIT_AFTER控件编辑后Function/null回调函数
EVENT_STAGE_CHANGE_WPV移动视窗Function/null回调函数
EVENT_STAGE_CHANGE_RATIO全局缩放Function/null回调函数

方法

addFile

  添加文件到列表中,默认添加到最后面

参数

参数名类型范围默认值备注
fileDDeiFile文件
indexnumber位置下标

返回值

  无

removeFile

  移除文件,可以传入文件或下标

参数

参数名类型范围默认值备注
fileDDeiFile文件
indexnumber位置下标

返回值

  无

changeFile

  交换文件

参数

参数名类型范围默认值备注
indexAnumber位置下标1
indexBnumber位置下标2

返回值

  无

addControls

  向当前画布添加控件,缺省坐标为当前画布的中心

参数

参数名类型范围默认值备注
controlsobject[]控件配置数组
controls[n].idstringID,画布唯一
controls[n].modelstring控件定义编号
controls[n].codestring编码,一般用于业务
controls[n].widthnumber初始化宽度
controls[n].heightnumber初始化高度
controls[n].textstring文本
controls[n].offsetXnumber初始偏移位置x,以中心为0,0
controls[n].offsetYnumber初始偏移位置y,以中心为0,0

返回值

  无

removeControls

  根据ID删除控件

参数

参数名类型范围默认值备注
idsstring[]ID数组

返回值

  无

getControlById

  根据ID获取控件

参数

参数名类型范围默认值备注
idstringID

返回值

类型备注
DDeiAbstractShape控件实例模型

changeTheme

  设置主题

参数

参数名类型范围默认值说明
themeNamestring主题名称

返回值

  无

changeStyle

  修改样式

参数

参数名类型范围默认值说明
namestring主题名称
objobjectK-V样式对象

返回值

  无

changeEditMode

  修改当前编辑模式

参数

参数名类型范围默认值说明
modenumber1指针/2手/3文本创建/4线创建1模式

返回值

  无

setEditable

  设置是否可以编辑

参数

参数名类型范围默认值说明
editablebooleantrue可编辑/false不可编辑

返回值

  无

setAccessInfo

  设置权限信息

参数

参数名类型范围默认值说明
configobject权限配置,K-V数据
config.keystringCREATE/EDIT/DRAG/SELECT/LINK/DEL
config.valuebooleantrue有权限/false无权限

返回值

  无

changeState

  修改编辑器状态

参数

参数名类型范围默认值说明
stateDDeiEditorState状态

返回值

  无

notifyChange

  通知改变,刷新画布

参数

  无

返回值

  无

示例

代码

vue
<script setup lang="ts">
import DDeiEditorView from "ddei-editor";
import {DDeiEditor,DDeiCoreStandLayout,DDeiAbstractShape} from "ddei-editor";
import { defineComponent, markRaw,getCurrentInstance } from "vue";
//获取主对象实例,代替this获取$refs
const {proxy} = getCurrentInstance()

const options = markRaw({
  config: { 
    "background": { color: "blue", opacity: 0.1 }, //背景色
  },
  //配置扩展插件
  extensions: [
    //布局的配置
    DDeiCoreStandLayout.configuration({
      //配置插件
      'top': [],
      'middle': ['ddei-core-panel-canvasview'],
      'bottom': [],
      'left': [],
      'right': []
    }),
  ],
})
const createControl = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_1"].editor;
  let editor1 = DDeiEditor.INSTANCE_POOL.get("ddei_editor_api_1")
  //添加控件
  editor.addControls([
        {
          id:"control_1",
          model: "102010",
          text: "新图形"
        },
      ]);
};
const removeControl = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_1"].editor;
  //添加控件
  editor1.removeControls(["control_1"]);
};
const changeControlText = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_1"].editor;
  //添加控件
  let model:DDeiAbstractShape = editor.getControlById("control_1");
  model.text += "-改"
  model.notifyChange()
};
const changeEditable = () => {
  this.editable = !this.editable
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_1"].editor;
  editor.setEditable(this.editable)
};
</script>

<template>

<button @click="createControl" style="border:1px solid grey;margin-left:5px;padding:5px">创建控件</button>
<button @click="removeControl" style="border:1px solid grey;margin-left:5px;padding:5px">删除控件</button>
<button @click="changeControlText" style="border:1px solid grey;margin-left:5px;padding:5px">修改文本</button>
<button @click="changeEditable" style="border:1px solid grey;margin-left:5px;padding:5px">锁定/解锁</button>

<div style="width:400px;height:400px;margin:100px auto;">
  <DDeiEditorView :options="options" ref="ddei_editor_api_1" id="ddei_editor_api_1"></DDeiEditorView>
</div>
</template>

效果预览

技术支持