Kaynağa Gözat

修改分配菜单全选 角色删除功能

DESKTOP-227F4HN\Zt 2 yıl önce
ebeveyn
işleme
6faeabfbb4

+ 9 - 0
chuanyi-admin/src/api/system/role.js

@@ -86,3 +86,12 @@ export function delDistributionMenu(data) {
     data
   })
 }
+
+// 批量删除角色
+export function delRolesById(data) {
+  return request({
+    url: '/role/deleteRoleByIds',
+    method: 'post',
+    data
+  })
+}

+ 13 - 20
chuanyi-admin/src/views/system/role/index.vue

@@ -128,7 +128,6 @@
                 type="text"
                 icon="el-icon-delete"
                 :disabled="!multiple"
-
                 @click="handleDelete(scope.row)"
               >删除</el-button>
               <el-button
@@ -216,7 +215,7 @@
 </template>
 
 <script>
-import { getRoleList, addRoleInfo, updateRoleInfo, delRoleById } from '@/api/system/role'
+import { getRoleList, addRoleInfo, updateRoleInfo, delRolesById } from '@/api/system/role'
 
 export default {
   name: 'Index',
@@ -293,7 +292,7 @@ export default {
     },
     /** 多选框选中数据 */
     handleSelectionChange(selection) {
-      this.ids = selection.map(item => item.userId)
+      this.ids = selection.map(item => item.id)
       this.multiple = !selection.length
     },
     /** 查询用户列表 */
@@ -324,14 +323,7 @@ export default {
           cancelButtonClass: 'btn_custom_cancel',
           type: 'warning'
         }).then(() => {
-          for (const i in roleIdList) {
-            const id = roleIdList[i]
-            delRoleById({
-              'roleId': id
-            }).then(response => {
-              this.getRoleList()
-            })
-          }
+          this.delRolesById(roleIdList)
         }).catch(() => {
           this.$refs.roleTable.clearSelection()
         })
@@ -343,18 +335,19 @@ export default {
         cancelButtonClass: 'btn_custom_cancel',
         type: 'warning'
       }).then(() => {
-        delRoleById({
-          roleId
-        }).then(response => {
-          this.$message({
-            message: '删除成功',
-            type: 'success'
-          })
-          this.getRoleList()
-        })
+        this.delRolesById([roleId])
       }).catch(() => {
       })
     },
+    /** 删除角色请求 */
+    delRolesById(ids) {
+      delRolesById(ids).then(res => {
+        this.$message({
+          message: '批量删除成功',
+          type: 'success'
+        })
+      })
+    },
     /** 修改按钮操作 */
     handleUpdate(row) {
       this.reset()

+ 5 - 1
chuanyi-admin/src/views/system/role/user-menu.vue

@@ -335,18 +335,22 @@ export default {
     },
     // 选中父节点时,子节点一起选中取消
     select(selection, row) {
+      // 选中
       if (
         selection.some((el) => {
           return row.id === el.id
         })
       ) {
+        console.log(selection, row)
+        // 选中行有children
         if (row.children.length) {
-          // 解决子节点没有被勾选到
+          // 全选children
           this.setChildren(row.children, true)
         } else {
           this.findParentNode(this.addMenuList, selection, row)
         }
       } else {
+        // 反选
         // 子节点有children全选中
         if (row.children.length) {
           this.setChildren(row.children, false)