index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <script setup lang="ts">
  2. import { ref, unref } from 'vue'
  3. import dayjs from 'dayjs'
  4. import { DICT_TYPE } from '@/utils/dict'
  5. import { useTable } from '@/hooks/web/useTable'
  6. import { useI18n } from '@/hooks/web/useI18n'
  7. import { FormExpose } from '@/components/Form'
  8. import type { FileConfigVO } from '@/api/infra/fileConfig/types'
  9. import { rules, allSchemas } from './fileConfig.data'
  10. import * as FileConfigApi from '@/api/infra/fileConfig'
  11. import { useMessage } from '@/hooks/web/useMessage'
  12. const message = useMessage()
  13. const { t } = useI18n() // 国际化
  14. // ========== 列表相关 ==========
  15. const { register, tableObject, methods } = useTable<FileConfigVO>({
  16. getListApi: FileConfigApi.getFileConfigPageApi,
  17. delListApi: FileConfigApi.deleteFileConfigApi
  18. })
  19. const { getList, setSearchParams, delList } = methods
  20. // ========== CRUD 相关 ==========
  21. const actionLoading = ref(false) // 遮罩层
  22. const actionType = ref('') // 操作按钮的类型
  23. const dialogVisible = ref(false) // 是否显示弹出层
  24. const dialogTitle = ref('edit') // 弹出层标题
  25. const formRef = ref<FormExpose>() // 表单 Ref
  26. // 设置标题
  27. const setDialogTile = (type: string) => {
  28. dialogTitle.value = t('action.' + type)
  29. actionType.value = type
  30. dialogVisible.value = true
  31. }
  32. // 新增操作
  33. const handleCreate = () => {
  34. setDialogTile('create')
  35. // 重置表单
  36. unref(formRef)?.getElFormRef()?.resetFields()
  37. }
  38. // 修改操作
  39. const handleUpdate = async (row: FileConfigVO) => {
  40. setDialogTile('update')
  41. // 设置数据
  42. const res = await FileConfigApi.getFileConfigApi(row.id)
  43. unref(formRef)?.setValues(res)
  44. }
  45. // 主配置操作
  46. const handleMaster = (row: FileConfigVO) => {
  47. message
  48. .confirm('是否确认修改配置【 ' + row.name + ' 】为主配置?', t('common.reminder'))
  49. .then(async () => {
  50. await FileConfigApi.updateFileConfigMasterApi(row.id)
  51. await getList()
  52. })
  53. }
  54. // 提交按钮
  55. const submitForm = async () => {
  56. actionLoading.value = true
  57. // 提交请求
  58. try {
  59. const data = unref(formRef)?.formModel as FileConfigVO
  60. if (actionType.value === 'create') {
  61. await FileConfigApi.createFileConfigApi(data)
  62. message.success(t('common.createSuccess'))
  63. } else {
  64. await FileConfigApi.updateFileConfigApi(data)
  65. message.success(t('common.updateSuccess'))
  66. }
  67. // 操作成功,重新加载列表
  68. dialogVisible.value = false
  69. await getList()
  70. } finally {
  71. actionLoading.value = false
  72. }
  73. }
  74. // ========== 详情相关 ==========
  75. const detailRef = ref() // 详情 Ref
  76. // 详情操作
  77. const handleDetail = async (row: FileConfigVO) => {
  78. // 设置数据
  79. detailRef.value = row
  80. setDialogTile('detail')
  81. }
  82. // ========== 初始化 ==========
  83. getList()
  84. </script>
  85. <template>
  86. <!-- 搜索工作区 -->
  87. <ContentWrap>
  88. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  89. </ContentWrap>
  90. <ContentWrap>
  91. <!-- 操作工具栏 -->
  92. <div class="mb-10px">
  93. <el-button type="primary" v-hasPermi="['infra:file-config:create']" @click="handleCreate">
  94. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
  95. </el-button>
  96. </div>
  97. <!-- 列表 -->
  98. <Table
  99. :columns="allSchemas.tableColumns"
  100. :selection="false"
  101. :data="tableObject.tableList"
  102. :loading="tableObject.loading"
  103. :pagination="{
  104. total: tableObject.total
  105. }"
  106. v-model:pageSize="tableObject.pageSize"
  107. v-model:currentPage="tableObject.currentPage"
  108. @register="register"
  109. >
  110. <template #storage="{ row }">
  111. <DictTag :type="DICT_TYPE.INFRA_FILE_STORAGE" :value="row.storage" />
  112. </template>
  113. <template #primary="{ row }">
  114. <DictTag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.master" />
  115. </template>
  116. <template #createTime="{ row }">
  117. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  118. </template>
  119. <template #action="{ row }">
  120. <el-button
  121. link
  122. type="primary"
  123. v-hasPermi="['infra:file-config:update']"
  124. @click="handleUpdate(row)"
  125. >
  126. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  127. </el-button>
  128. <el-button
  129. link
  130. type="primary"
  131. v-hasPermi="['infra:file-config:update']"
  132. @click="handleDetail(row)"
  133. >
  134. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  135. </el-button>
  136. <el-button
  137. link
  138. type="primary"
  139. v-hasPermi="['infra:file-config:update']"
  140. @click="handleMaster(row)"
  141. >
  142. <Icon icon="ep:flag" class="mr-1px" /> 主配置
  143. </el-button>
  144. <el-button
  145. link
  146. type="primary"
  147. v-hasPermi="['infra:file-config:update']"
  148. @click="handleUpdate(row)"
  149. >
  150. <Icon icon="ep:share" class="mr-1px" /> {{ t('action.test') }}
  151. </el-button>
  152. <el-button
  153. link
  154. type="primary"
  155. v-hasPermi="['infra:file-config:delete']"
  156. @click="delList(row.id, false)"
  157. >
  158. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  159. </el-button>
  160. </template>
  161. </Table>
  162. </ContentWrap>
  163. <Dialog v-model="dialogVisible" :title="dialogTitle">
  164. <!-- 对话框(添加 / 修改) -->
  165. <Form
  166. v-if="['create', 'update'].includes(actionType)"
  167. :schema="allSchemas.formSchema"
  168. :rules="rules"
  169. ref="formRef"
  170. />
  171. <!-- 对话框(详情) -->
  172. <Descriptions
  173. v-if="actionType === 'detail'"
  174. :schema="allSchemas.detailSchema"
  175. :data="detailRef"
  176. >
  177. <template #storage="{ row }">
  178. <DictTag :type="DICT_TYPE.INFRA_FILE_STORAGE" :value="row.storage" />
  179. </template>
  180. <template #primary="{ row }">
  181. <DictTag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.master" />
  182. </template>
  183. <template #createTime="{ row }">
  184. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  185. </template>
  186. </Descriptions>
  187. <!-- 操作按钮 -->
  188. <template #footer>
  189. <el-button
  190. v-if="['create', 'update'].includes(actionType)"
  191. type="primary"
  192. :loading="actionLoading"
  193. @click="submitForm"
  194. >
  195. {{ t('action.save') }}
  196. </el-button>
  197. <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
  198. </template>
  199. </Dialog>
  200. </template>