index.vue 5.3 KB

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