1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
| <script lang="ts" setup>
| import type { EChartsOption, EchartsUIType } from '#/packages/effects/plugins/src/echarts';
|
| import { nextTick, onMounted, ref } from 'vue';
|
| import { EchartsUI, useEcharts } from '#/packages/effects/plugins/src/echarts';
|
| import { Card, Select } from 'ant-design-vue';
|
| import {
| getMessageTrend,
| getUserTrend,
| } from '#/api/im/manager/statistics';
|
| const props = defineProps<{
| type: 'message' | 'user';
| }>();
|
| const title =
| props.type === 'message'
| ? '消息趋势(私聊 + 群聊)'
| : '用户趋势(新增注册 + 日活)';
|
| const days = ref(7);
| const loading = ref(false);
| const chartRef = ref<EchartsUIType>();
| const { renderEcharts } = useEcharts(chartRef);
|
| /** 获取图表配置 */
| function buildOptions(
| dates: string[],
| series: Record<string, number[]>,
| ): EChartsOption {
| if (props.type === 'message') {
| return {
| tooltip: { trigger: 'axis' },
| legend: { data: ['私聊消息', '群聊消息'], top: 0 },
| grid: { left: 24, right: 24, bottom: 16, top: 42, containLabel: true },
| xAxis: {
| type: 'category',
| data: dates,
| axisLabel: { formatter: (value: string) => value.slice(5, 10) },
| },
| yAxis: { type: 'value', name: '消息量' },
| series: [
| {
| name: '私聊消息',
| type: 'line',
| smooth: true,
| data: series.private || [],
| itemStyle: { color: '#2f7df6' },
| areaStyle: { color: 'rgba(47,125,246,0.12)' },
| },
| {
| name: '群聊消息',
| type: 'line',
| smooth: true,
| data: series.group || [],
| itemStyle: { color: '#18a058' },
| areaStyle: { color: 'rgba(24,160,88,0.12)' },
| },
| ],
| };
| }
| return {
| tooltip: { trigger: 'axis' },
| legend: { data: ['新增注册', '日活'], top: 0 },
| grid: { left: 24, right: 32, bottom: 16, top: 42, containLabel: true },
| xAxis: {
| type: 'category',
| data: dates,
| axisLabel: { formatter: (value: string) => value.slice(5, 10) },
| },
| yAxis: [
| { type: 'value', name: '新增注册', position: 'left' },
| { type: 'value', name: '日活', position: 'right' },
| ],
| series: [
| {
| name: '新增注册',
| type: 'bar',
| yAxisIndex: 0,
| data: series.register || [],
| itemStyle: { color: '#f59e0b' },
| barMaxWidth: 24,
| },
| {
| name: '日活',
| type: 'line',
| yAxisIndex: 1,
| smooth: true,
| data: series.active || [],
| itemStyle: { color: '#ef4444' },
| },
| ],
| };
| }
|
| /** 加载图表数据 */
| async function loadData() {
| loading.value = true;
| try {
| const data =
| props.type === 'message'
| ? await getMessageTrend(days.value)
| : await getUserTrend(days.value);
| await nextTick();
| await renderEcharts(buildOptions(data.dates, data.series));
| } finally {
| loading.value = false;
| }
| }
|
| onMounted(loadData);
| </script>
|
| <template>
| <Card :body-style="{ padding: '12px 16px 16px' }">
| <template #title>
| <div class="flex items-center justify-between">
| <span>{{ title }}</span>
| <Select
| v-model:value="days"
| :options="[
| { label: '近 7 天', value: 7 },
| { label: '近 15 天', value: 15 },
| { label: '近 30 天', value: 30 },
| ]"
| class="w-28"
| size="small"
| @change="loadData"
| />
| </div>
| </template>
| <div class="relative min-h-[320px]">
| <EchartsUI ref="chartRef" height="320px" />
| <div
| v-if="loading"
| class="absolute inset-0 flex items-center justify-center bg-card/70 text-sm text-muted-foreground"
| >
| 加载中
| </div>
| </div>
| </Card>
| </template>
|
|