Pārlūkot izejas kodu

增加批量修改用户角色功能

Guos 1 nedēļu atpakaļ
vecāks
revīzija
a665b04fb8
2 mainītis faili ar 78 papildinājumiem un 38 dzēšanām
  1. 9 0
      src/api/company/companyUser.js
  2. 69 38
      src/views/company/companyUser/index.vue

+ 9 - 0
src/api/company/companyUser.js

@@ -298,3 +298,12 @@ export function unBindDoctorId(userId) {
     method: 'get'
   })
 }
+
+//批量修改用户的角色
+export function updateBatchUserRoles(data) {
+  return request({
+    url: '/company/user/updateBatchUserRoles',
+    method: 'post',
+    data: data
+  })
+}

+ 69 - 38
src/views/company/companyUser/index.vue

@@ -46,6 +46,9 @@
           <el-col :span="1.5">
             <el-button  plain type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['company:user:edit']">修改</el-button>
           </el-col>
+          <el-col :span="1.5">
+            <el-button  plain type="success" icon="el-icon-edit" size="mini" :disabled="multiple" @click="batchEditRole"v-hasPermi="['company:user:edit']">批量修改角色</el-button>
+          </el-col>
           <el-col :span="1.5">
             <el-button  plain type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['company:user:remove']">删除</el-button>
           </el-col>
@@ -240,7 +243,28 @@
         <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
       </el-col>
     </el-row>
-<!--当点击查或换绑微信时候弹出此框-->
+
+    <!-- 批量修改角色对话框 -->
+    <el-dialog title="批量修改角色" :visible.sync="batchRoleDialogVisible" width="500px" append-to-body>
+      <el-form :model="batchRoleForm" label-width="80px">
+        <el-form-item label="选择角色">
+          <el-select v-model="selectedRoleIds" multiple placeholder="请选择角色" style="width: 100%;">
+            <el-option
+              v-for="item in roleOptions"
+              :key="item.roleId"
+              :label="item.roleName"
+              :value="item.roleId">
+            </el-option>
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="batchRoleDialogVisible = false">取 消</el-button>
+        <el-button type="primary" @click="submitBatchRoles">确 定</el-button>
+      </div>
+    </el-dialog>
+
+    <!--当点击查或换绑微信时候弹出此框-->
     <el-dialog title="绑定企微账号"  :visible.sync="qwOpen" width="800px" append-to-body >
       <el-form ref="form" :model="form"  label-width="80px" >
         <el-form-item label="查询"  prop="companyUserId">
@@ -490,10 +514,6 @@
       </div>
     </el-dialog>
 
-<!--    <el-dialog :title="user.title" :visible.sync="user.open" width="1000px" append-to-body>-->
-<!--      <selectUser ref="selectUser" @bindQwUser="bindQwUser"></selectUser>-->
-<!--    </el-dialog>-->
-
     <!-- 修改 selectUser 组件的引用 -->
     <el-dialog :title="user.title" :visible.sync="user.open" width="1000px" append-to-body>
       <selectUser ref="selectUser" @bindQwUser="bindQwUser" @close="handleSelectUserClose"/>
@@ -599,7 +619,7 @@ import {
   generateSubDomain,
   setIsRegisterMember,
   updateCompanyUserAreaList,
-  isAllowedAllRegister, unBindDoctorId, bindDoctorId
+  isAllowedAllRegister, unBindDoctorId, bindDoctorId,updateBatchUserRoles
 } from "@/api/company/companyUser";
 import { getToken } from "@/utils/auth";
 import { treeselect } from "@/api/company/companyDept";
@@ -797,6 +817,13 @@ export default {
       allowedAllRegisterForm: {
         status: true
       },
+      // 在 data() 中添加
+      batchRoleDialogVisible: false,
+      selectedRoleIds: [],
+      batchRoleForm: {
+        userIds: [],
+        roleIds: []
+      },
     };
   },
   watch: {
@@ -863,9 +890,6 @@ export default {
     },
 
     // edit G start
-    // selectQwUser(){
-    //   this.user.open=true;
-    // },
     // 修改 selectQwUser 方法
     selectQwUser() {
       this.user.open = true;
@@ -878,16 +902,6 @@ export default {
       });
     },
 
-    // bindQwUser(row){
-    //   this.user.open=false;
-    //   if (!this.qwUserList.some(item => item.id == row.id)) {
-    //     this.qwUserList.push(row)
-    //   }
-    //   if (!this.qwUser.some(item => item == row.id)) {
-    //     this.qwUser.push(row.id);
-    //   }
-    // },
-
     // 修改 bindQwUser 方法
     bindQwUser(row) {
       // this.user.open = false; // 暂时注释掉这行,改为在 handleBatchBind 中处理
@@ -899,30 +913,11 @@ export default {
       }
     },
 
-    // qwBind(row){
-    //   this.qwUser=[];
-    //   this.qwUserList=[];
-    //   this.qwForm.companyUserId=row.userId
-    //   getUser(row.userId).then((response) => {
-    //     if(response.data.qwUserId!=null){
-    //       this.qwUser=((response.data.qwUserId).split(",").map(Number))
-    //       getQwUserByIds(this.qwUser).then(res => {
-    //         this.qwUserList=res.data;
-    //       })
-    //       // this.qwUser.forEach(item => {
-    //       //     getQwUser(item).then(response => {
-    //       //         this.qwUserList.push(response.data);
-    //       //     });
-    //       // });
-    //     }
-    //     this.qwOpen = true;
-    //   });
     // 修改 qwBind 方法
     qwBind(row) {
       this.qwUser = [];
       this.qwUserList = [];
       this.qwForm.companyUserId = row.userId;
-
       getUser(row.userId).then((response) => {
         if (response.data.qwUserId != null) {
           // 保存已绑定的企微用户ID列表
@@ -936,6 +931,42 @@ export default {
       });
     },
 
+    // 在 methods 中添加批量修改角色的方法
+    batchEditRole() {
+      if (this.ids.length === 0) {
+        this.$message.warning("请至少选择一个用户");
+        return;
+      }
+      // 获取角色列表数据
+      getUser().then((response) => {
+        this.roleOptions = response.roles;
+        this.batchRoleDialogVisible = true;
+        this.selectedRoleIds = []; // 清空之前的选择
+      });
+    },
+
+    // 添加批量角色更新提交方法
+    submitBatchRoles() {
+      // 验证选择的角色
+      if (!this.selectedRoleIds || this.selectedRoleIds.length === 0) {
+        this.$message.warning("请至少选择一个角色");
+        return;
+      }
+      console.log(this.ids)
+      console.log(this.selectedRoleIds)
+
+      // 调用API批量更新用户角色
+      updateBatchUserRoles({ userIds: this.ids, roleIds: this.selectedRoleIds })
+        .then(response => {
+          if (response.code === 200) {
+            this.$message.success("批量修改角色成功");
+            this.batchRoleDialogVisible = false;
+            this.getList(); // 刷新列表
+          }
+        });
+    },
+    // edit G end
+
     /** 查询用户列表 */
     getList() {
       this.loading = true;