Newer
Older
KaiFengPC / src / views / system / role / selectUser.vue
@zhangdeliang zhangdeliang on 3 Sep 4 KB update
  1. <template>
  2. <!-- 授权用户 -->
  3. <el-dialog title="选择用户" v-model="visible" width="800px" top="5vh" append-to-body>
  4. <el-form :model="queryParams" ref="queryRef" :inline="true">
  5. <el-form-item label="用户名称" prop="userName">
  6. <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable style="width: 200px" @keyup.enter="handleQuery" />
  7. </el-form-item>
  8. <el-form-item label="手机号码" prop="phonenumber">
  9. <el-input
  10. v-model="queryParams.phonenumber"
  11. placeholder="请输入手机号码"
  12. clearable
  13. style="width: 200px"
  14. @keyup.enter="handleQuery"
  15. />
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  19. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  20. </el-form-item>
  21. </el-form>
  22. <el-row>
  23. <el-table @row-click="clickRow" ref="refTable" :data="userList" @selection-change="handleSelectionChange" height="260px">
  24. <el-table-column type="selection" width="55"></el-table-column>
  25. <el-table-column label="用户名称" prop="userName" show-overflow-tooltip />
  26. <el-table-column label="用户昵称" prop="nickName" show-overflow-tooltip />
  27. <el-table-column label="邮箱" prop="email" show-overflow-tooltip />
  28. <el-table-column label="手机" prop="phonenumber" show-overflow-tooltip />
  29. <el-table-column label="状态" prop="status">
  30. <template #default="scope">
  31. <dict-tag :options="sys_normal_disable" :value="scope.row.status" />
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="创建时间" prop="createTime" width="180">
  35. <template #default="scope">
  36. <span>{{ parseTime(scope.row.createTime) }}</span>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. <pagination
  41. v-show="total > 0"
  42. :total="total"
  43. v-model:page="queryParams.pageNum"
  44. v-model:limit="queryParams.pageSize"
  45. @pagination="getList"
  46. />
  47. </el-row>
  48. <template #footer>
  49. <div class="dialog-footer">
  50. <el-button type="info" @click="visible = false">取 消</el-button>
  51. <el-button type="primary" @click="handleSelectUser">确 定</el-button>
  52. </div>
  53. </template>
  54. </el-dialog>
  55. </template>
  56.  
  57. <script setup name="SelectUser">
  58. import { authUserSelectAll, unallocatedUserList } from '@/api/system/role';
  59.  
  60. const props = defineProps({
  61. roleId: {
  62. type: [Number, String],
  63. },
  64. });
  65.  
  66. const { proxy } = getCurrentInstance();
  67. const { sys_normal_disable } = proxy.useDict('sys_normal_disable');
  68.  
  69. const userList = ref([]);
  70. const visible = ref(false);
  71. const total = ref(0);
  72. const userIds = ref([]);
  73.  
  74. const queryParams = reactive({
  75. pageNum: 1,
  76. pageSize: 10,
  77. roleId: undefined,
  78. userName: undefined,
  79. phonenumber: undefined,
  80. });
  81.  
  82. // 显示弹框
  83. function show() {
  84. queryParams.roleId = props.roleId;
  85. getList();
  86. visible.value = true;
  87. }
  88. /**选择行 */
  89. function clickRow(row) {
  90. proxy.$refs['refTable'].toggleRowSelection(row);
  91. }
  92. // 多选框选中数据
  93. function handleSelectionChange(selection) {
  94. userIds.value = selection.map(item => item.userId);
  95. }
  96. // 搜索表数据
  97. function getList() {
  98. unallocatedUserList(queryParams).then(res => {
  99. userList.value = res.data;
  100. total.value = res.total;
  101. });
  102. }
  103. /** 搜索按钮操作 */
  104. function handleQuery() {
  105. queryParams.pageNum = 1;
  106. getList();
  107. }
  108. /** 重置按钮操作 */
  109. function resetQuery() {
  110. proxy.resetForm('queryRef');
  111. handleQuery();
  112. }
  113. const emit = defineEmits(['ok']);
  114. /** 选择授权用户操作 */
  115. function handleSelectUser() {
  116. const roleId = queryParams.roleId;
  117. const uIds = userIds.value.join(',');
  118. if (uIds == '') {
  119. proxy.$modal.msgError('请选择要分配的用户');
  120. return;
  121. }
  122. authUserSelectAll({ roleId: roleId, userIds: uIds }).then(res => {
  123. proxy.$modal.msgSuccess(res.msg);
  124. if (res.code === 200) {
  125. visible.value = false;
  126. emit('ok');
  127. }
  128. });
  129. }
  130.  
  131. defineExpose({
  132. show,
  133. });
  134. </script>