11<template >
22 <a-spin :loading =" loading" style =" width : 100% " >
3- <a-card title = " 访问趋势 " class =" general-card" >
3+ <a-card class =" general-card" title = " 访问趋势 " >
44 <template #extra >
55 <a-radio-group v-model:model-value =" dateRange" type =" button" size =" small" @change =" onChange as any" >
66 <a-radio :value =" 7" >近7天</a-radio >
77 <a-radio :value =" 30" >近30天</a-radio >
88 </a-radio-group >
99 </template >
10- <Chart :option =" option " : style =" { height: '326px' } " />
10+ <Chart :option =" chartOption " style =" height : 460 px " />
1111 </a-card >
1212 </a-spin >
1313</template >
1414
1515<script lang="ts" setup>
16- import { graphic } from ' echarts'
17- import { type DashboardAccessTrendResp , listDashboardAccessTrend } from ' @/apis'
16+ import { type EChartsOption , graphic } from ' echarts'
17+ import { type DashboardAccessTrendResp , getDashboardAccessTrend as getData } from ' @/apis'
1818import { useChart } from ' @/hooks'
1919
2020// 提示框
@@ -34,14 +34,14 @@ const tooltipItemsHtmlString = (items) => {
3434 .join (' ' )
3535}
3636
37- const xData = ref <string []>([])
38- const pvStatisticsData = ref <number []>([])
39- const ipStatisticsData = ref <number []>([])
40- const { option } = useChart ((isDark ) => {
37+ const xAxis = ref <string []>([])
38+ const pvChartData = ref <number []>([])
39+ const ipChartData = ref <number []>([])
40+ const { chartOption } = useChart ((isDark : EChartsOption ) => {
4141 return {
4242 grid: {
4343 left: ' 38' ,
44- right: ' 0 ' ,
44+ right: ' 5 ' ,
4545 top: ' 10' ,
4646 bottom: ' 50'
4747 },
@@ -55,13 +55,13 @@ const { option } = useChart((isDark) => {
5555 xAxis: {
5656 type: ' category' ,
5757 offset: 2 ,
58- data: xData .value ,
58+ data: xAxis .value ,
5959 boundaryGap: false ,
6060 axisLabel: {
6161 color: ' #4E5969' ,
6262 formatter(value : number , idx : number ) {
6363 if (idx === 0 ) return ' '
64- if (idx === xData .value .length - 1 ) return ' '
64+ if (idx === xAxis .value .length - 1 ) return ' '
6565 return ` ${value } `
6666 }
6767 },
@@ -75,7 +75,7 @@ const { option } = useChart((isDark) => {
7575 show: true ,
7676 interval : (idx : number ) => {
7777 if (idx === 0 ) return false
78- return idx !== xData .value .length - 1
78+ return idx !== xAxis .value .length - 1
7979 },
8080 lineStyle: {
8181 color: isDark ? ' #3F3F3F' : ' #E5E8EF'
@@ -124,8 +124,8 @@ const { option } = useChart((isDark) => {
124124 },
125125 series: [
126126 {
127- name: ' 浏览量(PV) ' ,
128- data: pvStatisticsData .value ,
127+ name: ' 访问次数 ' ,
128+ data: pvChartData .value ,
129129 type: ' line' ,
130130 smooth: true ,
131131 showSymbol: false ,
@@ -154,8 +154,8 @@ const { option } = useChart((isDark) => {
154154 }
155155 },
156156 {
157- name: ' IP数 ' ,
158- data: ipStatisticsData .value ,
157+ name: ' 独立IP ' ,
158+ data: ipChartData .value ,
159159 type: ' line' ,
160160 smooth: true ,
161161 showSymbol: false ,
@@ -193,14 +193,14 @@ const dateRange = ref(30)
193193const getChartData = async (days : number ) => {
194194 try {
195195 loading .value = true
196- xData .value = []
197- pvStatisticsData .value = []
198- ipStatisticsData .value = []
199- const { data : chartData } = await listDashboardAccessTrend (days )
200- chartData .forEach ((el : DashboardAccessTrendResp ) => {
201- xData .value .unshift ( el .date )
202- pvStatisticsData .value .unshift ( el .pvCount )
203- ipStatisticsData .value .unshift ( el .ipCount )
196+ xAxis .value = []
197+ pvChartData .value = []
198+ ipChartData .value = []
199+ const { data : chartData } = await getData (days )
200+ chartData .forEach ((item : DashboardAccessTrendResp ) => {
201+ xAxis .value .push ( item .date )
202+ pvChartData .value .push ( item .pvCount )
203+ ipChartData .value .push ( item .ipCount )
204204 })
205205 } finally {
206206 loading .value = false
0 commit comments