index.vue 6.5 KB

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