Browse Source

feat(group): add preconditions for deleting groups

deletion is allowed only when there is no account in the group
Casper Dai 3 năm trước cách đây
mục cha
commit
a6b5070635
1 tập tin đã thay đổi với 23 bổ sung7 xóa
  1. 23 7
      src/api/user.js

+ 23 - 7
src/api/user.js

@@ -1,4 +1,5 @@
 import store from '@/store'
+import { Message } from 'element-ui'
 import { Role } from '@/constant'
 import request, { keycloakRequest } from '@/utils/request'
 import {
@@ -199,10 +200,27 @@ export function updateGroup ({ id, name, remark }) {
 }
 
 export function deleteGroup ({ id, label }) {
-  return del({
-    url: `/groups/${id}`,
-    method: 'DELETE'
-  }, label, keycloakRequest)
+  return send({
+    url: `/groups/${id}/members`,
+    method: 'GET',
+    params: {
+      briefRepresentation: true,
+      max: 1,
+      first: 0
+    }
+  }, keycloakRequest).then(data => {
+    if (data.length) {
+      Message({
+        type: 'warning',
+        message: '请先移除部门下的人员'
+      })
+      return Promise.reject()
+    }
+    return del({
+      url: `/groups/${id}`,
+      method: 'DELETE'
+    }, label, keycloakRequest)
+  })
 }
 
 export function getUsersByGroup (query) {
@@ -216,9 +234,7 @@ export function getUsersByGroup (query) {
       first: pageNum ? (pageNum - 1) * max : void 0,
       ...params
     }
-  }).then(data => {
-    return { data }
-  })
+  }).then(data => { return { data } })
 }
 
 export function getUserGroups (id, briefRepresentation = true) {