authUser.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="userId" :request-api="allocatedUserListApi" :init-param="initParam">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['system:role:add']" :icon="CirclePlus" @click="addUser"> 添加用户 </el-button>
  7. <el-button
  8. type="danger"
  9. v-auth="['system:role:import']"
  10. :disabled="!scope.isSelected"
  11. :icon="CircleClose"
  12. plain
  13. @click="cancelAuthUserAll(scope.selectedListIds)"
  14. >
  15. 批量取消授权
  16. </el-button>
  17. <el-button type="warning" v-auth="['system:role:export']" :icon="Close" plain @click="closeCurrentTab"> 关闭 </el-button>
  18. </template>
  19. <!-- 表格操作 -->
  20. <template #operation="scope">
  21. <el-button type="primary" link :icon="CircleClose" v-auth="['system:role:query']" @click="cancelAuthUser(scope.row)"> 取消授权 </el-button>
  22. </template>
  23. </ProTable>
  24. <TableDialog ref="tableDialogRef" @submit-form="submitForm" />
  25. </div>
  26. </template>
  27. <script setup lang="tsx" name="Role">
  28. import { ref, reactive } from 'vue'
  29. import { useHandleData } from '@/hooks/useHandleData'
  30. import ProTable from '@/components/ProTable/index.vue'
  31. import TableDialog from '@/components/TableDialog/index.vue'
  32. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  33. import { CircleClose, Close, CirclePlus } from '@element-plus/icons-vue'
  34. import {
  35. allocatedUserListApi,
  36. unallocatedUserListApi,
  37. authUserSelectAllApi,
  38. authUserCancelApi,
  39. authUserCancelAllApi
  40. } from '@/api/modules/system/role'
  41. import { useRoute } from 'vue-router'
  42. import { useTabsStore } from '@/stores/modules/tabs'
  43. import { getDictsApi } from '@/api/modules/system/dictData'
  44. const tabStore = useTabsStore()
  45. const route = useRoute()
  46. // ProTable 实例
  47. const proTable = ref<ProTableInstance>()
  48. // 如果表格需要初始化请求参数
  49. const initParam = reactive({ roleId: route.params.roleId })
  50. // 批量取消用户授权
  51. const cancelAuthUserAll = async (ids: string[]) => {
  52. await useHandleData(authUserCancelAllApi, { userIds: ids, roleId: route.params.roleId }, '删除所选角色信息信息')
  53. proTable.value?.clearSelection()
  54. proTable.value?.getTableList()
  55. }
  56. // 取消用户授权
  57. const cancelAuthUser = async (params: any) => {
  58. await useHandleData(authUserCancelApi, { userId: params.userId, roleId: route.params.roleId }, `删除【${params.userName}】角色信息`)
  59. proTable.value?.getTableList()
  60. }
  61. // 批量添加
  62. const tableDialogRef = ref<InstanceType<typeof TableDialog> | null>(null)
  63. const addUser = () => {
  64. const params = {
  65. title: '选择用户',
  66. width: 880,
  67. toolButton: false,
  68. columns: subColumns,
  69. initParam: { roleId: route.params.roleId },
  70. apiParam: val => {
  71. const userIds = val.map((item: any) => item.userId)
  72. return {
  73. userIds,
  74. roleId: route.params.roleId
  75. }
  76. },
  77. rowKey: 'userId',
  78. api: authUserSelectAllApi,
  79. getTableList: unallocatedUserListApi,
  80. backTableList: allocatedUserListApi
  81. }
  82. tableDialogRef.value?.openDialog(params)
  83. }
  84. // 表格弹框提交
  85. const submitForm = () => {
  86. proTable.value?.getTableList()
  87. }
  88. const closeCurrentTab = () => {
  89. if (route.meta.affix) return
  90. tabStore.removeTabs(route.fullPath)
  91. }
  92. // 表格配置项
  93. const columns = reactive<ColumnProps<any>[]>([
  94. { type: 'selection', fixed: 'left', width: 70 },
  95. {
  96. prop: 'userName',
  97. label: '用户名称',
  98. search: {
  99. el: 'input'
  100. }
  101. },
  102. {
  103. prop: 'nickName',
  104. label: '角色昵称'
  105. },
  106. {
  107. prop: 'email',
  108. label: '邮箱'
  109. },
  110. {
  111. prop: 'phonenumber',
  112. label: '手机',
  113. search: {
  114. el: 'input'
  115. }
  116. },
  117. {
  118. prop: 'status',
  119. label: '状态',
  120. tag: true,
  121. enum: () => getDictsApi('sys_normal_disable'),
  122. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  123. },
  124. {
  125. prop: 'createTime',
  126. label: '创建时间',
  127. search: {
  128. el: 'date-picker',
  129. props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  130. },
  131. width: 120
  132. },
  133. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  134. ])
  135. // 表格配置项
  136. const subColumns: ColumnProps[] = [
  137. { type: 'selection', fixed: 'left', width: 60 },
  138. {
  139. label: '用户名称',
  140. prop: 'userName',
  141. search: {
  142. el: 'input'
  143. }
  144. },
  145. {
  146. label: '用户昵称',
  147. prop: 'nickName'
  148. },
  149. {
  150. label: '邮箱',
  151. prop: 'email'
  152. },
  153. {
  154. label: '手机',
  155. prop: 'phonenumber'
  156. },
  157. {
  158. prop: 'status',
  159. label: '状态',
  160. tag: true,
  161. enum: () => getDictsApi('sys_normal_disable'),
  162. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  163. },
  164. {
  165. prop: 'createTime',
  166. label: '创建时间'
  167. }
  168. ]
  169. </script>