index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. const elForm = unref(formRef)?.getElFormRef()
  57. if (!elForm) return
  58. elForm.validate(async (valid) => {
  59. if (valid) {
  60. actionLoading.value = true
  61. // 提交请求
  62. try {
  63. const data = unref(formRef)?.formModel as FileConfigVO
  64. if (actionType.value === 'create') {
  65. await FileConfigApi.createFileConfigApi(data)
  66. message.success(t('common.createSuccess'))
  67. } else {
  68. await FileConfigApi.updateFileConfigApi(data)
  69. message.success(t('common.updateSuccess'))
  70. }
  71. // 操作成功,重新加载列表
  72. dialogVisible.value = false
  73. await getList()
  74. } finally {
  75. actionLoading.value = false
  76. }
  77. }
  78. })
  79. }
  80. // ========== 详情相关 ==========
  81. const detailRef = ref() // 详情 Ref
  82. // 详情操作
  83. const handleDetail = async (row: FileConfigVO) => {
  84. // 设置数据
  85. detailRef.value = row
  86. setDialogTile('detail')
  87. }
  88. // ========== 初始化 ==========
  89. getList()
  90. </script>
  91. <template>
  92. <!-- 搜索工作区 -->
  93. <ContentWrap>
  94. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  95. </ContentWrap>
  96. <ContentWrap>
  97. <!-- 操作工具栏 -->
  98. <div class="mb-10px">
  99. <el-button type="primary" v-hasPermi="['infra:file-config:create']" @click="handleCreate">
  100. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
  101. </el-button>
  102. </div>
  103. <!-- 列表 -->
  104. <Table
  105. :columns="allSchemas.tableColumns"
  106. :selection="false"
  107. :data="tableObject.tableList"
  108. :loading="tableObject.loading"
  109. :pagination="{
  110. total: tableObject.total
  111. }"
  112. v-model:pageSize="tableObject.pageSize"
  113. v-model:currentPage="tableObject.currentPage"
  114. @register="register"
  115. >
  116. <template #storage="{ row }">
  117. <DictTag :type="DICT_TYPE.INFRA_FILE_STORAGE" :value="row.storage" />
  118. </template>
  119. <template #primary="{ row }">
  120. <DictTag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.master" />
  121. </template>
  122. <template #createTime="{ row }">
  123. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  124. </template>
  125. <template #action="{ row }">
  126. <el-button
  127. link
  128. type="primary"
  129. v-hasPermi="['infra:file-config:update']"
  130. @click="handleUpdate(row)"
  131. >
  132. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  133. </el-button>
  134. <el-button
  135. link
  136. type="primary"
  137. v-hasPermi="['infra:file-config:update']"
  138. @click="handleDetail(row)"
  139. >
  140. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  141. </el-button>
  142. <el-button
  143. link
  144. type="primary"
  145. v-hasPermi="['infra:file-config:update']"
  146. @click="handleMaster(row)"
  147. >
  148. <Icon icon="ep:flag" class="mr-1px" /> 主配置
  149. </el-button>
  150. <el-button
  151. link
  152. type="primary"
  153. v-hasPermi="['infra:file-config:update']"
  154. @click="handleUpdate(row)"
  155. >
  156. <Icon icon="ep:share" class="mr-1px" /> {{ t('action.test') }}
  157. </el-button>
  158. <el-button
  159. link
  160. type="primary"
  161. v-hasPermi="['infra:file-config:delete']"
  162. @click="delList(row.id, false)"
  163. >
  164. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  165. </el-button>
  166. </template>
  167. </Table>
  168. </ContentWrap>
  169. <Dialog v-model="dialogVisible" :title="dialogTitle">
  170. <!-- 对话框(添加 / 修改) -->
  171. <Form
  172. v-if="['create', 'update'].includes(actionType)"
  173. :schema="allSchemas.formSchema"
  174. :rules="rules"
  175. ref="formRef"
  176. />
  177. <!-- 对话框(详情) -->
  178. <Descriptions
  179. v-if="actionType === 'detail'"
  180. :schema="allSchemas.detailSchema"
  181. :data="detailRef"
  182. >
  183. <template #storage="{ row }">
  184. <DictTag :type="DICT_TYPE.INFRA_FILE_STORAGE" :value="row.storage" />
  185. </template>
  186. <template #primary="{ row }">
  187. <DictTag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.master" />
  188. </template>
  189. <template #createTime="{ row }">
  190. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  191. </template>
  192. </Descriptions>
  193. <!-- 操作按钮 -->
  194. <template #footer>
  195. <el-button
  196. v-if="['create', 'update'].includes(actionType)"
  197. type="primary"
  198. :loading="actionLoading"
  199. @click="submitForm"
  200. >
  201. {{ t('action.save') }}
  202. </el-button>
  203. <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
  204. </template>
  205. </Dialog>
  206. </template>