workflow-editor 0.9.66-dw → 0.9.66-pv1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/lib/workflow-editor.css +1 -1
  2. package/lib/workflow-editor.umd.min.js +10 -10
  3. package/package.json +2 -2
  4. package/packages/index.js +34 -0
  5. package/packages/plugins/formValidatorUtil.js +528 -0
  6. package/packages/plugins/index.js +8 -0
  7. package/packages/workflow-editor/index.js +14 -0
  8. package/packages/workflow-editor/src/api.js +7 -0
  9. package/packages/workflow-editor/src/assets/wf-editor-icons.js +2 -0
  10. package/packages/workflow-editor/src/constant.js +8 -0
  11. package/packages/workflow-editor/src/json-object-templates/copy-task.js +67 -0
  12. package/packages/workflow-editor/src/json-object-templates/decision.js +11 -0
  13. package/packages/workflow-editor/src/json-object-templates/end.js +14 -0
  14. package/packages/workflow-editor/src/json-object-templates/fork.js +10 -0
  15. package/packages/workflow-editor/src/json-object-templates/human-decision.js +9 -0
  16. package/packages/workflow-editor/src/json-object-templates/human-task.js +199 -0
  17. package/packages/workflow-editor/src/json-object-templates/join.js +10 -0
  18. package/packages/workflow-editor/src/json-object-templates/process.js +98 -0
  19. package/packages/workflow-editor/src/json-object-templates/start.js +13 -0
  20. package/packages/workflow-editor/src/json-object-templates/subprocess.js +30 -0
  21. package/packages/workflow-editor/src/json-object-templates/transition.js +26 -0
  22. package/packages/workflow-editor/src/main/admin-save-dialog.vue +66 -0
  23. package/packages/workflow-editor/src/main/canvas.vue +479 -0
  24. package/packages/workflow-editor/src/main/context-menu.vue +132 -0
  25. package/packages/workflow-editor/src/main/icon-svg.vue +32 -0
  26. package/packages/workflow-editor/src/main/selection-region.vue +66 -0
  27. package/packages/workflow-editor/src/main/tache-history-tooltip.vue +38 -0
  28. package/packages/workflow-editor/src/main/tache-name-input.vue +19 -0
  29. package/packages/workflow-editor/src/main/tache-subprocess-history-dialog.vue +35 -0
  30. package/packages/workflow-editor/src/main/toolbox.vue +60 -0
  31. package/packages/workflow-editor/src/main/wf-history-canvas.vue +302 -0
  32. package/packages/workflow-editor/src/process-json.js +622 -0
  33. package/packages/workflow-editor/src/process-service.js +31 -0
  34. package/packages/workflow-editor/src/properties-editors/common/additional-condition-utils.js +531 -0
  35. package/packages/workflow-editor/src/properties-editors/common/additional-condition.vue +276 -0
  36. package/packages/workflow-editor/src/properties-editors/common/auto-filled-fields-utils.js +34 -0
  37. package/packages/workflow-editor/src/properties-editors/common/auto-filled-fields.vue +239 -0
  38. package/packages/workflow-editor/src/properties-editors/common/common-notice-tool.vue +47 -0
  39. package/packages/workflow-editor/src/properties-editors/common/common-user-condition.vue +241 -0
  40. package/packages/workflow-editor/src/properties-editors/common/form-fields-utils.js +23 -0
  41. package/packages/workflow-editor/src/properties-editors/common/form-fields.vue +116 -0
  42. package/packages/workflow-editor/src/properties-editors/common/i18n-input.vue +75 -0
  43. package/packages/workflow-editor/src/properties-editors/common/i18n-set-dialog.vue +125 -0
  44. package/packages/workflow-editor/src/properties-editors/common/notice.vue +98 -0
  45. package/packages/workflow-editor/src/properties-editors/common/reminder.vue +179 -0
  46. package/packages/workflow-editor/src/properties-editors/common/select-mail-template.vue +83 -0
  47. package/packages/workflow-editor/src/properties-editors/common/standard-fields.vue +65 -0
  48. package/packages/workflow-editor/src/properties-editors/common/system-role-tree-inline.vue +355 -0
  49. package/packages/workflow-editor/src/properties-editors/common/system-role-tree.vue +63 -0
  50. package/packages/workflow-editor/src/properties-editors/common/task-title.vue +148 -0
  51. package/packages/workflow-editor/src/properties-editors/common/transactor-settings.vue +233 -0
  52. package/packages/workflow-editor/src/properties-editors/common/user-selection.vue +386 -0
  53. package/packages/workflow-editor/src/properties-editors/common/value-selection-dialog.vue +209 -0
  54. package/packages/workflow-editor/src/properties-editors/common/variables.vue +135 -0
  55. package/packages/workflow-editor/src/properties-editors/copy-task/basic-properties.vue +90 -0
  56. package/packages/workflow-editor/src/properties-editors/copy-task/permission-settings.vue +155 -0
  57. package/packages/workflow-editor/src/properties-editors/copy-task.vue +80 -0
  58. package/packages/workflow-editor/src/properties-editors/decision.vue +90 -0
  59. package/packages/workflow-editor/src/properties-editors/fork.vue +72 -0
  60. package/packages/workflow-editor/src/properties-editors/human-decision.vue +44 -0
  61. package/packages/workflow-editor/src/properties-editors/human-task/additional-condition-dialog.vue +60 -0
  62. package/packages/workflow-editor/src/properties-editors/human-task/basic-properties.vue +156 -0
  63. package/packages/workflow-editor/src/properties-editors/human-task/componentsConfigUtil.js +291 -0
  64. package/packages/workflow-editor/src/properties-editors/human-task/custom-actions.vue +249 -0
  65. package/packages/workflow-editor/src/properties-editors/human-task/editable-child-field-setting.vue +392 -0
  66. package/packages/workflow-editor/src/properties-editors/human-task/editable-child-fields.vue +241 -0
  67. package/packages/workflow-editor/src/properties-editors/human-task/editable-field-selection.vue +220 -0
  68. package/packages/workflow-editor/src/properties-editors/human-task/editable-fields.vue +204 -0
  69. package/packages/workflow-editor/src/properties-editors/human-task/events.vue +59 -0
  70. package/packages/workflow-editor/src/properties-editors/human-task/permission-settings.vue +207 -0
  71. package/packages/workflow-editor/src/properties-editors/human-task/selection-conditions.vue +390 -0
  72. package/packages/workflow-editor/src/properties-editors/human-task.vue +103 -0
  73. package/packages/workflow-editor/src/properties-editors/join.vue +44 -0
  74. package/packages/workflow-editor/src/properties-editors/process/basic-properties.vue +309 -0
  75. package/packages/workflow-editor/src/properties-editors/process/events.vue +76 -0
  76. package/packages/workflow-editor/src/properties-editors/process/notice-settings.vue +60 -0
  77. package/packages/workflow-editor/src/properties-editors/process/parameter-settings.vue +95 -0
  78. package/packages/workflow-editor/src/properties-editors/process/permission-settings.vue +28 -0
  79. package/packages/workflow-editor/src/properties-editors/process/selectPage.vue +81 -0
  80. package/packages/workflow-editor/src/properties-editors/process.vue +109 -0
  81. package/packages/workflow-editor/src/properties-editors/subprocess/basic-properties.vue +187 -0
  82. package/packages/workflow-editor/src/properties-editors/subprocess/events.vue +26 -0
  83. package/packages/workflow-editor/src/properties-editors/subprocess/field-mappings.vue +206 -0
  84. package/packages/workflow-editor/src/properties-editors/subprocess/transactor-settings.vue +64 -0
  85. package/packages/workflow-editor/src/properties-editors/subprocess.vue +79 -0
  86. package/packages/workflow-editor/src/properties-editors/transition/basic-properties.vue +53 -0
  87. package/packages/workflow-editor/src/properties-editors/transition.vue +74 -0
  88. package/packages/workflow-editor/src/properties-editors/user-condition.js +177 -0
  89. package/packages/workflow-editor/src/store/getters.js +28 -0
  90. package/packages/workflow-editor/src/store/workflow-editor.js +128 -0
  91. package/packages/workflow-editor/src/taches/common-methods.js +21 -0
  92. package/packages/workflow-editor/src/taches/copy-task.vue +99 -0
  93. package/packages/workflow-editor/src/taches/custom-task.vue +88 -0
  94. package/packages/workflow-editor/src/taches/decision.vue +102 -0
  95. package/packages/workflow-editor/src/taches/end.vue +76 -0
  96. package/packages/workflow-editor/src/taches/fork.vue +102 -0
  97. package/packages/workflow-editor/src/taches/human-decision.vue +102 -0
  98. package/packages/workflow-editor/src/taches/human-task.vue +113 -0
  99. package/packages/workflow-editor/src/taches/join.vue +91 -0
  100. package/packages/workflow-editor/src/taches/joint.vue +177 -0
  101. package/packages/workflow-editor/src/taches/start.vue +76 -0
  102. package/packages/workflow-editor/src/taches/subprocess.vue +99 -0
  103. package/packages/workflow-editor/src/taches/tache-resizer.vue +80 -0
  104. package/packages/workflow-editor/src/transitions/broken-line.vue +91 -0
  105. package/packages/workflow-editor/src/transitions/curve-line.vue +91 -0
  106. package/packages/workflow-editor/src/transitions/straight-line.vue +26 -0
  107. package/packages/workflow-editor/src/transitions/transition.vue +212 -0
  108. package/packages/workflow-editor/src/transitions/virtual-transition.vue +43 -0
  109. package/packages/workflow-editor/src/util.js +493 -0
  110. package/packages/workflow-editor/src/workflow-editor.vue +624 -0
  111. package/packages/workflow-editor/src/workflow-history.vue +153 -0
  112. package/src/i18n/i18n.js +1 -1
  113. package/src/i18n/langs/cn.js +6 -1
  114. package/src/i18n/langs/en.js +6 -1
@@ -0,0 +1,624 @@
1
+ <template>
2
+ <div
3
+ ref="wfEditor"
4
+ style="position:relative;height:100%;"
5
+ @mousedown="setContextMenuVisible(false)"
6
+ @mousewheel="setContextMenuVisible(false)"
7
+ >
8
+ <el-row class="button-area">
9
+ <el-button v-if="!readonly" type="primary" size="small" @click="saveXml">
10
+ {{ $t('workflowEditorPublicModel.save') }}
11
+ </el-button>
12
+ <el-button v-if="!readonly" v-permission="'wf.workflowDefinition.adminSave'" type="primary" size="small" @click="adminSave">
13
+ {{ $t('workflowEditorPublicModel.adminSave') }}
14
+ </el-button>
15
+ <el-button type="primary" size="small" @click="exportProcessFromClient">
16
+ {{ $t('workflowEditorPublicModel.export') }}
17
+ </el-button>
18
+ <el-button
19
+ v-if="!readonly"
20
+ size="small"
21
+ type="primary"
22
+ @click="selectProcessFile"
23
+ >
24
+ {{ $t('workflowEditorPublicModel.open') }}
25
+ <input
26
+ ref="processFile"
27
+ type="file"
28
+ name="processFile"
29
+ accept=".xml"
30
+ style="display:none"
31
+ @change="openXmlFromClient"
32
+ >
33
+ </el-button>
34
+
35
+ <el-button type="primary" size="small" @click="$emit('back')">
36
+ {{ $t('workflowEditorPublicModel.return') }}
37
+ </el-button>
38
+ </el-row>
39
+ <div
40
+ class="main"
41
+ @mousedown="startDrag"
42
+ @mousemove="drag"
43
+ @mouseup="endDrag"
44
+ @mouseleave="clearStatus"
45
+ >
46
+ <toolbox
47
+ v-if="!readonly"
48
+ class="toolbox"
49
+ onselectstart="return false"
50
+ oncontextmenu="return false"
51
+ />
52
+ <section>
53
+ <el-tabs v-model="activeTab" type="border-card" class="tabs">
54
+ <el-tab-pane :label="$t('workflowEditorPublicModel.flowChart')" name="canvas" class="tab-pane">
55
+ <workflow-canvas
56
+ onselectstart="return false"
57
+ :process="process"
58
+ class="canvas"
59
+ @mouseup.native="addTache"
60
+ @contextmenu.native.prevent="showContextMenu"
61
+ />
62
+ </el-tab-pane>
63
+ <el-tab-pane
64
+ label="XML"
65
+ name="xml"
66
+ class="tab-pane"
67
+ >
68
+ <pre v-if="activeTab==='xml'" class="xml line-numbers"><code ref="xml" class="language-xml">{{ xml }}</code></pre>
69
+ </el-tab-pane>
70
+ </el-tabs>
71
+ </section>
72
+ </div>
73
+ <icon-svg
74
+ v-if="componentToDraw"
75
+ :style="{
76
+ height:componentInfo.height,
77
+ width:componentInfo.width,
78
+ color:componentInfo.color,
79
+ left: currentPosition.x+'px',
80
+ top:currentPosition.y+'px',
81
+ }"
82
+ :icon="componentInfo.icon"
83
+ class="component-icon"
84
+ />
85
+ <context-menu v-if="contextMenuVisible" :style="{position:'absolute',left: contextMenuPosition.x+ 'px',top:contextMenuPosition.y+'px'}" />
86
+ <admin-save-dialog v-if="isAdminSave" @close="isAdminSave = false" @update="updateWfVersion" @add="addWfVersion" />
87
+ </div>
88
+ </template>
89
+ <script>
90
+ import './assets/wf-editor-icons.js'
91
+ import { mapGetters, mapMutations } from 'vuex'
92
+ import { getMousePosition, removeTextProperty, getComponentInfo, initializeProcessData, processTemplate } from './util'
93
+ import Toolbox from './main/toolbox'
94
+ import WorkflowCanvas from './main/canvas'
95
+ import IconSvg from './main/icon-svg'
96
+ import ContextMenu from './main/context-menu'
97
+ import convert from 'xml-js'
98
+ import processService from './process-service'
99
+ import FileSaver from 'file-saver'
100
+ import Prism from 'prismjs'
101
+ import AdminSaveDialog from './main/admin-save-dialog'
102
+ export default {
103
+ name: 'WorkflowEditor',
104
+ components: {
105
+ WorkflowCanvas,
106
+ Toolbox,
107
+ IconSvg,
108
+ ContextMenu,
109
+ AdminSaveDialog
110
+ },
111
+ props: {
112
+ // 流程编码
113
+ code: {
114
+ type: String,
115
+ default: null
116
+ },
117
+ // 流程版本
118
+ version: {
119
+ type: Number,
120
+ default: null
121
+ },
122
+ // 流程id
123
+ id: {
124
+ type: Number,
125
+ default: null
126
+ },
127
+ readonly: {
128
+ type: Boolean,
129
+ default: false
130
+ },
131
+ // 系统编码,新增时选中的系统编码,或修改时流程定义所属的系统编码
132
+ systemCode: {
133
+ type: String,
134
+ default: null
135
+ },
136
+ // 系统版本号,修改时流程定义中的系统版本号,例如:v1.0.0,新增不会使用该属性
137
+ systemPublishVersion: {
138
+ type: String,
139
+ default: null
140
+ }
141
+ },
142
+ data: function() {
143
+ return {
144
+ activeTab: 'canvas',
145
+ count: 1,
146
+ currentPosition: { x: 0, y: 0 },
147
+ process: null,
148
+ definitionId: null,
149
+ xml: '',
150
+ contextMenuPosition: null,
151
+ isAdminSave: false // 是否点击了管理员保存按钮
152
+ }
153
+ },
154
+ computed: {
155
+ ...mapGetters(
156
+ 'wfEditor', ['componentToDraw', 'taches', 'transitions', 'contextMenuVisible', 'systemVersion']
157
+ ),
158
+ ...mapGetters([
159
+ 'sidebar'
160
+ ]),
161
+ componentInfo() {
162
+ return getComponentInfo(this.componentToDraw)
163
+ }
164
+ },
165
+ watch: {
166
+ activeTab(name) {
167
+ if (name === 'xml') {
168
+ this.xml = this.getProcessXml()
169
+ this.$nextTick(function() {
170
+ Prism.highlightElement(this.$refs.xml)
171
+ })
172
+ }
173
+ }
174
+ },
175
+ created: function() {
176
+ if (this.systemPublishVersion) {
177
+ this.setSystemVersion(this.systemPublishVersion)
178
+ }
179
+ // 打开或新建流程图时先清空画布,开发过程中代码热更新的时候可以避免节点重复
180
+ this.clearCanvas()
181
+ if (this.id) {
182
+ this.definitionId = this.id
183
+ }
184
+ console.log('canvas-created=', this.code, this.id)
185
+ if (this.code || this.id) {
186
+ let url = this.baseAPI + '/wf-editor/open-xmls/with-definitions'
187
+ url = this.packageUrlParam(url)
188
+ this.$http.get(url).then(xml => {
189
+ this.initProcessByXml(xml)
190
+ })
191
+ } else {
192
+ this.process = processTemplate.newProcess()
193
+ initializeProcessData(this.process)
194
+ }
195
+ },
196
+ mounted: function() {
197
+
198
+ },
199
+ methods: {
200
+ ...mapMutations('wfEditor', [
201
+ 'setComponentToDraw',
202
+ 'clearCanvas',
203
+ 'setContextMenuVisible',
204
+ 'setSystemCode',
205
+ 'setSystemVersion',
206
+ 'setProcessCode'
207
+ ]),
208
+ showContextMenu(event) {
209
+ console.log(event)
210
+ this.setContextMenuVisible(true)
211
+ // 得到元素在页面上的位置信息,用来计算鼠标位置的偏移量
212
+ const offset = this.$refs.wfEditor.getBoundingClientRect()
213
+ this.contextMenuPosition = {
214
+ x: event.clientX - offset.x,
215
+ y: event.clientY - offset.y
216
+ }
217
+ },
218
+ initProcessByXml(xml) {
219
+ const options = { nativeType: true, attributesKey: 'attr', compact: true, ignoreComment: true, spaces: 4 }
220
+ const processObj = convert.xml2js(xml, options)
221
+ removeTextProperty(processObj.process)
222
+ this.process = processObj.process
223
+ if (this.process && this.process.properties && this.process.properties.basicProperties) {
224
+ this.setSystemCode(this.process.properties.basicProperties.systemCode)
225
+ } else {
226
+ // 新增时,将传过来的系统编码缓存起来
227
+ this.setSystemCode(this.systemCode)
228
+ }
229
+ if (this.process && this.process.attr) {
230
+ this.setProcessCode(this.process.attr.code)
231
+ }
232
+ // 得到表单字段放到vuex
233
+ this.fetchFormFields()
234
+ initializeProcessData(this.process)
235
+ this.count = this.getMaxCount() + 1
236
+ },
237
+ fetchFormFields() {
238
+ const processProperties = this.process.properties.basicProperties
239
+ const formCode = processProperties.formCode
240
+ const formVersion = processProperties.formVersion
241
+ if (formCode && formCode !== '' && formVersion) {
242
+ // 取出formFields放到vuex中
243
+ processService.fetchFormFields(processProperties.formCode, processProperties.formVersion)
244
+ }
245
+ },
246
+ packageUrlParam(url) {
247
+ if (this.id) {
248
+ url = url + '?id=' + this.id
249
+ } else if (this.code) {
250
+ url = url + '?code=' + this.code + '&version=' + this.version
251
+ }
252
+ return url
253
+ },
254
+ // 获得流程定义xml
255
+ getProcessXml() {
256
+ const process = {
257
+ start: [],
258
+ humanTask: [],
259
+ decision: [],
260
+ transition: [],
261
+ fork: [],
262
+ join: [],
263
+ subprocess: [],
264
+ humanDecision: [],
265
+ copyTask: [],
266
+ end: []
267
+ }
268
+ process.attr = this.process.attr
269
+ process.properties = this.process.properties
270
+ this.taches.map(tache => {
271
+ const type = tache.type
272
+ // type的首字母小写形式就是process中各个数组的名字,ref才是真正的环节信息
273
+ process[type.charAt(0).toLowerCase() + type.substring(1)].push(tache.ref)
274
+ // 补充完整图形位置信息
275
+ tache.ref.g = {
276
+ x: tache.x,
277
+ y: tache.y,
278
+ width: tache.width,
279
+ height: tache.height
280
+ }
281
+ })
282
+ this.transitions.map(transition => {
283
+ // ref才是真正的流向信息
284
+ process.transition.push(transition.ref)
285
+ // 补充完整图形位置信息
286
+ transition.ref.g = {
287
+ fromJoint: transition.startJoint.position,
288
+ toJoint: transition.endJoint.position,
289
+ coordinate: '',
290
+ lineType: transition.lineInfo.type
291
+ }
292
+ if (transition.lineInfo.type === 'CurveLine' && transition.lineInfo.controlPoint) {
293
+ transition.ref.g.coordinate = transition.lineInfo.controlPoint.x + ',' + transition.lineInfo.controlPoint.y
294
+ } else if (transition.lineInfo.type === 'BrokenLine' && transition.lineInfo.controlPoint) {
295
+ let coordinate = ''
296
+ transition.lineInfo.controlPoint.forEach(point => {
297
+ coordinate += point.x + ',' + point.y + ';'
298
+ })
299
+ transition.ref.g.coordinate = coordinate
300
+ }
301
+ })
302
+ const options = { attributesKey: 'attr', compact: true, ignoreComment: true, spaces: 4 }
303
+ let result = convert.json2xml({ process }, options)
304
+ result = '<?xml version="1.0" encoding="utf-8"?>\n' + result
305
+ return result
306
+ },
307
+ // 保存xml
308
+ saveXml() {
309
+ const xml = this.getProcessXml()
310
+ // console.log(xml)
311
+ // 保存流程定义xml
312
+ if (this.code || this.id || this.definitionId) {
313
+ // 表示修改
314
+ this.saveWf(xml, this.baseAPI + '/wf-editor/workflow-definitions/updates')
315
+ .then(() => {
316
+ this.$alert(this.$t('workflowEditorMessage.updateSuccessful'))
317
+ })
318
+ } else {
319
+ // 表示新建
320
+ const param = {
321
+ xml: xml,
322
+ publishVersion: this.systemVersion
323
+ }
324
+ this.$http.post(this.baseAPI + '/wf-editor/workflow-definitions', param).then(definition => {
325
+ this.definitionId = definition.id
326
+ this.$alert(this.$t('workflowEditorMessage.savedSuccessfully'))
327
+ // console.log('新建成功' + this.definitionId)
328
+ })
329
+ }
330
+ },
331
+ saveWf(xml, url, message) {
332
+ return new Promise((resolve, reject) => {
333
+ const param = this.packageSaveXmlParam(xml)
334
+
335
+ this.$http.post(url, param).then(definition => {
336
+ this.definitionId = definition.id
337
+ // console.log('更新成功' + this.definitionId)
338
+ resolve()
339
+ })
340
+ })
341
+ },
342
+ packageSaveXmlParam(xml) {
343
+ const param = {
344
+ xml: xml,
345
+ publishVersion: this.systemVersion
346
+ }
347
+ if (this.definitionId) {
348
+ // 表示已保存过,新流程定义的id
349
+ param.id = this.definitionId
350
+ } else {
351
+ if (this.id) {
352
+ param.id = this.id
353
+ } else if (this.code) {
354
+ param.code = this.code
355
+ param.version = this.version
356
+ }
357
+ }
358
+ return param
359
+ },
360
+ adminSave() {
361
+ const xml = this.getProcessXml()
362
+ // console.log(xml)
363
+ // 保存流程定义xml
364
+ if (this.code || this.id || this.definitionId) {
365
+ // 表示修改
366
+ const url = this.baseAPI + '/wf-editor/workflow-definitions/states'
367
+ const param = {}
368
+ if (this.definitionId) {
369
+ // 表示已保存过,新流程定义的id
370
+ param.id = this.definitionId
371
+ } else {
372
+ if (this.id) {
373
+ param.id = this.id
374
+ } else if (this.code) {
375
+ param.code = this.code
376
+ param.version = this.version
377
+ }
378
+ }
379
+ this.$http.post(url, param).then(state => {
380
+ if (state === 'DRAFT') {
381
+ // 如果是草稿状态直接保存
382
+ this.saveWf(xml, this.baseAPI + '/wf-editor/workflow-definitions/updates')
383
+ .then(() => {
384
+ this.$alert(this.$t('workflowEditorMessage.updateSuccessful'))
385
+ })
386
+ } else {
387
+ // 如果是禁用或启用状态,让用户选择是增加版本还是更新版本
388
+ this.isAdminSave = true
389
+ }
390
+ })
391
+ } else {
392
+ // 表示新建
393
+ const param = {
394
+ xml: xml
395
+ }
396
+ this.$http.post(this.baseAPI + '/wf-editor/workflow-definitions', param).then(definition => {
397
+ this.definitionId = definition.id
398
+ this.$alert(this.$t('workflowEditorMessage.savedSuccessfully'))
399
+ // console.log('新建成功' + this.definitionId)
400
+ })
401
+ }
402
+ },
403
+ updateWfVersion() {
404
+ const xml = this.getProcessXml()
405
+ this.saveWf(xml, this.baseAPI + '/wf-editor/workflow-definitions/update-version')
406
+ .then(() => {
407
+ this.isAdminSave = false
408
+ this.$alert(this.$t('workflowEditorMessage.updateVersionSuccessful'))
409
+ })
410
+ },
411
+ addWfVersion() {
412
+ const xml = this.getProcessXml()
413
+ this.saveWf(xml, this.baseAPI + '/wf-editor/workflow-definitions/updates')
414
+ .then(() => {
415
+ this.isAdminSave = false
416
+ this.$alert(this.$t('workflowEditorMessage.addVersionSuccessful'))
417
+ })
418
+ },
419
+ exportProcessFromClient() {
420
+ const blob = new Blob([this.getProcessXml()], { type: 'text/xml;charset=utf-8' })
421
+ FileSaver.saveAs(blob, this.process.attr.name + '.xml')
422
+ },
423
+ // 导出xml
424
+ exportProcess() {
425
+ const xml = this.getProcessXml()
426
+ this.$http({
427
+ method: 'post',
428
+ url: this.baseAPI + '/wf-editor/save-as-xmls',
429
+ data: {
430
+ xmlContent: xml
431
+ }
432
+ }).then((response) => {
433
+ this.download(response)
434
+ console.log(this.$t('workflowEditorMessage.exportSucceeded'))
435
+ })
436
+ },
437
+ // 下载文件
438
+ download(data) {
439
+ if (!data) {
440
+ return
441
+ }
442
+ const url = window.URL.createObjectURL(new Blob([data]))
443
+ const link = document.createElement('a')
444
+ link.style.display = 'none'
445
+ link.href = url
446
+ link.setAttribute('download', 'myXml.xml')
447
+
448
+ document.body.appendChild(link)
449
+ link.click()
450
+ },
451
+ // 打开xml文件成功后
452
+ uploadSuccess(response, file, fileList) {
453
+ const xml = response
454
+ // console.log('xml=', xml)
455
+ // 打开或新建流程图时先清空画布,开发过程中代码热更新的时候可以避免节点重复
456
+ this.clearCanvas()
457
+ this.initProcessByXml(xml)
458
+ this.$refs.upload.clearFiles()
459
+ },
460
+ getCurrentPosition(event) {
461
+ if (this.componentToDraw) {
462
+ const offset = this.$refs.wfEditor.getBoundingClientRect()
463
+
464
+ this.currentPosition = { x: event.clientX - offset.x - 22, y: event.clientY - offset.y - 22 }
465
+ }
466
+ },
467
+ startDrag(event) {
468
+ this.getCurrentPosition(event)
469
+ },
470
+ drag(event) {
471
+ this.getCurrentPosition(event)
472
+ },
473
+ endDrag() {
474
+ if (this.componentToDraw) {
475
+ this.setComponentToDraw('')
476
+ }
477
+ },
478
+
479
+ addTache(event) {
480
+ if (this.componentToDraw) {
481
+ const positionInSVG = getMousePosition(event)
482
+ const ref = processTemplate['new' + this.componentToDraw]()
483
+ // 组件类型转换为首字母小写形式
484
+ ref.attr.id = this.componentToDraw.charAt(0).toLowerCase() + this.componentToDraw.substring(1) + '_' + this.count
485
+ const tache = {
486
+ // 默认id是组件类型加上下划线和数字序号,每次打开流程图的时候都需要动态计算最大的序号,然后加1作为count的的初始值
487
+ id: ref.attr.id,
488
+ name: ref.attr.name,
489
+ x: positionInSVG.x - this.componentInfo.width / 2,
490
+ y: positionInSVG.y - this.componentInfo.height / 2,
491
+ width: this.componentInfo.width,
492
+ height: this.componentInfo.height,
493
+ type: this.componentToDraw,
494
+ isSelected: false
495
+ }
496
+ tache.ref = ref
497
+ this.taches.push(tache)
498
+ this.count++
499
+ }
500
+ },
501
+ clearStatus() {
502
+ if (this.componentToDraw) {
503
+ this.setComponentToDraw('')
504
+ }
505
+ },
506
+ getMaxCount() {
507
+ let max = 0
508
+ this.taches.map(item => {
509
+ // 自动生成的id以下划线加数字编号结尾
510
+ let index = item.id.substring(item.id.lastIndexOf('_') + 1)
511
+ index = +index
512
+ if (max < index) {
513
+ max = index
514
+ }
515
+ })
516
+ return max
517
+ },
518
+ selectProcessFile() {
519
+ this.$refs.processFile.click()
520
+ },
521
+ openXmlFromClient() {
522
+ if (this.$refs.processFile.value === '') return
523
+ const file = this.$refs.processFile.files[0]
524
+ const reader = new FileReader()
525
+ // 本地直接读取文件
526
+ reader.readAsText(file)
527
+ const vm = this
528
+ reader.onload = function() {
529
+ // 打开或新建流程图时先清空画布,开发过程中代码热更新的时候可以避免节点重复
530
+ vm.clearCanvas()
531
+ vm.initProcessByXml(reader.result)
532
+ vm.$refs.processFile.value = ''
533
+ }
534
+ }
535
+ }
536
+ }
537
+ </script>
538
+ <style lang="scss" scoped>
539
+ $toolboxWidth:150px;
540
+ $buttonAreaHeight:50px;
541
+ $tabsHeaderHeight:41px;
542
+ .button-area{
543
+ padding:5px 0 5px 5px;
544
+ height: $buttonAreaHeight;
545
+ }
546
+ .el-row{
547
+ border: 1px solid #f1f1f1;
548
+ border-radius: 5px;
549
+ }
550
+ .el-col{
551
+ padding-left:5px;
552
+ }
553
+ .main{
554
+ position: relative;
555
+ display:flex;
556
+ height: calc(100% - #{$buttonAreaHeight});
557
+ width:100%;
558
+ }
559
+ .canvas-container{
560
+ position: relative;
561
+ // display:flex;
562
+ height: calc(100% - #{$buttonAreaHeight});
563
+ width:100%;
564
+ }
565
+ .toolbox{
566
+ width:$toolboxWidth;
567
+ overflow-y:auto;
568
+ height: 100%;
569
+ // border:1px solid black;
570
+ background: #f7f7f7;
571
+ padding: 10px;
572
+ // min-height: 500px;
573
+ text-align: center;
574
+ flex:none;
575
+ // min-width: 140px;
576
+ // max-width:180px;
577
+ }
578
+ section{
579
+ overflow: hidden;
580
+ flex:1 1 auto;
581
+ height:100%;
582
+ padding: 0;
583
+ // min-height: 500px;
584
+ }
585
+ .tabs{
586
+ height:100%;
587
+ width:100%;
588
+ }
589
+
590
+ .tab-pane{
591
+ height:100%;
592
+ width:100%;
593
+ }
594
+ // 在scss中需要使用/deep/这个别名来代替 '>>>'
595
+ .tabs /deep/ .el-tabs__content{
596
+ height: calc(100% - #{$tabsHeaderHeight});
597
+ padding:10px;
598
+ width:100%;
599
+ }
600
+
601
+ .canvas,.xml{
602
+ overflow: auto;
603
+ height:100%;
604
+ width:100%;
605
+ // border:1px solid red;
606
+ // background: #ffffff;
607
+ padding: 0;
608
+ min-height: 500px;
609
+
610
+ }
611
+ pre{
612
+ margin:0;
613
+ font-size:16px;
614
+ }
615
+ .component-icon {
616
+ position: absolute;
617
+ pointer-events: none;
618
+ // border: 1px solid red;
619
+ }
620
+ .canvas /deep/ .draggable{
621
+ cursor: move;
622
+ }
623
+
624
+ </style>