This commit is contained in:
duanxiaohai 2024-06-17 11:50:40 +08:00
parent a06da0ccf7
commit da16ed499f
3 changed files with 45 additions and 296 deletions

View File

@ -131,7 +131,14 @@
</template>
<script setup>
import { ref, reactive, onMounted, onBeforeMount, computed } from "vue";
import {
ref,
reactive,
onMounted,
onBeforeMount,
onBeforeUnmount,
computed,
} from "vue";
import right2 from "./echart_analyze/right2.vue";
import right1 from "./echart_analyze/right1.vue";
import http from "@/utils/request.js";
@ -255,51 +262,48 @@ const minData = reactive({
});
//
const onViewData = (value, i) => {
clearInterval(interval); //
data.ViewData[i].show = !data.ViewData[i].show;
data.DataViewing = data.ViewData.filter((item) => item.show).map((item) => ({
name: item.name,
data: item.data,
}));
// console.log(data.DataViewing, 666);
// switch (value) {
// case "":
// data.ViewData[i].show = !data.ViewData[i].show;
// break;
// case "":
// data.ViewData[i].show = true;
// break;
// case "":
// data.ViewData[i].show = true;
// break;
// case "尿":
// data.ViewData[i].show = true;
// break;
// case "":
// data.ViewData[i].show = true;
// break;
// case "":
// data.ViewData[i].show = true;
// break;
// case "":
// data.ViewData[i].show = true;
// break;
// case "":
// data.ViewData[i].show = true;
// break;
// case "":
// data.ViewData[i].show = true;
// break;
// case "":
// data.ViewData[i].show = true;
// break;
// default:
// break;
// }
};
onMounted(() => {});
const onViewData1 = (i) => {
data.ViewData[i].show = !data.ViewData[i].show;
data.DataViewing = data.ViewData.filter((item) => item.show).map((item) => ({
name: item.name,
data: item.data,
}));
};
let interval;
let currentIndex = ref(0);
const toggleShow = () => {
const length = data.ViewData.length;
if (length === 0) return;
const current = currentIndex.value;
const nextIndex = (currentIndex.value + 1) % length;
// show
// data.ViewData[current].show = !data.ViewData[current].show;
data.ViewData[nextIndex].show = !data.ViewData[nextIndex].show;
onViewData1(current);
currentIndex.value = nextIndex;
};
const startAutoSwitching = () => {
interval = setInterval(toggleShow, 6000); // 6
};
onMounted(() => {
startAutoSwitching();
});
onBeforeMount(() => {});
onBeforeUnmount(() => {
clearInterval(interval); //
});
</script>
<style lang="scss" scoped>

View File

@ -1,257 +0,0 @@
<template>
<div ref="chart" style="width: 100%; height: 300px"></div>
</template>
<script setup>
import { onBeforeMount, reactive, ref, watch } from "vue";
// echarts
import * as echarts from "echarts";
const chart = ref(); // DOM
const clear = ref(false);
const props = defineProps({
list: {
type: Array,
default: () => {
return [];
},
},
list1: {
type: Array,
default: () => {
return [];
},
},
list2: {
type: Array,
default: () => {
return [];
},
},
year: {
type: Array,
default: () => {
return [];
},
},
});
const sers = ref([
{
name: "背景",
type: "bar",
data: [],
showBackground: true,
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
},
]);
const data = reactive({
list: [],
list1: [],
list2: [],
year: [],
option: {},
bg: [],
name: [],
ser: [],
len: {
data: [],
top: "3%",
right: "5%",
textStyle: {
fontSize: 16,
color: "#ffffff",
},
},
formatter: "{b0}<br />",
});
const getOption = () => {
data.option = {
tooltip: {
trigger: "axis",
padding: [20, 10, 20, 10],
formatter: data.formatter,
},
legend: data.len,
grid: {
top: "35%",
left: "6%",
right: "6%",
bottom: "3%",
containLabel: true,
},
xAxis: {
type: "category",
data: data.year,
axisLabel: {
//
textStyle: {
color: "#ffffff",
fontSize: 16,
},
},
},
yAxis: [
{
type: "value",
name: "人数/人",
splitLine: {
show: true,
lineStyle: {
color: "rgba(255, 255, 255, 0.2)",
fontSize: 16,
width: 1,
},
},
min: 0, // Y
max: function (value) {
// Y
return Math.ceil(Math.max(value.max, value.max * 1.2) / 50) * 50;
},
nameTextStyle: {
// Y
fontSize: 14, // 20
},
// axisLabel: {
// //
// textStyle: {
// color: "#ffffff",
// fontSize: 16,
// },
// },
axisLine: {
//y线
show: false,
lineStyle: {
color: "#ffffff",
fontSize: 16,
width: 1,
type: "solid",
},
},
},
{
type: "value",
// name: "尿",
splitLine: {
show: false,
lineStyle: {
color: "rgba(255, 255, 255, 0.2)",
fontSize: 16,
width: 1,
},
},
min: 0, // Y
max: function (value) {
// Y
return Math.ceil(Math.max(value.max, value.max * 1.6) / 50) * 50;
},
nameTextStyle: {
// Y
fontSize: 14, // 20
},
axisLabel: {
show: false,
//
},
axisLine: {
//y线
show: false,
lineStyle: {
color: "#ffffff",
fontSize: 16,
width: 1,
type: "solid",
},
},
},
],
series: data.ser,
};
};
const setChart = () => {
var myChart = echarts.init(chart.value);
if (clear.value) {
myChart.clear();
}
myChart.setOption(data.option);
};
const setChart1 = () => {
data.ser.length = 0;
sers.value.forEach((item) => {
data.ser.push(item);
});
if (data.name.length > 0) {
data.list.forEach((item) => {
data.ser.push({
yAxisIndex: 0,
name: item.name,
type: "line",
symbol: "emptyCircle",
symbolSize: 10,
itemStyle: {
borderColor: "#2468FF",
borderWidth: 1,
color: "#2468FF",
},
label: {
show: true,
color: "#2468FF",
formatter: function (data) {
return data.value;
},
},
data: item.data,
});
});
}
// console.log("", data.ser);
// console.log("1", sers.value);
};
//
watch(
() => props.list,
(newVal, oldVal) => {
if (newVal.length < oldVal.length) {
clear.value = true;
} else {
clear.value = false;
}
data.list = newVal;
data.name = props.list.map((item) => item.name);
data.len.data = data.name;
sers.value[0].data = data.year.map((item) => 0);
data.formatter = "{b0}<br />";
if (data.name.length > 0) {
for (let i = 1; i <= data.name.length; i++) {
let s1 = `{a${i}}:{c${i}}<br />`;
data.formatter += s1;
}
}
setChart1();
getOption();
setChart();
}
);
// 使
onBeforeMount(() => {
setTimeout(() => {
data.list = props.list;
data.year = props.year;
sers.value[0].data = data.year.map((item) => 0);
setChart1();
getOption();
setChart();
}, 600);
});
</script>
<style scoped></style>

View File

@ -176,7 +176,7 @@
</template>
<script setup>
import { ref, reactive, onMounted, onBeforeMount, computed } from "vue";
import { ref, reactive, onMounted, onBeforeMount,onBeforeUnmount, computed } from "vue";
import eP1 from "./echarts_work/eP1.vue";
import eP2 from "./echarts_work/eP2.vue";
import eP3 from "./echarts_work/eP3.vue";
@ -449,6 +449,8 @@ onMounted(() => {
onBeforeMount(() => {
getData();
});
onBeforeUnmount(() => {
clearInterval(interval); //
});
</script>