overview.vue
5.37 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<template>
<a-card :body-style="{ padding: '10px 20px 0 20px' }" :header-style="{ paddingBottom: 0 }" class="general-card" title="试听概览">
<template #extra>
<a-space size="12">
<export-button :on-download="onDownload" />
<a-range-picker
v-model="createBetween"
:allow-clear="false"
:disabled-date="disabledDate"
style="width: 260px"
value-format="YYYY-MM-DD"
@change="onFetch"
@select="onSelect"
/>
</a-space>
</template>
<Chart :option="chartOption" height="328px" />
</a-card>
</template>
<script lang="ts" setup>
import Chart from '@/components/chart/index.vue';
import useChartOption from '@/hooks/chart-option';
import { ToolTipFormatterParams } from '@/types/echarts';
import { onMounted, ref } from 'vue';
import dayjs from 'dayjs';
import { sum } from 'lodash';
import useDashboardApi from '@/http/dashboard';
const createBetween = ref([dayjs().subtract(7, 'day').format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]);
const disabledDate = (current?: Date) => {
const date = createBetween.value;
if (date && date.length) {
return (
dayjs(current).isBefore(dayjs(date[0]).subtract(15, 'day')) ||
dayjs(current).isAfter(dayjs(date[0]).add(15, 'day')) ||
dayjs(current).isAfter(dayjs())
);
}
return dayjs(current).isAfter(dayjs());
};
const onSelect = (value: any[]) => {
createBetween.value = value;
};
const tooltipItemsHtmlString = (items: ToolTipFormatterParams[]) => {
return items
.reverse()
.map(
(el) => `<div class="content-panel">
<p>
<span style="background-color: ${el.color}" class="tooltip-item-icon"></span><span>${el.seriesName}</span>
</p>
<span class="tooltip-value">${el.value?.toLocaleString()}</span>
</div>`
)
.reverse()
.join('');
};
const record = ref<{
time: string[];
listen_user_count: number[];
listen_count: number[];
like_count: number[];
submit_count: number[];
}>({
time: [],
listen_user_count: [],
listen_count: [],
like_count: [],
submit_count: [],
});
const { chartOption } = useChartOption((isDark) => {
return {
grid: {
left: '40',
right: '40',
top: '40',
bottom: '40',
},
legend: {
top: 0,
right: 0,
bottom: 0,
icon: 'rect',
textStyle: {
color: '#4E5969',
},
formatter: (name) => {
switch (name) {
case '试听用户':
return `${name}(${sum(record.value.listen_user_count)})`;
case '试听次数':
return `${name}(${sum(record.value.listen_count)})`;
case '收藏次数':
return `${name}(${sum(record.value.like_count)})`;
case '提交作品':
return `${name}(${sum(record.value.submit_count)})`;
default:
return name;
}
},
},
tooltip: {
trigger: 'axis',
formatter(params) {
const [firstElement] = params as ToolTipFormatterParams[];
return `<div>
<p class="tooltip-title">${firstElement.axisValueLabel}</p>
${tooltipItemsHtmlString(params as ToolTipFormatterParams[])}
</div>`;
},
className: 'echarts-tooltip-diy',
},
xAxis: [
{
type: 'category',
boundaryGap: true,
axisLine: {
lineStyle: { color: isDark ? '#3f3f3f' : '#A9AEB8' },
},
axisTick: {
show: true,
alignWithLabel: true,
lineStyle: { color: '#86909C' },
},
axisLabel: { color: '#86909C' },
data: record.value.time,
},
],
yAxis: {
show: true,
type: 'value',
axisLabel: { color: '#86909C' },
splitLine: {
lineStyle: { color: isDark ? '#3F3F3F' : '#E5E6EB' },
},
},
series: [
{
name: '试听用户',
type: 'bar',
data: record.value.listen_user_count,
color: '#01629f',
seriesLayoutBy: 'row',
barWidth: 14,
},
{
name: '试听次数',
type: 'bar',
data: record.value.listen_count,
color: '#246EFF',
seriesLayoutBy: 'row',
barWidth: 14,
},
{
name: '收藏次数',
type: 'bar',
data: record.value.like_count,
color: '#00B2FF',
seriesLayoutBy: 'row',
barWidth: 14,
},
{
name: '提交作品',
type: 'bar',
data: record.value.submit_count,
color: '#81c0ff',
seriesLayoutBy: 'row',
barWidth: 14,
},
],
};
});
const onFetch = async () => {
record.value = await useDashboardApi.overview({ createBetween: createBetween.value });
};
const onDownload = async () => useDashboardApi.getOverviewExport('活动数据', { createBetween: createBetween.value });
onMounted(() => onFetch());
</script>
<style lang="less" scoped>
.title {
line-height: normal;
font-weight: 500;
font-size: 16px;
color: var(--color-text-1);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>