diff --git a/src/pages/BaseAdmin/BaseAdmin/list.vue b/src/pages/BaseAdmin/BaseAdmin/list.vue index 98a1ca7..57e3d0c 100644 --- a/src/pages/BaseAdmin/BaseAdmin/list.vue +++ b/src/pages/BaseAdmin/BaseAdmin/list.vue @@ -303,6 +303,9 @@ export default { }) }, saveRoleSetting({ adds, removes }) { + if(!adds.length && !removes.length){ + return; + } let userRoleCreateRequest = []; adds.forEach(id => { userRoleCreateRequest.push({ @@ -318,8 +321,10 @@ export default { userRoleCreateRequest: userRoleCreateRequest } }).then(a => { - console.log(a) - }); + this.$mk.success(a.msg); + }).catch(a=>{ + this.$mk.error(a.data.msg); + }) }, confirmRoleSetting() { let rows = this.$refs.xRoleTable.getCheckboxRecords(); @@ -329,12 +334,12 @@ export default { target_uid: this.currentRow.uid } }).then(a => { - let roleList = a.data.UserRole || []; + let roleList = a.data.user_role || []; let adds = []; let removes = []; roleList.forEach(roleItem => { if (rows.filter(row => row.id == roleItem.role_id).length == 0) { - removes.push(roleItem.role_id); + removes.push(roleItem.id); } }); rows.forEach(row => { @@ -345,8 +350,56 @@ export default { this.saveRoleSetting({ adds, removes }); }); }, - confirmPermission() { - console.log(this.$refs.xPermissionTable.getCheckboxRecords()) + + savePermission({ adds, removes }) { + if(!adds.length && !removes.length){ + return; + } + let userCustomCreateRequest = []; + adds.forEach(id => { + userCustomCreateRequest.push({ + "permission_code": id, + "target_uid": this.currentRow.uid + }); + }) + + this.$mk.post({ + url: this.actions.savePermission, + data: { + ids: removes, + userCustomCreateRequest: userCustomCreateRequest + } + }).then(a => { + this.$mk.success(a.msg); + }).catch(a=>{ + this.$mk.error(a.data.msg); + }) + }, + confirmPermission() { + let rows = this.$refs.xPermissionTable.getCheckboxRecords(); + rows = rows.filter(row=>row.permission_code); + + this.$mk.post({ + url: this.actions.userPermissionList, + data: { + target_uid: this.currentRow.uid + } + }).then(a => { + let customList = a.data.UserCustom || []; + let adds = []; + let removes = []; + customList.forEach(customItem => { + if (rows.filter(row => row.permission_code == customItem.permission_code).length == 0) { + removes.push(customItem.id); + } + }); + rows.forEach(row => { + if (customList.filter(customItem => row.permission_code == customItem.permission_code).length == 0) { + adds.push(row.permission_code); + } + }) + this.savePermission({ adds, removes }); + }); }, roleDataInit() { this.$mk.post({ @@ -385,7 +438,8 @@ export default { parentId: "s-" + item.service_id, nodeTitle: item.title, service_id: item.service_id, - permission_id: item.id + permission_id: item.id, + permission_code: item.permission_code }) }); this.permissionData = arr; @@ -432,14 +486,14 @@ export default { this.$mk.post({ url: this.actions.userPermissionList, data: { - targe_uid: row.uid + target_uid: row.uid } }).then(a => { this.showPermission = true; let rows = []; - console.log(a.data.UserCustom) + let uesrCustom = a.data.UserCustom || []; this.permissionData.forEach(item => { - if (a.data.UserCustom.filter(customerItem => item.id == customerItem.permission_id).length) { + if (uesrCustom.filter(customerItem => item.permission_code == customerItem.permission_code).length) { rows.push(item); } }) diff --git a/src/pages/BaseAdmin/BaseRole/list.vue b/src/pages/BaseAdmin/BaseRole/list.vue index cd9da6e..80feaf9 100644 --- a/src/pages/BaseAdmin/BaseRole/list.vue +++ b/src/pages/BaseAdmin/BaseRole/list.vue @@ -38,8 +38,28 @@ + + + + + @@ -58,9 +78,18 @@ export default { keyName: 'id', actions: { getList: `${BASE_URL.BASE_URL}/BasePermission/v1/role/list`, - delete: `${BASE_URL.BASE_URL}/BasePermission/v1/role/batchDelete` + delete: `${BASE_URL.BASE_URL}/BasePermission/v1/role/batchDelete`, + + permissionList: `${BASE_URL.BASE_URL}/BasePermission/v1/service/permission/list`, + rolePermissionList: `${BASE_URL.BASE_URL}/BasePermission/v1/role/permission/list`, + savePermission: `${BASE_URL.BASE_URL}/BasePermission/v1/role/permission/batchHandle`, }, + permissionData: [], + + showPermission: false, + currentRow: null, + start_time: 0, end_time: 0, @@ -130,6 +159,7 @@ export default { { type: 'checkbox', width: 50 }, { type: 'seq', width: 50 }, { title: '操作', slots: { default: 'op' },width:120 }, + { title: '权限设置', slots: { default: 'op3' }, width: 120 }, { field: 'name', sortable: true, title: '名称' }, { field: 'desc', sortable: true, title: '描述', showHeaderOverflow: true } ] @@ -150,6 +180,8 @@ export default { // 将表格和工具栏进行关联 this.$refs.xGrid.connect(this.$refs.xToolbar) }); + + this.permissionDataInit(); }, // 监听 - 页面每次【加载时】执行 onLoad() { @@ -242,6 +274,121 @@ export default { }) }, + savePermission({ adds, removes }) { + if(!adds.length && !removes.length){ + return; + } + let rolePermissionCreateRequest = []; + adds.forEach(id => { + rolePermissionCreateRequest.push({ + "permission_code": id, + "role_id": this.currentRow.id + }); + }) + + this.$mk.post({ + url: this.actions.savePermission, + data: { + ids: removes, + rolePermissionCreateRequest: rolePermissionCreateRequest + } + }).then(a => { + this.$mk.success(a.msg); + }).catch(a=>{ + this.$mk.error(a.data.msg); + }) + }, + confirmPermission() { + let rows = this.$refs.xPermissionTable.getCheckboxRecords(); + rows = rows.filter(row=>row.permission_code); + + this.$mk.post({ + url: this.actions.rolePermissionList, + data: { + role_id: this.currentRow.id + } + }).then(a => { + let customList = a.data.RolePermission || []; + let adds = []; + let removes = []; + customList.forEach(customItem => { + if (rows.filter(row => row.permission_code == customItem.permission_code).length == 0) { + removes.push(customItem.id); + } + }); + rows.forEach(row => { + if (customList.filter(customItem => row.permission_code == customItem.permission_code).length == 0) { + adds.push(row.permission_code); + } + }) + this.savePermission({ adds, removes }); + }); + }, + permissionDataInit() { + + this.$mk.post({ + url: this.actions.permissionList, + data: { + } + }).then(a => { + let arr = []; + a.data.BasePermission.forEach(item => { + if (arr.filter(a => a.id == "s-" + item.service_id).length) { + return; + } + arr.push({ + id: "s-" + item.service_id, + parentId: null, + nodeTitle: item.service + }) + }); + a.data.BasePermission.forEach(item => { + + arr.push({ + id: item.id, + parentId: "s-" + item.service_id, + nodeTitle: item.title, + service_id: item.service_id, + permission_id: item.id, + permission_code: item.permission_code + }) + }); + this.permissionData = arr; + + }).catch((a) => { + this.$mk.error(a.data.msg); + }); + }, + pagePermission(row) { + if (!row) { + this.$mk.msg("请选择行"); + return; + } + this.currentRow = row; + this.$mk.post({ + url: this.actions.rolePermissionList, + data: { + role_id: row.id + } + }).then(a => { + this.showPermission = true; + let rows = []; + let rolePermission = a.data.RolePermission || []; + this.permissionData.forEach(item => { + if (rolePermission.filter(customerItem => item.permission_code == customerItem.permission_code).length) { + rows.push(item); + } + }) + + setTimeout(() => { + this.$refs.xPermissionTable.clearCheckboxRow(); + this.$refs.xPermissionTable.setCheckboxRow(rows, true); + }, 100); + + }); + + + }, pageDelete(row) {