From 22f4b99ab1ac00edb30079fb3cf064d1f05ea4b6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-FUDKNA8\\znjsz" Date: Tue, 30 Jan 2024 14:09:40 +0800 Subject: [PATCH] 1 --- src/components/TeamChartDay.vue | 76 +++++++++++++------------ src/components/TeamChartDayOptions.js | 10 ++-- src/components/TeamChartMonth.vue | 7 +-- src/components/TeamChartMonthOptions.js | 32 +++++------ src/pages/ThreeDimension.vue | 7 +-- 5 files changed, 64 insertions(+), 68 deletions(-) diff --git a/src/components/TeamChartDay.vue b/src/components/TeamChartDay.vue index 7ee3af9..4b15126 100644 --- a/src/components/TeamChartDay.vue +++ b/src/components/TeamChartDay.vue @@ -9,46 +9,44 @@ const store = useWsStore(); const chartChart = ref(null); const chart = ref(null); -const dayData = ref([]); -store.$subscribe((mutation, state) => { - console.log("[ChartDay] ===> state: ", state.data2.classTodayProductYield); - if ( - state.data2.classTodayProductYield == undefined || - state.data2.classTodayProductYield?.length == 0 - ) { - console.log("[ChartDay] ===> 清除状态"); - dayData.value.splice(0); +/** 无状态,处理数据 */ +function loadData(yieldArray) { + const result = []; + if (yieldArray == undefined || yieldArray?.length == 0) return null; + for (let i = 0; i < yieldArray.length; ++i) { + if (yieldArray[i].teamName == "A组") { + result[0] = parseInt(yieldArray[i].yield); + } else if (yieldArray[i].teamName == "B组") { + result[1] = parseInt(yieldArray[i].yield); + } else if (yieldArray[i].teamName == "C组") { + result[2] = parseInt(yieldArray[i].yield); + } + } + return result; +} +function setupChart(chart, dom, data) { + if (chart) chart.dispose(); + nextTick(() => { + chart = echarts.init(dom); + setupFn(chart, data); + }); +} + +/** 有状态,处理数据 */ +function __apply(yieldArray) { + const d = loadData(yieldArray); + if (!d) { if (chart.value) chart.value.dispose(); return; } - - for (let i = 0; i < state.data2.classTodayProductYield.length; ++i) { - if (state.data2.classTodayProductYield[i].teamName == "A组") { - dayData.value[0] = parseInt(state.data2.classTodayProductYield[i].yield); - } else if (state.data2.classTodayProductYield[i].teamName == "B组") { - dayData.value[1] = parseInt(state.data2.classTodayProductYield[i].yield); - } else if (state.data2.classTodayProductYield[i].teamName == "C组") { - dayData.value[2] = parseInt(state.data2.classTodayProductYield[i].yield); - } - } - console.log("[ChartDay] ===> dayData: ", dayData.value); - setupChart(); -}); - -// onMounted(() => { -// nextTick(() => { -// setupChart(); -// }) -// }) - -function setupChart() { - if (chart.value) chart.value.dispose(); - nextTick(() => { - chart.value = echarts.init(chartChart.value); - setupFn(chart.value, dayData.value); - }); + setupChart(chart.value, chartChart.value, d); } +// 订阅 +store.$subscribe((mutation, state) => { + __apply(state.data2.classTodayProductYield); +}); + onMounted(() => { chartChart.value.classList.add("h-full"); }); @@ -56,8 +54,12 @@ onMounted(() => {