index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" :request-api="listDictApi">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['system:dict:add']" @click="openDialog(1, '字典类型新增')">新增</el-button>
  7. <el-button type="primary" v-auth="['system:dict:export']" icon="Download" plain @click="downloadFile">导出</el-button>
  8. <el-button
  9. type="danger"
  10. v-auth="['system:user:remove']"
  11. icon="Delete"
  12. plain
  13. :disabled="!scope.isSelected"
  14. @click="batchDelete(scope.selectedListIds)"
  15. >
  16. 批量删除
  17. </el-button>
  18. </template>
  19. <!-- 表格操作 -->
  20. <template #operation="scope">
  21. <el-button type="primary" link icon="EditPen" v-auth="['system:dict:edit']" @click="openDialog(2, '字典类型编辑', scope.row)">
  22. 编辑
  23. </el-button>
  24. <el-button type="primary" link icon="Delete" v-auth="['system:dict:remove']" @click="deleteDict(scope.row)"> 删除 </el-button>
  25. </template>
  26. </ProTable>
  27. <FormDialog ref="formDialogRef" :items-options="itemsOptions" :model="model" />
  28. <ImportExcel ref="dialogRef" />
  29. </div>
  30. </template>
  31. <script setup lang="tsx" name="Dict">
  32. import { useHandleData } from '@/hooks/useHandleData'
  33. import { useDownload } from '@/hooks/useDownload'
  34. import { ElMessageBox } from 'element-plus'
  35. import ImportExcel from '@/components/ImportExcel/index.vue'
  36. import FormDialog from '@/components/FormDialog/index.vue'
  37. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  38. import { listDictApi, delDictApi, addDictApi, updateDictApi, exportApi, getDictApi } from '@/api/modules/system/dict'
  39. // ProTable 实例
  40. const proTable = ref<ProTableInstance>()
  41. // 表单model
  42. const model = ref({})
  43. // 删除用户信息
  44. const deleteDict = async (params: any) => {
  45. await useHandleData(delDictApi, params.dictId, `删除【${params.dictName}】字典类型`)
  46. proTable.value?.getTableList()
  47. }
  48. // 批量删除用户信息
  49. const batchDelete = async (ids: string[]) => {
  50. await useHandleData(delDictApi, ids, '删除所选字典类型信息')
  51. proTable.value?.clearSelection()
  52. proTable.value?.getTableList()
  53. }
  54. // 导出用户列表
  55. const downloadFile = async () => {
  56. ElMessageBox.confirm('确认导出字典类型数据?', '温馨提示', { type: 'warning' }).then(() =>
  57. useDownload(exportApi, '字典类型列表', proTable.value?.searchParam)
  58. )
  59. }
  60. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  61. // 打开弹框的功能
  62. const openDialog = async (type: number, title: string, row?: any) => {
  63. let res = { data: {} }
  64. if (row?.dictId) {
  65. res = await getDictApi(row?.dictId || null)
  66. }
  67. model.value = type == 1 ? { version: 0 } : { ...res.data, version: 0 }
  68. setItemsOptions()
  69. const params = {
  70. title,
  71. width: 500,
  72. isEdit: type !== 3,
  73. api: type == 1 ? addDictApi : updateDictApi,
  74. getTableList: proTable.value?.getTableList
  75. }
  76. formDialogRef.value?.openDialog(params)
  77. }
  78. const router = useRouter()
  79. // 跳转详情页
  80. const toDetail = (row: { dictId: any }) => {
  81. router.push(`/system/dict-data/index/${row.dictId}`)
  82. }
  83. // 表格配置项
  84. const columns = reactive<ColumnProps<any>[]>([
  85. { type: 'selection', fixed: 'left', width: 70 },
  86. { prop: 'dictId', label: '字典编号', width: 70 },
  87. {
  88. prop: 'dictName',
  89. label: '字典名称',
  90. search: {
  91. el: 'input'
  92. },
  93. width: 120
  94. },
  95. {
  96. prop: 'dictType',
  97. label: '字典类型',
  98. search: {
  99. el: 'input'
  100. },
  101. render: scope => {
  102. return (
  103. <el-button type="primary" link onClick={() => toDetail(scope.row)}>
  104. {scope.row.dictType}
  105. </el-button>
  106. )
  107. },
  108. width: 150
  109. },
  110. {
  111. prop: 'createTime',
  112. label: '创建时间'
  113. },
  114. {
  115. prop: 'remark',
  116. label: '备注',
  117. search: {
  118. el: 'input'
  119. }
  120. },
  121. { prop: 'operation', label: '操作', width: 230 }
  122. ])
  123. // 表单配置项
  124. let itemsOptions = ref<ProForm.ItemsOptions[]>([])
  125. const setItemsOptions = () => {
  126. itemsOptions.value = [
  127. {
  128. label: '字典名称',
  129. prop: 'dictName',
  130. rules: [{ required: true, message: '字典名称不能为空', trigger: 'blur' }],
  131. compOptions: {
  132. placeholder: '请输入字典名称'
  133. }
  134. },
  135. {
  136. label: '字典类型',
  137. prop: 'dictType',
  138. rules: [{ required: true, message: '字典类型不能为空', trigger: 'blur' }],
  139. compOptions: {
  140. placeholder: '请输入字典类型'
  141. }
  142. },
  143. {
  144. label: '备注',
  145. prop: 'remark',
  146. compOptions: {
  147. type: 'textarea',
  148. placeholder: '请输入备注'
  149. }
  150. }
  151. ]
  152. }
  153. </script>