index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <doc-alert title="定时任务" url="https://doc.iocoder.cn/job/" />
  3. <doc-alert title="异步任务" url="https://doc.iocoder.cn/async-task/" />
  4. <doc-alert title="消息队列" url="https://doc.iocoder.cn/message-queue/" />
  5. <ContentWrap>
  6. <!-- 搜索工作栏 -->
  7. <el-form
  8. class="-mb-15px"
  9. :model="queryParams"
  10. ref="queryFormRef"
  11. :inline="true"
  12. label-width="120px"
  13. >
  14. <el-form-item label="处理器的名字" prop="handlerName">
  15. <el-input
  16. v-model="queryParams.handlerName"
  17. placeholder="请输入处理器的名字"
  18. clearable
  19. @keyup.enter="handleQuery"
  20. class="!w-240px"
  21. />
  22. </el-form-item>
  23. <el-form-item label="开始执行时间" prop="beginTime">
  24. <el-date-picker
  25. v-model="queryParams.beginTime"
  26. type="date"
  27. value-format="YYYY-MM-DD HH:mm:ss"
  28. placeholder="选择开始执行时间"
  29. clearable
  30. class="!w-240px"
  31. />
  32. </el-form-item>
  33. <el-form-item label="结束执行时间" prop="endTime">
  34. <el-date-picker
  35. v-model="queryParams.endTime"
  36. type="date"
  37. value-format="YYYY-MM-DD HH:mm:ss"
  38. placeholder="选择结束执行时间"
  39. clearable
  40. :default-time="new Date('1 23:59:59')"
  41. class="!w-240px"
  42. />
  43. </el-form-item>
  44. <el-form-item label="任务状态" prop="status">
  45. <el-select
  46. v-model="queryParams.status"
  47. placeholder="请选择任务状态"
  48. clearable
  49. class="!w-240px"
  50. >
  51. <el-option
  52. v-for="dict in getIntDictOptions(DICT_TYPE.INFRA_JOB_LOG_STATUS)"
  53. :key="dict.value"
  54. :label="dict.label"
  55. :value="dict.value"
  56. />
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item>
  60. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  61. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  62. <el-button
  63. type="success"
  64. plain
  65. @click="handleExport"
  66. :loading="exportLoading"
  67. v-hasPermi="['infra:job:export']"
  68. >
  69. <Icon icon="ep:download" class="mr-5px" /> 导出
  70. </el-button>
  71. </el-form-item>
  72. </el-form>
  73. </ContentWrap>
  74. <!-- 列表 -->
  75. <ContentWrap>
  76. <el-table v-loading="loading" :data="list">
  77. <el-table-column label="日志编号" align="center" prop="id" />
  78. <el-table-column label="任务编号" align="center" prop="jobId" />
  79. <el-table-column label="处理器的名字" align="center" prop="handlerName" />
  80. <el-table-column label="处理器的参数" align="center" prop="handlerParam" />
  81. <el-table-column label="第几次执行" align="center" prop="executeIndex" />
  82. <el-table-column label="执行时间" align="center" width="170s">
  83. <template #default="scope">
  84. <span>{{ formatDate(scope.row.beginTime) + ' ~ ' + formatDate(scope.row.endTime) }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="执行时长" align="center" prop="duration">
  88. <template #default="scope">
  89. <span>{{ scope.row.duration + ' 毫秒' }}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="任务状态" align="center" prop="status">
  93. <template #default="scope">
  94. <dict-tag :type="DICT_TYPE.INFRA_JOB_LOG_STATUS" :value="scope.row.status" />
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="操作" align="center">
  98. <template #default="scope">
  99. <el-button
  100. type="primary"
  101. link
  102. @click="openDetail(scope.row.id)"
  103. v-hasPermi="['infra:job:query']"
  104. >
  105. 详细
  106. </el-button>
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <!-- 分页组件 -->
  111. <Pagination
  112. :total="total"
  113. v-model:page="queryParams.pageNo"
  114. v-model:limit="queryParams.pageSize"
  115. @pagination="getList"
  116. />
  117. </ContentWrap>
  118. <!-- 表单弹窗:查看 -->
  119. <JobLogDetail ref="detailRef" />
  120. </template>
  121. <script setup lang="ts" name="InfraJobLog">
  122. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  123. import { formatDate } from '@/utils/formatTime'
  124. import download from '@/utils/download'
  125. import JobLogDetail from './JobLogDetail.vue'
  126. import * as JobLogApi from '@/api/infra/jobLog'
  127. const message = useMessage() // 消息弹窗
  128. const { query } = useRoute() // 查询参数
  129. const loading = ref(true) // 列表的加载中
  130. const total = ref(0) // 列表的总页数
  131. const list = ref([]) // 列表的数据
  132. const queryParams = reactive({
  133. pageNo: 1,
  134. pageSize: 10,
  135. jobId: query.id,
  136. handlerName: undefined,
  137. beginTime: undefined,
  138. endTime: undefined,
  139. status: undefined
  140. })
  141. const queryFormRef = ref() // 搜索的表单
  142. const exportLoading = ref(false) // 导出的加载中
  143. /** 查询列表 */
  144. const getList = async () => {
  145. loading.value = true
  146. try {
  147. const data = await JobLogApi.getJobLogPage(queryParams)
  148. list.value = data.list
  149. total.value = data.total
  150. } finally {
  151. loading.value = false
  152. }
  153. }
  154. /** 搜索按钮操作 */
  155. const handleQuery = () => {
  156. queryParams.pageNo = 1
  157. getList()
  158. }
  159. /** 重置按钮操作 */
  160. const resetQuery = () => {
  161. queryFormRef.value.resetFields()
  162. handleQuery()
  163. }
  164. /** 查看操作 */
  165. const detailRef = ref()
  166. const openDetail = (rowId?: number) => {
  167. detailRef.value.open(rowId)
  168. }
  169. /** 导出按钮操作 */
  170. const handleExport = async () => {
  171. try {
  172. // 导出的二次确认
  173. await message.exportConfirm()
  174. // 发起导出
  175. exportLoading.value = true
  176. const data = await JobLogApi.exportJobLog(queryParams)
  177. download.excel(data, '定时任务执行日志.xls')
  178. } catch {
  179. } finally {
  180. exportLoading.value = false
  181. }
  182. }
  183. /** 初始化 **/
  184. onMounted(() => {
  185. getList()
  186. })
  187. </script>