forked from drone/command-center-dashboard

罗广辉
2025-04-13 898c836c57c22b9439321e96650f8a35b1cea917
src/views/TaskManage/TaskTop/TaskEvent.vue
@@ -10,13 +10,15 @@
import * as echarts from 'echarts';
import { jobEventBar } from '@/api/home/task';
import dayjs from 'dayjs';
import useEchartsResize from '@/hooks/useEchartsResize'
// 日期
const currenDate = dayjs().format('YYYY-MM-DD');
const newTime = ref([currenDate, currenDate]);
// 图表
const chartRef = ref(null);
let chart = null;
let { chart } = useEchartsResize(chartRef)
const option = {
  tooltip: {
@@ -104,33 +106,15 @@
    option.xAxis.data = res.data.data.map(item => item.name);
    option.series[0].data = res.data?.data.map(item => item.data[0].value);
    option.series[1].data = res.data?.data.map(item => item.data[1].value);
    chart.setOption(option);
    chart.value.setOption(option);
  });
};
onBeforeUnmount(() => {
  if (chart) {
    chart.dispose();
    chart = null;
  }
  window.removeEventListener('resize', handleResize);
});
onMounted(() => {
  chart = echarts.init(chartRef.value);
  getJobEventBar(newTime.value, 'CURRENT_YEAR');
  window.addEventListener('resize', () => {
    if (chart && !chart.isDisposed()) {
      chart.resize();
    }
  });
});
onUnmounted(() => {
  window.removeEventListener('resize', chart?.resize);
  chart?.dispose();
});
</script>
<style lang="scss" scoped>
@@ -140,7 +124,7 @@
  height: 100%;
  margin-left: 40px;
  .title {
    margin-top: 10px;
    margin-top: 10px;
    width: 660px;
    height: 28.6px;
    background: url('@/assets/images/task/task-event-total.png') no-repeat center / 100% 100%;
@@ -153,4 +137,4 @@
    height: 200px;
  }
}
</style>
</style>