Dict.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <script setup lang="ts">
  2. import type { BasicForm, ICRUD } from '@/types/form'
  3. import { getDictList, getDictValue, saveDict, deleteDict, saveDictValue, deleteDictValue } from '@/api/dict'
  4. const CRUD: ICRUD = {
  5. create(data) {
  6. return saveDict(data)
  7. },
  8. update(data) {
  9. return saveDict(data)
  10. },
  11. getList(data) {
  12. return getDictList(data).then((res: any) => {
  13. if (res.rows.length) {
  14. curRow.value = res.rows[0]
  15. }
  16. return {
  17. list: res.rows,
  18. total: res.total
  19. }
  20. })
  21. },
  22. delete(data) {
  23. return deleteDict({ ids: data.id })
  24. },
  25. deleteBatch(data) {
  26. return deleteDict(data)
  27. }
  28. }
  29. const itemCRUD: ICRUD = {
  30. create(data) {
  31. data['dictType.id'] = curRow.value.id
  32. return saveDictValue(data)
  33. },
  34. update(data) {
  35. data['dictType.id'] = curRow.value.id
  36. return saveDictValue({
  37. dictValueId: data.id,
  38. ['dictType.id']: curRow.value.id,
  39. label: data.label,
  40. value: data.value,
  41. sort: data.sort
  42. })
  43. },
  44. getList() {
  45. return getDictValue(curRow.value.id)
  46. },
  47. delete(data) {
  48. return deleteDictValue({ dictValueId: data.id, dictTypeId: curRow.value.id })
  49. }
  50. }
  51. const dictFormConfig = reactive<BasicForm>({
  52. span: 24,
  53. formItems: [
  54. {
  55. label: '字典名称',
  56. value: '',
  57. name: 'description',
  58. type: 'input',
  59. rules: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
  60. search: true
  61. },
  62. {
  63. label: '字典值',
  64. value: '',
  65. name: 'type',
  66. type: 'input',
  67. rules: [{ required: true, message: '请输入字典值', trigger: 'blur' }]
  68. }
  69. ]
  70. })
  71. const curRow = ref<any>(null)
  72. const handleRowClick = ({ row }: { row: any }) => {
  73. console.log(row)
  74. curRow.value = row
  75. }
  76. const rowClassName = ({ row }: { row: any }) => {
  77. if (row.id === curRow.value.id) {
  78. return 'active'
  79. }
  80. }
  81. const itemTableRef = ref<any>(null)
  82. watch(curRow, () => {
  83. itemTableRef.value?.refresh()
  84. })
  85. const dictItemFormConfig = reactive<BasicForm>({
  86. span: 12,
  87. formItems: [
  88. {
  89. label: '标签',
  90. value: '',
  91. name: 'label',
  92. type: 'input',
  93. rules: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
  94. },
  95. {
  96. label: '键值',
  97. value: '',
  98. name: 'value',
  99. type: 'input',
  100. rules: [{ required: true, message: '请输入密码', trigger: 'blur' }]
  101. },
  102. {
  103. label: '排序',
  104. value: '',
  105. name: 'sort',
  106. type: 'input-number',
  107. props: {
  108. maxlength: 11
  109. }
  110. }
  111. ]
  112. })
  113. </script>
  114. <template>
  115. <el-row :gutter="16" class="h-full">
  116. <el-col :span="12" class="h-full">
  117. <pro-table
  118. :crud="CRUD"
  119. :formConfig="dictFormConfig"
  120. :row-class-name="rowClassName"
  121. @cell-click="handleRowClick"
  122. :queryConfig="{ fold: false }"
  123. >
  124. <vxe-column field="description" title="字典名称"></vxe-column>
  125. <vxe-column field="type" title="字典值"></vxe-column>
  126. </pro-table>
  127. </el-col>
  128. <el-col :span="12">
  129. <div class="bg-white h-full">
  130. <pro-table
  131. ref="itemTableRef"
  132. :crud="itemCRUD"
  133. :formConfig="dictItemFormConfig"
  134. :selection="false"
  135. v-if="curRow"
  136. >
  137. <template #header>
  138. <div class="pb-15px mb-20px font-bold" style="border-bottom: 1px solid var(--el-border-color)">
  139. {{ curRow.description }}
  140. </div>
  141. </template>
  142. <vxe-column field="label" title="标签"></vxe-column>
  143. <vxe-column field="value" title="键值"></vxe-column>
  144. </pro-table>
  145. <el-empty v-else description="请选择左侧数据后操作"></el-empty>
  146. </div>
  147. </el-col>
  148. </el-row>
  149. </template>
  150. <style lang="scss" scoped>
  151. :deep(.active) {
  152. background-color: #f5f7fa !important;
  153. .el-table-fixed-column--right {
  154. background-color: #f5f7fa !important;
  155. }
  156. }
  157. </style>