Skip to content

Commit

Permalink
fix(*): bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ctank committed Aug 12, 2019
1 parent c7564f6 commit 43395fc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/core/designer.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,17 +496,17 @@ class Designer {
* @param {*} callback
*/
createElement(
{ type, eventDefinitionType, prefix, name, pos },
{ type, eventDefinitionType, prefix, name, pos, id },
callback = () => {}
) {
const id = prefix + '_' + this.options.ids.next()
const elementId = id || prefix + '_' + this.options.ids.next()
// 元素数据
const data = cloneJSON(
this.createModel({
descriptor: 'bpmn:' + type,
attrs: {
name,
id,
id: elementId,
eventDefinitions: this.createEventModel(eventDefinitionType),
extensionElements: this.createExtensionModel()
}
Expand Down
2 changes: 1 addition & 1 deletion src/draw/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Draw extends Operation {
if (planeElement && planeElement.length > 0) {
planeElement.forEach((plane, planeIndex) => {
if (plane.id === element.id + '_di') {
const data = cloneElement(element)
const data = cloneJSON(element)
if (element.extensionElements) {
data.extensionElements.values =
element.extensionElements.values || []
Expand Down
30 changes: 17 additions & 13 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,37 @@ const createContainer = options => {
*/
const initFeatures = ($container, options) => {
// 快捷键
new HotKey()
const hotKey = new HotKey()
// 国际化
new I18n(options.local)
const i18n = new I18n(options.local)
// xml
new BpmnXML(options.extensions)
const bpmnXML = new BpmnXML(options.extensions)
// 背景
new Background($container, options, options.config.background)
const background = new Background(
$container,
options,
options.config.background
)
// 手
new Hand($container, options.pageStyle)
const hand = new Hand($container, options.pageStyle)
// 非只读状态时
if (!options.readonly) {
// 锚点
new ShapeAnchor($container, options.config.anchor)
const shapeAnchor = new ShapeAnchor($container, options.config.anchor)
// 对齐
new Snapline($container, options.config.snapline)
const snapline = new Snapline($container, options.config.snapline)
// 流向
new Direction($container, options.config.direction)
const direction = new Direction($container, options.config.direction)
// 选择
new ShapeSelect($container, options.config.select)
const shapeSelect = new ShapeSelect($container, options.config.select)
// 记录
new Record()
const record = new Record()
// 提示
new Tooltip($container, options.config.tooltip)
const tooltip = new Tooltip($container, options.config.tooltip)
// 拖动
new ShapeDrag(options, $container)
const shapeDrag = new ShapeDrag(options, $container)
// 组面板
new GroupPanel($container, options)
const groupPanel = new GroupPanel($container, options)
}
}

Expand Down
59 changes: 55 additions & 4 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,61 @@ export const mergeArray = (array1, array2) => {
* @return {} 新元素
*/
export const cloneElement = element => {
return eventBus.trigger('shape.create', {
type: element.shape.bpmnName,
element: cloneJSON(element)
})
const { data, plane, shape } = element
// 判断格式
if (data && plane && shape) {
const type = shape.bpmnName
// 创建没有shape的element
const defaultElement = eventBus.trigger('element.create', {
name: data.name,
id: data.id,
type,
prefix: 'obj'
})
// 还原data和plane属性
if (type !== 'SequenceFlow') {
defaultElement.data.incoming = data.incoming ? data.incoming : ''
defaultElement.data.outgoing = data.outgoing ? data.outgoing : ''
if (data.extensionElements) {
defaultElement.data.extensionElements.values =
data.extensionElements.values || []
}
// 创建bound
eventBus.trigger(
'model.create',
{
descriptor: 'dc:Bounds',
attrs: {
height: plane.bounds.height,
width: plane.bounds.width,
x: plane.bounds.x,
y: plane.bounds.y
}
},
model => {
defaultElement.plane.bounds = model
}
)
} else {
defaultElement.plane.waypoint = cloneJSON(plane.waypoint)
defaultElement.data.sourceRef = data.sourceRef ? data.sourceRef : ''
defaultElement.data.targetRef = data.targetRef ? data.targetRef : ''
}
// 创建含shape的element
const newElement = eventBus.trigger('shape.create', {
type,
element: defaultElement
})
// 还原shape属性
if (type === 'SequenceFlow') {
newElement.shape.points = cloneJSON(shape.points)
}
return newElement
} else {
console.log('element error')
}

return null
}

/**
Expand Down

0 comments on commit 43395fc

Please sign in to comment.