gbflowengine 0.1.0 → 0.1.1

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 (79) hide show
  1. package/README.md +271 -271
  2. package/dist/gbflowengine.css +1 -1
  3. package/dist/gbflowengine.js +8232 -6913
  4. package/dist/gbflowengine.js.map +1 -1
  5. package/dist/gbflowengine.umd.cjs +2 -2
  6. package/dist/gbflowengine.umd.cjs.map +1 -1
  7. package/package.json +85 -84
  8. package/src/center/DefinitionInspect.vue +291 -291
  9. package/src/center/FlowCenter.vue +33 -33
  10. package/src/center/index.js +29 -29
  11. package/src/center/storage.js +748 -748
  12. package/src/core/flow/condition.js +160 -160
  13. package/src/core/flow/customNode.js +385 -385
  14. package/src/core/flow/defaults.js +124 -124
  15. package/src/core/flow/flowConstant.js +265 -265
  16. package/src/core/flow/flowNodeUtils.js +29 -29
  17. package/src/core/flow/index.js +47 -47
  18. package/src/core/flow/node.js +44 -44
  19. package/src/core/flow/nodeFactory.js +58 -58
  20. package/src/core/flow/prediction.js +325 -325
  21. package/src/core/flow/schema.js +864 -864
  22. package/src/definition/FlowDefinitionDesigner.vue +338 -338
  23. package/src/definition/index.js +9 -9
  24. package/src/index.js +39 -39
  25. package/src/storage.js +200 -200
  26. package/src/testing/FlowTestPanel.vue +2502 -2502
  27. package/src/testing/UserConfigDrawer.vue +376 -376
  28. package/src/testing/diagram/FlowProgressDiagram.vue +318 -318
  29. package/src/testing/diagramModel.js +517 -517
  30. package/src/testing/index.js +23 -23
  31. package/src/testing/mock.js +246 -246
  32. package/src/testing/oaExecutors.js +51 -51
  33. package/src/testing/oaSeed.js +467 -467
  34. package/src/testing/sample.js +412 -412
  35. package/src/testing/seed.js +122 -122
  36. package/src/utils/format.js +27 -27
  37. package/src/visual/FlowCanvas.vue +440 -440
  38. package/src/visual/NodeProgressDetail.vue +43 -43
  39. package/src/visual/NodeStatusBadge.vue +17 -17
  40. package/src/visual/NodeWrap.vue +46 -46
  41. package/src/visual/ScWorkflow.vue +49 -49
  42. package/src/visual/SelectDialog.vue +459 -459
  43. package/src/visual/conditionHelpers.js +116 -116
  44. package/src/visual/index.js +6 -6
  45. package/src/visual/nodes/AddNode.vue +222 -222
  46. package/src/visual/nodes/ApproverNode.vue +347 -347
  47. package/src/visual/nodes/BranchNode.vue +441 -441
  48. package/src/visual/nodes/CustomNode.vue +339 -339
  49. package/src/visual/nodes/EndNode.vue +21 -21
  50. package/src/visual/nodes/PassNode.vue +100 -100
  51. package/src/visual/nodes/PromoterNode.vue +134 -134
  52. package/src/visual/nodes/RejectNode.vue +100 -100
  53. package/src/visual/nodes/SendNode.vue +151 -151
  54. package/src/visual/styles.scss +879 -879
  55. package/src/visual/useScNodeStatus.js +18 -18
  56. package/src/workbench/OaWorkbench.vue +1341 -1341
  57. package/src/workbench/components/ApprovalWorkspace.vue +2090 -2090
  58. package/src/workbench/components/CategoryIcon.vue +74 -74
  59. package/src/workbench/components/NotificationIcon.vue +73 -73
  60. package/src/workbench/components/ProcessSteps.vue +557 -557
  61. package/src/workbench/components/ResubmitDialog.vue +227 -227
  62. package/src/workbench/components/SidebarNav.vue +138 -138
  63. package/src/workbench/components/StartFlowDialog.vue +1058 -1058
  64. package/src/workbench/components/UserAvatar.vue +68 -68
  65. package/src/workbench/model.js +1080 -1080
  66. package/src/workbench/pages/DesignPage.vue +798 -798
  67. package/src/workbench/pages/HomePage.vue +1050 -1050
  68. package/src/workbench/pages/MonitorPage.vue +1029 -1029
  69. package/src/workbench/pages/NotificationsPage.vue +554 -554
  70. package/src/workbench/pages/RequestsPage.vue +644 -644
  71. package/src/workbench/pages/TaskCenterPage.vue +1155 -1155
  72. package/src/workbench/pages/TemplatesPage.vue +680 -680
  73. package/src/workbench/styles.scss +555 -555
  74. package/types/center.d.ts +5 -5
  75. package/types/core.d.ts +479 -479
  76. package/types/definition.d.ts +4 -4
  77. package/types/index.d.ts +34 -34
  78. package/types/testing.d.ts +20 -20
  79. package/types/visual.d.ts +20 -20
@@ -1,338 +1,338 @@
1
- <template>
2
- <div class="gb-flow-definition">
3
- <template v-if="isDefinitionMode">
4
- <el-tabs v-model="activeTab" class="gb-flow-definition__tabs">
5
- <el-tab-pane label="基本信息" name="basic">
6
- <div class="gb-flow-definition__basic">
7
- <el-form :model="definition.meta" label-width="90px" style="max-width: 640px">
8
- <el-form-item label="流程名称">
9
- <el-input v-model="definition.meta.name" :disabled="readonly" placeholder="请输入流程名称" clearable />
10
- </el-form-item>
11
- <el-form-item label="流程分组">
12
- <el-input v-model="definition.meta.groupId" :disabled="readonly" placeholder="分组标识(可选)" clearable />
13
- </el-form-item>
14
- <el-form-item label="流程描述">
15
- <el-input v-model="definition.meta.description" :disabled="readonly" type="textarea" :rows="3" placeholder="请输入流程描述" />
16
- </el-form-item>
17
- <el-form-item label="标签">
18
- <el-input v-model="tagsText" :disabled="readonly" placeholder="多个标签使用英文逗号分隔" clearable />
19
- </el-form-item>
20
- </el-form>
21
- </div>
22
- </el-tab-pane>
23
-
24
- <el-tab-pane label="表单设计" name="form">
25
- <div class="gb-flow-definition__pane">
26
- <FormViewer
27
- v-if="readonly"
28
- :form-config="definition.form.components"
29
- :show-actions="false"
30
- readonly
31
- />
32
- <FormDesigner
33
- v-else
34
- v-model="definition.form.components"
35
- :options="definition.form.options"
36
- :meta="definition.meta"
37
- :file-name="`${fileName}-form`"
38
- />
39
- </div>
40
- </el-tab-pane>
41
-
42
- <el-tab-pane label="流程设计" name="flow">
43
- <div class="gb-flow-definition__pane">
44
- <FlowCanvas
45
- ref="canvasRef"
46
- v-model="definition.workflow"
47
- :form-variables="canvasFormVariables"
48
- :readonly="readonly"
49
- :meta="definition.meta"
50
- :file-name="fileName"
51
- :show-toolbar="showToolbar"
52
- :export-builder="buildDefinitionPayload"
53
- @change="emit('change', clone(definition))"
54
- />
55
- </div>
56
- </el-tab-pane>
57
- </el-tabs>
58
- </template>
59
-
60
- <FlowCanvas
61
- v-else
62
- ref="canvasRef"
63
- v-model="workflowData"
64
- :form-variables="props.formVariables"
65
- :readonly="readonly"
66
- :meta="meta"
67
- :file-name="fileName"
68
- :show-toolbar="showToolbar"
69
- />
70
- </div>
71
- </template>
72
-
73
- <script setup>
74
- import { computed, onMounted, provide, ref, watch } from 'vue'
75
- import { ElMessage } from 'element-plus'
76
- import FlowCanvas from '../visual/FlowCanvas.vue'
77
- import { FormDesigner, FormViewer } from 'gbformdesign'
78
- import {
79
- createDefinition,
80
- downloadJSON,
81
- enrichFormVariables,
82
- ensureEndNode,
83
- importDefinition,
84
- normalizeDefinition,
85
- normalizeForm,
86
- validateDefinition
87
- } from '../core/flow/index.js'
88
-
89
- defineOptions({ name: 'GbFlowDefinitionDesigner' })
90
-
91
- const props = defineProps({
92
- modelValue: { type: Object, default: null },
93
- formVariables: { type: Array, default: () => [] },
94
- readonly: { type: Boolean, default: false },
95
- adapters: { type: Object, default: () => ({}) },
96
- meta: { type: Object, default: () => ({}) },
97
- fileName: { type: String, default: 'flow' },
98
- defaultTab: { type: String, default: 'basic' },
99
- showToolbar: { type: Boolean, default: true },
100
- autoEnsureEnd: { type: Boolean, default: true }
101
- })
102
-
103
- const emit = defineEmits(['update:modelValue', 'import', 'export', 'validate', 'change'])
104
-
105
- const clone = (value) => JSON.parse(JSON.stringify(value))
106
-
107
- const isDefinitionMode = computed(() => {
108
- const value = props.modelValue
109
- if (!value || typeof value !== 'object') return false
110
- if (value.workflow || value.form || value.schemaVersion || value.kind) return true
111
- return false
112
- })
113
-
114
- provide('gbDesignerAdapters', props.adapters)
115
-
116
- const activeTab = ref(props.defaultTab || 'basic')
117
- const canvasRef = ref(null)
118
-
119
- // ==================== definition mode ====================
120
-
121
- function normalizeDefinitionInput(value) {
122
- if (value && (value.workflow || value.form || value.schemaVersion)) {
123
- const next = normalizeDefinition(value)
124
- ensureEndNode(next.workflow)
125
- if (!next.form.options?.name) {
126
- next.form.options = { ...(next.form.options || {}), name: next.meta?.name || '' }
127
- }
128
- return next
129
- }
130
- return normalizeDefinition(
131
- createDefinition({
132
- workflow: null,
133
- form: [],
134
- meta: {
135
- name: props.fileName,
136
- ...props.meta
137
- }
138
- })
139
- )
140
- }
141
-
142
- const definition = ref(normalizeDefinitionInput(props.modelValue))
143
- const workflowData = ref(props.modelValue && !isDefinitionMode.value ? clone(props.modelValue) : null)
144
-
145
- let syncing = false
146
-
147
- watch(
148
- () => props.modelValue,
149
- (value) => {
150
- if (syncing || !value) return
151
- if (!isDefinitionMode.value) {
152
- if (JSON.stringify(value) === JSON.stringify(workflowData.value)) return
153
- syncing = true
154
- workflowData.value = clone(value)
155
- requestAnimationFrame(() => {
156
- syncing = false
157
- })
158
- return
159
- }
160
- if (JSON.stringify(value) === JSON.stringify(definition.value)) return
161
- syncing = true
162
- definition.value = normalizeDefinitionInput(value)
163
- requestAnimationFrame(() => {
164
- syncing = false
165
- })
166
- },
167
- { deep: true }
168
- )
169
-
170
- watch(
171
- definition,
172
- (value) => {
173
- if (syncing) return
174
- if (props.autoEnsureEnd) ensureEndNode(value.workflow)
175
- emit('update:modelValue', clone(value))
176
- },
177
- { deep: true }
178
- )
179
-
180
- watch(
181
- workflowData,
182
- (value) => {
183
- if (syncing || !value) return
184
- emit('update:modelValue', clone(value))
185
- },
186
- { deep: true }
187
- )
188
-
189
- onMounted(() => {
190
- if (isDefinitionMode.value) {
191
- if (props.autoEnsureEnd) ensureEndNode(definition.value.workflow)
192
- if (!definition.value.form.options) {
193
- definition.value.form.options = normalizeForm(definition.value.form).options
194
- }
195
- }
196
- })
197
-
198
- const tagsText = computed({
199
- get: () => (definition.value.meta.tags || []).join(','),
200
- set: (value) => {
201
- definition.value.meta.tags = String(value || '')
202
- .split(/[,,]/)
203
- .map((tag) => tag.trim())
204
- .filter(Boolean)
205
- }
206
- })
207
-
208
- const canvasFormVariables = computed(() => {
209
- if (props.formVariables?.length) return props.formVariables
210
- const components = definition.value.form?.components || []
211
- return components.length ? enrichFormVariables(components) : []
212
- })
213
-
214
- const buildDefinitionPayload = () => {
215
- if (!isDefinitionMode.value) return null
216
- return clone(definition.value)
217
- }
218
-
219
- // ==================== shared API ====================
220
-
221
- const validate = () => {
222
- const result = isDefinitionMode.value
223
- ? validateDefinition(definition.value)
224
- : canvasRef.value?.validate()
225
- emit('validate', result)
226
- return result
227
- }
228
-
229
- const getWorkflow = () =>
230
- isDefinitionMode.value ? clone(definition.value.workflow) : canvasRef.value?.getWorkflow()
231
-
232
- const getDefinition = () =>
233
- isDefinitionMode.value
234
- ? clone(definition.value)
235
- : canvasRef.value?.getDefinition()
236
-
237
- const importJSON = (input) => {
238
- const result = importDefinition(input)
239
- if (isDefinitionMode.value) {
240
- definition.value = normalizeDefinitionInput(result.document)
241
- } else {
242
- canvasRef.value?.importJSON(input)
243
- }
244
- emit('import', result.document)
245
- return result
246
- }
247
-
248
- const exportJSON = (space = 2) => {
249
- if (isDefinitionMode.value) {
250
- const payload = clone(definition.value)
251
- emit('export', payload)
252
- return JSON.stringify(payload, null, space)
253
- }
254
- return canvasRef.value?.exportJSON(space)
255
- }
256
-
257
- const downloadWorkflow = () => {
258
- if (isDefinitionMode.value) {
259
- const payload = clone(definition.value)
260
- downloadJSON(payload, `${definition.value.meta?.name || props.fileName}.gbflow.json`)
261
- emit('export', payload)
262
- ElMessage.success('模板 JSON 已导出')
263
- return
264
- }
265
- canvasRef.value?.downloadWorkflow()
266
- }
267
-
268
- const saveAsPng = () => canvasRef.value?.saveAsPng()
269
-
270
- defineExpose({
271
- getWorkflow,
272
- getDefinition,
273
- importJSON,
274
- importDefinition,
275
- exportJSON,
276
- downloadWorkflow,
277
- validate,
278
- saveAsPng,
279
- zoomIn: () => canvasRef.value?.zoomIn(),
280
- zoomOut: () => canvasRef.value?.zoomOut(),
281
- resetZoom: () => canvasRef.value?.resetZoom(),
282
- definition
283
- })
284
- </script>
285
-
286
- <style lang="scss">
287
- .gb-flow-definition {
288
- display: flex;
289
- flex-direction: column;
290
- width: 100%;
291
- height: 100%;
292
- min-height: 420px;
293
- background: #efefef;
294
- box-sizing: border-box;
295
- overflow: hidden;
296
-
297
- &__tabs {
298
- flex: 1;
299
- min-height: 0;
300
- display: flex;
301
- flex-direction: column;
302
- }
303
-
304
- &__tabs > .el-tabs__header {
305
- margin: 0;
306
- padding: 0 16px;
307
- background: #fff;
308
- border-bottom: 1px solid var(--el-border-color-light);
309
- flex-shrink: 0;
310
- }
311
-
312
- &__tabs > .el-tabs__content {
313
- flex: 1;
314
- min-height: 0;
315
- }
316
-
317
- &__tabs .el-tab-pane {
318
- height: 100%;
319
- }
320
-
321
- &__basic {
322
- height: 100%;
323
- overflow: auto;
324
- background: #fff;
325
- padding: 24px 32px;
326
- }
327
-
328
- &__pane {
329
- height: 100%;
330
- overflow: hidden;
331
- }
332
-
333
- > .gb-flow-canvas {
334
- flex: 1;
335
- min-height: 0;
336
- }
337
- }
338
- </style>
1
+ <template>
2
+ <div class="gb-flow-definition">
3
+ <template v-if="isDefinitionMode">
4
+ <el-tabs v-model="activeTab" class="gb-flow-definition__tabs">
5
+ <el-tab-pane label="基本信息" name="basic">
6
+ <div class="gb-flow-definition__basic">
7
+ <el-form :model="definition.meta" label-width="90px" style="max-width: 640px">
8
+ <el-form-item label="流程名称">
9
+ <el-input v-model="definition.meta.name" :disabled="readonly" placeholder="请输入流程名称" clearable />
10
+ </el-form-item>
11
+ <el-form-item label="流程分组">
12
+ <el-input v-model="definition.meta.groupId" :disabled="readonly" placeholder="分组标识(可选)" clearable />
13
+ </el-form-item>
14
+ <el-form-item label="流程描述">
15
+ <el-input v-model="definition.meta.description" :disabled="readonly" type="textarea" :rows="3" placeholder="请输入流程描述" />
16
+ </el-form-item>
17
+ <el-form-item label="标签">
18
+ <el-input v-model="tagsText" :disabled="readonly" placeholder="多个标签使用英文逗号分隔" clearable />
19
+ </el-form-item>
20
+ </el-form>
21
+ </div>
22
+ </el-tab-pane>
23
+
24
+ <el-tab-pane label="表单设计" name="form">
25
+ <div class="gb-flow-definition__pane">
26
+ <FormViewer
27
+ v-if="readonly"
28
+ :form-config="definition.form.components"
29
+ :show-actions="false"
30
+ readonly
31
+ />
32
+ <FormDesigner
33
+ v-else
34
+ v-model="definition.form.components"
35
+ :options="definition.form.options"
36
+ :meta="definition.meta"
37
+ :file-name="`${fileName}-form`"
38
+ />
39
+ </div>
40
+ </el-tab-pane>
41
+
42
+ <el-tab-pane label="流程设计" name="flow">
43
+ <div class="gb-flow-definition__pane">
44
+ <FlowCanvas
45
+ ref="canvasRef"
46
+ v-model="definition.workflow"
47
+ :form-variables="canvasFormVariables"
48
+ :readonly="readonly"
49
+ :meta="definition.meta"
50
+ :file-name="fileName"
51
+ :show-toolbar="showToolbar"
52
+ :export-builder="buildDefinitionPayload"
53
+ @change="emit('change', clone(definition))"
54
+ />
55
+ </div>
56
+ </el-tab-pane>
57
+ </el-tabs>
58
+ </template>
59
+
60
+ <FlowCanvas
61
+ v-else
62
+ ref="canvasRef"
63
+ v-model="workflowData"
64
+ :form-variables="props.formVariables"
65
+ :readonly="readonly"
66
+ :meta="meta"
67
+ :file-name="fileName"
68
+ :show-toolbar="showToolbar"
69
+ />
70
+ </div>
71
+ </template>
72
+
73
+ <script setup>
74
+ import { computed, onMounted, provide, ref, watch } from 'vue'
75
+ import { ElMessage } from 'element-plus'
76
+ import FlowCanvas from '../visual/FlowCanvas.vue'
77
+ import { FormDesigner, FormViewer } from 'gbformdesign'
78
+ import {
79
+ createDefinition,
80
+ downloadJSON,
81
+ enrichFormVariables,
82
+ ensureEndNode,
83
+ importDefinition,
84
+ normalizeDefinition,
85
+ normalizeForm,
86
+ validateDefinition
87
+ } from '../core/flow/index.js'
88
+
89
+ defineOptions({ name: 'GbFlowDefinitionDesigner' })
90
+
91
+ const props = defineProps({
92
+ modelValue: { type: Object, default: null },
93
+ formVariables: { type: Array, default: () => [] },
94
+ readonly: { type: Boolean, default: false },
95
+ adapters: { type: Object, default: () => ({}) },
96
+ meta: { type: Object, default: () => ({}) },
97
+ fileName: { type: String, default: 'flow' },
98
+ defaultTab: { type: String, default: 'basic' },
99
+ showToolbar: { type: Boolean, default: true },
100
+ autoEnsureEnd: { type: Boolean, default: true }
101
+ })
102
+
103
+ const emit = defineEmits(['update:modelValue', 'import', 'export', 'validate', 'change'])
104
+
105
+ const clone = (value) => JSON.parse(JSON.stringify(value))
106
+
107
+ const isDefinitionMode = computed(() => {
108
+ const value = props.modelValue
109
+ if (!value || typeof value !== 'object') return false
110
+ if (value.workflow || value.form || value.schemaVersion || value.kind) return true
111
+ return false
112
+ })
113
+
114
+ provide('gbDesignerAdapters', props.adapters)
115
+
116
+ const activeTab = ref(props.defaultTab || 'basic')
117
+ const canvasRef = ref(null)
118
+
119
+ // ==================== definition mode ====================
120
+
121
+ function normalizeDefinitionInput(value) {
122
+ if (value && (value.workflow || value.form || value.schemaVersion)) {
123
+ const next = normalizeDefinition(value)
124
+ ensureEndNode(next.workflow)
125
+ if (!next.form.options?.name) {
126
+ next.form.options = { ...(next.form.options || {}), name: next.meta?.name || '' }
127
+ }
128
+ return next
129
+ }
130
+ return normalizeDefinition(
131
+ createDefinition({
132
+ workflow: null,
133
+ form: [],
134
+ meta: {
135
+ name: props.fileName,
136
+ ...props.meta
137
+ }
138
+ })
139
+ )
140
+ }
141
+
142
+ const definition = ref(normalizeDefinitionInput(props.modelValue))
143
+ const workflowData = ref(props.modelValue && !isDefinitionMode.value ? clone(props.modelValue) : null)
144
+
145
+ let syncing = false
146
+
147
+ watch(
148
+ () => props.modelValue,
149
+ (value) => {
150
+ if (syncing || !value) return
151
+ if (!isDefinitionMode.value) {
152
+ if (JSON.stringify(value) === JSON.stringify(workflowData.value)) return
153
+ syncing = true
154
+ workflowData.value = clone(value)
155
+ requestAnimationFrame(() => {
156
+ syncing = false
157
+ })
158
+ return
159
+ }
160
+ if (JSON.stringify(value) === JSON.stringify(definition.value)) return
161
+ syncing = true
162
+ definition.value = normalizeDefinitionInput(value)
163
+ requestAnimationFrame(() => {
164
+ syncing = false
165
+ })
166
+ },
167
+ { deep: true }
168
+ )
169
+
170
+ watch(
171
+ definition,
172
+ (value) => {
173
+ if (syncing) return
174
+ if (props.autoEnsureEnd) ensureEndNode(value.workflow)
175
+ emit('update:modelValue', clone(value))
176
+ },
177
+ { deep: true }
178
+ )
179
+
180
+ watch(
181
+ workflowData,
182
+ (value) => {
183
+ if (syncing || !value) return
184
+ emit('update:modelValue', clone(value))
185
+ },
186
+ { deep: true }
187
+ )
188
+
189
+ onMounted(() => {
190
+ if (isDefinitionMode.value) {
191
+ if (props.autoEnsureEnd) ensureEndNode(definition.value.workflow)
192
+ if (!definition.value.form.options) {
193
+ definition.value.form.options = normalizeForm(definition.value.form).options
194
+ }
195
+ }
196
+ })
197
+
198
+ const tagsText = computed({
199
+ get: () => (definition.value.meta.tags || []).join(','),
200
+ set: (value) => {
201
+ definition.value.meta.tags = String(value || '')
202
+ .split(/[,,]/)
203
+ .map((tag) => tag.trim())
204
+ .filter(Boolean)
205
+ }
206
+ })
207
+
208
+ const canvasFormVariables = computed(() => {
209
+ if (props.formVariables?.length) return props.formVariables
210
+ const components = definition.value.form?.components || []
211
+ return components.length ? enrichFormVariables(components) : []
212
+ })
213
+
214
+ const buildDefinitionPayload = () => {
215
+ if (!isDefinitionMode.value) return null
216
+ return clone(definition.value)
217
+ }
218
+
219
+ // ==================== shared API ====================
220
+
221
+ const validate = () => {
222
+ const result = isDefinitionMode.value
223
+ ? validateDefinition(definition.value)
224
+ : canvasRef.value?.validate()
225
+ emit('validate', result)
226
+ return result
227
+ }
228
+
229
+ const getWorkflow = () =>
230
+ isDefinitionMode.value ? clone(definition.value.workflow) : canvasRef.value?.getWorkflow()
231
+
232
+ const getDefinition = () =>
233
+ isDefinitionMode.value
234
+ ? clone(definition.value)
235
+ : canvasRef.value?.getDefinition()
236
+
237
+ const importJSON = (input) => {
238
+ const result = importDefinition(input)
239
+ if (isDefinitionMode.value) {
240
+ definition.value = normalizeDefinitionInput(result.document)
241
+ } else {
242
+ canvasRef.value?.importJSON(input)
243
+ }
244
+ emit('import', result.document)
245
+ return result
246
+ }
247
+
248
+ const exportJSON = (space = 2) => {
249
+ if (isDefinitionMode.value) {
250
+ const payload = clone(definition.value)
251
+ emit('export', payload)
252
+ return JSON.stringify(payload, null, space)
253
+ }
254
+ return canvasRef.value?.exportJSON(space)
255
+ }
256
+
257
+ const downloadWorkflow = () => {
258
+ if (isDefinitionMode.value) {
259
+ const payload = clone(definition.value)
260
+ downloadJSON(payload, `${definition.value.meta?.name || props.fileName}.gbflow.json`)
261
+ emit('export', payload)
262
+ ElMessage.success('模板 JSON 已导出')
263
+ return
264
+ }
265
+ canvasRef.value?.downloadWorkflow()
266
+ }
267
+
268
+ const saveAsPng = () => canvasRef.value?.saveAsPng()
269
+
270
+ defineExpose({
271
+ getWorkflow,
272
+ getDefinition,
273
+ importJSON,
274
+ importDefinition,
275
+ exportJSON,
276
+ downloadWorkflow,
277
+ validate,
278
+ saveAsPng,
279
+ zoomIn: () => canvasRef.value?.zoomIn(),
280
+ zoomOut: () => canvasRef.value?.zoomOut(),
281
+ resetZoom: () => canvasRef.value?.resetZoom(),
282
+ definition
283
+ })
284
+ </script>
285
+
286
+ <style lang="scss">
287
+ .gb-flow-definition {
288
+ display: flex;
289
+ flex-direction: column;
290
+ width: 100%;
291
+ height: 100%;
292
+ min-height: 420px;
293
+ background: #efefef;
294
+ box-sizing: border-box;
295
+ overflow: hidden;
296
+
297
+ &__tabs {
298
+ flex: 1;
299
+ min-height: 0;
300
+ display: flex;
301
+ flex-direction: column;
302
+ }
303
+
304
+ &__tabs > .el-tabs__header {
305
+ margin: 0;
306
+ padding: 0 16px;
307
+ background: #fff;
308
+ border-bottom: 1px solid var(--el-border-color-light);
309
+ flex-shrink: 0;
310
+ }
311
+
312
+ &__tabs > .el-tabs__content {
313
+ flex: 1;
314
+ min-height: 0;
315
+ }
316
+
317
+ &__tabs .el-tab-pane {
318
+ height: 100%;
319
+ }
320
+
321
+ &__basic {
322
+ height: 100%;
323
+ overflow: auto;
324
+ background: #fff;
325
+ padding: 24px 32px;
326
+ }
327
+
328
+ &__pane {
329
+ height: 100%;
330
+ overflow: hidden;
331
+ }
332
+
333
+ > .gb-flow-canvas {
334
+ flex: 1;
335
+ min-height: 0;
336
+ }
337
+ }
338
+ </style>