index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <doc-alert title="异常处理(错误码)" url="https://doc.iocoder.cn/exception/" />
  3. <!-- 搜索工作栏 -->
  4. <ContentWrap>
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="90px"
  11. >
  12. <el-form-item label="错误码类型" prop="type">
  13. <el-select v-model="queryParams.type" placeholder="请选择错误码类型" clearable>
  14. <el-option
  15. v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_ERROR_CODE_TYPE)"
  16. :key="dict.value as number"
  17. :label="dict.label"
  18. :value="dict.value"
  19. class="!w-240px"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="应用名" prop="applicationName">
  24. <el-input
  25. v-model="queryParams.applicationName"
  26. placeholder="请输入应用名"
  27. clearable
  28. @keyup.enter="handleQuery"
  29. class="!w-240px"
  30. />
  31. </el-form-item>
  32. <el-form-item label="错误码编码" prop="code">
  33. <el-input
  34. v-model="queryParams.code"
  35. placeholder="请输入错误码编码"
  36. clearable
  37. @keyup.enter="handleQuery"
  38. class="!w-240px"
  39. />
  40. </el-form-item>
  41. <el-form-item label="错误码提示" prop="message">
  42. <el-input
  43. v-model="queryParams.message"
  44. placeholder="请输入错误码提示"
  45. clearable
  46. @keyup.enter="handleQuery"
  47. class="!w-240px"
  48. />
  49. </el-form-item>
  50. <el-form-item label="创建时间" prop="createTime">
  51. <el-date-picker
  52. v-model="queryParams.createTime"
  53. value-format="YYYY-MM-DD HH:mm:ss"
  54. type="daterange"
  55. start-placeholder="开始日期"
  56. end-placeholder="结束日期"
  57. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  58. class="!w-240px"
  59. />
  60. </el-form-item>
  61. <el-form-item>
  62. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  63. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  64. <el-button
  65. type="primary"
  66. plain
  67. @click="openForm('create')"
  68. v-hasPermi="['system:error-code:create']"
  69. >
  70. <Icon icon="ep:plus" class="mr-5px" /> 新增
  71. </el-button>
  72. <el-button
  73. type="success"
  74. plain
  75. @click="handleExport"
  76. :loading="exportLoading"
  77. v-hasPermi="['system:error-code:export']"
  78. >
  79. <Icon icon="ep:download" class="mr-5px" /> 导出
  80. </el-button>
  81. </el-form-item>
  82. </el-form>
  83. </ContentWrap>
  84. <!-- 列表 -->
  85. <ContentWrap>
  86. <el-table v-loading="loading" :data="list">
  87. <el-table-column label="编号" align="center" prop="id" />
  88. <el-table-column label="类型" align="center" prop="type" width="80">
  89. <template #default="scope">
  90. <dict-tag :type="DICT_TYPE.SYSTEM_ERROR_CODE_TYPE" :value="scope.row.type" />
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="应用名" align="center" prop="applicationName" width="200" />
  94. <el-table-column label="错误码编码" align="center" prop="code" width="120" />
  95. <el-table-column label="错误码提示" align="center" prop="message" width="300" />
  96. <el-table-column label="备注" align="center" prop="memo" width="200" />
  97. <el-table-column
  98. label="创建时间"
  99. align="center"
  100. prop="createTime"
  101. width="180"
  102. :formatter="dateFormatter"
  103. />
  104. <el-table-column label="操作" align="center" class-name="small-paddingfixed-width">
  105. <template #default="scope">
  106. <el-button
  107. link
  108. type="primary"
  109. @click="openForm('update', scope.row.id)"
  110. v-hasPermi="['system:error-code:update']"
  111. >
  112. 编辑
  113. </el-button>
  114. <el-button
  115. link
  116. type="danger"
  117. @click="handleDelete(scope.row.id)"
  118. v-hasPermi="['system:error-code:delete']"
  119. >
  120. 删除
  121. </el-button>
  122. </template>
  123. </el-table-column>
  124. </el-table>
  125. <!-- 分页组件 -->
  126. <Pagination
  127. :total="total"
  128. v-model:page="queryParams.pageNo"
  129. v-model:limit="queryParams.pageSize"
  130. @pagination="getList"
  131. />
  132. </ContentWrap>
  133. <!-- 表单弹窗:添加/修改 -->
  134. <ErrorCodeForm ref="formRef" @success="getList" />
  135. </template>
  136. <script lang="ts" setup>
  137. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  138. import { dateFormatter } from '@/utils/formatTime'
  139. import download from '@/utils/download'
  140. import * as ErrorCodeApi from '@/api/system/errorCode'
  141. import ErrorCodeForm from './ErrorCodeForm.vue'
  142. defineOptions({ name: 'SystemErrorCode' })
  143. const message = useMessage() // 消息弹窗
  144. const { t } = useI18n() // 国际化
  145. const loading = ref(true) // 遮罩层
  146. const exportLoading = ref(false) // 导出遮罩层
  147. const total = ref(0) // 总条数
  148. const list = ref([]) // 错误码列表
  149. const queryParams = reactive({
  150. pageNo: 1,
  151. pageSize: 10,
  152. type: undefined,
  153. applicationName: undefined,
  154. code: undefined,
  155. message: undefined,
  156. createTime: []
  157. })
  158. const queryFormRef = ref() // 搜索的表单
  159. /** 查询列表 */
  160. const getList = async () => {
  161. loading.value = true
  162. try {
  163. const data = await ErrorCodeApi.getErrorCodePage(queryParams)
  164. list.value = data.list
  165. total.value = data.total
  166. } finally {
  167. loading.value = false
  168. }
  169. }
  170. /** 搜索按钮操作 */
  171. const handleQuery = () => {
  172. queryParams.pageNo = 1
  173. getList()
  174. }
  175. /** 重置按钮操作 */
  176. const resetQuery = () => {
  177. queryFormRef.value.resetFields()
  178. handleQuery()
  179. }
  180. /** 添加/修改操作 */
  181. const formRef = ref()
  182. const openForm = (type: string, id?: number) => {
  183. formRef.value.open(type, id)
  184. }
  185. /** 删除按钮操作 */
  186. const handleDelete = async (id: number) => {
  187. try {
  188. // 删除的二次确认
  189. await message.delConfirm()
  190. await ErrorCodeApi.deleteErrorCode(id)
  191. message.success(t('common.delSuccess'))
  192. // 刷新列表
  193. await getList()
  194. } catch {}
  195. }
  196. /** 导出按钮操作 */
  197. const handleExport = async () => {
  198. try {
  199. // 导出的二次确认
  200. await message.exportConfirm()
  201. // 发起导出
  202. exportLoading.value = true
  203. const data = await ErrorCodeApi.excelErrorCode(queryParams)
  204. download.excel(data, '错误码.xls')
  205. } catch {
  206. } finally {
  207. exportLoading.value = false
  208. }
  209. }
  210. /** 初始化 **/
  211. onMounted(() => {
  212. getList()
  213. })
  214. </script>