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
import React, { useState, useEffect } from 'react';
import {
Row,
Col,
Card,
Input,
Spin,
notification,
Button,
Tooltip,
Space,
Empty,
message,
Tabs,
Tree,
} from 'antd';
import TreeComponents from '@/components/ExpendableTree';
import PageContainer from '@/components/BasePageContainer';
import {
DoubleLeftOutlined,
DoubleRightOutlined,
BarsOutlined,
UserOutlined,
DesktopOutlined,
MobileOutlined,
FolderAddTwoTone,
PlusSquareOutlined,
FormOutlined,
EditOutlined,
DeleteOutlined,
UserAddOutlined,
WindowsOutlined,
IeOutlined,
InfoCircleOutlined,
} from '@ant-design/icons';
import {
setMenuToRole,
getRoleGroupList,
getMenuByRoleWithLevel,
DragGroup,
getWebConfigTypes,
} from '@/services/RoleManage/api';
import ListCard, { checkChildrenByCondition, getId } from '@/components/CheckGroup';
// import ListCard from '@/pages/orgnazation/ListCard';
import qs from 'qs';
import classnames from 'classnames';
import styles from '@/pages/userCenter/roleManage/RoleManage.less';
import AddModal from './AddModal';
import DelModal from './DelModal';
import EditModal from './EditModal';
import EditGroup from './EditGroup';
import userStyles from '@/pages/userCenter/userManage/UserManage.less';
import iconStyles from '@/assets/font/omsfont/iconfont.css';
import SelectUser from './SelectUser/SelectUser';
import NewSelectUser from './SelectUser/NewSelectUser';
import OpePermissions from './SelectUser/OpePermissions';
const { Search } = Input;
const placeholder = '请输入功能名称';
const { TabPane } = Tabs;
const SiteManage = () => {
const [treeData, setTreeData] = useState([]);
const [searchWord, setSearchWord] = useState('');
const [roleID, setRoleID] = useState(''); // 角色ID
const [saveTreeId, setSaveTreeId] = useState(''); // 保存点击回调的roleid
const [modalVisible, setModalVisible] = useState(false); // 新增弹窗
const [flag, setFlag] = useState(1);
const [flagSearch, setFlagSearch] = useState(0);
const [itemObj, setItemObj] = useState(''); // 选择的角色item
const [delVisible, setDelVisible] = useState(false); // 删除弹窗
const [editVisible, setEditVisible] = useState(false); // 修改弹窗
const [subList, setSubList] = useState([]); // 选中的数组
const [spinLoading, setSpinLoading] = useState(false);
const [currentSelectId, setCurrentSelectId] = useState([]); // 选中的树节点
const [saveCurId, setSaveCurId] = useState([]); // 树节点ID
const [groupVisible, setGroupVisible] = useState(false); // 分组编辑弹窗
const [userVisible, setUserVisible] = useState(false); // 用户关联弹窗
const [userNewVisible, setUserNewVisible] = useState(false); // 用户关联弹窗
const [hasData, setHasData] = useState(false);
const [valueList, setValueList] = useState([]);
const [dataList, setdataList] = useState([]);
const [loading, setLoading] = useState(true);
const [btnLoading, setBtnLoading] = useState(false);
const [mulu, setMulu] = useState(true); // 展示目录
const [siteList, setSiteList] = useState([]);
const [disFlag, setDisFlag] = useState(false);
const [chileID, setChildID] = useState([]);
const [descrip, setDescrip] = useState('当前未选中角色');
const [keepTree, setKeepTree] = useState([]);
const [keyValue, setKeyValue] = useState('0');
const [keepTreeData, setKeepTreeData] = useState([]);
const [searchTreeValue, setSearchTreeValue] = useState('');
// const [childData, setChildData] = useState({visibleValue:''})
const [operation, setOperation] = useState(false);
// 点击树的回调
const handleTreeSelect = (e, treenode) => {
setSearchWord('');
if (treenode) {
const { node } = treenode;
const { roleID: id } = node;
setItemObj(node);
if (node.BuiltInRole) {
setKeyValue('0');
}
setUserNewVisible(true);
if (id) {
if (node.subSystemValue === 'view') {
setOperation(true);
} else {
setOperation(false);
}
setSaveTreeId(id);
setRoleID(id);
setFlagSearch(1);
setValueList([...valueList]);
} else {
if (node.visibleValue === 'view') {
setOperation(true);
} else {
setOperation(false);
}
// setRoleID(saveTreeId);
setRoleID('');
setDescrip('当前未选中角色');
setFlagSearch(0);
}
}
if (e[0]) {
setCurrentSelectId(e);
setSaveCurId(e);
} else {
setCurrentSelectId(saveCurId);
}
};
useEffect(() => {
getRoleGroup();
}, []);
// 获取角色菜单树
const getRoleGroup = () => {
setSpinLoading(true);
getRoleGroupList({ userID: '1' }).then(res => {
setSpinLoading(false);
if (res.code === 0) {
const { roleList } = res.data;
console.log('roleList', roleList)
let list = [...roleList];
list.map((i, j) => {
if (i.visibleTitle.indexOf('手持') !== -1 && i.type !== 'mobile') {
list.splice(j, 1);
list.push(i);
}
});
setKeepTreeData([...list]);
console.log('list', list, JSON.parse(JSON.stringify(list)))
let arr = transTree(JSON.parse(JSON.stringify(list)), '');
console.log(333, arr)
setTreeData(arr);
let aa = [];
arr.forEach(i => {
aa.push(i.visibleValue);
});
console.log(1, arr, aa)
setKeepTree(aa);
}
});
};
useEffect(() => {
if (!roleID) return;
setLoading(true);
const defaultConfig = {
optionsList: [],
title: '默认组',
id: '',
};
getMenuByRoleWithLevel({
roleID: itemObj.roleID,
subSystemValue: itemObj.subSystemValue,
subSystemName: itemObj.subSystemValue,
})
.then(res => {
const list = [];
// eslint-disable-next-line no-unused-expressions
res.code === 0 &&
res.data.root.forEach(item => {
list.push({ ...defaultConfig, ...item });
});
setdataList(list);
setValueList(
list
.map(l =>
checkChildrenByCondition(
l,
it => (it.isChecked ? [getId(it)] : []),
true,
'map',
).flat(Infinity),
)
.flat(Infinity)
.filter(Boolean),
);
setLoading(false);
})
.catch(err => {
setLoading(false);
});
}, [roleID]);
const handleAdd = e => {
setModalVisible(true);
};
// 角色删除
const handleDel = e => {
setDelVisible(true);
};
// 编辑角色
const handleEdit = e => {
setEditVisible(true);
};
// 分组编辑
const groupEdit = () => {
setGroupVisible(true);
};
// 树形数据转换;
const transTree = (val, search) => {
let arr = val;
// 提取child里面的数组
let arr2 = arr.filter(item => {
if (item.child && item.child.length > 0) {
item.roleList = [...item.child, ...item.roleList]
}
if (item.type === 'mobile') {
item.icon = <MobileOutlined />;
} else if (item.visibleValue == 'CS') {
item.icon = <WindowsOutlined />;
} else {
if (item.visibleTitle.indexOf('手持') !== -1) {
item.icon = <MobileOutlined />;
} else {
item.icon = <DesktopOutlined />;
}
}
return (
item.visibleTitle !== '其它角色' &&
item.visibleTitle !== '运维管理' &&
item.visibleTitle !== '小程序'
);
});
let arr3 = arr2.map(item => {
if (item.visibleTitle === '小程序') {
item.visibleTitle = '移动应用';
}
item.title = item.visibleTitle || '';
item.key = item.visibleValue || '';
if (item.roleList && item.roleList.length > 0) {
item.roleList.map((itemRole, index) => {
if (itemRole.roleList) {
itemRole.title = itemRole.visibleTitle || '';
itemRole.key = itemRole.visibleTitle + itemRole.visibleValue || '';
itemRole.groupflag = itemRole.visibleTitle;
itemRole.icon = <BarsOutlined />;
itemRole.roleList.map(i => {
i.title = i.roleName;
const indexsearch = i.title.indexOf(search);
const beforeStr = i.title.substring(0, indexsearch);
const afterStr = i.title.slice(indexsearch + search.length);
i.title = (
<div className={styles.title}>
{i.title.includes(search) && search != '' ? (
<div className={styles.titleTop}>
{beforeStr}
<span className={styles.titleSearch}>{search}</span>
{afterStr}
</div>
) : (
<div className={styles.titleTop}>
{i.title}
{i.description && (
<Tooltip title={i.description}>
<InfoCircleOutlined
style={{
color: 'rgb(24, 144, 255)',
marginLeft: '5px',
marginTop: '3px',
}}
/>
</Tooltip>
)}
</div>
)}
<div className={styles.tip}>
{i.roleID && (
<>
<Tooltip title="编辑角色" className={styles.fs}>
<FormOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => editorUser(e, i)}
/>
</Tooltip>
{!i.BuiltInRole && (
<Tooltip title="删除角色" className={styles.fs}>
<DeleteOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => deletesUser(e, i)}
/>
</Tooltip>
)}
{/* <Tooltip title="关联用户" className={styles.fs}>
<UserAddOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => relevancyUser(e, i)}
/>
</Tooltip> */}
</>
)}
{!i.roleID && (
<Tooltip title="新增角色" className={styles.fs}>
<PlusSquareOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => addsUser(e, i)}
/>
</Tooltip>
)}
{i.groupflag && (
<Tooltip title="编辑分组" className={styles.fs}>
<EditOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => editorGroup(e, i)}
/>
</Tooltip>
)}
</div>
</div>
);
i.key = i.roleID;
i.subSystemValue = item.visibleValue;
i.group = itemRole.visibleTitle;
if (i.BuiltInRole === true) {
i.icon = <UserOutlined style={{ color: '#dfb14b' }} />;
} else {
i.icon = <UserOutlined />;
}
if (roleID && roleID === i.roleID) {
setItemObj(i);
// setCurrentSelectId(roleID);
}
});
itemRole.children = itemRole.roleList;
} else {
itemRole.title = itemRole.roleName;
itemRole.key = itemRole.roleID;
itemRole.subSystemValue = item.visibleValue;
if (itemRole.BuiltInRole === true) {
itemRole.icon = <UserOutlined style={{ color: '#dfb14b' }} />;
} else {
itemRole.icon = <UserOutlined />;
}
if (roleID && roleID === itemRole.roleID) {
setItemObj(itemRole);
// setCurrentSelectId(roleID);
}
}
const indexsearch = itemRole.title.indexOf(search);
const beforeStr = itemRole.title.substring(0, indexsearch);
const afterStr = itemRole.title.slice(indexsearch + search.length);
itemRole.title = (
<div className={styles.title}>
{itemRole.title.includes(search) && search != '' ? (
<div className={styles.titleTop}>
{beforeStr}
<span className={styles.titleSearch}>{search}</span>
{afterStr}
</div>
) : (
<div className={styles.titleTop}>
{itemRole.title}
{itemRole.description && (
<Tooltip title={itemRole.description}>
<InfoCircleOutlined
style={{ color: 'rgb(24, 144, 255)', marginLeft: '5px', marginTop: '3px' }}
/>
</Tooltip>
)}
</div>
)}
<div className={styles.tip}>
{itemRole.roleID && (
<>
<Tooltip title="编辑角色" className={styles.fs}>
<FormOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => editorUser(e, itemRole)}
/>
</Tooltip>
{!itemRole.BuiltInRole && (
<Tooltip title="删除角色" className={styles.fs}>
<DeleteOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => deletesUser(e, itemRole)}
/>
</Tooltip>
)}
{/* <Tooltip title="关联用户" className={styles.fs}>
<UserAddOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => relevancyUser(e, itemRole)}
/>
</Tooltip> */}
</>
)}
{!itemRole.roleID && (
<Tooltip title="新增角色" className={styles.fs}>
<PlusSquareOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => addsUser(e, itemRole)}
/>
</Tooltip>
)}
{itemRole.groupflag && (
<Tooltip title="编辑分组" className={styles.fs}>
<EditOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => editorGroup(e, itemRole)}
/>
</Tooltip>
)}
</div>
</div>
);
return itemRole;
});
}
item.children = item.roleList;
item.title = (
<div className={styles.title}>
<div className={styles.titleTop}>{item.title}</div>
<div className={styles.tip}>
{item.roleID && (
<>
<Tooltip title="编辑角色" className={styles.fs}>
<FormOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => editorUser(e, item)}
/>
</Tooltip>
{!item.BuiltInRole && (
<Tooltip title="删除角色" className={styles.fs}>
<DeleteOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => deletesUser(e, item)}
/>
</Tooltip>
)}
{/* <Tooltip title="关联用户" className={styles.fs}>
<UserAddOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => relevancyUser(e, item)}
/>
</Tooltip> */}
</>
)}
{!item.roleID && (
<Tooltip title="新增角色" className={styles.fs}>
<PlusSquareOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => addsUser(e, item)}
/>
</Tooltip>
)}
{item.groupflag && (
<Tooltip title="编辑分组" className={styles.fs}>
<EditOutlined
style={{ fontSize: '16px', color: '#1890FF', marginTop: '5px' }}
onClick={e => editorGroup(e, item)}
/>
</Tooltip>
)}
</div>
</div>
);
return item;
});
return arr3;
};
// 编辑角色
const editorUser = (e, record) => {
e.stopPropagation();
setItemObj(record);
setEditVisible(true);
};
// 删除角色
const deletesUser = (e, record) => {
e.stopPropagation();
setItemObj(record);
setDelVisible(true);
};
// 关联用户
const relevancyUser = (e, record) => {
e.stopPropagation();
setItemObj(record);
setUserVisible(true);
};
// 编辑分组
const editorGroup = (e, record) => {
e.stopPropagation();
setItemObj(record);
setGroupVisible(true);
};
// 新增角色
const addsUser = (e, record) => {
e.stopPropagation();
setItemObj(record);
setModalVisible(true);
};
const handleChange = e => {
const { value } = e.target;
setSearchWord(value);
};
// 确认回调
const confirmModal = e => {
setModalVisible(false);
// setRoleID(`${e}`);
// setCurrentSelectId([`${e}`]);
// setFlag(flag + 1);
getRoleGroup();
setItemObj('');
};
// 删除弹窗回调
const delModal = () => {
setDelVisible(false);
// setFlag(flag + 1);
getRoleGroup();
setRoleID('');
setItemObj('');
};
// 编辑弹窗回调
const editModal = prop => {
getRoleGroup();
let aa = itemObj;
aa.BuiltInRole = prop;
setItemObj(aa);
if (itemObj.roleID === currentSelectId[0]) {
if (prop == true) {
setRoleID(currentSelectId);
setFlagSearch(1);
} else {
setRoleID(currentSelectId);
setFlagSearch(1);
}
}
// setItemObj('');
};
// 分组编辑回调
const groupModal = () => {
setGroupVisible(false);
// setFlag(flag + 1);
getRoleGroup();
setItemObj('');
handleTreeSelect(saveCurId);
};
const userModal = () => {
setUserVisible(false);
// setFlag(flag + 1);
getRoleGroup();
setItemObj('');
handleTreeSelect(saveCurId);
};
const userNewModal = () => {
setUserNewVisible(false);
// setFlag(flag + 1);
// getRoleGroup();
// setItemObj('');
handleTreeSelect(saveCurId);
};
const valueCallback = valueObj => {
setSubList(valueObj);
};
const handleHide = () => {
setMulu(!mulu);
};
const handleCommit = results => {
setBtnLoading(true);
setMenuToRole({
roleID: Number(roleID),
menuIdList: String(results.flat()),
})
.then(res => {
setBtnLoading(false);
if (res.code === 0) {
setValueList([...results.flat()]);
notification.success({
message: '提示',
duration: 3,
description: '设置成功',
});
} else {
notification.error({
message: '提示',
duration: 15,
description: res.msg,
});
}
})
.catch(err => {
setBtnLoading(false);
});
};
const handleUserAttach = () => {
setUserVisible(true);
};
// 返回拖拽完毕后的信息
const loop = (data, key, callback) => {
for (let i = 0; i < data.length; i++) {
if (data[i].key === key) {
return callback(data[i], i, data);
}
if (data[i].children) {
loop(data[i].children, key, callback);
}
}
};
// 树的拖拽
const handleDrop = infos => {
const dropKey = infos.node.key;
const dragKey = infos.dragNode.key;
const dropPos = infos.node.pos.split('-');
const dropPosition = infos.dropPosition - Number(dropPos[dropPos.length - 1]);
const datas = JSON.parse(JSON.stringify(treeData));
// 找到拖拽的元素
let dragObj;
let id = '';
let dragList = [];
let params = {}
// 保存节点信息并删除节点
loop(datas, dragKey, (item, index, arr) => {
arr.splice(index, 1);
dragObj = item;
});
// 将节点插入到正确的位置
if (!infos.dropToGap) {
// Drop on the content
loop(datas, dropKey, (item) => {
item.children = item.children || [];
// where to insert 示例添加到头部,可以是随意位置
item.children.unshift(dragObj);
});
} else if (
(infos.node.props.children || []).length > 0 &&
// Has children
infos.node.props.expanded &&
// Is expanded
dropPosition === 1 // On the bottom gap
) {
loop(datas, dropKey, (item) => {
item.children = item.children || [];
item.children.unshift(dragObj);
});
} else {
let ar = [];
let i;
loop(datas, dropKey, (_item, index, arr) => {
ar = arr;
i = index;
});
if (dropPosition === -1) {
ar.splice(i, 0, dragObj);
} else {
ar.splice(i + 1, 0, dragObj);
}
}
//拖拽最上层
if (datas.includes(s => s.key === dragKey)) {
return
}
//拖拽的是分组
if (dragObj.groupflag) {
datas.forEach(v => {
if (v?.children?.length) {
if (v.children.some(s => s.key === dragKey)) {
dragList = v.children.filter(k => k.visibleValue).map(k => k.visibleTitle)
}
}
})
params = {
dragGroupType: 4,
groupList: dragList
}
} else {
//如果拖拽的是角色,有可能是角色互相拖拽有可能是角色拖入分组
datas.forEach(v => {
if (v?.children?.length) {
v.children.forEach(k => {
if (k.key === dragKey) {
dragList = v.children.filter(s => s.roleID).map(s => s.roleID)
}
if (k.children?.length) {
k.children.forEach(j => {
if (j.key === dragKey) {
id = k.visibleTitle
dragList = k.children.map(s => s.roleID)
}
})
}
})
}
})
params = {
MiniAppGroupName: id,
dragGroupType: 1,
groupId: dragKey,
groupList: dragList
}
}
console.log('datas', datas, params)
if (dragList.length) {
DragGroup(params).then(res => {
if (res.code === 0) {
getRoleGroup();
if (infos.dragNode.roleID == itemObj.roleID) {
if (id == '系统分组') {
setRoleID('');
setDescrip('系统分组下的角色不可配置菜单权限');
setFlagSearch(0);
} else {
setRoleID(infos.dragNode.roleID);
setFlagSearch(1);
}
}
}
});
}
};
const handleParChange = key => {
setKeyValue(key);
const { roleID: id } = itemObj;
if (id) {
setRoleID(id);
setFlagSearch(1);
} else {
setRoleID('');
setDescrip('当前未选中角色');
setFlagSearch(0);
}
};
const onSearch = value => {
setSearchTreeValue(value);
if (value !== '') {
let data = getNewData(JSON.parse(JSON.stringify(keepTreeData)), value);
let lastdata = JSON.parse(JSON.stringify(data));
lastdata.map(i => {
if (i.child.length > 0) {
i.child = i.child.filter(ele => ele.roleList.length > 0);
}
});
let last = lastdata.filter(ele => ele.roleList.length > 0 || ele.child.length > 0);
let arr = transTree(JSON.parse(JSON.stringify(last)), value);
setTreeData(arr);
} else {
let arr = transTree(JSON.parse(JSON.stringify(keepTreeData)), '');
setTreeData(arr);
}
};
// 获取搜索tree数据
const getNewData = (treedata, value) => {
treedata.map(i => {
if (i.roleList.length > 0) {
i.roleList = i.roleList.filter(ele => ele.roleName.includes(value));
}
if (i.child.length > 0) {
i.child.map(j => {
j.roleList = j.roleList.filter(ele => ele.roleName.includes(value));
});
}
});
return treedata;
};
console.log('treeData', treeData)
return (
<PageContainer>
<div
className={classnames({
[styles.content]: true,
})}
>
<Spin
tip="loading...."
spinning={spinLoading}
// style={{ margin: '20px auto ', display: 'block' }}
>
<Card
className={classnames({
[styles.cardBox]: true,
[styles.hideBox]: !mulu,
})}
>
<div style={{ marginLeft: '6px' }}>
<span
style={{
fontSize: '15px ',
fontWeight: 'bold',
}}
>
选择角色
</span>
</div>
<hr style={{ width: '95%', color: '#eeecec' }} />
<Search
style={{
marginBottom: 8,
width: '95%',
marginLeft: '7px',
}}
placeholder="快速搜索角色"
onSearch={onSearch}
/>
{searchTreeValue !== '' ? (
<>
{treeData && treeData.length > 0 && (
<div style={{ height: 'calc(100% - 60px)', overflowY: 'scroll' }}>
<Tree
showIcon
onSelect={handleTreeSelect}
defaultExpandAll
treeData={treeData}
selectedKeys={currentSelectId}
blockNode
draggable
onDrop={handleDrop}
keepTree={keepTree}
// setExpendKey={expendKey}
/>
</div>
)}
</>
) : (
<>
{treeData && treeData.length > 0 && (
<div style={{ height: 'calc(100% - 60px)', overflowY: 'scroll' }}>
<TreeComponents
showIcon
onSelect={handleTreeSelect}
autoExpandParent
treeData={treeData}
selectedKeys={currentSelectId}
blockNode
draggable
onDrop={handleDrop}
keepTree={keepTree}
// setExpendKey={expendKey}
/>
</div>
)}
</>
)}
<AddModal
visible={modalVisible}
onCancel={() => setModalVisible(false)}
itemObj={itemObj}
confirmModal={confirmModal}
siteList={siteList}
/>
<DelModal
visible={delVisible}
itemObj={itemObj}
onCancel={() => setDelVisible(false)}
confirmModal={delModal}
/>
<EditModal
visible={editVisible}
itemObj={itemObj}
onCancel={() => setEditVisible(false)}
confirmModal={editModal}
/>
<EditGroup
visible={groupVisible}
itemObj={itemObj}
onCancel={() => setGroupVisible(false)}
confirmModal={groupModal}
/>
{/* <UserModal
visible={userVisible}
itemObj={itemObj}
onCancel={() => setUserVisible(false)}
confirmModal={userModal}
/> */}
<SelectUser
visible={userVisible}
itemObj={itemObj}
onCancel={() => setUserVisible(false)}
confirmModal={userModal}
/>
<div className={styles.switcher}>
{mulu && (
<Tooltip title="隐藏角色栏" className={styles.hide}>
<DoubleLeftOutlined onClick={() => handleHide()} style={{ marginLeft: '-5px' }} />
</Tooltip>
)}
{!mulu && (
<Tooltip title="显示角色栏" className={styles.hide}>
<DoubleRightOutlined onClick={() => handleHide()} />
</Tooltip>
)}
</div>
</Card>
</Spin>
<div
className={classnames({
[styles.boxR]: true,
[styles.boxH]: mulu,
})}
>
<Card>
<Tabs style={{ marginTop: '-14px' }} activeKey={keyValue} onChange={handleParChange}>
<TabPane tab="关联用户" key="0">
{roleID ? (
<div className={styles.cardBoxRNew}>
<NewSelectUser
visible={userNewVisible}
itemObj={itemObj}
onCancel={() => setUserNewVisible(false)}
confirmModal={userNewModal}
/>
</div>
) : (
<div className={styles.cardBoxH}>
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={descrip} />
</div>
)}
</TabPane>
{!itemObj.BuiltInRole && (
<TabPane tab="菜单权限" key="1">
{flagSearch == 1 ? (
<Search
style={{ width: 260 }}
allowClear
value={searchWord}
placeholder={placeholder}
// onSearch={handleSearch}
onChange={handleChange}
enterButton
/>
) : (
<span />
)}
{roleID ? (
<div className={styles.cardBoxR}>
<ListCard
roleID={roleID}
loading={loading}
checkList={valueList}
dataList={dataList}
searchWord={searchWord}
onCommit={handleCommit}
btnLoading={btnLoading}
hasData={hasData}
/>
</div>
) : (
<div className={styles.cardBoxH}>
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={descrip} />
</div>
)}
</TabPane>
)}
{operation && (
<TabPane tab="操作权限" key="2">
{roleID ? (
<div className={styles.cardBoxRNew}>
<OpePermissions
visible={userNewVisible}
itemObj={itemObj}
onCancel={() => setUserNewVisible(false)}
confirmModal={userNewModal}
roleID={roleID}
/>
</div>
) : (
<div className={styles.cardBoxH}>
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={descrip} />
</div>
)}
</TabPane>
)}
{/* <TabPane tab="菜单权限优化" key="2">
{roleID ? (
<div className={styles.cardBoxR} />
) : (
<div className={styles.cardBoxH}>
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={descrip} />
</div>
)}
</TabPane> */}
</Tabs>
</Card>
</div>
</div>
</PageContainer>
);
};
export default SiteManage;