WorkflowExecution.vue 13 KB

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