index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <script setup lang="ts">
  2. import { ref, unref } from 'vue'
  3. import dayjs from 'dayjs'
  4. import { ElMessage } 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 { ConfigVO } from '@/api/infra/config/types'
  10. import { rules, allSchemas } from './config.data'
  11. import * as ConfigApi from '@/api/infra/config'
  12. const { t } = useI18n() // 国际化
  13. // ========== 列表相关 ==========
  14. const { register, tableObject, methods } = useTable<ConfigVO>({
  15. getListApi: ConfigApi.getConfigPageApi,
  16. delListApi: ConfigApi.deleteConfigApi,
  17. exportListApi: ConfigApi.exportConfigApi
  18. })
  19. const { getList, setSearchParams, delList, exportList } = 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: ConfigVO) => {
  40. setDialogTile('update')
  41. // 设置数据
  42. const res = await ConfigApi.getConfigApi(row.id)
  43. unref(formRef)?.setValues(res)
  44. }
  45. // 提交按钮
  46. const submitForm = async () => {
  47. actionLoading.value = true
  48. // 提交请求
  49. try {
  50. const data = unref(formRef)?.formModel as ConfigVO
  51. if (actionType.value === 'create') {
  52. await ConfigApi.createConfigApi(data)
  53. ElMessage.success(t('common.createSuccess'))
  54. } else {
  55. await ConfigApi.updateConfigApi(data)
  56. ElMessage.success(t('common.updateSuccess'))
  57. }
  58. // 操作成功,重新加载列表
  59. dialogVisible.value = false
  60. await getList()
  61. } finally {
  62. actionLoading.value = false
  63. }
  64. }
  65. // ========== 详情相关 ==========
  66. const detailRef = ref() // 详情 Ref
  67. // 详情操作
  68. const handleDetail = async (row: ConfigVO) => {
  69. // 设置数据
  70. detailRef.value = row
  71. setDialogTile('detail')
  72. }
  73. // ========== 初始化 ==========
  74. getList()
  75. </script>
  76. <template>
  77. <!-- 搜索工作区 -->
  78. <ContentWrap>
  79. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  80. </ContentWrap>
  81. <ContentWrap>
  82. <!-- 操作工具栏 -->
  83. <div class="mb-10px">
  84. <el-button type="primary" v-hasPermi="['infra:config:create']" @click="handleCreate">
  85. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
  86. </el-button>
  87. <el-button
  88. type="warning"
  89. v-hasPermi="['infra:config:export']"
  90. :loading="tableObject.exportLoading"
  91. @click="exportList('参数配置.xls')"
  92. >
  93. <Icon icon="ep:download" class="mr-5px" /> {{ t('action.export') }}
  94. </el-button>
  95. </div>
  96. <!-- 列表 -->
  97. <Table
  98. :columns="allSchemas.tableColumns"
  99. :selection="false"
  100. :data="tableObject.tableList"
  101. :loading="tableObject.loading"
  102. :pagination="{
  103. total: tableObject.total
  104. }"
  105. v-model:pageSize="tableObject.pageSize"
  106. v-model:currentPage="tableObject.currentPage"
  107. @register="register"
  108. >
  109. <template #visible="{ row }">
  110. <span>{{ row.visible ? '是' : '否' }} </span>
  111. </template>
  112. <template #type="{ row }">
  113. <DictTag :type="DICT_TYPE.INFRA_CONFIG_TYPE" :value="row.type" />
  114. </template>
  115. <template #createTime="{ row }">
  116. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  117. </template>
  118. <template #action="{ row }">
  119. <el-button
  120. link
  121. type="primary"
  122. v-hasPermi="['infra:config:update']"
  123. @click="handleUpdate(row)"
  124. >
  125. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  126. </el-button>
  127. <el-button
  128. link
  129. type="primary"
  130. v-hasPermi="['infra:config:update']"
  131. @click="handleDetail(row)"
  132. >
  133. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  134. </el-button>
  135. <el-button
  136. link
  137. type="primary"
  138. v-hasPermi="['infra:config:delete']"
  139. @click="delList(row.id, false)"
  140. >
  141. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  142. </el-button>
  143. </template>
  144. </Table>
  145. </ContentWrap>
  146. <Dialog v-model="dialogVisible" :title="dialogTitle">
  147. <!-- 对话框(添加 / 修改) -->
  148. <Form
  149. v-if="['create', 'update'].includes(actionType)"
  150. :schema="allSchemas.formSchema"
  151. :rules="rules"
  152. ref="formRef"
  153. />
  154. <!-- 对话框(详情) -->
  155. <Descriptions
  156. v-if="actionType === 'detail'"
  157. :schema="allSchemas.detailSchema"
  158. :data="detailRef"
  159. >
  160. <template #visible="{ row }">
  161. <span>{{ row.visible ? '是' : '否' }} </span>
  162. </template>
  163. <template #type="{ row }">
  164. <DictTag :type="DICT_TYPE.INFRA_CONFIG_TYPE" :value="row.type" />
  165. </template>
  166. <template #createTime="{ row }">
  167. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  168. </template>
  169. </Descriptions>
  170. <!-- 操作按钮 -->
  171. <template #footer>
  172. <el-button
  173. v-if="['create', 'update'].includes(actionType)"
  174. type="primary"
  175. :loading="actionLoading"
  176. @click="submitForm"
  177. >
  178. {{ t('action.save') }}
  179. </el-button>
  180. <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
  181. </template>
  182. </Dialog>
  183. </template>