You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.5 KiB
Vue

11 months ago
<template>
10 months ago
<div style="width: 100%;height: 100%" ref="chartRef" @resize="resize" />
11 months ago
</template>
10 months ago
<script setup>
11 months ago
import * as echarts from 'echarts';
6 months ago
import 'echarts-liquidfill';
10 months ago
import { queryGlobalCfg } from '@/api/configure/configuration/globalCfg.js';
const props = defineProps({
defaultOption: Object
});
const { defaultOption } = toRefs(props);
11 months ago
10 months ago
const chart = ref(null);
const option = ref(null);
const resizeTime = ref(true);
const chartRef = ref();
onMounted(async () => {
if (defaultOption.value) {
setData(defaultOption.value);
}
nextTick(() => {
const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
resize();
}
11 months ago
});
10 months ago
resizeObserver.observe(chartRef.value);
});
window.addEventListener('resize', resize);
});
const setData = (e) => {
option.value = e;
initChart(e);
};
2 months ago
const on = (a, b) => {
chart.value.on(a, b);
};
10 months ago
const initChart = (option) => {
if (!chart.value) {
chart.value = echarts.init(chartRef.value, 'macarons');
}
chart.value.setOption(option, true);
};
const resize = () => {
if (resizeTime.value) {
resizeTime.value = false;
10 months ago
if (option.value && chartRef.value) {
2 months ago
// chart.value.resize();
11 months ago
}
10 months ago
setTimeout(() => {
resizeTime.value = true;
}, 16);
}
};
onBeforeUnmount(() => {
if (!chart.value) {
return;
11 months ago
}
10 months ago
chart.value.dispose();
chart.value = null;
window.removeEventListener('resize', resize);
});
defineExpose({
2 months ago
setData,
on
10 months ago
});
11 months ago
</script>