selectUserView.vue
29.7 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
<!--
* @Date: 2023-11-01 10:18:53
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-11-22 11:39:41
* @FilePath: /vue-flow-editor/doc/selectUserView.vue
* @Description: 成员列表选择控件
-->
<template>
<el-dialog
v-model="dialogUserFormVisible"
title="成员列表"
@close="closeUserForm"
>
<div class="flow-tag__wrapper">
<el-tag
v-if="userTags.length"
v-for="tag in userTags"
:key="tag.name"
style="margin-left: 0.25rem; margin-right: 0.25rem; margin-bottom: 0.5rem;"
closable
@close="handleTagClose(tag)"
>
{{ tag.name }}
</el-tag>
<div v-else class="text-empty">请选择成员</div>
</div>
<div class="flow-tabs__wrapper">
<div style="height: 40px">
<div class="search_box">
<div v-if="!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: tabTextWidth,
transform: 'translateX' + '(' + tabOffset + ')'
}"
></div>
<div
v-for="(item, index) in userTabs"
:key="index"
:class="[
'flow-tabs__item',
'is-top',
item.id === activeTabId ? 'is-active' : ''
]"
:id="item.id"
@click="handleTabClick(item, $event, index)"
>
{{ item.name }}
</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="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="!is_active_search" style="max-height: 300px; overflow: scroll;">
<div v-for="(item, index) in userTabs" :key="index">
<!-- 组织结构树 -->
<div v-if="item.id === activeTabId && item.type === 'corp-tree'">
<el-row>
<el-col :span="24">
<el-tree
ref="corpTreeRef"
:data="item.data"
:props="defaultProps"
show-checkbox
node-key="id"
:default-expanded-keys="currentNodeKey"
:default-checked-keys="currentCheckedNodeKey"
:check-strictly="true"
empty-text="暂无数据"
@check="checkNode"
style="margin-top: 10px;"
/>
</el-col>
</el-row>
</div>
<!-- 成员选择树 -->
<div v-if="item.id === activeTabId && item.type === 'user-tree'">
<el-row>
<el-col :span="8">
<el-tree
ref="userTreeRef"
:data="item.data"
:props="defaultProps"
node-key="id"
:default-expanded-keys="currentNodeKey"
:highlight-current="true"
empty-text="暂无数据"
@node-click="handleNodeClick"
style="margin-top: 10px;"
/>
</el-col>
<el-col :span="16">
<div class="flow-checkbox-box">
<el-checkbox-group
class="flow-checkbox-group"
v-model="checkedUserList"
>
<el-checkbox
v-for="(user, idx) in userList"
:key="idx"
:label="user.id"
:disabled="user.disabled"
@change="handleCheckedUserListChange(user, $event)"
>{{ user.name }}</el-checkbox
>
</el-checkbox-group>
</div>
</el-col>
</el-row>
</div>
<div v-if="item.id === activeTabId && item.type === 'role-list'">
<el-row>
<el-col :span="24">
<el-checkbox-group
class="flow-checkbox-group"
v-model="checkedUserList"
>
<el-checkbox
v-for="(user, idx) in userList"
:key="idx"
:label="user.id"
:disabled="user.disabled"
@change="handleCheckedUserListChange(user, $event)"
>{{ user.name }}</el-checkbox
>
</el-checkbox-group>
</el-col>
</el-row>
</div>
<!-- 左右选择结构 -->
<!-- <div v-if="item.id === activeTabId && item.type === ''">
<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"
:name="role.name"
:label="role.name"
>
<el-checkbox-group
class="flow-checkbox-group"
v-model="checkedUserList"
>
<el-checkbox
v-for="(user, idx) in 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="checkedSearchUserList"
>
<el-checkbox
v-for="(user, idx) in searchUserList"
:key="idx"
:label="user.id"
:disabled="user.disabled"
@change="handleCheckedUserListChange(user, $event)"
>{{ user.name }}</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 setup>
import { ref, onMounted, watch, nextTick } from "vue";
import { useRoute, useRouter } from "vue-router";
import axios from "./axios";
import $ from "jquery";
import _ from "lodash";
const props = defineProps({
visible: Boolean
});
const emit = defineEmits(["close", "confirm"]);
const corpTreeRef = ref(null); // 组织结构树的ref
const userTreeRef = ref(null); // 成员选择树的ref
const dialogUserFormVisible = ref(false);
const userTags = ref([]); // 现在只维护选中的用户列表,以它为基准维护其他列表选中情况
const currentNodeKey = ref([]); // 当前展开的节点
const currentCheckedNodeKey = ref([]); // 当前选中的节点
const activeTabId = ref("tab-corp"); // TODO: 需要获取默认第一个ID
const activeTabIdx = ref(0); // 默认激活tab的index
const activeTabContent = ref("");
const userTabs = ref([
{
id: "tab-corp",
name: "组织结构",
type: "corp-tree",
data: []
},
{
id: "tab-uer",
name: "成员",
type: "user-tree",
data: []
},
{
id: "tab-role",
name: "角色",
type: "role-list",
data: []
}
]);
const tabSelectData = ref([]);
const userTabType = ref("user-tree");
const tabOffset = ref("0px");
const tabTextWidth = ref("76px"); // 文字宽度需要打开弹框时重新计算
const is_active_search = ref(false);
const search_input = ref("");
const userList = ref([]);
const checkedUserList = ref([]);
const searchUserList = ref([]); // 搜索框 选中 用户ID
const checkedSearchUserList = ref([]);
const defaultProps = ref({
children: "children",
label: "name"
});
// TAG: 接口获取数据
const getDeptList = () => {
return axios.get('/admin/?a=flow_dept_list')
}
const getRoleList = () => {
return axios.get('/admin/?a=flow_role_list')
}
const deptList = ref([]); // 部门列表
const deptUserList = ref([]); // 部门用户列表
const roleList = ref([]); // 角色列表
onMounted(async () => {
// TAG:接口获取组织结构数据
const dept_list = await getDeptList();
const role_list = await getRoleList();
if (dept_list.data.code) {
deptList.value = dept_list.data.data;
deptUserList.value = _.cloneDeep(dept_list.data.data);
}
if (role_list.data.code) {
roleList.value = role_list.data.data;
}
userTabs.value.forEach(item => {
if (item.type === 'corp-tree') {
item.data = deptList.value;
}
if (item.type === 'user-tree') {
item.data = deptUserList.value;
}
if (item.type === 'role-list') {
item.data = roleList.value;
}
});
// 根据数据获取选中的tag标签
// setTagsList(userTabs);
// TODO: 查询到的用户选中列表数据
userTags.value = [{ id: 35697, name: "西园寺" },{ id: 492081, name: "营员" }];
// //
// const role_raw_data = [
// {
// "id": 624337,
// "name": "八关斋戒"
// },
// {
// "id": 82983,
// "name": "场地管理"
// },
// {
// "id": 83245,
// "name": "场地使用"
// },
// ];
// let role_list = ref([]);
// role_raw_data.forEach(item => {
// role_list.value.push({
// id: item.id,
// label: item.name,
// checked: false,
// disabled: false
// })
// })
// const role_data = ref({
// id: "tab-2",
// label: "角色",
// type: "select",
// data: [
// {
// id: "",
// label: "",
// children: [],
// list: role_list.value
// },
// ]
// })
// TODO: 查询到的用户列表数据
// userTabs.value = [
// {
// id: "tab-0",
// label: "组织架构",
// type: "corp-tree",
// data: [
// {
// id: "corp-1",
// label: "组织结构 1",
// children: [
// {
// id: "dept-1-1",
// label: "组织结构 1-1",
// children: [],
// list: [
// {
// id: "user-1-1",
// label: "组织1-1",
// checked: false,
// 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-1",
// label: "成员",
// type: "user-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: false,
// 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: "role-list",
// data: [
// {
// id: "role-1-1",
// label: "流程发起人",
// children: [],
// list: [
// {
// id: "user-1-1",
// label: "用户1-1",
// checked: true,
// disabled: false
// },
// {
// id: "user-2-2",
// label: "用户2-2",
// checked: false,
// 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: []
// }
// ]
// }
// ];
// userTabs.value = userTabs.value.concat(role_data.value);
// 对比选中的用户的 ID,选中的 ID 同步状态到 userTabs 的数据结构上
// userTags.value.forEach(ele => {
// modifyFieldValue(userTabs.value, "id", ele.id, "checked", true);
// });
// TODO: 组织结构处理可能需要优化
// 因为第一个是组织结构树,默认展开第一个节点
if (userTabs.value[activeTabIdx.value]['type'] === 'corp-tree') {
if (userTabs.value[activeTabIdx.value]['data'].length) {
currentNodeKey.value = [userTabs.value[activeTabIdx.value]['data'][0]['id']];
// 把选中的节点注入树结构显示选中状态
nextTick(() => {
currentCheckedNodeKey.value = userTags.value.map(ele => ele.id);
});
}
}
});
watch(() => {
// TAG:监听弹框状态
if (props.visible) {
dialogUserFormVisible.value = true;
} else {
dialogUserFormVisible.value = false;
}
});
/**
* 点击Tab切换回调
*
* @param {object} tab - The tab object that was clicked.
* @param {object} event - The event object generated by the click event.
* @param {number} idx - The index of the clicked tab.
*/
const handleTabClick = (tab, event, idx) => {
// tabSelectData.value = tab.data; // tab选中数据提供给list类型使用
userList.value = []; // 清空用户列表
checkedUserList.value = []; // 清空选中用户列表
activeTabContent.value = ""; // 清空侧边栏显示
currentNodeKey.value = []; // 清空树形的默认展开
// 设置当前激活的tab
userTabType.value = tab.type;
activeTabId.value = tab.id;
activeTabIdx.value = idx;
// 子容器相对于父容器的相对x轴位移, 第一项为0
if (idx) {
tabOffset.value = $("#" + tab.id).position().left + 20 + "px";
} else {
tabOffset.value = "0px";
}
// 文字宽度
tabTextWidth.value = $("#" + tab.id).width() + "px";
//
console.warn(tab);
// 组织结构树,默认展开第一个节点, 把选中用户ID显示到数
if (tab.type === 'corp-tree') {
if (tab.data.length) {
currentNodeKey.value = [tab.data[0]['id']];
nextTick(() => {
// 把选中的节点注入树结构显示选中状态
corpTreeRef.value.setCheckedKeys(userTags.value.map(ele => ele.id), false)
})
}
}
// 成员选择树
if (tab.type === 'user-tree') {
if (tab.data.length) {
currentNodeKey.value = [tab.data[0]['id']];
}
}
// 角色选择列表
if (tab.type === 'role-list') {
userList.value = tab.data;
checkedUserList.value = userTags.value.map(ele => ele.id);
}
};
/**
* 侧边栏Tab点击回调
*
* @param {type} tab - description of parameter
* @param {type} event - description of parameter
*/
const handleTabContentClick = (tab, event) => {
tabSelectData.value.forEach(ele => {
if (ele.name === tab.props.name) {
console.warn(ele);
// 设置右侧显示数据
userList.value = ele.list;
checkedUserList.value = ele.list
.filter(ele => {
return ele.checked;
})
.map(ele => {
return ele.id;
});
}
});
};
/**
* 成员选择树 点击回调
*
* @param {object} data - The data associated with the clicked node.
* @return {void}
*/
const handleNodeClick = data => {
if (data.user) {
// 如果节点下存在 user 字段,设置为右侧显示数据列表
userList.value = data.user;
checkedUserList.value = userTags.value
.map(ele => {
return ele.id;
});
// 默认展开相应ID节点
currentNodeKey.value = [data.id];
}
};
/**
* 组织结构树形结构 选中回调
*
* @param {*} obj 传递给 data 属性的数组中该节点所对应的对象
* @param {*} status 树目前的选中状态对象,包含 checkedNodes、checkedKeys、halfCheckedNodes、halfCheckedKeys 四个属性
* @return {void}
*/
const checkNode = (obj, status) => {
// console.log(obj);
// console.log(status);
// 判断当前节点是选中还是取消选中
if (status.checkedKeys.indexOf(obj.id) > -1) { // 选中
// 新增勾选的用户
let check_nodes = status.checkedNodes.map(ele => {
return { id: ele.id, name: ele.name };
});
userTags.value = userTags.value.concat(check_nodes);
// 如果ID相同,需要数据去重
userTags.value = _.uniqBy(userTags.value, 'id');
} else {
// 移除勾选的用户
userTags.value = userTags.value.filter(ele => {
return ele.id!== obj.id;
});
}
}
/**
* 递归查找匹配字段,并修改字段的值为新值
*
* @param {object} obj - 修改对象
* @param {string} fieldName - 查找字段
* @param {any} fieldValue - 匹配值
* @param {any} targetName - 目标字段
* @param {any} newValue - 修改新值
*/
function modifyFieldValue(obj, fieldName, fieldValue, targetName, newValue) {
// 检查当前层级的字段值是否匹配目标值
if (obj[fieldName] === fieldValue) {
obj[targetName] = newValue;
}
// 遍历当前层级的子项(如果有)
for (var key in obj) {
if (typeof obj[key] === "object" && obj[key] !== null) {
modifyFieldValue(obj[key], fieldName, fieldValue, targetName, newValue);
}
}
}
/**
* 操作勾选框回调
*
* @param {type} user - description of parameter
* @param {type} checked - description of parameter
* @return {type} description of return value
*/
const handleCheckedUserListChange = (user, checked) => {
if (checked) { // 新增勾选的用户
userTags.value = userTags.value.concat({ id: user.id, name: user.name });
// 如果ID相同,需要数据去重
userTags.value = _.uniqBy(userTags.value, 'id');
} else {
// 移除勾选的用户
userTags.value = userTags.value.filter(ele => {
return ele.id!== user.id;
});
}
};
/**
* 递归获取树形结构下的所有 list 字段数据
*
* @param {Array} arr - The array to traverse.
* @return {Array} - The list items found.
*/
function getAllListItems(arr) {
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;
}
/**
* 根据 userTabs 的选中状态,更新 tag 选中列表显示
* 获取生成 list 集合的 checked 状态,生成 tags 的勾选显示
*
* @param {Array} val - userTabs
*/
const setTagsList = val => {
let userList = []; // 存储所有的list数据
val.forEach(ele => {
let data = getAllListItems(ele.data);
userList.push(data);
});
// 合并成一维数组列表
userList = [...userList.flat()];
// 如果ID相同,需要数据去重
let uniqueArray = userList.filter(
(value, index, self) => index === self.findIndex(obj => obj.id === value.id)
);
// 勾选变化后同步到选中列表
userTags.value = uniqueArray
.filter(ele => {
return ele.checked;
})
.map(ele => {
return {
id: ele.id,
name: ele.name
};
});
};
watch(
// TAG: watch userTabs.value 监听数据结构选中值变化
() => userTabs.value,
val => {
if (val) {
// 更新 tags 选中列表显示
// setTagsList(val);
}
},
{ deep: true }
);
/**
* 移除 tags 成员标签回调
*
* @param {string} tag - The tag to be closed.
* @return {undefined} No return value.
*/
const handleTagClose = tag => {
userTags.value.splice(userTags.value.indexOf(tag), 1); // 删除标签列表中的项
// 处理不同分支选中显示问题
switch (activeTabId.value) {
case 'tab-corp': // 组织结构
// 把选中的节点注入树结构显示选中状态
corpTreeRef.value.setCheckedKeys(userTags.value.map(ele => ele.id), false)
break;
case 'tab-uer': // 成员
break;
case 'tab-role': // 角色
break;
}
// // 移除数据结构中的选中值
// modifyFieldValue(userTabs.value, "id", tag.id, "checked", false);
// // ID集合
// let tagsId = userTags.value.map(ele => {
// return ele.id;
// });
// // 处理tags列表和下面选中列表同步问题
// let checkDataList = [];
// if (is_active_search.value) {
// // 激活搜索状态
// checkDataList = checkedSearchUserList.value;
// } else {
// // 激活非搜索状态
// checkDataList = checkedUserList.value;
// }
// // 获取 tags 中已删除的, 勾选列表中还勾选的值
// let result = checkDataList.filter(value => !tagsId.includes(value));
// // 如果存在不同步的值,需要在列表中删除勾选列表中的项
// if (result.length) {
// result.forEach(ele => {
// checkDataList.splice(checkDataList.indexOf(ele), 1);
// });
// }
};
/**
* 关闭用户列表表单回调
*
* @return {void} - No return value.
*/
const closeUserForm = () => {
dialogUserFormVisible.value = false;
emit("close", dialogUserFormVisible.value);
};
/**
* 确认用户列表表单回调
*
* @return {void} No return value.
*/
const confirmUserForm = () => {
dialogUserFormVisible.value = false;
emit("close", dialogUserFormVisible.value);
emit("confirm", userTags.value);
};
/**
* 激活搜索按钮操作
*
* @return {void} No return value.
*/
const activeSearchBtn = () => {
is_active_search.value = !is_active_search.value;
searchUserList.value = []; // 清空搜索列表
};
/**
* 在搜索框中同步显示tag框选中的用户
*
* @return {void}
*/
const checkSearchStatus = () => {
userTags.value.forEach(ele => {
searchUserList.value.forEach(item => {
if (ele.id === item.id) {
item.checked = true;
}
});
});
// 显示选中tags的用户
checkedSearchUserList.value = searchUserList.value
.filter(ele => ele.checked)
.map(ele => ele.id);
};
/**
* 在搜索框中同步显示tag框选中的用户
*
* @param {Array} userTags - The array of selected user tags.
* @param {Array} userList - The array of all users.
* @param {Array} checkedUserList - The array of users with selected tags.
* @return {void} No return value.
*/
const checkUserStatus = () => {
userTags.value.forEach(ele => {
userList.value.forEach(item => {
if (ele.id === item.id) {
item.checked = true;
}
});
});
// 显示选中tags的用户
checkedUserList.value = userList.value
.filter(ele => ele.checked)
.map(ele => ele.id);
};
/**
* 清空搜索回调
*
* @return {void}
*/
const onClearSearch = () => {
is_active_search.value = !is_active_search.value;
// 同步显示tag框选中的用户
checkUserStatus();
};
/**
* 搜索回调
*
* @return {void} No return value.
*/
const onSearch = () => {
// TODO: 获取后台数据
searchUserList.value = [
{
id: "user-1-1",
name: "用户1-1",
checked: false,
disabled: false
},
{
id: "user-1-2",
name: "用户1-2",
checked: false,
disabled: false
},
{
id: "user-1-3",
name: "用户1-3",
checked: false,
disabled: true
}
];
// 如果 tags 里存在的值,需要在搜索列表中勾选
checkSearchStatus();
};
watch(
// TAG: watch dialogUserFormVisible.value 监听弹框显示,修改tab文字宽度
() => dialogUserFormVisible.value,
val => {
if (val) {
nextTick(() => {
tabTextWidth.value = $("#" + activeTabId.value).width() + "px";
});
}
}
);
</script>
<style lang="scss">
.flow-tag__wrapper {
border: 1px dashed #dcdfe6;
padding: 10px;
.text-empty {
text-align: center;
color: #dcdfe6;
}
}
.flow-tabs__wrapper {
border: 1px solid #dcdfe6;
padding: 10px;
margin-top: 10px;
.search_box {
padding: 0;
position: relative;
margin: 0 0 15px;
}
.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-box {
border-left: 2px solid #e4e7ed;
width: 2px;
height: 100%;
padding-left: 10px;
}
.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>