yh-pub 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.MD +19 -19
  2. package/layout/admin/adminIndex.vue +104 -104
  3. package/layout/admin/api/loginApi.js +24 -24
  4. package/layout/admin/api/routers.js +93 -93
  5. package/layout/admin/api/tenantApi.js +123 -123
  6. package/layout/admin/home/homeIndex.vue +25 -25
  7. package/layout/admin/login/login.vue +161 -161
  8. package/layout/admin/menu/MenuIndex.vue +648 -648
  9. package/layout/admin/menu/icon.vue +108 -108
  10. package/layout/admin/menu/iconList.js +934 -934
  11. package/layout/admin/saTenant/saTenant.vue +173 -173
  12. package/layout/admin/saTenant/saTenantForm.js +80 -80
  13. package/layout/admin/saTenant/saTenantForm.vue +61 -61
  14. package/layout/admin/saTenant/saTenantRoleManage.js +417 -417
  15. package/layout/admin/saTenant/saTenantRoleManage.vue +99 -99
  16. package/layout/admin/user/saUser.less +6 -6
  17. package/layout/admin/user/saUser.vue +72 -72
  18. package/layout/main/components/console/console.vue +205 -205
  19. package/layout/main/components/error-store/error-store.vue +72 -72
  20. package/layout/main/components/error-store/index.js +2 -2
  21. package/layout/main/components/fullscreen/fullscreen.vue +57 -57
  22. package/layout/main/components/fullscreen/index.js +2 -2
  23. package/layout/main/components/language/language.vue +71 -71
  24. package/layout/main/components/side-menu/side-menu.less +73 -73
  25. package/layout/main/components/side-menu/side-menu.vue +75 -75
  26. package/layout/main/components/tags-nav/tags-nav.less +44 -44
  27. package/layout/main/components/tags-nav/tags-nav.vue +144 -144
  28. package/layout/main/components/user/user.less +12 -12
  29. package/layout/main/components/user/user.vue +185 -185
  30. package/layout/main/home/home.vue +480 -480
  31. package/layout/main/home/index.js +2 -2
  32. package/layout/main/home/toDoList.vue +32 -32
  33. package/layout/main/login/login.less +93 -93
  34. package/layout/main/login/login.vue +151 -151
  35. package/layout/main/main.less +81 -81
  36. package/layout/main/main.vue +254 -202
  37. package/layout/main/system/dict.vue +64 -64
  38. package/layout/main/system/orgManage.vue +473 -473
  39. package/layout/main/system/roleManage.js +807 -755
  40. package/layout/main/system/roleManage.vue +424 -399
  41. package/package.json +11 -11
  42. package/view/basic/error-logger.vue +74 -74
  43. package/view/basic/error-page/401.vue +22 -22
  44. package/view/basic/error-page/404.vue +22 -22
  45. package/view/basic/error-page/500.vue +22 -22
  46. package/view/basic/error-page/back-btn-group.vue +48 -48
  47. package/view/basic/error-page/error-content.vue +28 -28
  48. package/view/basic/error-page/error.less +46 -46
  49. package/view/config/component/confFormItem.vue +49 -49
  50. package/view/config/config.scss +45 -45
  51. package/view/config/configIndex.vue +150 -150
  52. package/view/config/subPage/router-config.vue +4 -4
  53. package/view/config/subPage/sys-config.vue +249 -249
  54. package/view/window/IframeFReportView.vue +27 -27
  55. package/view/window/windowIndex.vue +22 -22
@@ -1,755 +1,807 @@
1
- import dict from "yh-pub/layout/main/system/dict.vue";
2
- import { deepClone } from "@/libs/util";
3
-
4
- export default {
5
- name: "role-manage",
6
- components: {
7
- dict,
8
- },
9
- data() {
10
- return {
11
- maxHeight: 510,
12
- openTip: false,
13
- loading: true,
14
- treeLoading: true,
15
- submitPermLoading: false,
16
- submitDepLoading: false,
17
- searchKey: "",
18
- modalType: 0,
19
- roleModalVisible: false,
20
- roleOrgData: {},
21
- permModalVisible: false,
22
- orgModalVisible: false,
23
- orgData: [],
24
- modalTitle: "",
25
- searchForm: {
26
- // 搜索框初始化对象
27
- pageNumber: 1, // 当前页数
28
- pageSize: 10, // 页面大小
29
- sort: "createTime", // 默认排序字段
30
- order: "desc", // 默认排序方式
31
- key: "",
32
- },
33
- roleForm: {
34
- ad_org_id: "",
35
- name: "",
36
- isAdmin: "",
37
- description: "",
38
- ad_role_id: "",
39
- },
40
- roleFormValidate: {
41
- ad_org_id: [{ required: true, message: "组织机构不能为空", trigger: "change" }],
42
- name: [{ required: true, message: "角色名称不能为空", trigger: "change" }],
43
- },
44
- submitLoading: false,
45
- selectList: [],
46
- columns: [
47
- {
48
- title: "所属机构",
49
- dataIndex: "org_name",
50
- width: 150,
51
- sortable: true,
52
- },
53
- {
54
- title: "角色名称",
55
- dataIndex: "name",
56
- width: 300,
57
- sortable: true,
58
- },
59
- {
60
- title: "备注",
61
- dataIndex: "description",
62
- minWidth: 200,
63
- sortable: true,
64
- },
65
- {
66
- title: "操作",
67
- dataIndex: "action",
68
- fixed: "right",
69
- width: 280,
70
- scopedSlots: { customRender: "action", title: "操作" },
71
- },
72
- ],
73
- data: [],
74
- listLoading: false,
75
- pagination: { currentPage: 1, pageSize: 15, total: 0 },
76
- permData: [],
77
- editRolePermId: "",
78
- selectAllFlag: false,
79
- dataType: 0,
80
- indeterminate: false,
81
- checkAll: false,
82
- checkAllGroup: [],
83
- curWindowBtnList: [],
84
- saveWinBtnList: [],
85
- roleSavedBtnPermMap: {}, // 角色已授予的按钮权限
86
- curSelectedMenuId: "", // 当前选中目录ID
87
- selectedKeys: [],
88
- selectedNodes: [],
89
- halfSelectedNodes: [],
90
- deptCheckedKeys: [],
91
- timer: null,
92
- };
93
- },
94
- methods: {
95
- init() {
96
- this.getDataList();
97
- },
98
- parseOrgTreeData(curLevelData, curLevel, roleOrgData) {
99
- let curVm = this;
100
- let newLevelData = curLevelData;
101
- newLevelData.key = curLevelData.adOrgId;
102
- newLevelData.title = curLevelData.name;
103
- if (roleOrgData[curLevelData.adOrgId]) {
104
- if (roleOrgData[curLevelData.adOrgId].isOrgAdmin === "Y") {
105
- this.deptCheckedKeys.push(curLevelData.adOrgId);
106
- }
107
- }
108
- newLevelData["level"] = curLevel;
109
- if (curLevelData["_childs"] && curLevelData["_childs"].length > 0) {
110
- curLevelData["_childs"].forEach(function (sonTreeData) {
111
- if (!newLevelData.children) {
112
- newLevelData.children = [];
113
- }
114
- newLevelData.children.push(curVm.parseOrgTreeData(sonTreeData, curLevel + 1, roleOrgData));
115
- });
116
- }
117
- return newLevelData;
118
- },
119
- async loadRoleOrg() {
120
- let roleOrgData = {};
121
- // 请求系统数据
122
- this.axios
123
- .post(
124
- "/roleController/getRoleOrgAccess",
125
- this.$qs.stringify({
126
- roleId: this.editRolePermId,
127
- })
128
- )
129
- .then((response) => {
130
- if (response.data.result) {
131
- if (response.data.roleOrgAccess) {
132
- response.data.roleOrgAccess.forEach(function (sd) {
133
- roleOrgData[sd.orgId] = sd;
134
- });
135
- }
136
- }
137
- });
138
- return roleOrgData;
139
- },
140
- async editOrg(v) {
141
- this.editRolePermId = v.ad_role_id;
142
- this.modalTitle = "分配 " + v.name + " 的组织机构权限";
143
- let roleOrgData = await this.loadRoleOrg();
144
- this.roleOrgData = roleOrgData;
145
- // 请求系统数据
146
- this.axios.post("/orgController/getOrgData", this.$qs.stringify({})).then((response) => {
147
- if (response.data.result) {
148
- let newTreeData = [];
149
- this.deptCheckedKeys = [];
150
- response.data.orgList.forEach((e) => {
151
- newTreeData.push(this.parseOrgTreeData(e, 0, roleOrgData));
152
- });
153
- this.orgData = newTreeData;
154
- this.$nextTick(() => {
155
- this.$refs.depTree.setCheckedKeys(this.deptCheckedKeys);
156
- });
157
- }
158
- });
159
- this.orgModalVisible = true;
160
- },
161
- checkOrgTree() {
162
- if (this.timer) {
163
- clearTimeout(this.timer);
164
- }
165
- this.timer = setTimeout(() => {
166
- this.deptCheckedKeys = this.$refs.depTree.getCheckedKeys();
167
- }, 300);
168
- },
169
- submitRoleOrg() {
170
- let selectedNodes = this.$refs.depTree.getCheckedKeys() || [];
171
- let curVm = this;
172
- let subRoleOrgData = [];
173
- // 判断已提交角色机构数据
174
- selectedNodes.forEach(function (e) {
175
- subRoleOrgData.push({ ad_org_id: e, is_org_admin: "Y" });
176
- });
177
- this.axios
178
- .post(
179
- "/roleController/saveRoleOrgAccess",
180
- this.$qs.stringify({
181
- roleId: curVm.editRolePermId,
182
- subJsonData: JSON.stringify(subRoleOrgData),
183
- })
184
- )
185
- .then((response) => {
186
- if (response.data.result) {
187
- curVm.$message.success(response.data.msg);
188
- } else {
189
- curVm.$message.error(response.data.msg);
190
- }
191
- });
192
- this.orgModalVisible = false;
193
- },
194
- renderContent(h, { root, node, data }) {
195
- let icon = "";
196
- if (data.level === 0) {
197
- icon = "ios-navigate";
198
- } else if (data.level === 1) {
199
- icon = "md-list-box";
200
- } else if (data.level === 2) {
201
- icon = "md-list";
202
- } else if (data.level === 3) {
203
- icon = "md-radio-button-on";
204
- } else {
205
- icon = "md-radio-button-off";
206
- }
207
- return h(
208
- "span",
209
- {
210
- style: {
211
- display: "inline-block",
212
- cursor: "pointer",
213
- },
214
- on: {
215
- click: () => {
216
- data.checked = !data.checked;
217
- },
218
- },
219
- },
220
- [
221
- h("span", [
222
- h("Icon", {
223
- props: {
224
- type: icon,
225
- size: "16",
226
- },
227
- style: {
228
- "margin-right": "8px",
229
- "margin-bottom": "3px",
230
- },
231
- }),
232
- h("span", data.title),
233
- ]),
234
- ]
235
- );
236
- },
237
- checkedMenuTree() {
238
- if (this.timer) {
239
- clearTimeout(this.timer);
240
- }
241
- this.timer = setTimeout(() => {
242
- this.selectedNodes = this.$refs.tree.getCheckedKeys(true);
243
- this.halfSelectedNodes = this.$refs.tree.getHalfCheckedKeys(true);
244
- }, 300);
245
- },
246
- selectTree(data, node) {
247
- if (data) {
248
- this.curSelectedMenuId = data.sysWindowId;
249
- // 加载目录树
250
- this.axios
251
- .post("/rolePermissionsSetting/getMenuWindowButton", { windowId: this.curSelectedMenuId })
252
- .then((response) => {
253
- let { result, data } = response.data;
254
- if (result && data) {
255
- let roleBtnData = [];
256
- let tempQyBtnData = [];
257
- data.forEach((tData) => {
258
- if (tData.TYPE === "QY") {
259
- roleBtnData.push(tData);
260
- tempQyBtnData[tData.ID] = [];
261
- } else {
262
- if (tempQyBtnData[tData.PARENT_ID]) {
263
- tempQyBtnData[tData.PARENT_ID].push(tData);
264
- }
265
- }
266
- });
267
- roleBtnData.forEach((item) => {
268
- item["childs"] = tempQyBtnData[item.ID];
269
- // e['checkAll'] = false
270
- let checkChilds = this.roleSavedBtnPermMap[this.curSelectedMenuId] || [];
271
- let tcount = 0;
272
- tempQyBtnData[item.ID].forEach((es) => {
273
- if (checkChilds.includes(es.ID)) {
274
- tcount++;
275
- }
276
- });
277
- if (tcount === tempQyBtnData[item.ID].length) {
278
- item["checkAll"] = true;
279
- item["indeterminate"] = false;
280
- } else if (tcount > 0) {
281
- item["checkAll"] = false;
282
- item["indeterminate"] = true;
283
- } else {
284
- item["checkAll"] = false;
285
- item["indeterminate"] = false;
286
- }
287
- item["checkChilds"] = checkChilds;
288
- });
289
- this.curWindowBtnList = roleBtnData;
290
- // 加载角色已授权的按钮
291
- this.saveWinBtnList = this.roleSavedBtnPermMap[this.curSelectedMenuId];
292
- }
293
- });
294
- }
295
- },
296
- resetBtnPerData() {
297
- this.roleSavedBtnPermMap = {};
298
- this.curWindowBtnList = [];
299
- this.saveWinBtnList = [];
300
- },
301
- doWinBtnData(doType, btnId) {
302
- if (!this.saveWinBtnList) {
303
- this.saveWinBtnList = [];
304
- }
305
- if (doType === "add") {
306
- if (this.saveWinBtnList.length !== 0) {
307
- for (let i = 0; i < this.saveWinBtnList.length; i++) {
308
- if (this.saveWinBtnList[i] === btnId) {
309
- return;
310
- }
311
- }
312
- }
313
- this.saveWinBtnList.push(btnId);
314
- } else {
315
- for (let i = 0; i < this.saveWinBtnList.length; i++) {
316
- if (this.saveWinBtnList[i] === btnId) {
317
- this.saveWinBtnList.splice(i, 1);
318
- return;
319
- }
320
- }
321
- }
322
- },
323
- handleCheckAll(item, key) {
324
- let checkChilds = [];
325
- if (!item.checkAll) {
326
- // 已经全选取消全选状态
327
- item.checkAll = false;
328
- item.indeterminate = false;
329
- item.checkChilds = checkChilds;
330
- } else {
331
- // 不是全选状态,获取所有ids,并设定全选状态相关参数
332
- checkChilds = item.childs.map((item) => item.ID);
333
- item.checkAll = true;
334
- item.indeterminate = false;
335
- item.checkChilds = checkChilds;
336
- }
337
-
338
- // 状态设置完成,将数据赋值到 响应对象上去
339
- this.updateBtnsToList();
340
- this.curWindowBtnList[key] = item;
341
- },
342
- checkAllGroupChange(event, key) {
343
- let list = deepClone({}, this.curWindowBtnList);
344
- let currentItem = list[key];
345
- if (event.length > 0) {
346
- // 判断是否存在值
347
- let containFlag = 0; // 0 不包含 1 部分包括 2 全包括
348
- let okCount = 0; // 统计包括次数
349
- for (var i = 0; i < currentItem.childs.length; i++) {
350
- if (event.includes(currentItem.childs[i].ID)) {
351
- okCount++;
352
- }
353
- }
354
- if (okCount === currentItem.childs.length) {
355
- containFlag = 2;
356
- } else {
357
- containFlag = 1;
358
- }
359
- // 判断是否选中
360
- if (containFlag === 1) {
361
- currentItem.checkAll = false;
362
- if (okCount === 0) {
363
- currentItem.indeterminate = false;
364
- } else {
365
- currentItem.indeterminate = true;
366
- }
367
- } else if (containFlag === 2) {
368
- currentItem.checkAll = true;
369
- currentItem.indeterminate = false;
370
- }
371
- } else {
372
- currentItem.checkAll = false;
373
- currentItem.indeterminate = false;
374
- }
375
- currentItem.checkChilds = event;
376
- this.curWindowBtnList[key] = currentItem;
377
- this.updateBtnsToList();
378
- },
379
- updateBtnsToList() {
380
- let btns = new Set();
381
- this.curWindowBtnList.forEach((item) => {
382
- item.checkChilds.forEach((checkId) => {
383
- btns.add(checkId);
384
- });
385
- });
386
- btns = Array.from(btns);
387
- this.roleSavedBtnPermMap[this.curSelectedMenuId] = btns;
388
- },
389
- changePage(v) {
390
- this.searchForm.pageNumber = v;
391
- this.getDataList();
392
- this.clearSelectAll();
393
- },
394
- changePageSize(v) {
395
- this.searchForm.pageSize = v;
396
- this.getDataList();
397
- },
398
- changeSort(e) {
399
- this.searchForm.sort = e.key;
400
- this.searchForm.order = e.order;
401
- if (e.order === "normal") {
402
- this.searchForm.order = "";
403
- }
404
- this.getDataList();
405
- },
406
- getDataList() {
407
- this.loading = true;
408
- this.axios
409
- .post(
410
- "/roleController/getRoleList",
411
- this.$qs.stringify({
412
- name: this.searchForm.key,
413
- pageSize: this.pagination.pageSize,
414
- pageIndex: this.pagination.current,
415
- })
416
- )
417
- .then((response) => {
418
- this.loading = false;
419
- if (response.data.result) {
420
- this.data = response.data.data.records;
421
- this.pagination.total = response.data.data.total;
422
- }
423
- });
424
- },
425
- parseTreeData(curLevelData, curLevel) {
426
- let newLevelData = curLevelData;
427
- newLevelData["id"] = curLevelData.adMenuId;
428
- newLevelData["key"] = curLevelData.adMenuId;
429
- newLevelData["title"] = curLevelData.name;
430
- newLevelData["expand"] = true;
431
- newLevelData["checked"] = false;
432
- newLevelData["level"] = curLevel;
433
- if (curLevelData["_childs"] && curLevelData["_childs"].length > 0) {
434
- curLevelData["_childs"].forEach((sonTreeData) => {
435
- if (!newLevelData.children) {
436
- newLevelData.children = [];
437
- }
438
- newLevelData.children.push(this.parseTreeData(sonTreeData, curLevel + 1));
439
- });
440
- }
441
- return newLevelData;
442
- },
443
- getRoleMenus: async function () {
444
- // 请求角色菜单数据
445
- let roleMenuData = [];
446
- await this.axios
447
- .post("/rolePermissionsSetting/getRoleMenus", this.$qs.stringify({ roleId: this.editRolePermId }))
448
- .then((response) => {
449
- if (response.data.result) {
450
- response.data.data.forEach(function (e) {
451
- roleMenuData[e.AD_MENU_ID] = e;
452
- });
453
- }
454
- })
455
- .catch((e) => {
456
- console.error(e);
457
- });
458
- return roleMenuData;
459
- },
460
- // 递归标记是否选中
461
- calNewTreeData(newTreeData, roleMenuData) {
462
- let checkedCount = 0;
463
- newTreeData.forEach((e) => {
464
- if (e.level === 0 || e.level === 1) {
465
- e.expand = true;
466
- } else {
467
- e.expand = true;
468
- }
469
- // 判断是否选中
470
- if (roleMenuData[e.adMenuId]) {
471
- e.checked = true;
472
- checkedCount++;
473
- }
474
- if (e.children && e.children.length > 0) {
475
- let sonCheckedCount = this.calNewTreeData(e.children, roleMenuData);
476
- // 判断父节点是否选中
477
- if (sonCheckedCount === e.children.length) {
478
- e.checked = true;
479
- e.indeterminate = false;
480
- } else if (sonCheckedCount > 0 && sonCheckedCount < e.children.length) {
481
- e.indeterminate = true;
482
- e.checked = false;
483
- } else {
484
- e.checked = false;
485
- e.indeterminate = false;
486
- }
487
-
488
- if (e.checked) {
489
- this.halfSelectedNodes.push(e.adMenuId);
490
- }
491
- if (e.checked) {
492
- this.selectedNodes.push(e.adMenuId);
493
- }
494
- } else {
495
- if (e.checked) {
496
- // console.log('checked', e.adMenuId);
497
- this.selectedNodes.push(e.adMenuId);
498
- }
499
- }
500
- });
501
- return checkedCount;
502
- },
503
- getPermList: async function () {
504
- this.treeLoading = true;
505
-
506
- this.expandedKeys = [];
507
- this.selectedNodes = [];
508
-
509
- let roleMenuData = await this.getRoleMenus();
510
- this.axios.post("/rolePermissionsSetting/getMenuList", this.$qs.stringify({})).then((response) => {
511
- if (response.data.result) {
512
- let newTreeData = [];
513
- // 仅展开指定级数 默认后端已展开所有
514
- response.data.menuList.forEach((e) => {
515
- newTreeData.push(this.parseTreeData(e, 0));
516
- });
517
- this.calNewTreeData(newTreeData, roleMenuData);
518
- this.deleteDisableNode(newTreeData);
519
- this.permData = newTreeData;
520
- this.treeLoading = false;
521
-
522
- this.$nextTick(() => {
523
- let checked = this.selectedNodes.filter((item) => !this.halfSelectedNodes.includes(item));
524
- console.log(this.selectedNodes.length, checked.length);
525
- this.$refs.tree.setCheckedKeys(checked);
526
- });
527
- }
528
- this.loading = false;
529
- });
530
- },
531
- // 递归标记禁用节点
532
- deleteDisableNode(permData) {
533
- let that = this;
534
- permData.forEach(function (e) {
535
- if (e.status === -1) {
536
- e.title = "[已禁用] " + e.title;
537
- e.disabled = true;
538
- }
539
- if (e.children && e.children.length > 0) {
540
- that.deleteDisableNode(e.children);
541
- }
542
- });
543
- },
544
- cancelRole() {
545
- this.roleModalVisible = false;
546
- },
547
- submitRole() {
548
- let that = this;
549
- let subForm = {
550
- orgId: this.roleForm.ad_org_id,
551
- adRoleId: this.roleForm.ad_role_id,
552
- name: this.roleForm.name,
553
- description: this.roleForm.description,
554
- isAdmin: this.roleForm.isAdmin,
555
- };
556
- this.$refs.roleForm.validate((valid) => {
557
- if (valid) {
558
- this.submitLoading = true;
559
- this.axios.post("/roleController/submitRole", this.$qs.stringify(subForm)).then((response) => {
560
- that.submitLoading = false;
561
- if (response.data.result) {
562
- that.$message.success("操作成功");
563
- that.getDataList();
564
- that.roleModalVisible = false;
565
- } else {
566
- that.$message.error(response.data.msg);
567
- }
568
- });
569
- }
570
- });
571
- },
572
- addRole() {
573
- // 处理状态
574
- this.modalType = 0;
575
- this.modalTitle = "添加角色";
576
- // 清理表单
577
- this.roleForm.ad_role_id = undefined;
578
- this.roleForm.name = "";
579
- this.roleForm.isAdmin = "N";
580
- this.roleForm.description = "";
581
- this.roleForm.ad_role_id = "";
582
- // 显示弹窗
583
- this.roleModalVisible = true;
584
- },
585
- edit(v) {
586
- // 处理状态
587
- this.modalType = 1;
588
- this.modalTitle = "编辑角色";
589
- // 填充表单
590
- this.roleForm.ad_org_id = v.ad_org_id;
591
- this.roleForm.name = v.name;
592
- this.roleForm.isAdmin = v.is_admin == "Y";
593
- this.roleForm.description = v.description;
594
- this.roleForm.ad_role_id = v.ad_role_id;
595
- // 显示弹窗
596
- this.roleModalVisible = true;
597
- },
598
- deleteRole(delId) {
599
- this.axios
600
- .post(
601
- "/roleController/delRoleByIds",
602
- this.$qs.stringify({
603
- ids: delId,
604
- })
605
- )
606
- .then((response) => {
607
- if (response.data.result) {
608
- this.$message.success("删除成功");
609
- this.clearSelectAll();
610
- this.getDataList();
611
- } else {
612
- this.$message.success("删除失败");
613
- }
614
- });
615
- },
616
- remove(v) {
617
- if (v && v.ad_role_id) {
618
- this.deleteRole(v.ad_role_id);
619
- }
620
- },
621
- clearSelectAll() {
622
- this.selectList = [];
623
- },
624
- changeSelect(e) {
625
- this.selectList = e;
626
- },
627
- delAll() {
628
- if (this.selectList.length <= 0) {
629
- this.$message.warning("您还未选择要删除的数据");
630
- return;
631
- }
632
- let ids = this.selectList.join(",");
633
- // 删除按钮代码
634
- this.deleteRole(ids);
635
- },
636
- editPerm(v) {
637
- this.editRolePermId = v.ad_role_id;
638
- // 获取所有菜单权限树
639
- this.getPermList();
640
- this.modalTitle = "分配 " + v.name + " 的菜单权限";
641
- // 递归判断子节点
642
- this.checkPermTree(this.permData, []);
643
- // 加载所有已授予的按钮权限
644
- this.axios
645
- .post("/roleController/getRoleWindowButton", this.$qs.stringify({ roleId: this.editRolePermId }))
646
- .then((response) => {
647
- if (response.data.result && response.data.data) {
648
- let roleBtnPermMap = {};
649
- response.data.data.forEach(function (e) {
650
- if (!roleBtnPermMap[e.WINDOW_ID]) {
651
- roleBtnPermMap[e.WINDOW_ID] = [];
652
- }
653
- roleBtnPermMap[e.WINDOW_ID].push(e.BUTTON_ID);
654
- });
655
- this.roleSavedBtnPermMap = roleBtnPermMap;
656
- }
657
- });
658
- this.permModalVisible = true;
659
- },
660
- // 递归判断子节点
661
- checkPermTree(permData, rolePerms) {
662
- let that = this;
663
- permData.forEach(function (p) {
664
- if (that.hasPerm(p, rolePerms) && p.status !== -1) {
665
- p.checked = true;
666
- } else {
667
- p.checked = false;
668
- }
669
- if (p.children && p.children.length > 0) {
670
- that.checkPermTree(p.children, rolePerms);
671
- }
672
- });
673
- },
674
- // 判断角色拥有的权限节点勾选
675
- hasPerm(p, rolePerms) {
676
- let flag = false;
677
- for (let i = 0; i < rolePerms.length; i++) {
678
- if (p.id === rolePerms[i].permissionId) {
679
- flag = true;
680
- break;
681
- }
682
- }
683
- if (flag) {
684
- return true;
685
- }
686
- return false;
687
- },
688
- // 全选反选
689
- selectTreeAll() {
690
- this.selectAllFlag = !this.selectAllFlag;
691
- let select = this.selectAllFlag;
692
- this.selectedTreeAll(this.permData, select);
693
- },
694
- // 递归全选节点
695
- selectedTreeAll(permData, select) {
696
- let that = this;
697
- permData.forEach(function (e) {
698
- e.checked = select;
699
- if (!select) {
700
- e.indeterminate = false;
701
- }
702
- if (e.children && e.children.length > 0) {
703
- that.selectedTreeAll(e.children, select);
704
- }
705
- });
706
- },
707
- async submitPermEdit() {
708
- let curVm = this;
709
- this.submitPermLoading = true;
710
- let permMenuIds = "";
711
- let selectedNodes = this.selectedNodes.concat(this.halfSelectedNodes);
712
- permMenuIds = selectedNodes.join(",");
713
- // 所有菜单项
714
- // 所有菜单窗口按钮
715
- let permMenuBtnIds = {};
716
- Object.keys(curVm.roleSavedBtnPermMap).forEach(function (key) {
717
- permMenuBtnIds["W_" + key] = curVm.roleSavedBtnPermMap[key];
718
- });
719
- this.axios
720
- .post(
721
- "/rolePermissionsSetting/setMenus",
722
- this.$qs.stringify({
723
- roleId: this.editRolePermId,
724
- ids: permMenuIds,
725
- btns: JSON.stringify(permMenuBtnIds),
726
- })
727
- )
728
- .then((response) => {
729
- this.submitPermLoading = false;
730
- if (response.data.result) {
731
- this.$message.success("操作成功");
732
- this.getDataList();
733
- this.permModalVisible = false;
734
- this.cancelPermEdit();
735
- } else {
736
- this.$message.error(response.data.msg);
737
- }
738
- });
739
- },
740
- cancelPermEdit() {
741
- this.selectedKeys = [];
742
- this.expandedKeys = [];
743
- this.selectedNodes = [];
744
- this.halfSelectedNodes = [];
745
- this.$nextTick(() => {
746
- this.permModalVisible = false;
747
- this.resetBtnPerData();
748
- });
749
- },
750
- },
751
- mounted() {
752
- this.maxHeight = Number(document.documentElement.clientHeight - 121) + "px";
753
- this.init();
754
- },
755
- };
1
+ import dict from "./dict.vue";
2
+ import { deepClone } from "@/libs/util";
3
+
4
+ export default {
5
+ name: "role-manage",
6
+ components: {
7
+ dict,
8
+ },
9
+ data () {
10
+ return {
11
+ maxHeight: 510,
12
+ openTip: false,
13
+ loading: true,
14
+ userLoading: false,
15
+ treeLoading: true,
16
+ submitPermLoading: false,
17
+ submitDepLoading: false,
18
+ searchKey: "",
19
+ modalType: 0,
20
+ roleModalVisible: false,
21
+ roleOrgData: {},
22
+ permModalVisible: false,
23
+ orgModalVisible: false,
24
+ orgData: [],
25
+ modalTitle: "",
26
+ searchForm: {
27
+ // 搜索框初始化对象
28
+ pageNumber: 1, // 当前页数
29
+ pageSize: 10, // 页面大小
30
+ sort: "createTime", // 默认排序字段
31
+ order: "desc", // 默认排序方式
32
+ key: "",
33
+ },
34
+ roleForm: {
35
+ adOrgId: "",
36
+ name: "",
37
+ isAdmin: "N",
38
+ description: "",
39
+ adRoleId: "",
40
+ },
41
+ roleFormValidate: {
42
+ adOrgId: [{ required: true, message: "组织机构不能为空", trigger: "change" }],
43
+ name: [{ required: true, message: "角色名称不能为空", trigger: "change" }],
44
+ },
45
+ submitLoading: false,
46
+ selectList: [],
47
+ data: [],
48
+ userData: [],
49
+ paginationUser: { currentPage: 1, pageSize: 10, total: 0 },
50
+ listLoading: false,
51
+ pagination: { currentPage: 1, pageSize: 10, total: 0 },
52
+ permData: [],
53
+ editRolePermId: "",
54
+ selectAllFlag: false,
55
+ dataType: 0,
56
+ indeterminate: false,
57
+ checkAll: false,
58
+ checkAllGroup: [],
59
+ curWindowBtnList: [],
60
+ saveWinBtnList: [],
61
+ roleSavedBtnPermMap: {}, // 角色已授予的按钮权限
62
+ curSelectedMenuId: "", // 当前选中目录ID
63
+ selectedKeys: [],
64
+ selectedNodes: [],
65
+ halfSelectedNodes: [],
66
+ deptCheckedKeys: [],
67
+ timer: null,
68
+ queryOrgId: "",
69
+ queryRoteId: "",
70
+ queryUserList: [],
71
+ currentRow: null,
72
+ userIds: [],
73
+ userListVisible: false,
74
+ };
75
+ },
76
+ methods: {
77
+ init () {
78
+ this.getDataList();
79
+ },
80
+ parseOrgTreeData (curLevelData, curLevel, roleOrgData) {
81
+ let curVm = this;
82
+ let newLevelData = curLevelData;
83
+ newLevelData.key = curLevelData.adOrgId;
84
+ newLevelData.title = curLevelData.name;
85
+ if (roleOrgData[curLevelData.adOrgId]) {
86
+ if (roleOrgData[curLevelData.adOrgId].isOrgAdmin === "Y") {
87
+ this.deptCheckedKeys.push(curLevelData.adOrgId);
88
+ }
89
+ }
90
+ newLevelData["level"] = curLevel;
91
+ if (curLevelData["_childs"] && curLevelData["_childs"].length > 0) {
92
+ curLevelData["_childs"].forEach(function (sonTreeData) {
93
+ if (!newLevelData.children) {
94
+ newLevelData.children = [];
95
+ }
96
+ newLevelData.children.push(curVm.parseOrgTreeData(sonTreeData, curLevel + 1, roleOrgData));
97
+ });
98
+ }
99
+ return newLevelData;
100
+ },
101
+ async loadRoleOrg () {
102
+ let roleOrgData = {};
103
+ // 请求系统数据
104
+ this.axios
105
+ .post(
106
+ "/roleController/getRoleOrgAccess",
107
+ this.$qs.stringify({
108
+ roleId: this.editRolePermId,
109
+ }),
110
+ )
111
+ .then((response) => {
112
+ if (response.data.result) {
113
+ if (response.data.roleOrgAccess) {
114
+ response.data.roleOrgAccess.forEach(function (sd) {
115
+ roleOrgData[sd.orgId] = sd;
116
+ });
117
+ }
118
+ }
119
+ });
120
+ return roleOrgData;
121
+ },
122
+ async editOrg (v) {
123
+ this.editRolePermId = v.adRoleId;
124
+ this.modalTitle = "分配 " + v.name + " 的组织机构权限";
125
+ let roleOrgData = await this.loadRoleOrg();
126
+ this.roleOrgData = roleOrgData;
127
+ // 请求系统数据
128
+ this.axios.post("/orgController/getUserOrgTree", {}).then((response) => {
129
+ if (response.data.result) {
130
+ let newTreeData = [];
131
+ this.deptCheckedKeys = [];
132
+ response.data.list.forEach((e) => {
133
+ newTreeData.push(this.parseOrgTreeData(e, 0, roleOrgData));
134
+ });
135
+ this.orgData = newTreeData;
136
+ this.$nextTick(() => {
137
+ this.$refs.depTree.setCheckedKeys(this.deptCheckedKeys);
138
+ });
139
+ }
140
+ });
141
+ this.orgModalVisible = true;
142
+ },
143
+ checkOrgTree () {
144
+ if (this.timer) {
145
+ clearTimeout(this.timer);
146
+ }
147
+ this.timer = setTimeout(() => {
148
+ this.deptCheckedKeys = this.$refs.depTree.getCheckedKeys();
149
+ }, 300);
150
+ },
151
+ submitRoleOrg () {
152
+ let selectedNodes = this.$refs.depTree.getCheckedKeys() || [];
153
+ let curVm = this;
154
+ let subRoleOrgData = [];
155
+ // 判断已提交角色机构数据
156
+ selectedNodes.forEach(function (e) {
157
+ subRoleOrgData.push({ ad_org_id: e, is_org_admin: "Y" });
158
+ });
159
+ this.axios
160
+ .post(
161
+ "/roleController/saveRoleOrgAccess",
162
+ this.$qs.stringify({
163
+ roleId: curVm.editRolePermId,
164
+ subJsonData: JSON.stringify(subRoleOrgData),
165
+ }),
166
+ )
167
+ .then((response) => {
168
+ if (response.data.result) {
169
+ curVm.$message.success(response.data.msg);
170
+ } else {
171
+ curVm.$message.error(response.data.msg);
172
+ }
173
+ });
174
+ this.orgModalVisible = false;
175
+ },
176
+ renderContent (h, { root, node, data }) {
177
+ let icon = "";
178
+ if (data.level === 0) {
179
+ icon = "ios-navigate";
180
+ } else if (data.level === 1) {
181
+ icon = "md-list-box";
182
+ } else if (data.level === 2) {
183
+ icon = "md-list";
184
+ } else if (data.level === 3) {
185
+ icon = "md-radio-button-on";
186
+ } else {
187
+ icon = "md-radio-button-off";
188
+ }
189
+ return h(
190
+ "span",
191
+ {
192
+ style: {
193
+ display: "inline-block",
194
+ cursor: "pointer",
195
+ },
196
+ on: {
197
+ click: () => {
198
+ data.checked = !data.checked;
199
+ },
200
+ },
201
+ },
202
+ [
203
+ h("span", [
204
+ h("Icon", {
205
+ props: {
206
+ type: icon,
207
+ size: "16",
208
+ },
209
+ style: {
210
+ "margin-right": "8px",
211
+ "margin-bottom": "3px",
212
+ },
213
+ }),
214
+ h("span", data.title),
215
+ ]),
216
+ ],
217
+ );
218
+ },
219
+ checkedMenuTree () {
220
+ if (this.timer) {
221
+ clearTimeout(this.timer);
222
+ }
223
+ this.timer = setTimeout(() => {
224
+ this.selectedNodes = this.$refs.tree.getCheckedKeys(true);
225
+ this.halfSelectedNodes = this.$refs.tree.getHalfCheckedKeys(true);
226
+ }, 300);
227
+ },
228
+ selectTree (data, node) {
229
+ if (data) {
230
+ this.curSelectedMenuId = data.sysWindowId;
231
+ // 加载目录树
232
+ this.axios
233
+ .post("/rolePermissionsSetting/getMenuWindowButton", { windowId: this.curSelectedMenuId })
234
+ .then((response) => {
235
+ let { result, data } = response.data;
236
+ if (result && data) {
237
+ let roleBtnData = [];
238
+ let tempQyBtnData = [];
239
+ data.forEach((tData) => {
240
+ if (tData.TYPE === "QY") {
241
+ roleBtnData.push(tData);
242
+ tempQyBtnData[tData.ID] = [];
243
+ } else {
244
+ if (tempQyBtnData[tData.PARENT_ID]) {
245
+ tempQyBtnData[tData.PARENT_ID].push(tData);
246
+ }
247
+ }
248
+ });
249
+ roleBtnData.forEach((item) => {
250
+ item["childs"] = tempQyBtnData[item.ID];
251
+ // e['checkAll'] = false
252
+ let roleSavedBtns = this.roleSavedBtnPermMap[this.curSelectedMenuId] || [];
253
+ let checkChilds = [];
254
+ let tcount = 0;
255
+ tempQyBtnData[item.ID].forEach((es) => {
256
+ if (roleSavedBtns.includes(es.ID)) {
257
+ checkChilds.push(es.ID);
258
+ tcount++;
259
+ }
260
+ });
261
+ if (tcount === tempQyBtnData[item.ID].length) {
262
+ item["checkAll"] = true;
263
+ item["indeterminate"] = false;
264
+ } else if (tcount > 0) {
265
+ item["checkAll"] = false;
266
+ item["indeterminate"] = true;
267
+ } else {
268
+ item["checkAll"] = false;
269
+ item["indeterminate"] = false;
270
+ }
271
+ item["checkChilds"] = checkChilds;
272
+ });
273
+ this.curWindowBtnList = roleBtnData;
274
+ // 加载角色已授权的按钮
275
+ this.saveWinBtnList = this.roleSavedBtnPermMap[this.curSelectedMenuId];
276
+ }
277
+ });
278
+ }
279
+ },
280
+ resetBtnPerData () {
281
+ this.roleSavedBtnPermMap = {};
282
+ this.curWindowBtnList = [];
283
+ this.saveWinBtnList = [];
284
+ },
285
+ doWinBtnData (doType, btnId) {
286
+ if (!this.saveWinBtnList) {
287
+ this.saveWinBtnList = [];
288
+ }
289
+ if (doType === "add") {
290
+ if (this.saveWinBtnList.length !== 0) {
291
+ for (let i = 0; i < this.saveWinBtnList.length; i++) {
292
+ if (this.saveWinBtnList[i] === btnId) {
293
+ return;
294
+ }
295
+ }
296
+ }
297
+ this.saveWinBtnList.push(btnId);
298
+ } else {
299
+ for (let i = 0; i < this.saveWinBtnList.length; i++) {
300
+ if (this.saveWinBtnList[i] === btnId) {
301
+ this.saveWinBtnList.splice(i, 1);
302
+ return;
303
+ }
304
+ }
305
+ }
306
+ },
307
+ handleCheckAll (item, key) {
308
+ let checkChilds = [];
309
+ if (!item.checkAll) {
310
+ // 已经全选取消全选状态
311
+ item.checkAll = false;
312
+ item.indeterminate = false;
313
+ item.checkChilds = checkChilds;
314
+ } else {
315
+ // 不是全选状态,获取所有ids,并设定全选状态相关参数
316
+ checkChilds = item.childs.map((item) => item.ID);
317
+ item.checkAll = true;
318
+ item.indeterminate = false;
319
+ item.checkChilds = checkChilds;
320
+ }
321
+
322
+ // 状态设置完成,将数据赋值到 响应对象上去
323
+ this.updateBtnsToList();
324
+ this.curWindowBtnList[key] = item;
325
+ },
326
+ checkAllGroupChange (event, key) {
327
+ let list = deepClone({}, this.curWindowBtnList);
328
+ let currentItem = list[key];
329
+ if (event.length > 0) {
330
+ // 判断是否存在值
331
+ let containFlag = 0; // 0 不包含 1 部分包括 2 全包括
332
+ let okCount = 0; // 统计包括次数
333
+ for (var i = 0; i < currentItem.childs.length; i++) {
334
+ if (event.includes(currentItem.childs[i].ID)) {
335
+ okCount++;
336
+ }
337
+ }
338
+ if (okCount === currentItem.childs.length) {
339
+ containFlag = 2;
340
+ } else {
341
+ containFlag = 1;
342
+ }
343
+ // 判断是否选中
344
+ if (containFlag === 1) {
345
+ currentItem.checkAll = false;
346
+ if (okCount === 0) {
347
+ currentItem.indeterminate = false;
348
+ } else {
349
+ currentItem.indeterminate = true;
350
+ }
351
+ } else if (containFlag === 2) {
352
+ currentItem.checkAll = true;
353
+ currentItem.indeterminate = false;
354
+ }
355
+ } else {
356
+ currentItem.checkAll = false;
357
+ currentItem.indeterminate = false;
358
+ }
359
+ currentItem.checkChilds = event;
360
+ this.curWindowBtnList[key] = currentItem;
361
+ this.updateBtnsToList();
362
+ },
363
+ updateBtnsToList () {
364
+ let btns = new Set();
365
+ this.curWindowBtnList.forEach((item) => {
366
+ item.checkChilds.forEach((checkId) => {
367
+ btns.add(checkId);
368
+ });
369
+ });
370
+ btns = Array.from(btns);
371
+ this.roleSavedBtnPermMap[this.curSelectedMenuId] = btns;
372
+ },
373
+ changePage (v) {
374
+ this.searchForm.pageNumber = v;
375
+ this.getDataList();
376
+ this.clearSelectAll();
377
+ },
378
+ changePageSize (v) {
379
+ this.searchForm.pageSize = v;
380
+ this.getDataList();
381
+ },
382
+ changeSort (e) {
383
+ this.searchForm.sort = e.key;
384
+ this.searchForm.order = e.order;
385
+ if (e.order === "normal") {
386
+ this.searchForm.order = "";
387
+ }
388
+ this.getDataList();
389
+ },
390
+ getDataList () {
391
+ this.loading = true;
392
+ this.axios.post("/roleController/getRoleList",
393
+ this.$qs.stringify({
394
+ name: this.searchForm.key,
395
+ pageSize: this.pagination.pageSize,
396
+ pageIndex: this.pagination.currentPage,
397
+ }),
398
+ ).then((response) => {
399
+ this.loading = false;
400
+ if (response.data.result) {
401
+ this.data = response.data.data.records;
402
+ this.pagination.total = response.data.data.total;
403
+ }
404
+ });
405
+ },
406
+ getUserDataList (val) {
407
+ if (val === undefined) {
408
+ this.userData = [];
409
+ return;
410
+ }
411
+ if (val != 1) {
412
+ this.currentRow = val;
413
+ }
414
+ this.userLoading = true;
415
+ this.userIds = [];
416
+ this.axios.post("/roteUser/getAdRoleUsers",
417
+ this.$qs.stringify({
418
+ roteId: this.currentRow.adRoleId,
419
+ orgId: this.currentRow.adOrgId,
420
+ pageSize: this.paginationUser.pageSize,
421
+ pageIndex: this.paginationUser.currentPage,
422
+ }),
423
+ ).then((response) => {
424
+ this.userLoading = false;
425
+ if (response.data.result) {
426
+ this.queryOrgId = this.currentRow.adOrgId;
427
+ this.queryRoteId = this.currentRow.adRoleId;
428
+ this.userData = response.data.data.records;
429
+ this.paginationUser.total = response.data.data.total;
430
+ this.userData.forEach(value => {
431
+ this.userIds.push(value.ad_user_id);
432
+ });
433
+ }
434
+ });
435
+ },
436
+ getUserList () {
437
+ this.userListVisible = true;
438
+ this.axios.post("/roteUser/getUserList",
439
+ this.$qs.stringify({
440
+ orgId: this.queryOrgId,
441
+ }),
442
+ ).then((response) => {
443
+ this.userLoading = false;
444
+ if (response.data.result) {
445
+ this.queryUserList = response.data.data;
446
+ }
447
+ });
448
+ },
449
+ addUserRote () {
450
+ this.axios.post("/roteUser/addUserRote",
451
+ this.$qs.stringify({
452
+ roteId: this.queryRoteId,
453
+ userIds: this.userIds.toString(),
454
+ }),
455
+ ).then((response) => {
456
+ this.userLoading = false;
457
+ this.userListVisible = false;
458
+ this.$message.success("操作成功");
459
+ this.getUserDataList(this.currentRow);
460
+ });
461
+ },
462
+ deleteUserRote (v) {
463
+ if (v && v.adRoleId && v.ad_user_id) {
464
+ this.axios.post("/roteUser/deleteUserRote",
465
+ this.$qs.stringify({
466
+ roteId: v.adRoleId,
467
+ userId: v.ad_user_id,
468
+ }),
469
+ ).then((response) => {
470
+ this.userLoading = false;
471
+ this.$message.success("操作成功");
472
+ this.getUserDataList(this.currentRow);
473
+ });
474
+ }
475
+ },
476
+ onCanael () {
477
+ this.userListVisible = false;
478
+ },
479
+ parseTreeData (curLevelData, curLevel) {
480
+ let newLevelData = curLevelData;
481
+ newLevelData["id"] = curLevelData.adMenuId;
482
+ newLevelData["key"] = curLevelData.adMenuId;
483
+ newLevelData["title"] = curLevelData.name;
484
+ newLevelData["expand"] = true;
485
+ newLevelData["checked"] = false;
486
+ newLevelData["level"] = curLevel;
487
+ if (curLevelData["_childs"] && curLevelData["_childs"].length > 0) {
488
+ curLevelData["_childs"].forEach((sonTreeData) => {
489
+ if (!newLevelData.children) {
490
+ newLevelData.children = [];
491
+ }
492
+ newLevelData.children.push(this.parseTreeData(sonTreeData, curLevel + 1));
493
+ });
494
+ }
495
+ return newLevelData;
496
+ },
497
+ getRoleMenus: async function () {
498
+ // 请求角色菜单数据
499
+ let roleMenuData = [];
500
+ await this.axios
501
+ .post("/rolePermissionsSetting/getRoleMenus", this.$qs.stringify({ roleId: this.editRolePermId }))
502
+ .then((response) => {
503
+ if (response.data.result) {
504
+ response.data.data.forEach(function (e) {
505
+ roleMenuData[e.AD_MENU_ID] = e;
506
+ });
507
+ }
508
+ }).catch((e) => {
509
+ console.error(e);
510
+ });
511
+ return roleMenuData;
512
+ },
513
+ // 递归标记是否选中
514
+ calNewTreeData (newTreeData, roleMenuData) {
515
+ let checkedCount = 0;
516
+ newTreeData.forEach((e) => {
517
+ if (e.level === 0 || e.level === 1) {
518
+ e.expand = true;
519
+ } else {
520
+ e.expand = true;
521
+ }
522
+ // 判断是否选中
523
+ if (roleMenuData[e.adMenuId]) {
524
+ e.checked = true;
525
+ checkedCount++;
526
+ }
527
+ if (e.children && e.children.length > 0) {
528
+ let sonCheckedCount = this.calNewTreeData(e.children, roleMenuData);
529
+ // 判断父节点是否选中
530
+ if (sonCheckedCount === e.children.length) {
531
+ e.checked = true;
532
+ e.indeterminate = false;
533
+ } else if (sonCheckedCount > 0 && sonCheckedCount < e.children.length) {
534
+ e.indeterminate = true;
535
+ e.checked = false;
536
+ } else {
537
+ e.checked = false;
538
+ e.indeterminate = false;
539
+ }
540
+
541
+ if (e.checked) {
542
+ this.halfSelectedNodes.push(e.adMenuId);
543
+ }
544
+ if (e.checked) {
545
+ this.selectedNodes.push(e.adMenuId);
546
+ }
547
+ } else {
548
+ if (e.checked) {
549
+ this.selectedNodes.push(e.adMenuId);
550
+ }
551
+ }
552
+ });
553
+ return checkedCount;
554
+ },
555
+ getPermList: async function () {
556
+ this.treeLoading = true;
557
+
558
+ this.expandedKeys = [];
559
+ this.selectedNodes = [];
560
+
561
+ let roleMenuData = await this.getRoleMenus();
562
+ this.axios.post("/rolePermissionsSetting/getMenuList", this.$qs.stringify({})).then((response) => {
563
+ if (response.data.result) {
564
+ let newTreeData = [];
565
+ // 仅展开指定级数 默认后端已展开所有
566
+ response.data.menuList.forEach((e) => {
567
+ newTreeData.push(this.parseTreeData(e, 0));
568
+ });
569
+ this.calNewTreeData(newTreeData, roleMenuData);
570
+ this.deleteDisableNode(newTreeData);
571
+ this.permData = newTreeData;
572
+ this.treeLoading = false;
573
+
574
+ this.$nextTick(() => {
575
+ let checked = this.selectedNodes.filter((item) => !this.halfSelectedNodes.includes(item));
576
+ this.$refs.tree.setCheckedKeys(checked);
577
+ });
578
+ }
579
+ this.loading = false;
580
+ });
581
+ },
582
+ // 递归标记禁用节点
583
+ deleteDisableNode (permData) {
584
+ let that = this;
585
+ permData.forEach(function (e) {
586
+ if (e.status === -1) {
587
+ e.title = "[已禁用] " + e.title;
588
+ e.disabled = true;
589
+ }
590
+ if (e.children && e.children.length > 0) {
591
+ that.deleteDisableNode(e.children);
592
+ }
593
+ });
594
+ },
595
+ cancelRole () {
596
+ this.roleModalVisible = false;
597
+ },
598
+ submitRole () {
599
+ let that = this;
600
+ let subForm = {
601
+ orgId: this.roleForm.adOrgId,
602
+ adRoleId: this.roleForm.adRoleId,
603
+ name: this.roleForm.name,
604
+ description: this.roleForm.description,
605
+ isAdmin: this.roleForm.isAdmin,
606
+ };
607
+ this.$refs.roleForm.validate((valid) => {
608
+ if (valid) {
609
+ this.submitLoading = true;
610
+ debugger;
611
+ this.axios.post("/roleController/submitRole", this.$qs.stringify(subForm)).then((response) => {
612
+ that.submitLoading = false;
613
+ if (response.data.result) {
614
+ that.$message.success("操作成功");
615
+ that.getDataList();
616
+ that.roleModalVisible = false;
617
+ } else {
618
+ that.$message.error(response.data.msg);
619
+ }
620
+ });
621
+ }
622
+ });
623
+ },
624
+ addRole () {
625
+ // 处理状态
626
+ this.modalType = 0;
627
+ this.modalTitle = "添加角色";
628
+ // 清理表单
629
+ this.roleForm.adRoleId = undefined;
630
+ this.roleForm.name = "";
631
+ this.roleForm.isAdmin = "N";
632
+ this.roleForm.description = "";
633
+ this.roleForm.adRoleId = "";
634
+ // 显示弹窗
635
+ this.roleModalVisible = true;
636
+ },
637
+ edit (v) {
638
+ // 处理状态
639
+ this.modalType = 1;
640
+ this.modalTitle = "编辑角色";
641
+ // 填充表单
642
+ this.roleForm.adOrgId = v.adOrgId;
643
+ this.roleForm.name = v.name;
644
+ this.roleForm.isAdmin = v.isAdmin;
645
+ this.roleForm.description = v.description;
646
+ this.roleForm.adRoleId = v.adRoleId;
647
+ // 显示弹窗
648
+ this.roleModalVisible = true;
649
+ },
650
+ deleteRole (delId) {
651
+ this.axios
652
+ .post(
653
+ "/roleController/delRoleByIds",
654
+ this.$qs.stringify({
655
+ ids: delId,
656
+ }),
657
+ )
658
+ .then((response) => {
659
+ if (response.data.result) {
660
+ this.$message.success("删除成功");
661
+ this.clearSelectAll();
662
+ this.getDataList();
663
+ } else {
664
+ this.$message.success("删除失败");
665
+ }
666
+ });
667
+ },
668
+ remove (v) {
669
+ if (v && v.adRoleId) {
670
+ this.deleteRole(v.adRoleId);
671
+ }
672
+ },
673
+ clearSelectAll () {
674
+ this.selectList = [];
675
+ },
676
+ changeSelect (e) {
677
+ this.selectList = e;
678
+ },
679
+ delAll () {
680
+ if (this.selectList.length <= 0) {
681
+ this.$message.warning("您还未选择要删除的数据");
682
+ return;
683
+ }
684
+ let ids = this.selectList.join(",");
685
+ // 删除按钮代码
686
+ this.deleteRole(ids);
687
+ },
688
+ editPerm (v) {
689
+ this.editRolePermId = v.adRoleId;
690
+ // 获取所有菜单权限树
691
+ this.getPermList();
692
+ this.modalTitle = "分配 " + v.name + " 的菜单权限";
693
+ // 递归判断子节点
694
+ this.checkPermTree(this.permData, []);
695
+ // 加载所有已授予的按钮权限
696
+ this.axios
697
+ .post("/roleController/getRoleWindowButton", this.$qs.stringify({ roleId: this.editRolePermId }))
698
+ .then((response) => {
699
+ if (response.data.result && response.data.data) {
700
+ let roleBtnPermMap = {};
701
+ response.data.data.forEach(function (e) {
702
+ if (!roleBtnPermMap[e.WINDOW_ID]) {
703
+ roleBtnPermMap[e.WINDOW_ID] = [];
704
+ }
705
+ roleBtnPermMap[e.WINDOW_ID].push(e.BUTTON_ID);
706
+ });
707
+ this.roleSavedBtnPermMap = roleBtnPermMap;
708
+ }
709
+ });
710
+ this.permModalVisible = true;
711
+ },
712
+ // 递归判断子节点
713
+ checkPermTree (permData, rolePerms) {
714
+ let that = this;
715
+ permData.forEach(function (p) {
716
+ if (that.hasPerm(p, rolePerms) && p.status !== -1) {
717
+ p.checked = true;
718
+ } else {
719
+ p.checked = false;
720
+ }
721
+ if (p.children && p.children.length > 0) {
722
+ that.checkPermTree(p.children, rolePerms);
723
+ }
724
+ });
725
+ },
726
+ // 判断角色拥有的权限节点勾选
727
+ hasPerm (p, rolePerms) {
728
+ let flag = false;
729
+ for (let i = 0; i < rolePerms.length; i++) {
730
+ if (p.id === rolePerms[i].permissionId) {
731
+ flag = true;
732
+ break;
733
+ }
734
+ }
735
+ if (flag) {
736
+ return true;
737
+ }
738
+ return false;
739
+ },
740
+ // 全选反选
741
+ selectTreeAll () {
742
+ this.selectAllFlag = !this.selectAllFlag;
743
+ let select = this.selectAllFlag;
744
+ this.selectedTreeAll(this.permData, select);
745
+ },
746
+ // 递归全选节点
747
+ selectedTreeAll (permData, select) {
748
+ let that = this;
749
+ permData.forEach(function (e) {
750
+ e.checked = select;
751
+ if (!select) {
752
+ e.indeterminate = false;
753
+ }
754
+ if (e.children && e.children.length > 0) {
755
+ that.selectedTreeAll(e.children, select);
756
+ }
757
+ });
758
+ },
759
+ async submitPermEdit () {
760
+ let curVm = this;
761
+ this.submitPermLoading = true;
762
+ let permMenuIds = "";
763
+ let selectedNodes = this.selectedNodes.concat(this.halfSelectedNodes);
764
+ permMenuIds = selectedNodes.join(",");
765
+ // 所有菜单项
766
+ // 所有菜单窗口按钮
767
+ let permMenuBtnIds = {};
768
+ Object.keys(curVm.roleSavedBtnPermMap).forEach(function (key) {
769
+ permMenuBtnIds["W_" + key] = curVm.roleSavedBtnPermMap[key];
770
+ });
771
+ this.axios
772
+ .post(
773
+ "/rolePermissionsSetting/setMenus",
774
+ this.$qs.stringify({
775
+ roleId: this.editRolePermId,
776
+ ids: permMenuIds,
777
+ btns: JSON.stringify(permMenuBtnIds),
778
+ }),
779
+ )
780
+ .then((response) => {
781
+ this.submitPermLoading = false;
782
+ if (response.data.result) {
783
+ this.$message.success("操作成功");
784
+ this.getDataList();
785
+ this.permModalVisible = false;
786
+ this.cancelPermEdit();
787
+ } else {
788
+ this.$message.error(response.data.msg);
789
+ }
790
+ });
791
+ },
792
+ cancelPermEdit () {
793
+ this.selectedKeys = [];
794
+ this.expandedKeys = [];
795
+ this.selectedNodes = [];
796
+ this.halfSelectedNodes = [];
797
+ this.$nextTick(() => {
798
+ this.permModalVisible = false;
799
+ this.resetBtnPerData();
800
+ });
801
+ },
802
+ },
803
+ mounted () {
804
+ this.maxHeight = Number(document.documentElement.clientHeight - 121) + "px";
805
+ this.init();
806
+ },
807
+ };