QueueJobLog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <div class="queue-job-log-container">
  3. <!-- 搜索区域 -->
  4. <el-card shadow="never" class="search-card">
  5. <el-form :model="searchForm" inline>
  6. <el-form-item label="任务名称">
  7. <el-input
  8. v-model="searchForm.name"
  9. placeholder="请输入任务名称"
  10. clearable
  11. style="width: 240px"
  12. @keyup.enter="handleSearch"
  13. />
  14. </el-form-item>
  15. <el-form-item label="执行状态">
  16. <el-select
  17. v-model="searchForm.success"
  18. placeholder="请选择状态"
  19. clearable
  20. style="width: 150px"
  21. >
  22. <el-option label="成功" :value="1" />
  23. <el-option label="失败" :value="0" />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="执行时间">
  27. <el-date-picker
  28. v-model="searchForm.date_range"
  29. type="daterange"
  30. range-separator="-"
  31. start-placeholder="开始日期"
  32. end-placeholder="结束日期"
  33. value-format="YYYY-MM-DD HH:mm:ss"
  34. :default-time="[new Date(2000, 0, 1, 0, 0, 0), new Date(2000, 0, 1, 23, 59, 59)]"
  35. style="width: 360px"
  36. />
  37. </el-form-item>
  38. <el-form-item>
  39. <el-button type="primary" @click="handleSearch">
  40. <el-icon><Search /></el-icon>
  41. 搜索
  42. </el-button>
  43. <el-button @click="handleReset">
  44. <el-icon><Refresh /></el-icon>
  45. 重置
  46. </el-button>
  47. </el-form-item>
  48. </el-form>
  49. </el-card>
  50. <!-- 统计卡片 -->
  51. <el-row :gutter="16" class="stats-row">
  52. <el-col :span="6">
  53. <el-card shadow="never">
  54. <div class="stat-item">
  55. <div class="stat-label">总执行次数</div>
  56. <div class="stat-value">{{ stats.total }}</div>
  57. </div>
  58. </el-card>
  59. </el-col>
  60. <el-col :span="6">
  61. <el-card shadow="never">
  62. <div class="stat-item">
  63. <div class="stat-label">成功次数</div>
  64. <div class="stat-value stat-success">{{ stats.success_count }}</div>
  65. </div>
  66. </el-card>
  67. </el-col>
  68. <el-col :span="6">
  69. <el-card shadow="never">
  70. <div class="stat-item">
  71. <div class="stat-label">失败次数</div>
  72. <div class="stat-value stat-fail">{{ stats.fail_count }}</div>
  73. </div>
  74. </el-card>
  75. </el-col>
  76. <el-col :span="6">
  77. <el-card shadow="never">
  78. <div class="stat-item">
  79. <div class="stat-label">成功率</div>
  80. <div class="stat-value">{{ stats.success_rate }}%</div>
  81. </div>
  82. </el-card>
  83. </el-col>
  84. </el-row>
  85. <!-- 表格区域 -->
  86. <el-card shadow="never" class="table-card">
  87. <template #header>
  88. <div class="card-header">
  89. <span>日志列表</span>
  90. <div class="header-actions">
  91. <el-button
  92. type="danger"
  93. :disabled="selectedIds.length === 0"
  94. @click="handleBatchDelete"
  95. >
  96. 批量删除
  97. </el-button>
  98. <el-button
  99. type="danger"
  100. plain
  101. @click="handleClearAll"
  102. >
  103. 清空所有日志
  104. </el-button>
  105. </div>
  106. </div>
  107. </template>
  108. <el-table
  109. v-loading="loading"
  110. :data="tableData"
  111. border
  112. stripe
  113. @selection-change="handleSelectionChange"
  114. >
  115. <el-table-column type="selection" width="50" align="center" />
  116. <el-table-column prop="id" label="ID" width="80" align="center" />
  117. <el-table-column prop="name" label="任务名称" min-width="240" show-overflow-tooltip />
  118. <el-table-column prop="connection" label="连接" width="100" align="center" />
  119. <el-table-column prop="queue" label="队列" width="100" align="center" />
  120. <el-table-column prop="attempts" label="尝试次数" width="100" align="center" />
  121. <el-table-column prop="duration" label="执行耗时" width="120" align="center">
  122. <template #default="{ row }">
  123. {{ row.duration ? row.duration + 's' : '-' }}
  124. </template>
  125. </el-table-column>
  126. <el-table-column prop="success" label="执行结果" width="100" align="center">
  127. <template #default="{ row }">
  128. <el-tag :type="row.success ? 'success' : 'danger'" size="small">
  129. {{ row.success ? '成功' : '失败' }}
  130. </el-tag>
  131. </template>
  132. </el-table-column>
  133. <el-table-column prop="exception" label="异常信息" min-width="200" show-overflow-tooltip>
  134. <template #default="{ row }">
  135. <span v-if="row.exception" class="exception-text">{{ row.exception }}</span>
  136. <span v-else>-</span>
  137. </template>
  138. </el-table-column>
  139. <el-table-column prop="create_time" label="执行时间" width="180" align="center" />
  140. <el-table-column label="操作" width="100" align="center" fixed="right">
  141. <template #default="{ row }">
  142. <el-button
  143. type="danger"
  144. link
  145. size="small"
  146. @click="handleDelete(row)"
  147. >
  148. 删除
  149. </el-button>
  150. </template>
  151. </el-table-column>
  152. </el-table>
  153. <!-- 分页 -->
  154. <div class="pagination-wrapper">
  155. <el-pagination
  156. v-model:current-page="pagination.page"
  157. v-model:page-size="pagination.list_rows"
  158. :total="pagination.total"
  159. :page-sizes="[10, 15, 30, 50, 100]"
  160. layout="total, sizes, prev, pager, next, jumper"
  161. @size-change="handleSizeChange"
  162. @current-change="handlePageChange"
  163. />
  164. </div>
  165. </el-card>
  166. </div>
  167. </template>
  168. <script setup>
  169. import { ref, onMounted, reactive } from 'vue'
  170. import { ElMessage, ElMessageBox } from 'element-plus'
  171. import { Search, Refresh } from '@element-plus/icons-vue'
  172. import { getQueueJobLogList, deleteQueueJobLog, batchDeleteQueueJobLog, clearAllQueueJobLog } from '../api'
  173. const loading = ref(false)
  174. const tableData = ref([])
  175. const selectedIds = ref([])
  176. const searchForm = reactive({
  177. name: '',
  178. success: null,
  179. date_range: []
  180. })
  181. const pagination = reactive({
  182. page: 1,
  183. list_rows: 15,
  184. total: 0
  185. })
  186. const stats = reactive({
  187. total: 0,
  188. success_count: 0,
  189. fail_count: 0,
  190. success_rate: 0
  191. })
  192. const getList = async () => {
  193. loading.value = true
  194. try {
  195. const params = {
  196. page: pagination.page,
  197. list_rows: pagination.list_rows,
  198. name: searchForm.name
  199. }
  200. if (searchForm.success !== null && searchForm.success !== '') {
  201. params.success = searchForm.success
  202. }
  203. if (searchForm.date_range && searchForm.date_range.length === 2) {
  204. params.start_time = searchForm.date_range[0]
  205. params.end_time = searchForm.date_range[1]
  206. }
  207. const res = await getQueueJobLogList(params)
  208. if (res.code === 200) {
  209. tableData.value = res.page?.data || []
  210. pagination.total = res.page?.total || 0
  211. const s = res.data || {}
  212. stats.total = s.total || 0
  213. stats.success_count = s.success_count || 0
  214. stats.fail_count = s.fail_count || 0
  215. stats.success_rate = stats.total > 0 ? parseFloat((stats.success_count / stats.total * 100).toFixed(4)) : 0
  216. }
  217. } catch (e) {
  218. console.error('获取日志列表失败:', e)
  219. } finally {
  220. loading.value = false
  221. }
  222. }
  223. const handleSearch = () => {
  224. pagination.page = 1
  225. getList()
  226. }
  227. const handleReset = () => {
  228. searchForm.name = ''
  229. searchForm.success = null
  230. searchForm.date_range = []
  231. pagination.page = 1
  232. getList()
  233. }
  234. const handlePageChange = () => {
  235. getList()
  236. }
  237. const handleSizeChange = () => {
  238. pagination.page = 1
  239. getList()
  240. }
  241. const handleSelectionChange = (selection) => {
  242. selectedIds.value = selection.map(item => item.id)
  243. }
  244. const handleDelete = (row) => {
  245. ElMessageBox.confirm(
  246. `确定要删除任务「${row.name}」的这条执行日志吗?`,
  247. '删除确认',
  248. {
  249. confirmButtonText: '确定',
  250. cancelButtonText: '取消',
  251. type: 'warning'
  252. }
  253. ).then(async () => {
  254. try {
  255. const res = await deleteQueueJobLog(row.id)
  256. if (res.code === 200) {
  257. ElMessage.success('删除成功')
  258. getList()
  259. }
  260. } catch (e) {
  261. console.error('删除失败:', e)
  262. }
  263. }).catch(() => {})
  264. }
  265. const handleBatchDelete = () => {
  266. if (selectedIds.value.length === 0) return
  267. ElMessageBox.confirm(
  268. `确定要删除选中的 ${selectedIds.value.length} 条日志吗?`,
  269. '批量删除确认',
  270. {
  271. confirmButtonText: '确定',
  272. cancelButtonText: '取消',
  273. type: 'warning'
  274. }
  275. ).then(async () => {
  276. try {
  277. const res = await batchDeleteQueueJobLog(selectedIds.value)
  278. if (res.code === 200) {
  279. ElMessage.success('批量删除成功')
  280. selectedIds.value = []
  281. getList()
  282. }
  283. } catch (e) {
  284. console.error('批量删除失败:', e)
  285. }
  286. }).catch(() => {})
  287. }
  288. const handleClearAll = () => {
  289. ElMessageBox.confirm(
  290. '确定要清空所有队列任务执行日志吗?此操作不可恢复!',
  291. '清空确认',
  292. {
  293. confirmButtonText: '确定清空',
  294. cancelButtonText: '取消',
  295. type: 'warning',
  296. confirmButtonClass: 'el-button--danger'
  297. }
  298. ).then(async () => {
  299. try {
  300. const res = await clearAllQueueJobLog()
  301. if (res.code === 200) {
  302. ElMessage.success('清空成功')
  303. pagination.page = 1
  304. getList()
  305. }
  306. } catch (e) {
  307. console.error('清空失败:', e)
  308. }
  309. }).catch(() => {})
  310. }
  311. onMounted(() => {
  312. getList()
  313. })
  314. </script>
  315. <style scoped lang="scss">
  316. .queue-job-log-container {
  317. padding: 0;
  318. }
  319. .stats-row {
  320. margin-bottom: 16px;
  321. .stat-item {
  322. text-align: center;
  323. }
  324. .stat-label {
  325. font-size: 14px;
  326. color: #909399;
  327. margin-bottom: 8px;
  328. }
  329. .stat-value {
  330. font-size: 28px;
  331. font-weight: 600;
  332. color: #303133;
  333. }
  334. .stat-success {
  335. color: #67c23a;
  336. }
  337. .stat-fail {
  338. color: #f56c6c;
  339. }
  340. }
  341. .search-card {
  342. margin-bottom: 16px;
  343. }
  344. .table-card {
  345. .card-header {
  346. display: flex;
  347. justify-content: space-between;
  348. align-items: center;
  349. }
  350. }
  351. .pagination-wrapper {
  352. display: flex;
  353. justify-content: flex-end;
  354. margin-top: 16px;
  355. }
  356. .exception-text {
  357. color: #f56c6c;
  358. }
  359. </style>