From b6fd39998f67f7fea48ac8b3be169dc6de3985b5 Mon Sep 17 00:00:00 2001 From: longyvfengyun <496960745@qq.com> Date: 星期四, 28 九月 2023 14:41:51 +0800 Subject: [PATCH] 内容提交 --- src/components/echarts/hdwChart.vue | 84 +++++++++++++++++++++++++++++++++++------ 1 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/components/echarts/hdwChart.vue b/src/components/echarts/hdwChart.vue index 1aa5cad..1fd561c 100644 --- a/src/components/echarts/hdwChart.vue +++ b/src/components/echarts/hdwChart.vue @@ -1,23 +1,81 @@ <script setup> -import {onMounted, ref} from "vue"; -import basicEcharts from "@/components/echarts/basic"; +import {computed, onMounted, onUnmounted, ref, watch} from "vue"; import "./transparent"; +import usePageMenuStore from "@/stores/pageMenu"; +import * as echarts from "echarts"; +const pageMenu = usePageMenuStore() const hdwChart = ref({}); -const { - init, - resize, - setOption -} = basicEcharts(); -const setChartOption = (option)=>{ - setOption(option); +let chart = ""; + +const init = (container)=>{ + chart = echarts.init(container); } -onMounted(async ()=>{ - await init(hdwChart.value, 'transparent'); - setChartOption(); + +/** + * 璁剧疆鍥捐〃鍐呭 + * @param option 鐢熸垚鍥捐〃鐨勯厤缃」 + */ +const setOption = (option)=> { + if (chart) { + chart.setOption(option); + } +} + +/** + * 閲嶇疆鍥捐〃鐨勫ぇ灏� + */ +const resize = ()=>{ + if (chart) { + chart.resize(); + setTimeout(()=>{ + chart.resize(); + }); + } +} + +/** + * 閿�姣乪charts瀹炰緥閲婃斁鍐呭瓨 + * @return {[type]} [return description] + */ +const dispose = ()=>{ + // 閿�姣乧hart + if(chart) { + chart.dispose(); + } +} + +/** + * 鑾峰彇鍥捐〃瀵硅薄 + * @return {string} + */ +const getChart=()=>{ + return chart; +} + +const isCollapse = computed(()=>{ + return pageMenu.isCollapse; +}) + +watch(isCollapse, ()=>{ + setTimeout(()=>{ + resize(); + }, 300); +}); +onMounted(()=>{ + init(hdwChart.value); + + // 鐩戝惉windows绐楀彛鐨勭缉鏀�,缁戝畾resize浜嬩欢 + window.addEventListener("resize", resize); +}); + +onUnmounted(()=>{ + // 閿�姣乺esize浜嬩欢 + window.removeEventListener("resize", resize); + dispose(); }); defineExpose({ - setChartOption, + setOption, resize }); </script> -- Gitblit v1.9.1