App.vue
18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
<template>
<div class="app" style="height: 100vh">
<vue-flow-editor
ref="editor"
modelWidth="30%"
:data="state.data"
:grid="showGrid"
:miniMap="showMiniMap"
:onRef="onRef"
:multipleSelect="showMultipleSelect"
:loading="state.editorLoading"
:beforeDelete="handleBeforeDelete"
:afterDelete="handleAfterDelete"
:beforeAdd="handleBeforeAdd"
:afterAdd="handleAfterAdd"
@dblclick-node="onDblclickNode"
@dblclick-edge="onDblClickEdge"
:activityConfig="state.activityConfig"
>
<!-- 左侧菜单 -->
<template v-slot:menu>
<vue-flow-edit-menu-group label="活动节点" value>
<vue-flow-edit-menu
v-for="(value, key) in state.activityConfig"
:key="key"
:model="{ activity: key, text: value.text, desc: value.desc }"
>
<template v-slot:content>
<div class="activity-menu">
<img :src="value.img" />
<span>{{ value.text }}</span>
</div>
</template>
</vue-flow-edit-menu>
</vue-flow-edit-menu-group>
<vue-flow-edit-menu-group
v-for="(group, groupIndex) in state.menuData"
:label="group.label"
:key="groupIndex"
value
>
<vue-flow-edit-menu
v-for="(menu, menuIndex) in group.menus"
:key="menuIndex"
:model="menu"
/>
</vue-flow-edit-menu-group>
</template>
<!-- 右侧表单 -->
<template v-slot:model>
<el-form
v-if="!!state.detailModel"
ref="form"
:model="state.detailModel"
label-position="top"
label-width="100px"
>
<template v-if="state.detailModel.activity === undefined">
<el-tabs
v-model="state.activeName"
class=""
@tab-change="handleActiveChange"
stretch
>
<el-tab-pane label="节点属性" name="node" style="padding: 0 1rem">
<el-form-item prop="label">
<div slot="label">
节点名称 <span style="color: red;">*</span>
</div>
<el-input v-model="state.detailModel.label" />
</el-form-item>
<el-form-item prop="attr">
<el-radio-group
v-model="state.attr_radio"
size="large"
class="attr-radio-group"
>
<el-radio-button label="基础属性" />
<el-radio-button label="更多属性" />
</el-radio-group>
</el-form-item>
<el-form-item v-if="state.attr_radio === '基础属性'" prop="">
<div slot="label">
字段权限 <span style="color: red;">*</span>
</div>
<el-row
style="width: 100%; background-color: #f0f1f4; padding-left: 10px;"
>
<el-col :span="12">字段</el-col>
<el-col :span="6">可见</el-col>
<el-col :span="6">可编辑</el-col>
</el-row>
<el-row style="width: 100%; padding-left: 10px;">
<el-col :span="12" style="color: #409eff;">全选</el-col>
<el-col :span="6" style="padding-left: 5px;"
><el-checkbox
@change="onAuthAllChange"
v-model="state.auth_all_checked"
label=""
size="large"
/></el-col>
<el-col :span="6" style="padding-left: 5px;"
><el-checkbox
@change="onAuthAllEditChange"
v-model="state.auth_all_edit"
label=""
size="large"
/></el-col>
</el-row>
<el-row
v-for="(field, index) in state.field_auths"
:key="index"
style="width: 100%; padding-left: 10px;"
>
<el-col :span="12" style="">{{ field.name }}</el-col>
<el-col :span="6" style="padding-left: 5px;"
><el-checkbox
v-model="field.visible.checked"
:disabled="field.visible.disabled"
label=""
size="large"
/></el-col>
<el-col :span="6" style="padding-left: 5px;"
><el-checkbox
v-model="field.editable.checked"
:disabled="field.editable.disabled"
label=""
size="large"
/></el-col>
</el-row>
</el-form-item>
</el-tab-pane>
<el-tab-pane label="流程属性" name="flow" style="padding: 0 1rem">
<el-form-item prop="label">
<div slot="label">
测试属性 <span style="color: red;">*</span>
</div>
<el-input v-model="state.detailModel.data.test" />
</el-form-item>
</el-tab-pane>
</el-tabs>
<!-- <template v-if="state.detailModel.type !== 'edge'">
<el-form-item label="节点背景色" prop="style.fill">
<el-color-picker v-model="state.detailModel.style.fill" />
</el-form-item>
<el-form-item label="节点边框色" prop="style.stroke">
<el-color-picker v-model="state.detailModel.style.stroke" />
</el-form-item>
<el-form-item label="节点文字色" prop="labelCfg.style.stroke">
<el-color-picker
v-model="state.detailModel.labelCfg.style.fill"
/>
</el-form-item>
</template> -->
<div style="margin-left: 20px;">
<el-button type="primary" @click="openUserForm">
设置人员配置
</el-button>
</div>
</template>
<template v-else>
<el-form-item label="活动标题">
<el-input v-model="state.detailModel.text" />
</el-form-item>
<el-form-item label="活动副标题">
<el-input v-model="state.detailModel.desc" />
</el-form-item>
<el-form-item label="活动类型">
<el-select v-model="state.detailModel.activity">
<el-option
v-for="(value, key) in state.activityConfig"
:key="key"
:label="value.text"
:value="key"
/>
</el-select>
</el-form-item>
</template>
</el-form>
</template>
<!-- 工具栏 -->
<template v-slot:toolbar>
<el-tooltip content="打印流程图数据结构">
<div class="vue-flow-editor-toolbar-item" @click="logData">
<i class="el-icon-search" style=" margin-top: 4px;" />
<span style="font-size: 12px; transform: scale(0.8); margin-top: 2px;">log数据</span>
</div>
</el-tooltip>
</template>
<!-- 表单底部按钮 -->
<template v-slot:foot>
<el-button type="primary" @click="save">保存</el-button>
<el-button @click="cancel">取消</el-button>
</template>
</vue-flow-editor>
</div>
<select-user-view
:visible="state.dialogUserFormVisible"
@close="onCloseUserView"
@confirm="onConfirmUserView"
/>
</template>
<script lang="ts">
import { reactive, onMounted, watch, nextTick } from "vue";
import { AppData } from "./data.js";
import { staticPath } from "./utils";
import { ElNotification } from "element-plus";
import axios from "./axios";
import $ from "jquery";
import { Calendar, Search } from "@element-plus/icons-vue";
import SelectUserView from "./selectUserView.vue";
import { Function } from 'lodash';
import { extend } from '@vue/shared';
const G6 = (window as any).G6.default as any;
function delay(time: number) {
return new Promise(resolve => setTimeout(resolve, time));
}
interface myObj {
source: string;
id: string;
label: string;
}
interface myEvent {
item: {
get(T: string): {
source: any,
target: any,
style: any,
labelCfg: any
label: any
}
}
}
export default {
components: {
Calendar,
Search,
SelectUserView
},
setup(props, context) {
const state = reactive({
data: AppData, // 渲染的数据,数据格式参考G6文档
detailModel: null,
editorLoading: false, // 开始编辑器的loading状态
selectOptions: [
{ label: "待确认", value: "0" },
{ label: "填写表单", value: "1" },
{ label: "部门负责人审批", value: "2" },
{ label: "总经理审批", value: "3" }
],
menuData: [
{
label: "流程节点",
menus: [
{ label: "开始", shape: "ellipse", id: "start-node" },
{ label: "结束", shape: "ellipse", id: "end-node" },
{ label: "审批节点", busType: "123" },
{ label: "判断节点", shape: "diamond" }
]
},
{
label: "其他形状节点",
menus: [
{ label: "矩形节点", shape: "rect" },
{ label: "圆形节点", shape: "circle" },
{ label: "椭圆节点", shape: "ellipse" },
{ label: "菱形节点", shape: "diamond" },
{ label: "三角形节点", shape: "triangle" },
{ label: "星形节点", shape: "star" }
]
}
],
activityConfig: {
advertisement: {
text: "广告宣传1",
desc: "通过广告宣传新品",
color: "#9283ed",
img: "https://cdn.ipadbiz.cn/oa/advertisement-node.svg"
},
coupon: {
text: "优惠券",
desc: "发放奖励优惠券",
color: "#ed8383",
img: "https://cdn.ipadbiz.cn/oa/coupon-node.svg"
},
crowd: {
text: "用户反馈",
desc: "收集用户反馈信息",
color: "#92dba8",
img: "https://cdn.ipadbiz.cn/oa/crowd-node.svg"
}
},
dialogUserFormVisible: false,
activeName: "node",
attr_radio: "基础属性",
auth_all_checked: false,
auth_all_edit: false,
field_auths: [
{
name: "字段1",
visible: {
checked: true,
disabled: false
},
editable: {
checked: false,
disabled: true
}
},
{
name: "字段2",
visible: {
checked: true,
disabled: false
},
editable: {
checked: false,
disabled: false
}
},
{
name: "字段3",
visible: {
checked: true,
disabled: false
},
editable: {
checked: false,
disabled: false
}
}
],
});
onMounted(() => {
document.title = '可视化流程设计器';
// // 显示提示框的标志位
// var showConfirmation = true;
// // 监听 beforeunload 事件
// window.addEventListener('beforeunload', function (event) {
// if (showConfirmation) {
// // 取消事件的默认行为(弹出确认对话框)
// event.preventDefault();
// // Chrome 和 Firefox 需要返回一个值以显示确认对话框
// event.returnValue = '';
// // 显示自定义的提示信息
// var confirmationMessage = '确定要离开此页面吗?';
// (event || window.event).returnValue = confirmationMessage; // 兼容旧版浏览器
// return confirmationMessage;
// }
// });
// // 监听 unload 事件
// window.addEventListener('unload', function () {
// // 设置标志位为 false,避免在刷新页面时再次显示提示框
// showConfirmation = false;
// });
});
function handleActiveChange(name) {
console.warn(name);
}
const onAuthAllChange = (val: any) => { // 全选可见按钮回调
if (val) {
// 全部选中
state.field_auths.forEach(ele => {
ele.visible.checked = true;
});
} else {
// 全部取消选中
state.field_auths.forEach(ele => {
ele.visible.checked = false;
});
}
};
const onAuthAllEditChange = (val: any) => { // 全选可编辑按钮回调
console.warn(val);
};
/****** 用户选择控件弹框 ******/
const openUserForm = () => { // 打开设置用户弹框
state.dialogUserFormVisible = true;
};
const onCloseUserView = (status: boolean) => {
state.dialogUserFormVisible = status;
}
const onConfirmUserView = (data: any) => {
console.log(data);
}
/******************* END *******************/
/********** 流程图功能函数 **********/
let editor: { openModel: () => void; closeModel: () => void; updateModel: (arg0: any) => void; editorState: { graph: { save: () => { nodes: any; edges: any; }; }; }; };
/**
* 双击节点回调
*
* @param {Object} e - The event object
*/
function onDblclickNode(e: myEvent) {
const model = G6.Util.clone(e.item.get("model"));
model.style = model.style || {};
model.labelCfg = model.labelCfg || { style: {} };
state.detailModel = model;
editor.openModel();
}
/**
* 双击连接线回调
*
* @param {Event} e - The event object representing the double click event.
*/
function onDblClickEdge(e: myEvent) {
const { source, target, style, labelCfg, label } = e.item.get("model");
const model = {
label,
source,
target,
style: style || {},
labelCfg: labelCfg || { style: {} },
type: null,
id: null
};
model.type = e.item.get("type");
model.id = e.item.get("id");
state.detailModel = model;
editor.openModel();
}
/**
* Cancels the operation and closes the editor model.
*
*/
function cancel() {
editor.closeModel();
}
/**
* Saves the changes made in the editor.
*
*/
function save() {
editor.updateModel(state.detailModel);
editor.closeModel();
}
/**
* 删除前校验
*
* @param {Object} model - The model object.
* @param {string} type - The type of the model.
* @return {Promise} A promise that resolves when the event is handled.
*/
async function handleBeforeDelete(model: myObj, type: string): Promise<any> {
if (type === "node") {
if (model.label === "开始") {
state.editorLoading = true;
await delay(1000);
state.editorLoading = false;
ElNotification.error("不可以删除【开始】节点");
return Promise.reject("reject");
}
}
}
/**
* 删除后动作
*
* @param {Object} model - The model being deleted.
* @param {string} type - The type of the model being deleted.
*/
function handleAfterDelete(model: myObj, type: string) {
if (type === "edge") {
console.log("delete edge");
} else {
console.log("after delete", model.label, { ...model });
}
}
/**
* 添加前校验
*
* @param {object} model - The model object.
* @param {string} type - The type of the model.
* @return {Promise} A promise that resolves to a result or rejects with an error.
*/
function handleBeforeAdd(model: myObj, type: string): Promise<any> {
if (type === "edge") {
if (model.source === "end-node") {
ElNotification.error("结束节点不能输出连线其他节点");
return Promise.reject("reject");
}
}
if (type === "node") {
if (model.id === "start-node" || model.id === "end-node") {
const data = editor.editorState.graph.save();
for (let i = 0; i < data.nodes.length; i++) {
const node = data.nodes[i];
if (node.id === model.id) {
ElNotification.error(
`只能有一个${model.id === "start-node" ? "开始" : "结束"}节点`
);
return Promise.reject("reject");
}
}
}
}
}
/**
* 添加后动作
*
* @param {model} model - The model being handled.
* @param {type} type - The type of the event.
*/
function handleAfterAdd(model: myObj, type: string) {
if (type === "edge") {
console.log(`新增连接线`);
}
}
/**
* 打印流程图数据结构
*
* @return {void} No return value.
*/
function logData(): void {
let { nodes, edges } = editor.editorState.graph.save();
nodes = nodes.map(
({ data, id, label, shape, x, y, text, desc, img }) => ({
data,
id,
label,
shape,
x,
y,
text,
desc,
img
})
);
edges = edges.map(({ source, sourceAnchor, target, targetAnchor }) => ({
source,
sourceAnchor,
target,
targetAnchor
}));
console.log(JSON.stringify({ nodes, edges }, null, 2));
}
return {
state,
showGrid: true, // 是否开启网格
showMiniMap: true, // 是否开启缩略图
showMultipleSelect: true, // 编辑器是否可以多选
onDblclickNode,
onDblClickEdge,
cancel,
save,
handleBeforeDelete,
handleAfterDelete,
handleBeforeAdd,
handleAfterAdd,
handleActiveChange,
onAuthAllChange,
onAuthAllEditChange,
openUserForm,
onCloseUserView,
onConfirmUserView,
logData,
onRef: (e: any) => (editor = e),
staticPath
};
}
};
</script>
<style lang="scss">
html,
body {
padding: 0;
margin: 0;
.activity-menu {
display: flex;
align-items: center;
img {
margin-right: 1em;
width: 30px;
height: 30px;
}
}
}
.attr-radio-group {
width: 100% !important;
.el-radio-button.el-radio-button--large {
width: 50% !important;
span {
width: 100% !important;
}
}
}
.demo-tabs > .el-tabs__content {
/* padding: 32px; */
}
</style>