VisitAnalysis.vue
5.32 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
<template>
<span style="margin-left: 50px; font-size: 18px">选择年份:</span>
<a-select
v-model:value="yearValue"
show-search
placeholder="请选择"
style="width: 200px"
:options="yearOptions"
:filter-option="filterOption"
@change="handleChangeYear"
/>
<div style="position: fixed; top: 80px; right: 70px">
<a-radio-group
v-model:value="periodCopy"
class="custom-radio-group"
:style="{ marginLeft: '100px' }"
>
<a-radio-button value="月" @click="handlePeriodChange('月')">月</a-radio-button>
<a-radio-button value="年" @click="handlePeriodChange('年')">年</a-radio-button>
</a-radio-group>
</div>
<div ref="chartRef" :style="{ height: '500px', width }"></div>
</template>
<script lang="ts" setup>
import { ref, Ref, watchEffect } from 'vue';
import { useECharts } from '/@/hooks/web/useECharts';
import { basicProps } from './props';
import { max } from 'lodash-es';
import { useDataStoreWithOut } from '/@/store/modules/data';
import { getChartData } from '/@/api/project/global';
import { dateTime, period } from '/@/store/modules/user';
import { useMessage } from '/@/hooks/web/useMessage';
defineProps({
...basicProps,
});
const yearValue = ref();
const yearOptions = [
// {
// label: '2025',
// value: 2025,
// },
{
label: '2024',
value: 2024,
},
{
label: '2023',
value: 2023,
},
];
const periodCopy = ref();
const { createMessage } = useMessage(); //错误提示组件
const { error } = createMessage;
const chartRef = ref<HTMLDivElement | null>(null);
const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
const filterOption = (input: string, option: any) => {
return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0;
};
function handlePeriodChange(value) {
//没选年份报错
if (value == '月') {
if (dateTime.value == undefined) {
error('请选择年份');
return;
}
} else if (value == '年') {
yearValue.value = null;
}
period.value = value;
}
function handleChangeYear(value) {
if (period.value == null) {
period.value = '月';
periodCopy.value = '月';
}
yearValue.value = value;
dateTime.value = yearValue.value;
}
const dataStore = useDataStoreWithOut();
//监控选择器变化
watchEffect(async () => {
// const data = dataStore?.getChartData || {};
const chartData = await getChartData({
dateTime: dateTime.value,
period: period.value,
});
const x = [],
y = [];
for (const key in chartData) {
x.push(chartData[key].date);
y.push(chartData[key].count);
}
const data = { x, y };
const maxY = data?.y ? max(data?.y) : 0;
setOptions({
tooltip: {
trigger: 'axis',
axisPointer: {
lineStyle: {
width: 1,
color: '#019680',
},
},
},
xAxis: {
type: 'category',
data: data?.x,
splitLine: {
show: true,
lineStyle: {
width: 1,
type: 'solid',
color: 'rgba(226,226,226,0.5)',
},
},
axisTick: {
show: false,
},
},
yAxis: [
{
type: 'value',
max: maxY + 20,
splitNumber: 20,
axisTick: {
show: false,
},
splitArea: {
show: true,
areaStyle: {
color: ['rgba(255,255,255,0.2)', 'rgba(226,226,226,0.2)'],
},
},
},
],
grid: { left: '1%', right: '1%', top: '2 %', bottom: 0, containLabel: true },
series: [
{
smooth: true,
data: data?.y,
type: 'line',
areaStyle: {},
itemStyle: {
color: '#5ab1ef',
},
},
// {
// smooth: true,
// data: [
// 33, 66, 88, 333, 3333, 5000, 18000, 3000, 1200, 13000, 22000, 11000, 2221, 1201, 390,
// 198, 60, 30, 22, 11,
// ],
// type: 'line',
// areaStyle: {},
// itemStyle: {
// color: '#019680',
// },
// },
],
});
});
</script>
<style scoped>
.custom-radio-group .ant-radio-button-wrapper {
border-color: #1684fc; /* 未选中按钮的边框颜色 */
background-color: white; /* 未选中按钮的背景颜色为白色 */
color: #1684fc; /* 未选中按钮的文字颜色为 #1684fc */
}
.custom-radio-group .ant-radio-button-wrapper-checked {
border-color: #1684fc; /* 选中按钮的边框颜色 */
background-color: #1684fc; /* 选中按钮的背景颜色为 #1684fc */
color: white; /* 选中按钮的文字颜色为白色 */
}
.custom-radio-group .ant-radio-button-wrapper-checked:hover {
background-color: #1684fc; /* 悬停在选中按钮时保持相同的背景颜色 */
color: white; /* 悬停在选中按钮时保持文字为白色 */
}
.custom-radio-group .ant-radio-button-wrapper:hover {
border-color: #1684fc; /* 悬停在未选中按钮时的边框颜色 */
}
.custom-radio-group .ant-radio-button-wrapper:not(.ant-radio-button-wrapper-checked):hover {
color: #1684fc; /* 悬停在未选中按钮时文字颜色为 #1684fc */
}
</style>