|
@@ -2,7 +2,7 @@
|
|
|
<div class="visitor-trend">
|
|
|
<div ref="chartRef" style="width: 100%; height: 300px;"></div>
|
|
|
<div style="position: absolute;top: 20px;right: 0;">
|
|
|
- <el-select v-model="value" style="width: 84px;">
|
|
|
+ <el-select v-model="value" style="width: 84px;" @change="initChart">
|
|
|
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
|
|
|
</el-select>
|
|
|
</div>
|
|
@@ -10,7 +10,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, onMounted, onBeforeUnmount } from 'vue';
|
|
|
+import { ref, onMounted } from 'vue';
|
|
|
import * as echarts from 'echarts';
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
@@ -49,7 +49,13 @@ const colorList = [
|
|
|
'rgba(22, 122, 240, 1)' // 跳出率
|
|
|
];
|
|
|
|
|
|
-onMounted(() => {
|
|
|
+const initChart = () => {
|
|
|
+ if (!chartRef.value) return;
|
|
|
+
|
|
|
+ if (chartInstance) {
|
|
|
+ chartInstance.dispose();
|
|
|
+ }
|
|
|
+
|
|
|
chartInstance = echarts.init(chartRef.value);
|
|
|
|
|
|
// 准备数据
|
|
@@ -60,13 +66,22 @@ onMounted(() => {
|
|
|
const option = {
|
|
|
tooltip: {
|
|
|
trigger: 'axis',
|
|
|
- backgroundColor: 'rgba(255, 255, 255, 0.5)',
|
|
|
+ backgroundColor: 'rgba(255, 255, 255, 0)',
|
|
|
borderColor: 'rgba(204, 204, 204, 1)',
|
|
|
- borderWidth: 1,
|
|
|
+ shadowColor: 'transparent', // 将阴影颜色设为透明
|
|
|
+ borderWidth: 0,
|
|
|
borderRadius: 0,
|
|
|
+ padding: 0,
|
|
|
formatter: function (params) {
|
|
|
+ let result = `<div style="
|
|
|
+ background-color: rgba(255, 255, 255, 0.5);
|
|
|
+ border: 1px solid rgba(204, 204, 204, 1);
|
|
|
+ border: 1px solid rgba(204, 204, 204, 1);
|
|
|
+ padding: 10px;
|
|
|
+ backdrop-filter: blur(4px)
|
|
|
+ ">`;
|
|
|
const date = params[0].axisValue;
|
|
|
- let result = `<div style="font-weight: bold; font-size: 12px; color: rgba(18, 18, 18, 1); margin-bottom: 5px;">${dayjs(date).format('YYYY年MM月DD日')} ${WEEK_DAYS[dayjs(date).day()]}</div>`;
|
|
|
+ result += `<div style="font-weight: bold; font-size: 12px; color: rgba(18, 18, 18, 1); margin-bottom: 5px;">${dayjs(date).format('YYYY年MM月DD日')} ${WEEK_DAYS[dayjs(date).day()]}</div>`;
|
|
|
params.forEach(item => {
|
|
|
let value = item.value;
|
|
|
// // 特殊处理不同指标的单位
|
|
@@ -77,7 +92,7 @@ onMounted(() => {
|
|
|
// }
|
|
|
result += `<div style="font-size: 12px; color: #666; margin-top: 2px;">${item.marker} <span style="font-weight: bold; color: #000000;">${value}</span> ${item.seriesName}</div>`;
|
|
|
});
|
|
|
- return result;
|
|
|
+ return result + `</div>`;
|
|
|
},
|
|
|
},
|
|
|
legend: {
|
|
@@ -187,15 +202,14 @@ onMounted(() => {
|
|
|
};
|
|
|
|
|
|
chartInstance.setOption(option);
|
|
|
+}
|
|
|
|
|
|
- // 响应式调整
|
|
|
- const handleResize = () => chartInstance?.resize();
|
|
|
- window.addEventListener('resize', handleResize);
|
|
|
+defineExpose({
|
|
|
+ initChart
|
|
|
});
|
|
|
|
|
|
-onBeforeUnmount(() => {
|
|
|
- window.removeEventListener('resize', handleResize);
|
|
|
- chartInstance?.dispose();
|
|
|
+onMounted(async () => {
|
|
|
+ initChart();
|
|
|
});
|
|
|
</script>
|
|
|
|