QueueJobLog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. // 获取列表
  193. const getList = async () => {
  194. loading.value = true
  195. try {
  196. const params = {
  197. page: pagination.page,
  198. list_rows: pagination.list_rows,
  199. name: searchForm.name
  200. }
  201. if (searchForm.success !== null && searchForm.success !== '') {
  202. params.success = searchForm.success
  203. }
  204. if (searchForm.date_range && searchForm.date_range.length === 2) {
  205. params.start_time = searchForm.date_range[0]
  206. params.end_time = searchForm.date_range[1]
  207. }
  208. const res = await getQueueJobLogList(params)
  209. if (res.code === 200) {
  210. tableData.value = res.page?.data || []
  211. pagination.total = res.page?.total || 0
  212. // 统计数据
  213. const s = res.data || {}
  214. stats.total = s.total || 0
  215. stats.success_count = s.success_count || 0
  216. stats.fail_count = s.fail_count || 0
  217. stats.success_rate = stats.total > 0 ? parseFloat((stats.success_count / stats.total * 100).toFixed(4)) : 0
  218. }
  219. } catch (e) {
  220. console.error('获取日志列表失败:', e)
  221. } finally {
  222. loading.value = false
  223. }
  224. }
  225. // 搜索
  226. const handleSearch = () => {
  227. pagination.page = 1
  228. getList()
  229. }
  230. // 重置
  231. const handleReset = () => {
  232. searchForm.name = ''
  233. searchForm.success = null
  234. searchForm.date_range = []
  235. pagination.page = 1
  236. getList()
  237. }
  238. // 分页
  239. const handlePageChange = () => {
  240. getList()
  241. }
  242. const handleSizeChange = () => {
  243. pagination.page = 1
  244. getList()
  245. }
  246. // 选择变化
  247. const handleSelectionChange = (selection) => {
  248. selectedIds.value = selection.map(item => item.id)
  249. }
  250. // 删除单条
  251. const handleDelete = (row) => {
  252. ElMessageBox.confirm(
  253. `确定要删除任务「${row.name}」的这条执行日志吗?`,
  254. '删除确认',
  255. {
  256. confirmButtonText: '确定',
  257. cancelButtonText: '取消',
  258. type: 'warning'
  259. }
  260. ).then(async () => {
  261. try {
  262. const res = await deleteQueueJobLog(row.id)
  263. if (res.code === 200) {
  264. ElMessage.success('删除成功')
  265. getList()
  266. }
  267. } catch (e) {
  268. console.error('删除失败:', e)
  269. }
  270. }).catch(() => {})
  271. }
  272. // 批量删除
  273. const handleBatchDelete = () => {
  274. if (selectedIds.value.length === 0) return
  275. ElMessageBox.confirm(
  276. `确定要删除选中的 ${selectedIds.value.length} 条日志吗?`,
  277. '批量删除确认',
  278. {
  279. confirmButtonText: '确定',
  280. cancelButtonText: '取消',
  281. type: 'warning'
  282. }
  283. ).then(async () => {
  284. try {
  285. const res = await batchDeleteQueueJobLog(selectedIds.value)
  286. if (res.code === 200) {
  287. ElMessage.success('批量删除成功')
  288. selectedIds.value = []
  289. getList()
  290. }
  291. } catch (e) {
  292. console.error('批量删除失败:', e)
  293. }
  294. }).catch(() => {})
  295. }
  296. // 清空所有
  297. const handleClearAll = () => {
  298. ElMessageBox.confirm(
  299. '确定要清空所有队列任务执行日志吗?此操作不可恢复!',
  300. '清空确认',
  301. {
  302. confirmButtonText: '确定清空',
  303. cancelButtonText: '取消',
  304. type: 'warning',
  305. confirmButtonClass: 'el-button--danger'
  306. }
  307. ).then(async () => {
  308. try {
  309. const res = await clearAllQueueJobLog()
  310. if (res.code === 200) {
  311. ElMessage.success('清空成功')
  312. pagination.page = 1
  313. getList()
  314. }
  315. } catch (e) {
  316. console.error('清空失败:', e)
  317. }
  318. }).catch(() => {})
  319. }
  320. onMounted(() => {
  321. getList()
  322. })
  323. </script>
  324. <style scoped lang="scss">
  325. .queue-job-log-container {
  326. padding: 0;
  327. }
  328. .stats-row {
  329. margin-bottom: 16px;
  330. .stat-item {
  331. text-align: center;
  332. }
  333. .stat-label {
  334. font-size: 14px;
  335. color: #909399;
  336. margin-bottom: 8px;
  337. }
  338. .stat-value {
  339. font-size: 28px;
  340. font-weight: 600;
  341. color: #303133;
  342. }
  343. .stat-success {
  344. color: #67c23a;
  345. }
  346. .stat-fail {
  347. color: #f56c6c;
  348. }
  349. }
  350. .search-card {
  351. margin-bottom: 16px;
  352. }
  353. .table-card {
  354. .card-header {
  355. display: flex;
  356. justify-content: space-between;
  357. align-items: center;
  358. }
  359. }
  360. .pagination-wrapper {
  361. display: flex;
  362. justify-content: flex-end;
  363. margin-top: 16px;
  364. }
  365. .exception-text {
  366. color: #f56c6c;
  367. }
  368. </style>