forked from drone/command-center-dashboard

罗广辉
2025-04-13 898c836c57c22b9439321e96650f8a35b1cea917
src/views/TaskManage/TaskTop/TaskTime.vue
@@ -10,13 +10,15 @@
import * as echarts from 'echarts';
import { jobNumBar } 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: {
@@ -96,30 +98,15 @@
    if (res.data.code !== 0) return;
    option.xAxis.data = res.data.data.map(item => item.name);
    option.series[0].data = res.data.data.map(item => item.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);
  getJobNumBar(newTime.value, 'CURRENT_YEAR');
  if (chart && !chart.isDisposed()) {
    chart.resize();
  }
});
onUnmounted(() => {
  window.removeEventListener('resize', chart?.resize);
  chart?.dispose();
});
</script>
<style lang="scss" scoped>
@@ -129,7 +116,7 @@
  height: 100%;
  margin-left: 14px;
  .title {
    margin-top: 10px;
    margin-top: 10px;
    width: 502px;
    height: 28.6px;
    background: url('@/assets/images/task/task-num-total.png') no-repeat center / 100% 100%;
@@ -142,4 +129,4 @@
    height: 200px;
  }
}
</style>
</style>