Skip to content

Commit 86a5e6d

Browse files
committed
feat: integrate nuxt-echarts to monitor page chart visualization
1 parent 9b9d020 commit 86a5e6d

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

app/pages/monitor.vue

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,69 @@
22
definePageMeta({
33
title: 'pages.monitor.title',
44
})
5+
6+
const monitorData = useState<MonitorInfo[]>('monitorData')
7+
8+
function formatTime(timestamp: number): string {
9+
return new Date(timestamp).toLocaleTimeString()
10+
}
11+
12+
function getChartOption(item: MonitorInfo) {
13+
const times = item.data.map(data => formatTime(data.time))
14+
const delays = item.data.map(data => data.delay)
15+
16+
return {
17+
tooltip: {
18+
trigger: 'axis',
19+
},
20+
xAxis: {
21+
type: 'category',
22+
data: times,
23+
axisLabel: {
24+
rotate: 45,
25+
formatter: (value: string) => value.slice(0, 8),
26+
},
27+
},
28+
yAxis: {
29+
type: 'value',
30+
name: '延迟 (ms)',
31+
},
32+
series: [
33+
{
34+
name: '延迟',
35+
type: 'line',
36+
smooth: true,
37+
data: delays,
38+
lineStyle: {
39+
width: 2,
40+
color: '#5470c6',
41+
},
42+
areaStyle: {
43+
color: 'rgba(84, 112, 198, 0.2)',
44+
},
45+
},
46+
],
47+
}
48+
}
549
</script>
650

751
<template>
8-
<div></div>
52+
<ACard class="w-full p-4">
53+
<template v-for="item in monitorData" :key="item.host">
54+
<div
55+
class="mb-6 flex flex-col items-start rounded-lg bg-gray-50 p-4 shadow lg:flex-row"
56+
>
57+
<div class="mb-4 w-full lg:mb-0 lg:w-1/4 lg:pr-4">
58+
<h2 class="text-lg font-semibold text-gray-700">{{ item.host }}</h2>
59+
<p class="text-sm text-gray-500">监控点数:{{ item.data.length }}</p>
60+
</div>
61+
<div class="w-full lg:w-3/4">
62+
<VChart
63+
:option="getChartOption(item)"
64+
style="width: 100%; height: 200px"
65+
/>
66+
</div>
67+
</div>
68+
</template>
69+
</ACard>
970
</template>

nuxt.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default defineNuxtConfig({
4545
'@nuxtjs/i18n',
4646
'@nuxtjs/color-mode',
4747
'@vueuse/nuxt',
48+
'nuxt-echarts',
4849
],
4950
i18n: {
5051
defaultLocale: 'en',
@@ -82,4 +83,9 @@ export default defineNuxtConfig({
8283
},
8384
],
8485
},
86+
echarts: {
87+
charts: ['LineChart'],
88+
components: ['TooltipComponent', 'GridComponent'],
89+
features: ['UniversalTransition', 'LabelLayout'],
90+
},
8591
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@vueuse/nuxt": "12.2.0",
2020
"arco-design-nuxt-module": "^0.2.1",
2121
"nuxt": "^3.16.0",
22+
"nuxt-echarts": "^0.2.6",
2223
"prettier": "^3.5.3",
2324
"prettier-plugin-tailwindcss": "^0.6.11",
2425
"vue": "^3.5.13"

pnpm-lock.yaml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)