|
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+<template>
|
|
|
2
|
+ <div class="bpmn-designer">
|
|
|
3
|
+ <!-- 工具栏 -->
|
|
|
4
|
+ <div class="toolbar">
|
|
|
5
|
+ <el-button-group>
|
|
|
6
|
+ <el-button type="primary" :icon="Document" @click="handleNew">新建</el-button>
|
|
|
7
|
+ <el-button :icon="FolderOpened" @click="handleImport">导入</el-button>
|
|
|
8
|
+ <el-button :icon="Download" @click="handleExport">导出</el-button>
|
|
|
9
|
+ <el-button :icon="Check" @click="handleSave" type="success">保存</el-button>
|
|
|
10
|
+ </el-button-group>
|
|
|
11
|
+ <el-button-group>
|
|
|
12
|
+ <el-button :icon="RefreshLeft" @click="handleUndo" title="撤销">撤销</el-button>
|
|
|
13
|
+ <el-button :icon="RefreshRight" @click="handleRedo" title="重做">重做</el-button>
|
|
|
14
|
+ </el-button-group>
|
|
|
15
|
+ <el-button-group>
|
|
|
16
|
+ <el-button :icon="ZoomIn" @click="handleZoomIn">放大</el-button>
|
|
|
17
|
+ <el-button :icon="ZoomOut" @click="handleZoomOut">缩小</el-button>
|
|
|
18
|
+ <el-button :icon="FullScreen" @click="handleResetZoom">重置</el-button>
|
|
|
19
|
+ </el-button-group>
|
|
|
20
|
+ <span class="zoom-label">{{ Math.round(currentZoom * 100) }}%</span>
|
|
|
21
|
+ </div>
|
|
|
22
|
+
|
|
|
23
|
+ <div class="designer-main">
|
|
|
24
|
+ <!-- BPMN 画布 -->
|
|
|
25
|
+ <div class="canvas-container" ref="canvasRef">
|
|
|
26
|
+ <div class="canvas" ref="bpmnCanvas"></div>
|
|
|
27
|
+ </div>
|
|
|
28
|
+
|
|
|
29
|
+ <!-- 属性面板 -->
|
|
|
30
|
+ <div class="properties-panel" v-if="selectedElement">
|
|
|
31
|
+ <el-card shadow="never">
|
|
|
32
|
+ <template #header>
|
|
|
33
|
+ <div class="panel-header">
|
|
|
34
|
+ <span>属性面板</span>
|
|
|
35
|
+ <el-tag size="small" type="info">{{ elementTypeLabel }}</el-tag>
|
|
|
36
|
+ </div>
|
|
|
37
|
+ </template>
|
|
|
38
|
+ <el-form label-width="80px" size="small">
|
|
|
39
|
+ <el-form-item label="ID">
|
|
|
40
|
+ <el-input v-model="selectedElement.id" disabled />
|
|
|
41
|
+ </el-form-item>
|
|
|
42
|
+ <el-form-item label="名称">
|
|
|
43
|
+ <el-input v-model="elementProps.name" @blur="applyNameChange" placeholder="输入名称" />
|
|
|
44
|
+ </el-form-item>
|
|
|
45
|
+ <el-form-item label="审批人" v-if="isUserTask">
|
|
|
46
|
+ <el-input v-model="elementProps.assignee" @blur="applyAssigneeChange" placeholder="审批人ID或表达式" />
|
|
|
47
|
+ </el-form-item>
|
|
|
48
|
+ <el-form-item label="候选组" v-if="isUserTask">
|
|
|
49
|
+ <el-input v-model="elementProps.candidateGroups" @blur="applyCandidateGroupsChange" placeholder="候选组" />
|
|
|
50
|
+ </el-form-item>
|
|
|
51
|
+ <el-form-item label="条件表达式" v-if="isSequenceFlow">
|
|
|
52
|
+ <el-input v-model="elementProps.conditionExpression" @blur="applyConditionChange" type="textarea" :rows="2" />
|
|
|
53
|
+ </el-form-item>
|
|
|
54
|
+ <el-form-item label="文档说明">
|
|
|
55
|
+ <el-input v-model="elementProps.documentation" @blur="applyDocumentationChange" type="textarea" :rows="2" />
|
|
|
56
|
+ </el-form-item>
|
|
|
57
|
+ </el-form>
|
|
|
58
|
+ </el-card>
|
|
|
59
|
+ </div>
|
|
|
60
|
+ </div>
|
|
|
61
|
+
|
|
|
62
|
+ <!-- 保存对话框 -->
|
|
|
63
|
+ <el-dialog v-model="saveDialogVisible" title="保存模板" width="500px">
|
|
|
64
|
+ <el-form :model="saveForm" label-width="100px">
|
|
|
65
|
+ <el-form-item label="模板名称" required>
|
|
|
66
|
+ <el-input v-model="saveForm.name" placeholder="输入模板名称" />
|
|
|
67
|
+ </el-form-item>
|
|
|
68
|
+ <el-form-item label="分类">
|
|
|
69
|
+ <el-select v-model="saveForm.category" placeholder="选择分类" style="width:100%">
|
|
|
70
|
+ <el-option label="审批流程" value="approval" />
|
|
|
71
|
+ <el-option label="工作流程" value="workflow" />
|
|
|
72
|
+ <el-option label="通知流程" value="notification" />
|
|
|
73
|
+ <el-option label="巡检流程" value="inspection" />
|
|
|
74
|
+ </el-select>
|
|
|
75
|
+ </el-form-item>
|
|
|
76
|
+ <el-form-item label="描述">
|
|
|
77
|
+ <el-input v-model="saveForm.description" type="textarea" :rows="3" />
|
|
|
78
|
+ </el-form-item>
|
|
|
79
|
+ <el-form-item label="标签">
|
|
|
80
|
+ <el-input v-model="saveForm.tags" placeholder="逗号分隔,如: 审批,通用" />
|
|
|
81
|
+ </el-form-item>
|
|
|
82
|
+ </el-form>
|
|
|
83
|
+ <template #footer>
|
|
|
84
|
+ <el-button @click="saveDialogVisible = false">取消</el-button>
|
|
|
85
|
+ <el-button type="primary" @click="confirmSave" :loading="saving">保存</el-button>
|
|
|
86
|
+ </template>
|
|
|
87
|
+ </el-dialog>
|
|
|
88
|
+
|
|
|
89
|
+ <!-- 导入对话框 -->
|
|
|
90
|
+ <el-dialog v-model="importDialogVisible" title="导入 BPMN XML" width="600px">
|
|
|
91
|
+ <el-input v-model="importXml" type="textarea" :rows="15" placeholder="粘贴 BPMN XML 内容" />
|
|
|
92
|
+ <template #footer>
|
|
|
93
|
+ <el-button @click="importDialogVisible = false">取消</el-button>
|
|
|
94
|
+ <el-button type="primary" @click="confirmImport">导入</el-button>
|
|
|
95
|
+ </template>
|
|
|
96
|
+ </el-dialog>
|
|
|
97
|
+ </div>
|
|
|
98
|
+</template>
|
|
|
99
|
+
|
|
|
100
|
+<script setup lang="ts">
|
|
|
101
|
+import { ref, reactive, computed, onMounted, onBeforeUnmount, nextTick } from 'vue'
|
|
|
102
|
+import { useRoute, useRouter } from 'vue-router'
|
|
|
103
|
+import { ElMessage } from 'element-plus'
|
|
|
104
|
+import {
|
|
|
105
|
+ Document, FolderOpened, Download, Check,
|
|
|
106
|
+ RefreshLeft, RefreshRight, ZoomIn, ZoomOut, FullScreen
|
|
|
107
|
+} from '@element-plus/icons-vue'
|
|
|
108
|
+import { createTemplate, getTemplate, updateTemplate, type ProcessTemplate } from '@/api/bpmApi'
|
|
|
109
|
+
|
|
|
110
|
+const route = useRoute()
|
|
|
111
|
+const router = useRouter()
|
|
|
112
|
+
|
|
|
113
|
+// Refs
|
|
|
114
|
+const canvasRef = ref<HTMLElement>()
|
|
|
115
|
+const bpmnCanvas = ref<HTMLElement>()
|
|
|
116
|
+
|
|
|
117
|
+// State
|
|
|
118
|
+const currentZoom = ref(1)
|
|
|
119
|
+const selectedElement = ref<any>(null)
|
|
|
120
|
+const saveDialogVisible = ref(false)
|
|
|
121
|
+const importDialogVisible = ref(false)
|
|
|
122
|
+const importXml = ref('')
|
|
|
123
|
+const saving = ref(false)
|
|
|
124
|
+let viewer: any = null
|
|
|
125
|
+let modeler: any = null
|
|
|
126
|
+let commandStack: any = null
|
|
|
127
|
+
|
|
|
128
|
+const elementProps = reactive({
|
|
|
129
|
+ name: '',
|
|
|
130
|
+ assignee: '',
|
|
|
131
|
+ candidateGroups: '',
|
|
|
132
|
+ conditionExpression: '',
|
|
|
133
|
+ documentation: ''
|
|
|
134
|
+})
|
|
|
135
|
+
|
|
|
136
|
+const saveForm = reactive({
|
|
|
137
|
+ id: undefined as number | undefined,
|
|
|
138
|
+ name: '',
|
|
|
139
|
+ category: 'approval',
|
|
|
140
|
+ description: '',
|
|
|
141
|
+ tags: ''
|
|
|
142
|
+})
|
|
|
143
|
+
|
|
|
144
|
+// Computed
|
|
|
145
|
+const isUserTask = computed(() => selectedElement.value?.type === 'bpmn:UserTask')
|
|
|
146
|
+const isSequenceFlow = computed(() => selectedElement.value?.type === 'bpmn:SequenceFlow')
|
|
|
147
|
+
|
|
|
148
|
+const elementTypeLabel = computed(() => {
|
|
|
149
|
+ if (!selectedElement.value) return ''
|
|
|
150
|
+ const typeMap: Record<string, string> = {
|
|
|
151
|
+ 'bpmn:StartEvent': '开始事件',
|
|
|
152
|
+ 'bpmn:EndEvent': '结束事件',
|
|
|
153
|
+ 'bpmn:UserTask': '用户任务',
|
|
|
154
|
+ 'bpmn:ServiceTask': '服务任务',
|
|
|
155
|
+ 'bpmn:ExclusiveGateway': '排他网关',
|
|
|
156
|
+ 'bpmn:ParallelGateway': '并行网关',
|
|
|
157
|
+ 'bpmn:InclusiveGateway': '包容网关',
|
|
|
158
|
+ 'bpmn:SequenceFlow': '连接线',
|
|
|
159
|
+ 'bpmn:Task': '任务',
|
|
|
160
|
+ 'bpmn:SubProcess': '子流程',
|
|
|
161
|
+ 'bpmn:IntermediateThrowEvent': '中间事件',
|
|
|
162
|
+ 'bpmn:IntermediateCatchEvent': '中间捕获事件'
|
|
|
163
|
+ }
|
|
|
164
|
+ return typeMap[selectedElement.value.type] || selectedElement.value.type
|
|
|
165
|
+})
|
|
|
166
|
+
|
|
|
167
|
+// 默认 BPMN 模板
|
|
|
168
|
+const DEFAULT_BPMN = `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
169
|
+<definitions xmlns="http://www.omg.org/spec/BPMN20"
|
|
|
170
|
+ xmlns:bpmndi="http://www.omg.org/spec/BPMN20/di"
|
|
|
171
|
+ xmlns:dc="http://www.omg.org/spec/DD/20100524/DI"
|
|
|
172
|
+ xmlns:di="http://www.omg.org/spec/DD/20100524/DC"
|
|
|
173
|
+ id="Definitions_1"
|
|
|
174
|
+ targetNamespace="http://water.com/bpm">
|
|
|
175
|
+ <process id="Process_1" name="新建流程" isExecutable="true">
|
|
|
176
|
+ <startEvent id="StartEvent_1" name="开始"/>
|
|
|
177
|
+ </process>
|
|
|
178
|
+ <bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
|
|
179
|
+ <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
|
|
|
180
|
+ <bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="StartEvent_1">
|
|
|
181
|
+ <dc:Bounds x="180" y="160" width="36" height="36"/>
|
|
|
182
|
+ <bpmndi:BPMNLabel>
|
|
|
183
|
+ <dc:Bounds x="187" y="203" width="22" height="14"/>
|
|
|
184
|
+ </bpmndi:BPMNLabel>
|
|
|
185
|
+ </bpmndi:BPMNShape>
|
|
|
186
|
+ </bpmndi:BPMNPlane>
|
|
|
187
|
+ </bpmndi:BPMNDiagram>
|
|
|
188
|
+</definitions>`
|
|
|
189
|
+
|
|
|
190
|
+onMounted(async () => {
|
|
|
191
|
+ await initModeler()
|
|
|
192
|
+ // 如果有模板 ID,加载模板
|
|
|
193
|
+ const templateId = route.query.id
|
|
|
194
|
+ if (templateId) {
|
|
|
195
|
+ await loadTemplate(Number(templateId))
|
|
|
196
|
+ }
|
|
|
197
|
+})
|
|
|
198
|
+
|
|
|
199
|
+onBeforeUnmount(() => {
|
|
|
200
|
+ if (modeler) {
|
|
|
201
|
+ modeler.destroy()
|
|
|
202
|
+ }
|
|
|
203
|
+})
|
|
|
204
|
+
|
|
|
205
|
+/** 初始化 BPMN.js Modeler(CDN 加载) */
|
|
|
206
|
+async function initModeler() {
|
|
|
207
|
+ // 动态加载 bpmn-js CDN
|
|
|
208
|
+ await loadBpmnJs()
|
|
|
209
|
+
|
|
|
210
|
+ if (!bpmnCanvas.value) return
|
|
|
211
|
+
|
|
|
212
|
+ const BpmnModeler = (window as any).BpmnJS
|
|
|
213
|
+ if (!BpmnModeler) {
|
|
|
214
|
+ // CDN 加载失败时使用 fallback 简单画布
|
|
|
215
|
+ ElMessage.warning('BPMN.js CDN 加载失败,使用简化模式')
|
|
|
216
|
+ initFallbackCanvas()
|
|
|
217
|
+ return
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
|
220
|
+ modeler = new BpmnModeler({
|
|
|
221
|
+ container: bpmnCanvas.value,
|
|
|
222
|
+ keyboard: { bindTo: document },
|
|
|
223
|
+ additionalModules: [],
|
|
|
224
|
+ moddleExtensions: {}
|
|
|
225
|
+ })
|
|
|
226
|
+
|
|
|
227
|
+ commandStack = modeler.get('commandStack')
|
|
|
228
|
+
|
|
|
229
|
+ // 监听选中事件
|
|
|
230
|
+ const selection = modeler.get('selection')
|
|
|
231
|
+ const eventBus = modeler.get('eventBus')
|
|
|
232
|
+
|
|
|
233
|
+ eventBus.on('selection.changed', (e: any) => {
|
|
|
234
|
+ const selected = e.newSelection
|
|
|
235
|
+ if (selected.length === 1) {
|
|
|
236
|
+ selectedElement.value = selected[0]
|
|
|
237
|
+ loadElementProps(selected[0])
|
|
|
238
|
+ } else {
|
|
|
239
|
+ selectedElement.value = null
|
|
|
240
|
+ }
|
|
|
241
|
+ })
|
|
|
242
|
+
|
|
|
243
|
+ await modeler.importXML(DEFAULT_BPMN)
|
|
|
244
|
+ const canvas = modeler.get('canvas')
|
|
|
245
|
+ canvas.zoom('fit-viewport')
|
|
|
246
|
+}
|
|
|
247
|
+
|
|
|
248
|
+/** 加载 bpmn-js CDN */
|
|
|
249
|
+function loadBpmnJs(): Promise<void> {
|
|
|
250
|
+ return new Promise((resolve) => {
|
|
|
251
|
+ if ((window as any).BpmnJS) {
|
|
|
252
|
+ resolve()
|
|
|
253
|
+ return
|
|
|
254
|
+ }
|
|
|
255
|
+ // 加载 bpmn-js 独立版本
|
|
|
256
|
+ const script = document.createElement('script')
|
|
|
257
|
+ script.src = 'https://unpkg.com/bpmn-js@17.11.1/dist/bpmn-modeler.production.min.js'
|
|
|
258
|
+ script.onload = () => resolve()
|
|
|
259
|
+ script.onerror = () => resolve() // 允许 fallback
|
|
|
260
|
+ document.head.appendChild(script)
|
|
|
261
|
+
|
|
|
262
|
+ // 加载 bpmn-js CSS
|
|
|
263
|
+ const link = document.createElement('link')
|
|
|
264
|
+ link.rel = 'stylesheet'
|
|
|
265
|
+ link.href = 'https://unpkg.com/bpmn-js@17.11.1/dist/assets/diagram-js.css'
|
|
|
266
|
+ document.head.appendChild(link)
|
|
|
267
|
+
|
|
|
268
|
+ const link2 = document.createElement('link')
|
|
|
269
|
+ link2.rel = 'stylesheet'
|
|
|
270
|
+ link2.href = 'https://unpkg.com/bpmn-js@17.11.1/dist/assets/bpmn-js.css'
|
|
|
271
|
+ document.head.appendChild(link2)
|
|
|
272
|
+
|
|
|
273
|
+ const link3 = document.createElement('link')
|
|
|
274
|
+ link3.rel = 'stylesheet'
|
|
|
275
|
+ link3.href = 'https://unpkg.com/bpmn-js@17.11.1/dist/assets/bpmn-font/css/bpmn-embedded.css'
|
|
|
276
|
+ document.head.appendChild(link3)
|
|
|
277
|
+ })
|
|
|
278
|
+}
|
|
|
279
|
+
|
|
|
280
|
+/** Fallback: 简化 SVG 画布(CDN 不可用时) */
|
|
|
281
|
+function initFallbackCanvas() {
|
|
|
282
|
+ if (!bpmnCanvas.value) return
|
|
|
283
|
+ bpmnCanvas.value.innerHTML = `
|
|
|
284
|
+ <div style="padding:40px;text-align:center;color:#999;">
|
|
|
285
|
+ <h3>BPMN 设计器(简化模式)</h3>
|
|
|
286
|
+ <p>CDN 不可用,请确保网络连接正常。</p>
|
|
|
287
|
+ <p>您仍可通过导入/导出 XML 来编辑流程模板。</p>
|
|
|
288
|
+ <textarea id="fallback-xml" style="width:100%;height:300px;margin-top:20px;font-family:monospace;" placeholder="在此粘贴或编辑 BPMN XML"></textarea>
|
|
|
289
|
+ </div>
|
|
|
290
|
+ `
|
|
|
291
|
+}
|
|
|
292
|
+
|
|
|
293
|
+/** 加载元素属性 */
|
|
|
294
|
+function loadElementProps(element: any) {
|
|
|
295
|
+ const bo = element.businessObject
|
|
|
296
|
+ elementProps.name = bo.name || ''
|
|
|
297
|
+ elementProps.assignee = bo.assignee || ''
|
|
|
298
|
+ elementProps.candidateGroups = bo.candidateGroups || ''
|
|
|
299
|
+ elementProps.conditionExpression = bo.conditionExpression?.body || ''
|
|
|
300
|
+ elementProps.documentation = bo.documentation?.[0]?.text || ''
|
|
|
301
|
+}
|
|
|
302
|
+
|
|
|
303
|
+/** 应用名称变更 */
|
|
|
304
|
+function applyNameChange() {
|
|
|
305
|
+ if (!selectedElement.value || !modeler) return
|
|
|
306
|
+ const modeling = modeler.get('modeling')
|
|
|
307
|
+ modeling.updateProperties(selectedElement.value, { name: elementProps.name })
|
|
|
308
|
+}
|
|
|
309
|
+
|
|
|
310
|
+/** 应用审批人变更 */
|
|
|
311
|
+function applyAssigneeChange() {
|
|
|
312
|
+ if (!selectedElement.value || !modeler) return
|
|
|
313
|
+ const modeling = modeler.get('modeling')
|
|
|
314
|
+ modeling.updateProperties(selectedElement.value, { assignee: elementProps.assignee })
|
|
|
315
|
+}
|
|
|
316
|
+
|
|
|
317
|
+/** 应用候选组变更 */
|
|
|
318
|
+function applyCandidateGroupsChange() {
|
|
|
319
|
+ if (!selectedElement.value || !modeler) return
|
|
|
320
|
+ const modeling = modeler.get('modeling')
|
|
|
321
|
+ modeling.updateProperties(selectedElement.value, { candidateGroups: elementProps.candidateGroups })
|
|
|
322
|
+}
|
|
|
323
|
+
|
|
|
324
|
+/** 应用条件表达式变更 */
|
|
|
325
|
+function applyConditionChange() {
|
|
|
326
|
+ if (!selectedElement.value || !modeler) return
|
|
|
327
|
+ const moddle = modeler.get('moddle')
|
|
|
328
|
+ const modeling = modeler.get('modeling')
|
|
|
329
|
+ const condition = moddle.create('bpmn:FormalExpression', { body: elementProps.conditionExpression })
|
|
|
330
|
+ modeling.updateProperties(selectedElement.value, { conditionExpression: condition })
|
|
|
331
|
+}
|
|
|
332
|
+
|
|
|
333
|
+/** 应用文档说明变更 */
|
|
|
334
|
+function applyDocumentationChange() {
|
|
|
335
|
+ if (!selectedElement.value || !modeler) return
|
|
|
336
|
+ const moddle = modeler.get('moddle')
|
|
|
337
|
+ const modeling = modeler.get('modeling')
|
|
|
338
|
+ const doc = moddle.create('bpmn:Documentation', { text: elementProps.documentation })
|
|
|
339
|
+ modeling.updateProperties(selectedElement.value, { documentation: [doc] })
|
|
|
340
|
+}
|
|
|
341
|
+
|
|
|
342
|
+// 工具栏操作
|
|
|
343
|
+function handleNew() {
|
|
|
344
|
+ if (modeler) {
|
|
|
345
|
+ modeler.importXML(DEFAULT_BPMN)
|
|
|
346
|
+ saveForm.id = undefined
|
|
|
347
|
+ saveForm.name = ''
|
|
|
348
|
+ ElMessage.success('已创建新流程')
|
|
|
349
|
+ }
|
|
|
350
|
+}
|
|
|
351
|
+
|
|
|
352
|
+async function handleImport() {
|
|
|
353
|
+ importXml.value = ''
|
|
|
354
|
+ importDialogVisible.value = true
|
|
|
355
|
+}
|
|
|
356
|
+
|
|
|
357
|
+async function confirmImport() {
|
|
|
358
|
+ if (!importXml.value.trim()) {
|
|
|
359
|
+ ElMessage.warning('请输入 BPMN XML 内容')
|
|
|
360
|
+ return
|
|
|
361
|
+ }
|
|
|
362
|
+ try {
|
|
|
363
|
+ if (modeler) {
|
|
|
364
|
+ await modeler.importXML(importXml.value)
|
|
|
365
|
+ const canvas = modeler.get('canvas')
|
|
|
366
|
+ canvas.zoom('fit-viewport')
|
|
|
367
|
+ } else {
|
|
|
368
|
+ const textarea = document.getElementById('fallback-xml') as HTMLTextAreaElement
|
|
|
369
|
+ if (textarea) textarea.value = importXml.value
|
|
|
370
|
+ }
|
|
|
371
|
+ importDialogVisible.value = false
|
|
|
372
|
+ ElMessage.success('导入成功')
|
|
|
373
|
+ } catch (e: any) {
|
|
|
374
|
+ ElMessage.error('导入失败: ' + (e.message || 'XML 格式错误'))
|
|
|
375
|
+ }
|
|
|
376
|
+}
|
|
|
377
|
+
|
|
|
378
|
+async function handleExport() {
|
|
|
379
|
+ try {
|
|
|
380
|
+ if (modeler) {
|
|
|
381
|
+ const { xml } = await modeler.saveXML({ format: true })
|
|
|
382
|
+ downloadXml(xml)
|
|
|
383
|
+ } else {
|
|
|
384
|
+ const textarea = document.getElementById('fallback-xml') as HTMLTextAreaElement
|
|
|
385
|
+ if (textarea && textarea.value) {
|
|
|
386
|
+ downloadXml(textarea.value)
|
|
|
387
|
+ }
|
|
|
388
|
+ }
|
|
|
389
|
+ ElMessage.success('导出成功')
|
|
|
390
|
+ } catch (e: any) {
|
|
|
391
|
+ ElMessage.error('导出失败')
|
|
|
392
|
+ }
|
|
|
393
|
+}
|
|
|
394
|
+
|
|
|
395
|
+function downloadXml(xml: string) {
|
|
|
396
|
+ const blob = new Blob([xml], { type: 'application/xml' })
|
|
|
397
|
+ const url = URL.createObjectURL(blob)
|
|
|
398
|
+ const a = document.createElement('a')
|
|
|
399
|
+ a.href = url
|
|
|
400
|
+ a.download = `${saveForm.name || 'process'}.bpmn`
|
|
|
401
|
+ a.click()
|
|
|
402
|
+ URL.revokeObjectURL(url)
|
|
|
403
|
+}
|
|
|
404
|
+
|
|
|
405
|
+function handleSave() {
|
|
|
406
|
+ saveDialogVisible.value = true
|
|
|
407
|
+}
|
|
|
408
|
+
|
|
|
409
|
+async function confirmSave() {
|
|
|
410
|
+ if (!saveForm.name.trim()) {
|
|
|
411
|
+ ElMessage.warning('请输入模板名称')
|
|
|
412
|
+ return
|
|
|
413
|
+ }
|
|
|
414
|
+ saving.value = true
|
|
|
415
|
+ try {
|
|
|
416
|
+ let xml = ''
|
|
|
417
|
+ if (modeler) {
|
|
|
418
|
+ const result = await modeler.saveXML({ format: true })
|
|
|
419
|
+ xml = result.xml
|
|
|
420
|
+ } else {
|
|
|
421
|
+ const textarea = document.getElementById('fallback-xml') as HTMLTextAreaElement
|
|
|
422
|
+ xml = textarea?.value || DEFAULT_BPMN
|
|
|
423
|
+ }
|
|
|
424
|
+
|
|
|
425
|
+ const data: ProcessTemplate = {
|
|
|
426
|
+ name: saveForm.name,
|
|
|
427
|
+ description: saveForm.description,
|
|
|
428
|
+ bpmnXml: xml,
|
|
|
429
|
+ category: saveForm.category,
|
|
|
430
|
+ tags: saveForm.tags
|
|
|
431
|
+ }
|
|
|
432
|
+
|
|
|
433
|
+ if (saveForm.id) {
|
|
|
434
|
+ await updateTemplate(saveForm.id, data)
|
|
|
435
|
+ ElMessage.success('模板更新成功')
|
|
|
436
|
+ } else {
|
|
|
437
|
+ await createTemplate(data)
|
|
|
438
|
+ ElMessage.success('模板创建成功')
|
|
|
439
|
+ }
|
|
|
440
|
+ saveDialogVisible.value = false
|
|
|
441
|
+ } catch (e: any) {
|
|
|
442
|
+ ElMessage.error('保存失败: ' + (e.message || ''))
|
|
|
443
|
+ } finally {
|
|
|
444
|
+ saving.value = false
|
|
|
445
|
+ }
|
|
|
446
|
+}
|
|
|
447
|
+
|
|
|
448
|
+function handleUndo() {
|
|
|
449
|
+ if (commandStack) {
|
|
|
450
|
+ try { commandStack.undo() } catch {}
|
|
|
451
|
+ }
|
|
|
452
|
+}
|
|
|
453
|
+
|
|
|
454
|
+function handleRedo() {
|
|
|
455
|
+ if (commandStack) {
|
|
|
456
|
+ try { commandStack.redo() } catch {}
|
|
|
457
|
+ }
|
|
|
458
|
+}
|
|
|
459
|
+
|
|
|
460
|
+function handleZoomIn() {
|
|
|
461
|
+ if (!modeler) return
|
|
|
462
|
+ currentZoom.value = Math.min(currentZoom.value + 0.1, 3)
|
|
|
463
|
+ modeler.get('canvas').zoom(currentZoom.value)
|
|
|
464
|
+}
|
|
|
465
|
+
|
|
|
466
|
+function handleZoomOut() {
|
|
|
467
|
+ if (!modeler) return
|
|
|
468
|
+ currentZoom.value = Math.max(currentZoom.value - 0.1, 0.2)
|
|
|
469
|
+ modeler.get('canvas').zoom(currentZoom.value)
|
|
|
470
|
+}
|
|
|
471
|
+
|
|
|
472
|
+function handleResetZoom() {
|
|
|
473
|
+ if (!modeler) return
|
|
|
474
|
+ currentZoom.value = 1
|
|
|
475
|
+ modeler.get('canvas').zoom('fit-viewport')
|
|
|
476
|
+}
|
|
|
477
|
+
|
|
|
478
|
+/** 加载已有模板 */
|
|
|
479
|
+async function loadTemplate(id: number) {
|
|
|
480
|
+ try {
|
|
|
481
|
+ const res: any = await getTemplate(id)
|
|
|
482
|
+ const template = res.data
|
|
|
483
|
+ if (template) {
|
|
|
484
|
+ saveForm.id = template.id
|
|
|
485
|
+ saveForm.name = template.name
|
|
|
486
|
+ saveForm.category = template.category || 'approval'
|
|
|
487
|
+ saveForm.description = template.description || ''
|
|
|
488
|
+ saveForm.tags = template.tags || ''
|
|
|
489
|
+ if (template.bpmnXml && modeler) {
|
|
|
490
|
+ await modeler.importXML(template.bpmnXml)
|
|
|
491
|
+ const canvas = modeler.get('canvas')
|
|
|
492
|
+ canvas.zoom('fit-viewport')
|
|
|
493
|
+ }
|
|
|
494
|
+ }
|
|
|
495
|
+ } catch (e: any) {
|
|
|
496
|
+ ElMessage.error('加载模板失败')
|
|
|
497
|
+ }
|
|
|
498
|
+}
|
|
|
499
|
+</script>
|
|
|
500
|
+
|
|
|
501
|
+<style scoped lang="scss">
|
|
|
502
|
+.bpmn-designer {
|
|
|
503
|
+ height: 100%;
|
|
|
504
|
+ display: flex;
|
|
|
505
|
+ flex-direction: column;
|
|
|
506
|
+ background: #f5f5f5;
|
|
|
507
|
+}
|
|
|
508
|
+
|
|
|
509
|
+.toolbar {
|
|
|
510
|
+ padding: 10px 16px;
|
|
|
511
|
+ background: #fff;
|
|
|
512
|
+ border-bottom: 1px solid #e4e7ed;
|
|
|
513
|
+ display: flex;
|
|
|
514
|
+ align-items: center;
|
|
|
515
|
+ gap: 12px;
|
|
|
516
|
+ flex-shrink: 0;
|
|
|
517
|
+
|
|
|
518
|
+ .zoom-label {
|
|
|
519
|
+ font-size: 13px;
|
|
|
520
|
+ color: #606266;
|
|
|
521
|
+ min-width: 50px;
|
|
|
522
|
+ text-align: center;
|
|
|
523
|
+ }
|
|
|
524
|
+}
|
|
|
525
|
+
|
|
|
526
|
+.designer-main {
|
|
|
527
|
+ flex: 1;
|
|
|
528
|
+ display: flex;
|
|
|
529
|
+ overflow: hidden;
|
|
|
530
|
+}
|
|
|
531
|
+
|
|
|
532
|
+.canvas-container {
|
|
|
533
|
+ flex: 1;
|
|
|
534
|
+ position: relative;
|
|
|
535
|
+ overflow: hidden;
|
|
|
536
|
+
|
|
|
537
|
+ .canvas {
|
|
|
538
|
+ width: 100%;
|
|
|
539
|
+ height: 100%;
|
|
|
540
|
+ }
|
|
|
541
|
+}
|
|
|
542
|
+
|
|
|
543
|
+.properties-panel {
|
|
|
544
|
+ width: 320px;
|
|
|
545
|
+ border-left: 1px solid #e4e7ed;
|
|
|
546
|
+ background: #fff;
|
|
|
547
|
+ overflow-y: auto;
|
|
|
548
|
+ flex-shrink: 0;
|
|
|
549
|
+
|
|
|
550
|
+ .panel-header {
|
|
|
551
|
+ display: flex;
|
|
|
552
|
+ align-items: center;
|
|
|
553
|
+ justify-content: space-between;
|
|
|
554
|
+ font-weight: 600;
|
|
|
555
|
+ }
|
|
|
556
|
+
|
|
|
557
|
+ :deep(.el-card__body) {
|
|
|
558
|
+ padding: 12px;
|
|
|
559
|
+ }
|
|
|
560
|
+}
|
|
|
561
|
+</style>
|