workflow-editor 0.9.68-dw → 0.9.68-pv

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