index.vue 6.4 KB

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