data.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="dictCode" :request-api="getTableList" :init-param="initParam">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['system/dict:data:add']" @click="openDialog(1, '字典数据新增')">新增</el-button>
  7. <el-button type="primary" v-auth="['system/dict:data: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="View" v-auth="['system/dict:data:query']" @click="openDialog(3, '字典数据查看', scope.row)">
  22. 查看
  23. </el-button>
  24. <el-button type="primary" link icon="EditPen" v-auth="['system/dict:data:edit']" @click="openDialog(2, '字典数据编辑', scope.row)">
  25. 编辑
  26. </el-button>
  27. <el-button type="primary" link icon="Delete" v-auth="['system/dict:data:remove']" @click="deleteDictData(scope.row)"> 删除 </el-button>
  28. </template>
  29. </ProTable>
  30. <FormDialog ref="formDialogRef" />
  31. <ImportExcel ref="dialogRef" />
  32. </div>
  33. </template>
  34. <script setup lang="tsx" name="Data">
  35. import { ref, reactive } from 'vue'
  36. import { useHandleData } from '@/hooks/useHandleData'
  37. import { useDownload } from '@/hooks/useDownload'
  38. import { ElMessageBox } from 'element-plus'
  39. import ProTable from '@/components/ProTable/index.vue'
  40. import ImportExcel from '@/components/ImportExcel/index.vue'
  41. import FormDialog from '@/components/FormDialog/index.vue'
  42. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  43. import { listDataApi, delDataApi, addDataApi, updateDataApi, getDataApi, exportApi } from '@/api/modules/system/dictData'
  44. import { getDictApi } from '@/api/modules/system/dict'
  45. import { useRoute } from 'vue-router'
  46. const route = useRoute()
  47. // ProTable 实例
  48. const proTable = ref<ProTableInstance>()
  49. // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
  50. const initParam = reactive({})
  51. // 数据标签回显样式
  52. const listClassOptions = ref([
  53. { value: 'default', label: '默认' },
  54. { value: 'primary', label: '主要' },
  55. { value: 'success', label: '成功' },
  56. { value: 'info', label: '信息' },
  57. { value: 'warning', label: '警告' },
  58. { value: 'danger', label: '危险' }
  59. ])
  60. const defaultDictType = ref('')
  61. const getTableList = async (params: any) => {
  62. const res = await getDictApi(route.params && (route.params.dictId as string))
  63. params.dictType = res.data.dictType
  64. defaultDictType.value = res.data.dictType
  65. return listDataApi(params)
  66. }
  67. // 删除用户信息
  68. const deleteDictData = async (params: any) => {
  69. await useHandleData(delDataApi, params.dictCode, `删除【${params.dictLabel}】字典数据`)
  70. proTable.value?.getTableList()
  71. }
  72. // 批量删除用户信息
  73. const batchDelete = async (ids: string[]) => {
  74. await useHandleData(delDataApi, ids, '删除所选字典数据信息')
  75. proTable.value?.clearSelection()
  76. proTable.value?.getTableList()
  77. }
  78. // 导出用户列表
  79. const downloadFile = async () => {
  80. ElMessageBox.confirm('确认导出字典数据数据?', '温馨提示', { type: 'warning' }).then(() =>
  81. useDownload(exportApi, '字典数据列表', proTable.value?.searchParam)
  82. )
  83. }
  84. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  85. // 打开弹框的功能
  86. const openDialog = async (type: number, title: string, row?: any) => {
  87. let res = { data: {} }
  88. if (row?.dictCode) {
  89. res = await getDataApi(row?.dictCode || null)
  90. }
  91. setItemsOptions()
  92. const params = {
  93. title,
  94. width: 500,
  95. isEdit: type !== 3,
  96. itemsOptions: itemsOptions,
  97. model: type == 1 ? { dictType: defaultDictType.value, version: 0 } : { ...res.data, version: 0 },
  98. api: type == 1 ? addDataApi : updateDataApi,
  99. getTableList: proTable.value?.getTableList
  100. }
  101. formDialogRef.value?.openDialog(params)
  102. }
  103. // 表格配置项
  104. const columns = reactive<ColumnProps<any>[]>([
  105. { type: 'selection', fixed: 'left', width: 70 },
  106. { prop: 'dictCode', label: '字典编码' },
  107. {
  108. prop: 'dictLabel',
  109. label: '数据标签',
  110. search: {
  111. el: 'input'
  112. },
  113. width: 120
  114. },
  115. {
  116. prop: 'dictSort',
  117. label: '显示排序排序',
  118. search: {
  119. el: 'input'
  120. },
  121. width: 120
  122. },
  123. {
  124. prop: 'dictValue',
  125. label: '数据键值',
  126. search: {
  127. el: 'input'
  128. },
  129. width: 120
  130. },
  131. {
  132. prop: 'cssClass',
  133. label: '样式属性',
  134. search: {
  135. el: 'input'
  136. },
  137. width: 120
  138. },
  139. {
  140. prop: 'createTime',
  141. label: '创建时间',
  142. width: 120
  143. },
  144. {
  145. prop: 'remark',
  146. label: '备注',
  147. width: 120
  148. },
  149. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  150. ])
  151. // 表单配置项
  152. let itemsOptions: ProForm.ItemsOptions[] = []
  153. const setItemsOptions = () => {
  154. itemsOptions = [
  155. {
  156. label: '标签类型',
  157. prop: 'dictType',
  158. compOptions: {
  159. disabled: true
  160. }
  161. },
  162. {
  163. label: '数据标签',
  164. prop: 'dictLabel',
  165. rules: [{ required: true, message: '数据标签不能为空', trigger: 'blur' }],
  166. compOptions: {
  167. placeholder: '请输入数据标签'
  168. }
  169. },
  170. {
  171. label: '数据键值',
  172. prop: 'dictValue',
  173. rules: [{ required: true, message: '数据键值不能为空', trigger: 'blur' }],
  174. compOptions: {
  175. placeholder: '请输入数据键值'
  176. }
  177. },
  178. {
  179. label: '显示排序',
  180. prop: 'dictSort',
  181. rules: [{ required: true, message: '显示排序不能为空', trigger: 'blur' }],
  182. compOptions: {
  183. elTagName: 'input-number',
  184. min: 0,
  185. placeholder: '请输入显示排序'
  186. }
  187. },
  188. {
  189. label: '样式属性',
  190. prop: 'cssClass',
  191. compOptions: {
  192. placeholder: '请输入样式属性'
  193. }
  194. },
  195. {
  196. label: '回显样式',
  197. prop: 'listClass',
  198. compOptions: {
  199. elTagName: 'select',
  200. enum: listClassOptions,
  201. valueKey: 'value',
  202. labelKey: 'label',
  203. placeholder: '请输入回显样式'
  204. }
  205. },
  206. {
  207. label: '备注',
  208. prop: 'remark',
  209. compOptions: {
  210. type: 'textarea',
  211. placeholder: '请输入备注'
  212. }
  213. }
  214. ]
  215. }
  216. </script>