增强采集监控页面图表展示(Task 13-14)

- 添加 ECharts 图表支持
- 实现采集趋势折线图(近7天成功/失败统计)
- 实现数据源采集分布饼图
- 安装 echarts 和 vue-echarts 依赖

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hughhuangandClaude Opus 4.5 committed 2026-02-05 15:50:29 +08:00
1 parent 457d69799d
commit 07edbca4af
3 files changed
+205 -2

No files matched your search

+38
View File
@@ -11,10 +11,12 @@
"@element-plus/icons-vue": "^2.3.2",
"@types/markdown-it": "^14.1.2",
"axios": "^1.13.4",
"echarts": "^6.0.0",
"element-plus": "^2.13.2",
"markdown-it": "^14.1.0",
"pinia": "^3.0.4",
"vue": "^3.5.24",
"vue-echarts": "^8.0.1",
"vue-router": "^4.6.4"
},
"devDependencies": {
@@ -1415,6 +1417,17 @@
"node": ">= 0.4"
}
},
"node_modules/echarts": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/echarts/-/echarts-6.0.0.tgz",
"integrity": "sha512-Tte/grDQRiETQP4xz3iZWSvoHrkCQtwqd6hs+mifXcjrCuo2iKWbajFObuLJVBlDIJlOzgQPd1hsaKt/3+OMkQ==",
"license": "Apache-2.0",
"peer": true,
"dependencies": {
"tslib": "2.3.0",
"zrender": "6.0.0"
}
},
"node_modules/element-plus": {
"version": "2.13.2",
"resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.13.2.tgz",
@@ -2075,6 +2088,12 @@
"url": "https://github.com/sponsors/SuperchupuDev"
}
},
"node_modules/tslib": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==",
"license": "0BSD"
},
"node_modules/typescript": {
"version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
@@ -2208,6 +2227,16 @@
}
}
},
"node_modules/vue-echarts": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/vue-echarts/-/vue-echarts-8.0.1.tgz",
"integrity": "sha512-23rJTFLu1OUEGRWjJGmdGt8fP+8+ja1gVgzMYPIPaHWpXegcO1viIAaeu2H4QHESlVeHzUAHIxKXGrwjsyXAaA==",
"license": "MIT",
"peerDependencies": {
"echarts": "^6.0.0",
"vue": "^3.3.0"
}
},
"node_modules/vue-router": {
"version": "4.6.4",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.6.4.tgz",
@@ -2245,6 +2274,15 @@
"peerDependencies": {
"typescript": ">=5.0.0"
}
},
"node_modules/zrender": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/zrender/-/zrender-6.0.0.tgz",
"integrity": "sha512-41dFXEEXuJpNecuUQq6JlbybmnHaqqpGlbH1yxnA5V9MMP4SbohSVZsJIwz+zdjQXSSlR1Vc34EgH1zxyTDvhg==",
"license": "BSD-3-Clause",
"dependencies": {
"tslib": "2.3.0"
}
}
}
}
+2
View File
@@ -12,10 +12,12 @@
"@element-plus/icons-vue": "^2.3.2",
"@types/markdown-it": "^14.1.2",
"axios": "^1.13.4",
"echarts": "^6.0.0",
"element-plus": "^2.13.2",
"markdown-it": "^14.1.0",
"pinia": "^3.0.4",
"vue": "^3.5.24",
"vue-echarts": "^8.0.1",
"vue-router": "^4.6.4"
},
"devDependencies": {
+165 -2
View File
@@ -8,8 +8,28 @@
</el-button>
</div>
<!-- 数据源状态概览 -->
<!-- 统计图表 -->
<el-row :gutter="20">
<el-col :span="12">
<el-card>
<template #header>
<span>采集趋势(近7天)</span>
</template>
<v-chart class="chart" :option="trendChartOption" autoresize />
</el-card>
</el-col>
<el-col :span="12">
<el-card>
<template #header>
<span>数据源采集分布</span>
</template>
<v-chart class="chart" :option="pieChartOption" autoresize />
</el-card>
</el-col>
</el-row>
<!-- 数据源状态概览 -->
<el-row :gutter="20" style="margin-top: 20px">
<el-col :span="24">
<el-card>
<template #header>
@@ -137,12 +157,33 @@
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { ref, reactive, computed, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { Refresh } from '@element-plus/icons-vue'
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { LineChart, PieChart } from 'echarts/charts'
import {
TitleComponent,
TooltipComponent,
LegendComponent,
GridComponent,
} from 'echarts/components'
import VChart from 'vue-echarts'
import request from '@/api/request'
import type { CollectionStats, CollectionLog, Source } from '@/api/types'
// 注册 ECharts 组件
use([
CanvasRenderer,
LineChart,
PieChart,
TitleComponent,
TooltipComponent,
LegendComponent,
GridComponent,
])
const statsLoading = ref(false)
const logsLoading = ref(false)
const statsData = ref<CollectionStats[]>([])
@@ -160,6 +201,124 @@ const logPagination = reactive({
total: 0,
})
// 采集趋势图表配置
const trendChartOption = computed(() => {
// 生成近7天的日期
const dates: string[] = []
const successData: number[] = []
const failedData: number[] = []
for (let i = 6; i >= 0; i--) {
const date = new Date()
date.setDate(date.getDate() - i)
dates.push(`${date.getMonth() + 1}/${date.getDate()}`)
// 统计当天的成功和失败次数
const dayStart = new Date(date)
dayStart.setHours(0, 0, 0, 0)
const dayEnd = new Date(date)
dayEnd.setHours(23, 59, 59, 999)
const dayLogs = logsData.value.filter(log => {
const logDate = new Date(log.startedAt)
return logDate >= dayStart && logDate <= dayEnd
})
successData.push(dayLogs.filter(l => l.status === 'success').length)
failedData.push(dayLogs.filter(l => l.status === 'failed').length)
}
return {
tooltip: {
trigger: 'axis',
},
legend: {
data: ['成功', '失败'],
bottom: 0,
},
grid: {
left: '3%',
right: '4%',
bottom: '15%',
top: '10%',
containLabel: true,
},
xAxis: {
type: 'category',
boundaryGap: false,
data: dates,
},
yAxis: {
type: 'value',
minInterval: 1,
},
series: [
{
name: '成功',
type: 'line',
smooth: true,
data: successData,
itemStyle: { color: '#67c23a' },
areaStyle: { color: 'rgba(103, 194, 58, 0.1)' },
},
{
name: '失败',
type: 'line',
smooth: true,
data: failedData,
itemStyle: { color: '#f56c6c' },
areaStyle: { color: 'rgba(245, 108, 108, 0.1)' },
},
],
}
})
// 数据源采集分布饼图配置
const pieChartOption = computed(() => {
const data = statsData.value
.filter(s => s.totalArticles > 0)
.map(s => ({
name: s.name,
value: s.totalArticles,
}))
return {
tooltip: {
trigger: 'item',
formatter: '{b}: {c} ({d}%)',
},
legend: {
orient: 'vertical',
right: '5%',
top: 'center',
},
series: [
{
type: 'pie',
radius: ['40%', '70%'],
center: ['40%', '50%'],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 4,
borderColor: '#fff',
borderWidth: 2,
},
label: {
show: false,
},
emphasis: {
label: {
show: true,
fontSize: 14,
fontWeight: 'bold',
},
},
data: data.length > 0 ? data : [{ name: '暂无数据', value: 1 }],
},
],
}
})
const loadData = () => {
loadStats()
loadLogs()
@@ -283,6 +442,10 @@ onMounted(() => {
color: #303133;
}
.chart {
height: 280px;
}
.card-header {
display: flex;
justify-content: space-between;