authUser.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 {
  34. allocatedUserListApi,
  35. unallocatedUserListApi,
  36. authUserSelectAllApi,
  37. authUserCancelApi,
  38. authUserCancelAllApi
  39. } from '@/api/modules/system/role'
  40. import { useRoute } from 'vue-router'
  41. import { useTabsStore } from '@/stores/modules/tabs'
  42. import { getDictsApi } from '@/api/modules/system/dictData'
  43. const tabStore = useTabsStore()
  44. const route = useRoute()
  45. // ProTable 实例
  46. const proTable = ref<ProTableInstance>()
  47. // 如果表格需要初始化请求参数
  48. const initParam = reactive({ roleId: route.params.roleId })
  49. // 批量取消用户授权
  50. const cancelAuthUserAll = async (ids: string[]) => {
  51. await useHandleData(authUserCancelAllApi, { userIds: ids, roleId: route.params.roleId }, '删除所选角色信息信息')
  52. proTable.value?.clearSelection()
  53. proTable.value?.getTableList()
  54. }
  55. // 取消用户授权
  56. const cancelAuthUser = async (params: any) => {
  57. await useHandleData(authUserCancelApi, { userId: params.userId, roleId: route.params.roleId }, `删除【${params.userName}】角色信息`)
  58. proTable.value?.getTableList()
  59. }
  60. // 批量添加
  61. const tableDialogRef = ref<InstanceType<typeof TableDialog> | null>(null)
  62. const addUser = () => {
  63. const params = {
  64. title: '选择用户',
  65. width: 880,
  66. toolButton: false,
  67. columns: subColumns,
  68. initParam: { roleId: route.params.roleId },
  69. apiParam: val => {
  70. const userIds = val.map((item: any) => item.userId)
  71. return {
  72. userIds,
  73. roleId: route.params.roleId
  74. }
  75. },
  76. rowKey: 'userId',
  77. api: authUserSelectAllApi,
  78. getTableList: unallocatedUserListApi,
  79. backTableList: allocatedUserListApi
  80. }
  81. tableDialogRef.value?.openDialog(params)
  82. }
  83. // 表格弹框提交
  84. const submitForm = () => {
  85. proTable.value?.getTableList()
  86. }
  87. const closeCurrentTab = () => {
  88. if (route.meta.affix) return
  89. tabStore.removeTabs(route.fullPath)
  90. }
  91. // 表格配置项
  92. const columns = reactive<ColumnProps<any>[]>([
  93. { type: 'selection', fixed: 'left', width: 70 },
  94. {
  95. prop: 'userName',
  96. label: '用户名称',
  97. search: {
  98. el: 'input'
  99. }
  100. },
  101. {
  102. prop: 'nickName',
  103. label: '角色昵称'
  104. },
  105. {
  106. prop: 'email',
  107. label: '邮箱'
  108. },
  109. {
  110. prop: 'phonenumber',
  111. label: '手机',
  112. search: {
  113. el: 'input'
  114. }
  115. },
  116. {
  117. prop: 'status',
  118. label: '状态',
  119. tag: true,
  120. enum: () => getDictsApi('sys_normal_disable'),
  121. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  122. },
  123. {
  124. prop: 'createTime',
  125. label: '创建时间',
  126. search: {
  127. el: 'date-picker',
  128. props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  129. },
  130. width: 120
  131. },
  132. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  133. ])
  134. // 表格配置项
  135. const subColumns: ColumnProps[] = [
  136. { type: 'selection', fixed: 'left', width: 60 },
  137. {
  138. label: '用户名称',
  139. prop: 'userName',
  140. search: {
  141. el: 'input'
  142. }
  143. },
  144. {
  145. label: '用户昵称',
  146. prop: 'nickName'
  147. },
  148. {
  149. label: '邮箱',
  150. prop: 'email'
  151. },
  152. {
  153. label: '手机',
  154. prop: 'phonenumber'
  155. },
  156. {
  157. prop: 'status',
  158. label: '状态',
  159. tag: true,
  160. enum: () => getDictsApi('sys_normal_disable'),
  161. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  162. },
  163. {
  164. prop: 'createTime',
  165. label: '创建时间'
  166. }
  167. ]
  168. </script>