Skip to content

Commit

Permalink
fix(*): bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ctank committed Aug 19, 2019
1 parent d088977 commit 01bfe98
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 22 deletions.
15 changes: 14 additions & 1 deletion src/draw/shape/CallActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,21 @@ class CallActivity extends Shape {
* 获取文本范围
*/
getTextBlock() {
const { textStyle } = this.style
const { height, width } = this.plane.bounds
return { x: 10, y: 0, width: width - 20, height }

let textWidth = width - 20
let textHeight = height
if (textStyle) {
textWidth = textStyle.width || textWidth
textHeight = textStyle.height || textHeight
}
return {
x: width / 2 - textWidth / 2,
y: height / 2 - textHeight / 2,
width: textWidth,
height: textHeight
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/draw/shape/ComplexGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,20 @@ class ComplexGateway extends Shape {
* 获取文本范围
*/
getTextBlock() {
const { textStyle } = this.style
const { height, width } = this.plane.bounds
return { x: width / 2 - 60, y: height, width: 120, height: 30 }
let textWidth = 120
let textHeight = 30
if (textStyle) {
textWidth = textStyle.width || textWidth
textHeight = textStyle.height || textHeight
}
return {
x: width / 2 - textWidth / 2,
y: height,
width: textWidth,
height: textHeight
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/draw/shape/ExclusiveGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,20 @@ class ExclusiveGateway extends Shape {
* 获取文本范围
*/
getTextBlock() {
const { textStyle } = this.style
const { height, width } = this.plane.bounds
return { x: width / 2 - 60, y: height, width: 120, height: 30 }
let textWidth = 120
let textHeight = 30
if (textStyle) {
textWidth = textStyle.width || textWidth
textHeight = textStyle.height || textHeight
}
return {
x: width / 2 - textWidth / 2,
y: height,
width: textWidth,
height: textHeight
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/draw/shape/InclusiveGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,20 @@ class InclusiveGateway extends Shape {
* 获取文本范围
*/
getTextBlock() {
const { textStyle } = this.style
const { height, width } = this.plane.bounds
return { x: width / 2 - 60, y: height, width: 120, height: 30 }
let textWidth = 120
let textHeight = 30
if (textStyle) {
textWidth = textStyle.width || textWidth
textHeight = textStyle.height || textHeight
}
return {
x: width / 2 - textWidth / 2,
y: height,
width: textWidth,
height: textHeight
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/draw/shape/ParallelGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,20 @@ class ParallelGateway extends Shape {
* 获取文本范围
*/
getTextBlock() {
const { textStyle } = this.style
const { height, width } = this.plane.bounds
return { x: width / 2 - 60, y: height, width: 120, height: 30 }
let textWidth = 120
let textHeight = 30
if (textStyle) {
textWidth = textStyle.width || textWidth
textHeight = textStyle.height || textHeight
}
return {
x: width / 2 - textWidth / 2,
y: height,
width: textWidth,
height: textHeight
}
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/draw/shape/ServiceTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,21 @@ class ServiceTask extends Shape {
* 获取文本范围
*/
getTextBlock() {
const { textStyle } = this.style
const { height, width } = this.plane.bounds
return { x: 10, y: 0, width: width - 20, height: height }

let textWidth = width - 20
let textHeight = height
if (textStyle) {
textWidth = textStyle.width || textWidth
textHeight = textStyle.height || textHeight
}
return {
x: width / 2 - textWidth / 2,
y: height / 2 - textHeight / 2,
width: textWidth,
height: textHeight
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/features/edit-name/editName.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class EditName {
})

$edit.trigger('keyup')
$edit.select()
}
}

Expand Down
42 changes: 31 additions & 11 deletions src/features/record/record.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import eventBus from '../../core/eventBus'
import ArrayStack from './arrayStack'
import { cloneJSON } from '../../utils/clone'

class Record {
constructor() {
Expand All @@ -12,6 +13,8 @@ class Record {
// 重做堆栈
this.redoStack = new ArrayStack()
//
this.initStatus = false
//
this.init()
}

Expand All @@ -26,6 +29,8 @@ class Record {
key: 'Ctrl+Y',
fun: this.redo.bind(this)
})
// 设定初始化状态
eventBus.on('record.init', this.setInitStatus.bind(this))
// 开始处理
eventBus.on('record.start', this.start.bind(this))
// 结束处理
Expand All @@ -40,32 +45,38 @@ class Record {
* 开始处理,修改数量
*/
start() {
this.batSize++
if (this.initStatus) {
this.batSize++
}
}

/**
* 结束处理,执行堆栈操作
*/
end() {
this.batSize--
this.execute()
if (this.initStatus) {
this.batSize--
this.execute()
}
}

/**
* 添加记录
* @param {*} data
*/
push(data) {
this.records.push(data)
// 如果不是多任务则立即执行
this.execute()
if (this.initStatus) {
this.records.push(data)
// 如果不是多任务则立即执行
this.execute()
}
}

/**
* 执行
*/
execute() {
if (this.batSize === 0 && this.records.length !== 0) {
if (this.initStatus && this.batSize === 0 && this.records.length !== 0) {
if (this.undoStack.status) {
// 将事件压入撤销堆栈
this.undoStack.push(this.records)
Expand All @@ -74,6 +85,13 @@ class Record {
}
}

/**
* 设定状态
*/
setInitStatus(status) {
this.initStatus = status
}

/**
* 撤销
*/
Expand All @@ -82,7 +100,7 @@ class Record {
this.undoStack.setStatus(false)
// 获取撤销栈长度
const undoSize = this.undoStack.size()
if (undoSize > 0) {
if (this.initStatus && undoSize > 0) {
// 获取最新记录
const record = this.undoStack.top()
// 清除最新记录
Expand All @@ -92,7 +110,8 @@ class Record {

this.start()

record.forEach(item => {
for (let i = record.length - 1; i >= 0; i -= 1) {
const item = record[i]
switch (item.action) {
case 'create':
// 清除选择
Expand Down Expand Up @@ -138,7 +157,8 @@ class Record {
default:
break
}
})
}

this.end()
}
// 解锁撤销栈
Expand All @@ -153,7 +173,7 @@ class Record {
this.undoStack.setStatus(false)
// 获取重做栈长度
const redoSize = this.redoStack.size()
if (redoSize > 0) {
if (this.initStatus && redoSize > 0) {
// 获取最新记录
const record = this.redoStack.top()
// 清除最新记录
Expand Down
11 changes: 6 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ class BPDCore {
}

init(callback = () => {}) {
this.importBpmn(this.options.definition, callback)
this.importBpmn(this.options.definition, () => {
callback()
eventBus.trigger('record.init', true)
})

DomSize.bind(this.$container[0], () => {
this.resizeContainer()
Expand Down Expand Up @@ -489,10 +492,9 @@ class BPDCore {
if (err) {
console.log(err)
} else {
eventBus.trigger('record.start')
self.draw.render(definitions)
// self.exportBpmn(function(xmlStrUpdated) {
// console.log('导出回调', xmlStrUpdated)
// })
eventBus.trigger('record.end')
// 执行回调
callback()
}
Expand All @@ -504,7 +506,6 @@ class BPDCore {
* 导出Bpmn
*/
exportBpmn(callback = () => {}) {
const self = this
const definitions = this.draw.designer.createDefinition()
eventBus.trigger('model.export', definitions, (err, xmlStrUpdated) => {
if (err) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export const setExportData = element => {
for (let key in data) {
switch (key) {
case '$type':
case '$instanceOf':
break
case 'extensionElements':
exportData.extensions = setExportExtensions(data[key].values || [])
Expand Down

0 comments on commit 01bfe98

Please sign in to comment.