App.vue
34.2 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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
<template>
<div class="app" style="height: 100vh">
<vue-flow-editor
ref="editor"
modelWidth="30%"
:data="state.data"
:grid="showGrid"
:miniMap="showMiniMap"
:onRef="onRef"
:multipleSelect="true"
: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" />
</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>
<el-dialog v-model="state.dialogUserFormVisible" title="成员列表">
<div style="border: 1px dashed #DCDFE6; padding: 10px;">
<el-tag
v-for="tag in state.userTags"
:key="tag.name"
class=""
style="margin-left: 0.25rem; margin-right: 0.25rem;"
closable
@close="handleTagClose(tag)"
>
{{ tag.name }}
</el-tag>
</div>
<div style="border: 1px solid #DCDFE6; padding: 10px; margin-top: 10px;">
<div style="height: 40px">
<div style="padding: 0; position: relative; margin: 0 0 15px;">
<div v-if="!state.is_active_search">
<div class="flow-tabs__nav-wrap">
<div class="flow-tabs__nav-scroll">
<div class="flow-tabs__nav is-top">
<div
ref_key="barRef"
class="flow-tabs__active-bar"
:style="{
width: state.tabTextWidth,
transform: 'translateX' + '(' + state.tabOffset + ')'
}"
></div>
<div
v-for="(item, index) in state.userTabs"
:key="index"
:class="[
'flow-tabs__item',
'is-top',
item.id === state.activeTabId ? 'is-active' : ''
]"
:id="item.id"
@click="handleTabClick(item, $event, index)"
>
{{ item.label }}
</div>
</div>
</div>
</div>
<div class="flow-tab-search" @click="activeSearchBtn">
<el-icon :size="15"><Search /></el-icon> 搜索框
</div>
</div>
<div v-else>
<el-input
v-model="state.search_input"
class="search-btn-wrapper"
placeholder="请输入关键字"
>
<template #prefix>
<el-icon class="el-input__icon"><search /></el-icon>
</template>
<template #append>
<div class="search-group">
<div class="confirm-btn" @click="onSearch">搜索</div>
<div class="cancel-btn" @click="onClearSearch">取消</div>
</div>
</template>
</el-input>
</div>
</div>
</div>
<!-- 未激活搜索框 -->
<div v-if="!state.is_active_search">
<div v-for="(item, index) in state.userTabs" :key="index">
<div v-if="item.id === state.activeTabId && item.type === 'tree'">
<el-row>
<el-col :span="8">
<el-tree
:data="item.data"
:props="state.defaultProps"
empty-text="暂无数据"
@node-click="handleNodeClick"
/>
</el-col>
<el-col :span="16">
<div
style="border-left: 2px solid #e4e7ed; width: 2px; height: 100%; padding-left: 10px;"
>
<el-checkbox-group
class="flow-checkbox-group"
v-model="state.checkedUserList"
>
<el-checkbox
v-for="(user, idx) in state.userList"
:key="idx"
:label="user.id"
:disabled="user.disabled"
@change="handleCheckedUserListChange(user, $event)"
>{{ user.label }}</el-checkbox
>
</el-checkbox-group>
</div>
</el-col>
</el-row>
</div>
<div v-if="item.id === state.activeTabId && item.type === 'list'">
<el-tabs
tab-position="left"
style=""
class="demo-tabs"
v-model="activeTabContent"
@tab-click="handleTabContentClick"
>
<el-tab-pane
v-for="(role, idx) in item.data"
:key="idx"
:label="role.label"
>
<el-checkbox-group
class="flow-checkbox-group"
v-model="state.checkedUserList"
>
<el-checkbox
v-for="(user, idx) in state.userList"
:key="idx"
:label="user.id"
:disabled="user.disabled"
@change="handleCheckedUserListChange(user, $event)"
>{{ user.label }}</el-checkbox
>
</el-checkbox-group>
</el-tab-pane>
</el-tabs>
</div>
</div>
</div>
<!-- 激活搜索框 -->
<div v-else>
<el-checkbox-group
class="flow-checkbox-group"
style="padding-left: 10px;"
v-model="state.checkedSearchUserList"
>
<el-checkbox
v-for="(user, idx) in state.searchUserList"
:key="idx"
:label="user.id"
:disabled="user.disabled"
@change="handleCheckedUserListChange(user, $event)"
>{{ user.label }}</el-checkbox
>
</el-checkbox-group>
</div>
</div>
<template #footer>
<span class="dialog-footer">
<el-button @click="closeUserForm">取消</el-button>
<el-button type="primary" @click="confirmUserForm">确定</el-button>
</span>
</template>
</el-dialog>
</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";
const G6 = (window as any).G6.default as any;
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
export default {
setup(props, context) {
const state = reactive({
data: AppData,
detailModel: null,
editorLoading: false,
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
}
}
],
userTags: [],
activeTabId: "tab-1", // TODO: 需要获取默认第一个ID
userTabs: [],
tabSelectData: [],
userTabType: "tree",
tabOffset: "0px",
tabTextWidth: "76px", // 文字宽度需要打开弹框时重新计算
is_active_search: false,
search_input: "",
userList: [],
checkedUserList: [],
searchUserList: [], // 搜索框 选中 用户ID
checkedSearchUserList: [],
defaultProps: {
children: "children",
label: "label"
}
});
function handleActiveChange(name) {
console.warn(name);
}
const onAuthAllChange = val => {
// 全选可见按钮回调
if (val) {
// 全部选中
state.field_auths.forEach(ele => {
ele.visible.checked = true;
});
} else {
// 全部取消选中
state.field_auths.forEach(ele => {
ele.visible.checked = false;
});
}
};
const onAuthAllEditChange = val => {
// 全选可编辑按钮回调
console.warn(val);
};
const openUserForm = () => {
state.dialogUserFormVisible = true;
// TODO:查询到的用户列表数据
state.userTabs = [
{
id: "tab-1",
label: "组织架构",
type: "tree",
data: [
{
id: "dept-1",
label: "上级部门 1",
children: [
{
id: "dept-1-1",
label: "部门名称 1-1",
children: [],
list: [
{
id: "user-1-1",
label: "用户1-1",
checked: true,
disabled: false
},
{
id: "user-1-2",
label: "用户1-2",
checked: false,
disabled: false
},
{
id: "user-1-3",
label: "用户1-3",
checked: false,
disabled: true
}
]
}
]
},
{
id: "dept-2",
label: "上级部门 2",
children: [
{
id: "dept-2-1",
label: "部门名称 2-1",
children: [],
list: [
{
id: "user-2-1",
label: "用户2-1",
checked: false,
disabled: false
},
{
id: "user-2-2",
label: "用户2-2",
checked: false,
disabled: false
},
{
id: "user-2-3",
label: "用户2-3",
checked: false,
disabled: true
}
]
}
]
}
]
},
{
id: "tab-2",
label: "角色",
type: "list",
data: [
{
id: "role-1-1",
label: "流程发起人",
children: [],
list: [
{
id: "role-1-2",
label: "选项 A",
checked: false,
disabled: false
},
{
id: "role-1-3",
label: "选项 B",
checked: true,
disabled: false
},
{
id: "role-1-4",
label: "选项 C",
checked: false,
disabled: true
}
]
},
{
id: "role-1-2",
label: "成员字段",
children: [],
list: []
},
{
id: "role-1-3",
label: "部门字段",
children: [],
list: []
},
{
id: "role-1-4",
label: "主管",
children: [],
list: []
}
]
}
]
};
const handleTabClick = (tab, event, idx) => {
// 点击Tab切换回调
state.tabSelectData = tab.data; // tab选中数据提供给list类型使用
state.userList = []; // 清空用户列表
state.checkedUserList = []; // 清空选中用户列表
// console.log(tab, event);
// 设置当前激活的tab
state.userTabType = tab.type;
state.activeTabId = tab.id;
// 子容器相对于父容器的相对x轴位移, 第一项为0
if (idx) {
state.tabOffset = $("#" + tab.id).position().left + 20 + "px";
} else {
state.tabOffset = "0px";
}
// 文字宽度
state.tabTextWidth = $("#" + tab.id).width() + "px";
// 检查列表第一项是否有值
if (tab?.data[0]?.list) {
let list = tab.data[0].list;
state.userList = list;
state.checkedUserList = list
.filter(ele => {
return ele.checked;
})
.map(ele => {
return ele.id;
});
}
};
const handleTabContentClick = (tab, event) => {
// 侧边栏Tab点击回调
// console.log(event);
state.tabSelectData.forEach(ele => {
if (ele.label === tab.props.label) {
state.userList = ele.list;
state.checkedUserList = ele.list
.filter(ele => {
return ele.checked;
})
.map(ele => {
return ele.id;
});
}
});
};
const handleNodeClick = data => {
// console.log(data);
if (data.list) {
state.userList = data.list;
state.checkedUserList = data.list
.filter(ele => {
return ele.checked;
})
.map(ele => {
return ele.id;
});
// console.warn(state.checkedUserList);
}
};
function modifyFieldValue(obj, fieldName, targetValue, newValue) {
// 遍历相应ID修改选中值
// 检查当前层级的字段值是否匹配目标值
if (obj[fieldName] === targetValue) {
obj["checked"] = newValue;
}
// 遍历当前层级的子项(如果有)
for (var key in obj) {
if (typeof obj[key] === "object" && obj[key] !== null) {
modifyFieldValue(obj[key], fieldName, targetValue, newValue);
}
}
}
const handleCheckedUserListChange = (user, checked) => {
// 勾选用户回调
// 修改选中值状态
modifyFieldValue(state.userTabs, "id", user.id, checked);
};
function getAllListItems(arr) {
// 遍历递归获取list下面的数据
var result = [];
function recursiveGetListItems(subArr) {
for (var i = 0; i < subArr.length; i++) {
var item = subArr[i];
if (item.list && Array.isArray(item.list)) {
result = result.concat(item.list);
}
if (item.children && Array.isArray(item.children)) {
recursiveGetListItems(item.children);
}
}
}
recursiveGetListItems(arr);
return result;
}
const setTagsList = val => {
let userList = [];
val.forEach(ele => {
let data = getAllListItems(ele.data);
userList.push(data);
});
// 合并成一维数组列表
userList = [...userList.flat()];
// 勾选变化后同步到选中列表
state.userTags = userList
.filter(ele => {
return ele.checked;
})
.map(ele => {
return {
id: ele.id,
name: ele.label
};
});
};
// 监听数据结构选中值变化
watch(
() => state.userTabs,
val => {
if (val) {
// 设置tag选中列表
setTagsList(val);
}
},
{ deep: true }
);
const handleTagClose = tag => {
// 移除成员标签回调
state.userTags.splice(state.userTags.indexOf(tag), 1); // 删除标签列表中的项
// 移除数据结构中的选中值
modifyFieldValue(state.userTabs, "id", tag.id, false);
//
let tagsId = state.userTags.map(ele => {
return ele.id;
});
// console.warn(tagsId);
// 获取tags中已删除的, 勾选列表中还勾选的值
let result = state.checkedUserList.filter(
value => !tagsId.includes(value)
);
// 选中列表中不存在勾选列表中项时,需要删除勾选列表中的项
if (result.length) {
result.forEach(ele => {
state.checkedUserList.splice(state.checkedUserList.indexOf(ele), 1);
});
}
// console.log(result);
// console.log(state.userTags);
// console.log(state.checkedUserList);
};
const closeUserForm = () => {
// 关闭用户列表表单回调
state.dialogUserFormVisible = false;
};
const confirmUserForm = () => {
// 确认用户列表表单回调
state.dialogUserFormVisible = false;
console.log(state.userTags);
};
const activeSearchBtn = () => {
state.is_active_search = !state.is_active_search;
state.searchUserList = [];
};
const checkSearchStatus = () => {
// 在搜索框中同步显示tag框选中的用户
state.userTags.forEach(ele => {
state.searchUserList.forEach(item => {
if (ele.id === item.id) {
item.checked = true;
}
});
});
// 显示选中tags的用户
state.checkedSearchUserList = state.searchUserList
.filter(ele => ele.checked)
.map(ele => ele.id);
};
const onClearSearch = () => {
// 清空搜索回调
state.is_active_search = !state.is_active_search;
};
const onSearch = () => {
// TODO: 搜索回调
state.searchUserList = [
{
id: "user-1-1",
label: "用户1-1",
checked: true,
disabled: false
},
{
id: "user-1-2",
label: "用户1-2",
checked: false,
disabled: false
},
{
id: "user-1-3",
label: "用户1-3",
checked: false,
disabled: true
},
{
id: "role-1-2",
label: "选项 A",
checked: false,
disabled: false
},
{
id: "role-1-3",
label: "选项 B",
checked: true,
disabled: false
},
{
id: "role-1-4",
label: "选项 C",
checked: false,
disabled: true
}
];
// console.log(state.userTags);
checkSearchStatus();
};
onMounted(() => {
// // 显示提示框的标志位
// 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;
// });
// axios.get('/srv/?a=query_form_all_field')
// .then(res => {
// console.warn(res.data);
// });
// $('.el-tabs__nav')
// 根据数据获取选中的tag标签
setTagsList(state.userTabs);
});
watch(
() => state.dialogUserFormVisible,
val => {
if (val) {
nextTick(() => {
state.tabTextWidth = $("#" + state.activeTabId).width() + "px";
});
}
}
);
let editor;
function onDblclickNode(e) {
const model = G6.Util.clone(e.item.get("model"));
model.style = model.style || {};
model.labelCfg = model.labelCfg || { style: {} };
state.detailModel = model;
editor.openModel();
}
function onDblClickEdge(e) {
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();
}
function cancel() {
editor.closeModel();
}
function save() {
editor.updateModel(state.detailModel);
editor.closeModel();
}
async function handleBeforeDelete(model, type) {
if (type === "node") {
if (model.label === "开始") {
state.editorLoading = true;
await delay(1000);
state.editorLoading = false;
ElNotification.error("不可以删除【开始】节点");
return Promise.reject("reject");
}
}
}
function handleAfterDelete(model, type) {
if (type === "edge") {
console.log("delete edge");
} else {
console.log("after delete", model.label, { ...model });
}
}
function handleBeforeAdd(model, type) {
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");
}
}
}
}
}
function handleAfterAdd(model, type) {
if (type === "edge") {
console.log(`新增连接线`);
}
}
function logData() {
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,
onDblclickNode,
onDblClickEdge,
cancel,
save,
handleBeforeDelete,
handleAfterDelete,
handleBeforeAdd,
handleAfterAdd,
handleActiveChange,
onAuthAllChange,
onAuthAllEditChange,
handleTabClick,
handleTabContentClick,
handleNodeClick,
handleTagClose,
closeUserForm,
confirmUserForm,
handleCheckedUserListChange,
onSearch,
onClearSearch,
activeSearchBtn,
openUserForm,
logData,
onRef: e => (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; */
}
.flow-tabs__nav-wrap {
overflow: hidden;
margin-bottom: -1px;
position: relative;
}
.flow-tabs__nav-wrap::after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2px;
background-color: #e4e7ed;
/* z-index: 1; */
}
.flow-tabs__nav-scroll {
/* overflow: hidden; */
overflow: scroll;
}
.flow-tabs__active-bar {
position: absolute;
bottom: 0;
left: 0;
height: 2px;
background-color: #409eff;
z-index: 1;
transition: width 0.3s cubic-bezier(0.645, 0.045, 0.355, 1),
transform 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
list-style: none;
}
.flow-tabs__nav {
display: flex;
white-space: nowrap;
position: relative;
transition: transformX(0px);
float: left;
.flow-tabs__item {
padding: 0 20px;
height: 40px;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
list-style: none;
font-size: 14px;
font-weight: 500;
color: #303133;
position: relative;
&:hover {
color: #409eff;
cursor: pointer;
}
&.is-active {
color: #409eff;
}
&.is-top:nth-child(2) {
padding-left: 0;
}
}
}
.flow-tab-search {
position: absolute;
top: 0;
right: 0;
width: 100px;
display: flex;
align-items: center;
background-color: #e4e7ed;
padding: 5px 5px 5px 15px;
border-radius: 15px;
color: #b1b3b8;
&:hover {
cursor: pointer;
}
}
.flow-checkbox-group {
.el-checkbox {
display: flex !important;
}
}
.search-btn-wrapper {
.el-input-group__append {
width: 100px !important;
padding: 0 !important;
}
.search-group {
display: flex;
text-align: center;
.confirm-btn {
width: 50px;
color: #fff;
background-color: #409eff;
&:hover {
cursor: pointer;
}
}
.cancel-btn {
width: 50px;
&:hover {
cursor: pointer;
}
}
}
}
</style>