Skip to content

Commit 8a3f456

Browse files
committed
feat: 分析页增加数据总览和热门模块列表,调整分析页布局
1 parent 1cb0172 commit 8a3f456

File tree

17 files changed

+863
-175
lines changed

17 files changed

+863
-175
lines changed

src/apis/common/home.ts renamed to src/apis/common/dashboard.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@ export type * from './type'
55

66
const BASE_URL = '/dashboard'
77

8-
/** @desc 查询访问趋势 */
9-
export function listDashboardAccessTrend(days: number) {
10-
return http.get<T.DashboardAccessTrendResp[]>(`${BASE_URL}/access/trend/${days}`)
11-
}
12-
138
/** @desc 查询公告列表 */
149
export function listDashboardNotice() {
1510
return http.get<T.DashboardNoticeResp[]>(`${BASE_URL}/notice`)
1611
}
1712

13+
/** @desc 查询 PV 总览 */
14+
export function getDashboardOverviewPv() {
15+
return http.get<T.DashboardOverviewCommonResp>(`${BASE_URL}/analysis/overview/pv`)
16+
}
17+
18+
/** @desc 查询 IP 总览 */
19+
export function getDashboardOverviewIp() {
20+
return http.get<T.DashboardOverviewCommonResp>(`${BASE_URL}/analysis/overview/ip`)
21+
}
22+
23+
/** @desc 查询访问趋势 */
24+
export function getDashboardAccessTrend(days: number) {
25+
return http.get<T.DashboardAccessTrendResp[]>(`${BASE_URL}/access/trend/${days}`)
26+
}
27+
1828
/** @desc 查询访问时段分析 */
1929
export function getAnalysisTimeslot() {
2030
return http.get<T.DashboardChartCommonResp[]>(`${BASE_URL}/analysis/timeslot`)

src/apis/common/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './common'
22
export * from './captcha'
3-
export * from './home'
3+
export * from './dashboard'

src/apis/common/type.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,34 @@ export interface ImageCaptchaResp {
55
expireTime: number
66
}
77

8+
/** 仪表盘公告类型 */
9+
export interface DashboardNoticeResp {
10+
id: number
11+
title: string
12+
type: number
13+
}
14+
815
/** 仪表盘访问趋势类型 */
916
export interface DashboardAccessTrendResp {
1017
date: string
1118
pvCount: number
1219
ipCount: number
1320
}
1421

15-
/** 仪表盘图表类型 */
22+
/** 仪表盘通用总览类型 */
23+
export interface DashboardOverviewCommonResp {
24+
total: number
25+
today: number
26+
growth: number
27+
dataList: DashboardChartCommonResp[]
28+
}
29+
30+
/** 仪表盘通用图表类型 */
1631
export interface DashboardChartCommonResp {
1732
name: string
1833
value: number
1934
}
2035

21-
/** 仪表盘公告类型 */
22-
export interface DashboardNoticeResp {
23-
id: number
24-
title: string
25-
type: number
26-
}
27-
2836
/* 行为验证码类型 */
2937
export interface BehaviorCaptchaResp {
3038
originalImageBase64: string

src/hooks/modules/useChart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export function useChart(sourceOption: optionsFn) {
1818
// echarts support https://echarts.apache.org/zh/theme-builder.html
1919
// 这里不使用
2020
// TODO 图表主题
21-
const option = computed<EChartsOption>(() => {
21+
const chartOption = computed<EChartsOption>(() => {
2222
return sourceOption(isDark.value)
2323
})
2424

25-
return { option }
25+
return { chartOption }
2626
}

src/views/dashboard/analysis/components/AccessTimeslot.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
22
<a-spin :loading="loading" style="width: 100%">
3-
<a-card title="访问时段分析" class="general-card" :header-style="{ paddingBottom: '16px' }">
4-
<Chart style="width: 100%; height: 370px" :option="option" />
3+
<a-card class="general-card" title="访问时段分析">
4+
<Chart :option="chartOption" style="width: 100%; height: 370px" />
55
</a-card>
66
</a-spin>
77
</template>
88

99
<script lang="ts" setup>
10-
import { graphic } from 'echarts'
10+
import { type EChartsOption, graphic } from 'echarts'
1111
import { useChart } from '@/hooks'
1212
import { type DashboardChartCommonResp, getAnalysisTimeslot as getData } from '@/apis/common'
1313
@@ -29,8 +29,8 @@ const tooltipItemsHtmlString = (items) => {
2929
}
3030
3131
const xAxis = ref<string[]>([])
32-
const dataList = ref<number[]>([])
33-
const { option } = useChart((isDark) => {
32+
const chartData = ref<number[]>([])
33+
const { chartOption } = useChart((isDark: EChartsOption) => {
3434
return {
3535
grid: {
3636
left: '40',
@@ -121,12 +121,14 @@ const { option } = useChart((isDark) => {
121121
},
122122
series: [
123123
{
124-
name: '浏览量(PV)',
125-
data: dataList.value,
124+
name: '访问次数',
125+
data: chartData.value,
126126
type: 'line',
127127
smooth: true,
128128
showSymbol: false,
129-
color: '#246EFF',
129+
color: isDark ? '#3D72F6' : '#246EFF',
130+
symbol: 'circle',
131+
symbolSize: 10,
130132
emphasis: {
131133
focus: 'series',
132134
itemStyle: {
@@ -185,7 +187,7 @@ const getChartData = async () => {
185187
const { data } = await getData()
186188
data.forEach((item: DashboardChartCommonResp) => {
187189
xAxis.value.push(item.name)
188-
dataList.value.push(item.value)
190+
chartData.value.push(item.value)
189191
})
190192
} finally {
191193
loading.value = false

src/views/dashboard/analysis/components/AccessTrend.vue

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
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: 460px" />
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'
1818
import { 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)
193193
const 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

src/views/dashboard/analysis/components/BrowserItem.vue renamed to src/views/dashboard/analysis/components/Browser.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
<template>
22
<a-spin :loading="loading" style="width: 100%">
3-
<a-card class="general-card" title="浏览器分析" :header-style="{ paddingBottom: '12px' }">
3+
<a-card class="general-card" title="浏览器">
44
<div class="chart">
5-
<Chart v-if="!loading" style="height: 210px" :option="option" />
5+
<Chart v-if="!loading" :option="chartOption" style="height: 190px" />
66
</div>
77
</a-card>
88
</a-spin>
99
</template>
1010

1111
<script lang="ts" setup>
12+
import type { EChartsOption } from 'echarts'
1213
import { useChart } from '@/hooks'
1314
import { type DashboardChartCommonResp, getAnalysisBrowser as getData } from '@/apis/common'
1415
1516
const xAxis = ref<string[]>([])
16-
const dataList = ref([])
17-
const { option } = useChart((isDark) => {
17+
const chartData = ref([])
18+
const { chartOption } = useChart((isDark: EChartsOption) => {
1819
return {
1920
legend: {
20-
bottom: 'center',
2121
data: xAxis.value,
2222
bottom: 0,
2323
icon: 'circle',
@@ -36,8 +36,8 @@ const { option } = useChart((isDark) => {
3636
series: [
3737
{
3838
type: 'pie',
39-
radius: ['50%', '70%'],
40-
center: ['50%', '45%'],
39+
radius: ['35%', '60%'],
40+
center: ['50%', '42%'],
4141
label: {
4242
formatter: '{d}% ',
4343
color: isDark ? 'rgba(255, 255, 255, 0.7)' : '#4E5969'
@@ -46,22 +46,22 @@ const { option } = useChart((isDark) => {
4646
borderColor: isDark ? '#000' : '#fff',
4747
borderWidth: 1
4848
},
49-
data: dataList.value
49+
data: chartData.value
5050
}
5151
]
5252
}
5353
})
5454
5555
const loading = ref(false)
56-
const colors = ['#249EFF', '#846BCE', '#21CCFF', '#0E42D2', '#86DF6C']
56+
const colors = ['#246EFF', '#00B2FF', '#81E2FF', '#846BCE', '#86DF6C']
5757
// 查询图表数据
5858
const getChartData = async () => {
5959
try {
6060
loading.value = true
6161
const { data } = await getData()
62-
data.forEach((item: DashboardChartCommonResp, index) => {
62+
data.forEach((item: DashboardChartCommonResp, index: number) => {
6363
xAxis.value.push(item.name)
64-
dataList.value.push({
64+
chartData.value.push({
6565
...item,
6666
itemStyle: {
6767
color: data.length > 1 && index === data.length - 1 ? colors[colors.length - 1] : colors[index]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<a-card class="general-card" title="数据总览">
3+
<a-grid :cols="24" :col-gap="12" :row-gap="12">
4+
<a-grid-item :span="{ xs: 24, sm: 24, md: 24, lg: 24, xl: 6, xxl: 6 }">
5+
<Pv />
6+
</a-grid-item>
7+
<a-grid-item :span="{ xs: 24, sm: 24, md: 24, lg: 24, xl: 6, xxl: 6 }">
8+
<Ip />
9+
</a-grid-item>
10+
<a-grid-item :span="{ xs: 24, sm: 24, md: 24, lg: 24, xl: 6, xxl: 6 }">
11+
<Demo1 />
12+
</a-grid-item>
13+
<a-grid-item :span="{ xs: 24, sm: 24, md: 24, lg: 24, xl: 6, xxl: 6 }">
14+
<Demo2 />
15+
</a-grid-item>
16+
</a-grid>
17+
<template #extra>
18+
<slot name="extra"></slot>
19+
</template>
20+
</a-card>
21+
</template>
22+
23+
<script lang="ts" setup>
24+
import Pv from './flow/Pv.vue'
25+
import Ip from './flow/Ip.vue'
26+
import Demo1 from './flow/Demo1.vue'
27+
import Demo2 from './flow/Demo2.vue'
28+
</script>
29+
30+
<style scoped lang="less"></style>

0 commit comments

Comments
 (0)