index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
  5. <template #toolbar_buttons>
  6. <!-- 操作:新增 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. :title="t('action.add')"
  11. v-hasPermi="['infra:file-config:create']"
  12. @click="handleCreate()"
  13. />
  14. </template>
  15. <template #actionbtns_default="{ row }">
  16. <XTextButton
  17. preIcon="ep:edit"
  18. :title="t('action.edit')"
  19. v-hasPermi="['infra:file-config:update']"
  20. @click="handleUpdate(row.id)"
  21. />
  22. <XTextButton
  23. preIcon="ep:view"
  24. :title="t('action.detail')"
  25. v-hasPermi="['infra:file-config:query']"
  26. @click="handleDetail(row.id)"
  27. />
  28. <XTextButton
  29. preIcon="ep:flag"
  30. title="主配置"
  31. v-hasPermi="['infra:file-config:update']"
  32. @click="handleMaster(row)"
  33. />
  34. <XTextButton
  35. preIcon="ep:share"
  36. :title="t('action.test')"
  37. v-hasPermi="['infra:file-config:update']"
  38. @click="handleUpdate(row.id)"
  39. />
  40. <XTextButton
  41. preIcon="ep:delete"
  42. :title="t('action.del')"
  43. v-hasPermi="['infra:file-config:delete']"
  44. @click="handleDelete(row.id)"
  45. />
  46. </template>
  47. </vxe-grid>
  48. </ContentWrap>
  49. <XModal v-model="dialogVisible" :title="dialogTitle">
  50. <!-- 对话框(添加 / 修改) -->
  51. <Form
  52. v-if="['create', 'update'].includes(actionType)"
  53. :schema="allSchemas.formSchema"
  54. :rules="rules"
  55. ref="formRef"
  56. />
  57. <!-- 对话框(详情) -->
  58. <Descriptions
  59. v-if="actionType === 'detail'"
  60. :schema="allSchemas.detailSchema"
  61. :data="detailData"
  62. />
  63. <!-- 操作按钮 -->
  64. <template #footer>
  65. <!-- 按钮:保存 -->
  66. <XButton
  67. v-if="['create', 'update'].includes(actionType)"
  68. type="primary"
  69. :title="t('action.save')"
  70. :loading="actionLoading"
  71. @click="submitForm()"
  72. />
  73. <!-- 按钮:关闭 -->
  74. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  75. </template>
  76. </XModal>
  77. </template>
  78. <script setup lang="ts">
  79. // 全局相关的 import
  80. import { ref, unref } from 'vue'
  81. import { useI18n } from '@/hooks/web/useI18n'
  82. import { useMessage } from '@/hooks/web/useMessage'
  83. import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  84. import { VxeGridInstance } from 'vxe-table'
  85. import { FormExpose } from '@/components/Form'
  86. // 业务相关的 import
  87. import * as FileConfigApi from '@/api/infra/fileConfig'
  88. import type { FileConfigVO } from '@/api/infra/fileConfig/types'
  89. import { rules, allSchemas } from './fileConfig.data'
  90. const { t } = useI18n() // 国际化
  91. const message = useMessage() // 消息弹窗
  92. // 列表相关的变量
  93. const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
  94. const { gridOptions, getList, deleteData } = useVxeGrid<FileConfigVO>({
  95. allSchemas: allSchemas,
  96. getListApi: FileConfigApi.getFileConfigPageApi,
  97. deleteApi: FileConfigApi.deleteFileConfigApi
  98. })
  99. // ========== CRUD 相关 ==========
  100. const actionLoading = ref(false) // 遮罩层
  101. const actionType = ref('') // 操作按钮的类型
  102. const dialogVisible = ref(false) // 是否显示弹出层
  103. const dialogTitle = ref('edit') // 弹出层标题
  104. const formRef = ref<FormExpose>() // 表单 Ref
  105. const detailData = ref() // 详情 Ref
  106. // 设置标题
  107. const setDialogTile = (type: string) => {
  108. dialogTitle.value = t('action.' + type)
  109. actionType.value = type
  110. dialogVisible.value = true
  111. }
  112. // 新增操作
  113. const handleCreate = () => {
  114. setDialogTile('create')
  115. }
  116. // 修改操作
  117. const handleUpdate = async (rowId: number) => {
  118. setDialogTile('update')
  119. // 设置数据
  120. const res = await FileConfigApi.getFileConfigApi(rowId)
  121. unref(formRef)?.setValues(res)
  122. }
  123. // 详情操作
  124. const handleDetail = async (rowId: number) => {
  125. setDialogTile('detail')
  126. // 设置数据
  127. const res = await FileConfigApi.getFileConfigApi(rowId)
  128. detailData.value = res
  129. }
  130. // 主配置操作
  131. const handleMaster = (row: FileConfigVO) => {
  132. message
  133. .confirm('是否确认修改配置【 ' + row.name + ' 】为主配置?', t('common.reminder'))
  134. .then(async () => {
  135. await FileConfigApi.updateFileConfigMasterApi(row.id)
  136. await getList(xGrid)
  137. })
  138. }
  139. // 删除操作
  140. const handleDelete = async (rowId: number) => {
  141. await deleteData(xGrid, rowId)
  142. }
  143. // 提交按钮
  144. const submitForm = async () => {
  145. const elForm = unref(formRef)?.getElFormRef()
  146. if (!elForm) return
  147. elForm.validate(async (valid) => {
  148. if (valid) {
  149. actionLoading.value = true
  150. // 提交请求
  151. try {
  152. const data = unref(formRef)?.formModel as FileConfigVO
  153. if (actionType.value === 'create') {
  154. await FileConfigApi.createFileConfigApi(data)
  155. message.success(t('common.createSuccess'))
  156. } else {
  157. await FileConfigApi.updateFileConfigApi(data)
  158. message.success(t('common.updateSuccess'))
  159. }
  160. dialogVisible.value = false
  161. } finally {
  162. actionLoading.value = false
  163. await getList(xGrid)
  164. }
  165. }
  166. })
  167. }
  168. </script>