WorkflowExecution.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <div class="execution-container">
  3. <div class="header">
  4. <div>
  5. <h1>{{ t('pages.execution.title') }}</h1>
  6. <p class="subtitle">{{ t('pages.execution.subtitle') }}</p>
  7. </div>
  8. <el-button type="primary" :loading="statsLoading || tableLoading" @click="refresh">
  9. <el-icon><RefreshRight /></el-icon>
  10. {{ t('common.refresh') }}
  11. </el-button>
  12. </div>
  13. <div class="stats-grid">
  14. <div class="stat-card">
  15. <div class="stat-icon">
  16. <SvgIcon name="play" size="20" />
  17. </div>
  18. <div>
  19. <div class="stat-value">{{ stats.runTotal }}</div>
  20. <div class="stat-label">{{ t('pages.execution.stats.recentExecutions') }}</div>
  21. </div>
  22. </div>
  23. <div class="stat-card">
  24. <div class="stat-icon success">
  25. <SvgIcon name="check-circle" size="20" />
  26. </div>
  27. <div>
  28. <div class="stat-value">{{ successRateText }}</div>
  29. <div class="stat-label">{{ t('pages.execution.stats.successRate') }}</div>
  30. </div>
  31. </div>
  32. <div class="stat-card">
  33. <div class="stat-icon warning">
  34. <SvgIcon name="clock" size="20" />
  35. </div>
  36. <div>
  37. <div class="stat-value">{{ stats.avgElapsedSec }}s</div>
  38. <div class="stat-label">{{ t('pages.execution.stats.avgDuration') }}</div>
  39. </div>
  40. </div>
  41. <div class="stat-card">
  42. <div class="stat-icon danger">
  43. <SvgIcon name="x-circle" size="20" />
  44. </div>
  45. <div>
  46. <div class="stat-value">{{ stats.errorTotal }}</div>
  47. <div class="stat-label">{{ t('pages.execution.stats.failedCount') }}</div>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="filters">
  52. <div class="filters-left">
  53. <el-input
  54. v-model="keyword"
  55. :placeholder="t('pages.execution.filters.keyword')"
  56. clearable
  57. class="filter-item"
  58. @keyup.enter="handleSearch"
  59. @clear="handleSearch"
  60. >
  61. <template #prefix>
  62. <el-icon><Search /></el-icon>
  63. </template>
  64. </el-input>
  65. <el-select
  66. v-model="status"
  67. :placeholder="t('pages.execution.filters.status')"
  68. class="filter-item"
  69. clearable
  70. @change="handleSearch"
  71. >
  72. <el-option :label="t('common.all')" value="" />
  73. <el-option :label="t('common.status.running')" value="running" />
  74. <el-option :label="t('common.status.success')" value="finish" />
  75. <el-option :label="t('common.status.failed')" value="error" />
  76. </el-select>
  77. <el-select
  78. v-model="source"
  79. :placeholder="t('pages.execution.filters.source')"
  80. class="filter-item"
  81. clearable
  82. @change="handleSearch"
  83. >
  84. <el-option :label="t('common.all')" value="" />
  85. <el-option :label="t('pages.execution.sources.manual')" value="manual" />
  86. <el-option :label="t('pages.execution.sources.schedule')" value="schedule" />
  87. <el-option :label="t('pages.execution.sources.webhook')" value="webhook" />
  88. <el-option :label="t('pages.execution.sources.api')" value="api" />
  89. </el-select>
  90. <div class="toolbar-actions">
  91. <el-button type="primary" @click="handleSearch">
  92. <el-icon><Search /></el-icon>
  93. {{ t('common.search') }}
  94. </el-button>
  95. <el-button @click="resetFilters">
  96. <el-icon><RefreshRight /></el-icon>
  97. {{ t('common.reset') }}
  98. </el-button>
  99. </div>
  100. </div>
  101. </div>
  102. <div class="panel">
  103. <el-table v-loading="tableLoading" :data="executions" stripe style="width: 100%">
  104. <el-table-column
  105. prop="agentName"
  106. :label="t('pages.execution.table.agentName')"
  107. min-width="220"
  108. show-overflow-tooltip
  109. />
  110. <el-table-column
  111. prop="executionId"
  112. :label="t('pages.execution.table.executionId')"
  113. min-width="260"
  114. show-overflow-tooltip
  115. />
  116. <el-table-column
  117. prop="startedAt"
  118. :label="t('pages.execution.table.startedAt')"
  119. min-width="180"
  120. />
  121. <el-table-column
  122. prop="endedAt"
  123. :label="t('pages.execution.table.endedAt')"
  124. min-width="180"
  125. />
  126. <el-table-column
  127. prop="duration"
  128. :label="t('pages.execution.table.duration')"
  129. min-width="120"
  130. />
  131. <el-table-column prop="source" :label="t('pages.execution.filters.source')" />
  132. <el-table-column :label="t('pages.execution.table.status')">
  133. <template #default="scope">
  134. <el-tag :type="statusType(scope.row.status)">
  135. {{ statusText(scope.row.status) }}
  136. </el-tag>
  137. </template>
  138. </el-table-column>
  139. </el-table>
  140. <div v-if="pagination.totalCount" class="pagination">
  141. <el-pagination
  142. v-model:current-page="pagination.pageIndex"
  143. v-model:page-size="pagination.pageSize"
  144. background
  145. layout="total, prev, pager, next"
  146. :page-sizes="[10, 20, 50, 100]"
  147. :total="pagination.totalCount"
  148. @current-change="handlePageChange"
  149. @size-change="handleSizeChange"
  150. />
  151. </div>
  152. </div>
  153. <div class="side-panels">
  154. <div class="panel">
  155. <div class="panel-title">{{ t('pages.execution.panels.summary') }}</div>
  156. <div class="summary-item" v-for="item in summary" :key="item.label">
  157. <span class="label">{{ item.label }}</span>
  158. <span class="value">{{ item.value }}</span>
  159. </div>
  160. </div>
  161. <div class="panel">
  162. <div class="panel-title">{{ t('pages.execution.panels.tips') }}</div>
  163. <ul class="tips">
  164. <li v-for="item in tips" :key="item">{{ item }}</li>
  165. </ul>
  166. </div>
  167. </div>
  168. </div>
  169. </template>
  170. <script setup lang="ts">
  171. import { computed, onMounted, reactive, ref } from 'vue'
  172. import { ElMessage } from 'element-plus'
  173. import { RefreshRight, Search } from '@element-plus/icons-vue'
  174. import { useI18n } from '@/composables/useI18n'
  175. import { agentLog } from '@repo/api-service'
  176. type AgentRunnerPageResponse = Awaited<ReturnType<typeof agentLog.postAgentGetAgentRunnerPageList>>
  177. type AgentRunnerPageItem = NonNullable<AgentRunnerPageResponse['result']>['model'][number]
  178. interface ExecutionRow {
  179. agentName: string
  180. executionId: string
  181. startedAt: string
  182. endedAt: string
  183. duration: string
  184. status: string
  185. }
  186. const { t } = useI18n()
  187. const keyword = ref('')
  188. const status = ref('')
  189. const source = ref('')
  190. const tableLoading = ref(false)
  191. const statsLoading = ref(false)
  192. const executions = ref<ExecutionRow[]>([])
  193. const pagination = reactive({
  194. pageIndex: 1,
  195. pageSize: 20,
  196. totalCount: 0,
  197. totalPages: 0
  198. })
  199. const stats = reactive({
  200. runTotal: 0,
  201. successTotal: 0,
  202. errorTotal: 0,
  203. processTotal: 0,
  204. avgElapsedSec: 0
  205. })
  206. const sourceMap = {
  207. manual: t('pages.execution.sources.manual'),
  208. schedule: t('pages.execution.sources.schedule'),
  209. webhook: t('pages.execution.sources.webhook'),
  210. api: t('pages.execution.sources.api')
  211. }
  212. const summary = computed(() => [
  213. { label: t('pages.execution.summaryLabels.processing'), value: `${stats.processTotal}` },
  214. { label: t('pages.execution.summaryLabels.success'), value: `${stats.successTotal}` },
  215. { label: t('pages.execution.summaryLabels.failed'), value: `${stats.errorTotal}` }
  216. ])
  217. const tips = computed(() => [
  218. t('pages.execution.tips.0'),
  219. t('pages.execution.tips.1'),
  220. t('pages.execution.tips.2')
  221. ])
  222. const successRateText = computed(() => {
  223. if (!stats.runTotal) return '0%'
  224. return `${((stats.successTotal / stats.runTotal) * 100).toFixed(1)}%`
  225. })
  226. const allStatuses = 'running,finish,error'
  227. const allSources = 'manual,schedule,webhook,api'
  228. const formatDuration = (value?: number | string | null) => {
  229. const duration = Number(value || 0)
  230. if (!Number.isFinite(duration) || duration <= 0) return '-'
  231. if (duration < 1000) return `${Math.round(duration)}ms`
  232. if (duration < 60_000) {
  233. const seconds = duration / 1000
  234. return `${Number.isInteger(seconds) ? seconds.toFixed(0) : seconds.toFixed(1)}s`
  235. }
  236. const minutes = Math.floor(duration / 60_000)
  237. const seconds = Math.round((duration % 60_000) / 1000)
  238. return `${minutes}m ${seconds}s`
  239. }
  240. const normalizeStatus = (value?: string) => `${value || ''}`.trim().toLowerCase()
  241. const getStatusQuery = () => status.value || allStatuses
  242. const getSourceQuery = () => source.value || allSources
  243. const mapExecutionRow = (item: AgentRunnerPageItem): ExecutionRow => ({
  244. agentName: item.agentName || '-',
  245. executionId: item.runnerId || '-',
  246. startedAt: item.beginDate || '-',
  247. endedAt: item.endDate || '-',
  248. duration: formatDuration(item.useTime),
  249. status: normalizeStatus(item.status),
  250. source: sourceMap[item.source]
  251. })
  252. const statusType = (value: string) => {
  253. if (value === 'finish') return 'success'
  254. if (value === 'error') return 'danger'
  255. if (value === 'running') return 'warning'
  256. return 'info'
  257. }
  258. const statusText = (value: string) => {
  259. if (value === 'finish') return t('common.status.success')
  260. if (value === 'error') return t('common.status.failed')
  261. if (value === 'running') return t('common.status.running')
  262. return t('common.status.unknown')
  263. }
  264. const loadStats = async () => {
  265. statsLoading.value = true
  266. try {
  267. const res = await agentLog.postAgentGetBefore7DayAgentRunnerStatic({})
  268. if (!res.isSuccess || !res.result) throw new Error('load stats failed')
  269. const avgElapsedValue = (res.result as typeof res.result & { avg_elapsed_time?: string })
  270. .avg_elapsed_time
  271. stats.runTotal = res.result.run_total || 0
  272. stats.successTotal = res.result.success_total || 0
  273. stats.errorTotal = res.result.error_total || 0
  274. stats.processTotal = res.result.process_total || 0
  275. stats.avgElapsedSec = Number(res.result.avg_elapsed_sec || avgElapsedValue || 0)
  276. } catch (error) {
  277. console.error(error)
  278. ElMessage.error(t('pages.execution.messages.loadStatsFailed'))
  279. } finally {
  280. statsLoading.value = false
  281. }
  282. }
  283. const loadExecutions = async (pageIndex = pagination.pageIndex) => {
  284. tableLoading.value = true
  285. try {
  286. const res = await agentLog.postAgentGetAgentRunnerPageList({
  287. keyword: keyword.value.trim(),
  288. status: getStatusQuery(),
  289. source: getSourceQuery(),
  290. pageIndex,
  291. pageSize: pagination.pageSize
  292. })
  293. if (!res.isSuccess || !res.result) throw new Error('load executions failed')
  294. executions.value = (res.result.model || []).map(mapExecutionRow)
  295. pagination.pageIndex = res.result.currentPage || pageIndex
  296. pagination.pageSize = res.result.pageSize || pagination.pageSize
  297. pagination.totalCount = res.result.totalCount || 0
  298. pagination.totalPages = res.result.totalPages || 0
  299. } catch (error) {
  300. console.error(error)
  301. ElMessage.error(t('pages.execution.messages.loadListFailed'))
  302. } finally {
  303. tableLoading.value = false
  304. }
  305. }
  306. const refresh = async () => {
  307. await Promise.all([loadStats(), loadExecutions(pagination.pageIndex)])
  308. }
  309. const handleSearch = async () => {
  310. pagination.pageIndex = 1
  311. await loadExecutions(1)
  312. }
  313. const handlePageChange = async (page: number) => {
  314. pagination.pageIndex = page
  315. await loadExecutions(page)
  316. }
  317. const handleSizeChange = async (size: number) => {
  318. pagination.pageSize = size
  319. pagination.pageIndex = 1
  320. await loadExecutions(1)
  321. }
  322. const resetFilters = () => {
  323. keyword.value = ''
  324. status.value = ''
  325. source.value = ''
  326. handleSearch()
  327. }
  328. onMounted(() => {
  329. refresh()
  330. })
  331. </script>
  332. <style lang="less" scoped>
  333. .execution-container {
  334. margin: 0 auto;
  335. padding: 24px;
  336. .header {
  337. display: flex;
  338. justify-content: space-between;
  339. align-items: center;
  340. margin-bottom: 24px;
  341. h1 {
  342. font-size: 28px;
  343. margin: 0;
  344. color: var(--text-primary);
  345. }
  346. .subtitle {
  347. margin: 6px 0 0;
  348. color: var(--text-secondary);
  349. font-size: 14px;
  350. }
  351. }
  352. .stats-grid {
  353. display: grid;
  354. grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  355. gap: 16px;
  356. margin-bottom: 20px;
  357. .stat-card {
  358. background: var(--bg-base);
  359. border-radius: 12px;
  360. padding: 18px;
  361. box-shadow: var(--shadow-sm);
  362. display: flex;
  363. gap: 12px;
  364. align-items: center;
  365. .stat-icon {
  366. width: 40px;
  367. height: 40px;
  368. border-radius: 10px;
  369. background: #eef2ff;
  370. color: #4f46e5;
  371. display: flex;
  372. align-items: center;
  373. justify-content: center;
  374. &.success {
  375. background: #ecfdf3;
  376. color: #10b981;
  377. }
  378. &.warning {
  379. background: #fff7ed;
  380. color: #f97316;
  381. }
  382. &.danger {
  383. background: #fef2f2;
  384. color: #ef4444;
  385. }
  386. }
  387. .stat-value {
  388. font-size: 22px;
  389. font-weight: 700;
  390. color: var(--text-primary);
  391. }
  392. .stat-label {
  393. font-size: 13px;
  394. color: var(--text-secondary);
  395. }
  396. }
  397. }
  398. .filters {
  399. display: flex;
  400. flex-wrap: wrap;
  401. gap: 12px;
  402. margin-bottom: 16px;
  403. align-items: center;
  404. justify-content: space-between;
  405. .filters-left {
  406. display: flex;
  407. flex-wrap: wrap;
  408. gap: 12px;
  409. align-items: center;
  410. }
  411. .filter-item {
  412. width: 220px;
  413. }
  414. .toolbar-actions {
  415. display: flex;
  416. align-items: center;
  417. gap: 8px;
  418. .el-button + .el-button {
  419. margin-left: 0;
  420. }
  421. }
  422. }
  423. .panel {
  424. background: var(--bg-base);
  425. border-radius: 12px;
  426. padding: 20px;
  427. box-shadow: var(--shadow-sm);
  428. }
  429. .pagination {
  430. display: flex;
  431. justify-content: flex-end;
  432. margin-top: 16px;
  433. }
  434. .side-panels {
  435. display: grid;
  436. grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  437. gap: 16px;
  438. margin-top: 16px;
  439. .panel-title {
  440. font-size: 16px;
  441. font-weight: 600;
  442. margin-bottom: 12px;
  443. color: var(--text-primary);
  444. }
  445. .summary-item {
  446. display: flex;
  447. justify-content: space-between;
  448. padding: 10px 0;
  449. border-bottom: 1px solid var(--border-light);
  450. .label {
  451. color: var(--text-secondary);
  452. font-size: 13px;
  453. }
  454. .value {
  455. font-weight: 600;
  456. color: var(--text-primary);
  457. }
  458. }
  459. .tips {
  460. margin: 0;
  461. padding-left: 16px;
  462. color: var(--text-secondary);
  463. line-height: 1.6;
  464. font-size: 13px;
  465. }
  466. }
  467. }
  468. </style>