index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="roleId" :request-api="listRoleApi" :init-param="initParam">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['system:role:add']" :icon="CirclePlus" @click="openDialog(1, '角色信息新增')">
  7. 新增
  8. </el-button>
  9. <el-button type="primary" v-auth="['system:role:import']" :icon="Upload" plain @click="batchAdd"> 导入 </el-button>
  10. <el-button type="primary" v-auth="['system:role:export']" :icon="Download" plain @click="downloadFile"> 导出 </el-button>
  11. <el-button
  12. type="danger"
  13. v-auth="['system:user:remove']"
  14. :icon="Delete"
  15. plain
  16. :disabled="!scope.isSelected"
  17. @click="batchDelete(scope.selectedListIds)"
  18. >
  19. 批量删除
  20. </el-button>
  21. </template>
  22. <!-- 表格操作 -->
  23. <template #operation="scope">
  24. <el-button
  25. type="primary"
  26. link
  27. :icon="EditPen"
  28. v-auth="['system:role:edit']"
  29. @click="openDialog(2, '角色信息编辑', scope.row)"
  30. >
  31. 编辑
  32. </el-button>
  33. <el-button
  34. type="primary"
  35. link
  36. :icon="View"
  37. v-auth="['system:role:query']"
  38. @click="openDialog(3, '角色信息查看', scope.row)"
  39. >
  40. 查看
  41. </el-button>
  42. <el-button type="primary" link :icon="Delete" v-auth="['system:role:remove']" @click="deleteRole(scope.row)">
  43. 删除
  44. </el-button>
  45. </template>
  46. </ProTable>
  47. <FormDialog ref="formDialogRef" />
  48. <ImportExcel ref="dialogRef" />
  49. </div>
  50. </template>
  51. <script setup lang="tsx" name="Role">
  52. import { ref, reactive } from 'vue'
  53. import { useHandleData } from '@/hooks/useHandleData'
  54. import { useDownload } from '@/hooks/useDownload'
  55. import { ElMessageBox } from 'element-plus'
  56. import ProTable from '@/components/ProTable/index.vue'
  57. import ImportExcel from '@/components/ImportExcel/index.vue'
  58. import FormDialog from '@/components/FormDialog/index.vue'
  59. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  60. import { Delete, EditPen, Download, Upload, View, CirclePlus } from '@element-plus/icons-vue'
  61. import {
  62. listRoleApi,
  63. delRoleApi,
  64. addRoleApi,
  65. updateRoleApi,
  66. importTemplateApi,
  67. importDataApi,
  68. exportApi,
  69. getRoleApi
  70. } from '@/api/modules/system/role'
  71. // ProTable 实例
  72. const proTable = ref<ProTableInstance>()
  73. // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
  74. const initParam = reactive({ type: 1 })
  75. // 删除角色信息信息
  76. const deleteRole = async (params: any) => {
  77. await useHandleData(delRoleApi, params.roleId, `删除编号为【${params.roleId}】角色信息`)
  78. proTable.value?.getTableList()
  79. }
  80. // 批量删除角色信息信息
  81. const batchDelete = async (ids: string[]) => {
  82. await useHandleData(delRoleApi, ids, '删除所选角色信息信息')
  83. proTable.value?.clearSelection()
  84. proTable.value?.getTableList()
  85. }
  86. // 导出角色信息列表
  87. const downloadFile = async () => {
  88. ElMessageBox.confirm('确认导出角色信息数据?', '温馨提示', { type: 'warning' }).then(() =>
  89. useDownload(exportApi, '角色信息列表', proTable.value?.searchParam)
  90. )
  91. }
  92. // 批量添加角色信息
  93. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  94. const batchAdd = () => {
  95. const params = {
  96. title: '角色信息',
  97. tempApi: importTemplateApi,
  98. importApi: importDataApi,
  99. getTableList: proTable.value?.getTableList
  100. }
  101. dialogRef.value?.acceptParams(params)
  102. }
  103. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  104. // 打开弹框的功能
  105. const openDialog = async (type: number, title: string, row?: any) => {
  106. let res = { data: {} }
  107. if (row?.roleId) {
  108. res = await getRoleApi(row?.roleId || null)
  109. }
  110. // 重置表单
  111. setFormItems()
  112. const params = {
  113. title,
  114. width: 580,
  115. isEdit: type !== 3, // 是否编辑
  116. itemsOptions: formItems,
  117. model: type == 1 ? {} : res.data, // 表单数据
  118. api: type == 1 ? addRoleApi : updateRoleApi, // 提交api
  119. getTableList: proTable.value?.getTableList // 刷新表格
  120. }
  121. formDialogRef.value?.openDialog(params)
  122. }
  123. // 表格配置项
  124. const columns = reactive<ColumnProps<any>[]>([
  125. { type: 'selection', fixed: 'left', width: 70 },
  126. { prop: 'roleId', label: '角色编号' },
  127. {
  128. prop: 'roleName',
  129. label: '角色名称',
  130. search: {
  131. el: 'input'
  132. }
  133. },
  134. {
  135. prop: 'roleKey',
  136. label: '角色权限字符串',
  137. search: {
  138. el: 'input'
  139. }
  140. },
  141. {
  142. prop: 'roleSort',
  143. label: '显示顺序',
  144. search: {
  145. el: 'input'
  146. }
  147. },
  148. {
  149. prop: 'status',
  150. label: '角色状态',
  151. search: {
  152. el: 'input'
  153. }
  154. },
  155. {
  156. prop: 'createTime',
  157. label: '创建时间',
  158. search: {
  159. el: 'date-picker',
  160. props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  161. }
  162. },
  163. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  164. ])
  165. let formItems: ProForm.ItemsOptions[] = []
  166. const setFormItems = () => {
  167. formItems = [
  168. {
  169. label: '角色名称',
  170. prop: 'roleName',
  171. rules: [{ required: true, message: '角色名称不能为空', trigger: 'blur' }],
  172. compOptions: {
  173. placeholder: '请输入角色名称'
  174. }
  175. },
  176. {
  177. label: '角色权限字符串',
  178. prop: 'roleKey',
  179. rules: [{ required: true, message: '角色权限字符串不能为空', trigger: 'blur' }],
  180. compOptions: {
  181. placeholder: '请输入角色权限字符串'
  182. }
  183. },
  184. {
  185. label: '显示顺序',
  186. prop: 'roleSort',
  187. rules: [{ required: true, message: '显示顺序不能为空', trigger: 'blur' }],
  188. compOptions: {
  189. placeholder: '请输入显示顺序'
  190. }
  191. },
  192. {
  193. label: '数据范围',
  194. prop: 'dataScope',
  195. compOptions: {
  196. placeholder: '请输入数据范围'
  197. }
  198. },
  199. {
  200. label: '菜单树选择项是否关联显示',
  201. prop: 'menuCheckStrictly',
  202. compOptions: {
  203. placeholder: '请输入菜单树选择项是否关联显示'
  204. }
  205. },
  206. {
  207. label: '部门树选择项是否关联显示',
  208. prop: 'deptCheckStrictly',
  209. compOptions: {
  210. placeholder: '请输入部门树选择项是否关联显示'
  211. }
  212. },
  213. {
  214. label: '角色状态',
  215. prop: 'status',
  216. rules: [{ required: true, message: '角色状态不能为空', trigger: 'blur' }],
  217. compOptions: {
  218. placeholder: '请输入角色状态'
  219. }
  220. },
  221. {
  222. label: '备注',
  223. prop: 'remark',
  224. compOptions: {
  225. placeholder: '请输入备注'
  226. }
  227. }
  228. ]
  229. }
  230. </script>