forked from drone/command-center-dashboard

罗广辉
2025-04-21 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7
src/views/TaskManage/TaskTop/TaskTime.vue
@@ -1,53 +1,89 @@
<!-- 任务事件统计 -->
<!-- 任务数量统计 -->
<template>
  <!-- <common-title title="任务时间统计"></common-title> -->
  <div class="task-time">
    <div class="title">任务数量统计</div>
    <div class="chart" ref="chartRef"></div>
  </div>
 </template>
<script setup>
import CommonTitle from '@/components/CommonTitle.vue';
import * as echarts from 'echarts';
import { jobNumBar } from '@/api/home/task';
import dayjs from 'dayjs';
import useEchartsResize from '@/hooks/useEchartsResize'
import { useStore } from 'vuex';
const store = useStore();
// 日期
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: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    },
    formatter: '{b}: {c} 件'
  },
  legend: {
    top: '2%',
    textStyle: {
      color: '#6B90B5',
      fontSize: 12,
    }
  },
  grid: {
    top: '15%',
    left: '3%',
    right: '4%',
    bottom: '3%',
    bottom: '2%',
    containLabel: true
  },
  // xAxis: {
  //   type: 'category',
  //   axisLine: {
  //     lineStyle: {
  //       color: '#fff'
  //     }
  //   },
  //   axisLabel: {
  //     color: '#fff',
  //     interval: 0,
  //     rotate: 30
  //   }
  // },
  xAxis: {
    type: 'category',
    axisLine: {
      lineStyle: {
        color: '#fff'
      }
    },
    axisLabel: {
      color: '#fff',
      interval: 0,
      rotate: 30
    }
  },
      type: 'category',
      data: ['1'],
      axisLine: {
         show: false, // 隐藏轴线
      },
      axisTick: {
         show: true,
         length: 2,
         lineStyle: {
            color: '#ffffff',
         },
      },
      axisLabel: {
         color: '#ffffff',
         margin: 8,
      },
   },
  yAxis: {
    type: 'value',
    name: '单位:件',
    nameTextStyle: {
      color: '#E6F7FF',
      fontSize: 12,
      padding: [0, 0, 0, 0]  // 调整单位文字位置
    },
    axisLine: {
      lineStyle: {
        color: '#fff'
@@ -64,12 +100,13 @@
  },
  series: [
    {
      name: '任务数量',
      type: 'bar',
      barWidth: '40%',
      barWidth: '6px',
      itemStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          { offset: 0, color: '#1EE7E7' },
          { offset: 1, color: 'rgba(30, 231, 231, 0.1)' }
          { offset: 0, color: '#0EECE4' },
          { offset: 1, color: '#058FE7' }
        ])
      }
    }
@@ -77,55 +114,48 @@
};
// 获取任务时间统计数据
const getJobNumBar = (value,date_enum) => {
  jobNumBar({date_enum}).then(res => {
const getJobNumBar = (value) => {
  jobNumBar(value).then(res => {
    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;
// 添加监听
watch(() => store.state.task.taskSearchParams, (newVal) => {
  if (newVal) {
    getJobNumBar(newVal);
    (newVal);
  }
  window.removeEventListener('resize', handleResize);
});
}, { deep: true });
onMounted(() => {
  chart = echarts.init(chartRef.value);
  getJobNumBar(newTime.value, 'CURRENT_YEAR');
  if (chart && !chart.isDisposed()) {
    chart.resize();
  }
  getJobNumBar({date_enum: 'TODAY'});
});
onUnmounted(() => {
  window.removeEventListener('resize', chart?.resize);
  chart?.dispose();
});
</script>
<style lang="scss" scoped>
.task-time {
  font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
  // margin-left: 29px;
  // padding: 16px 16px;
  width: 340px;
  height: 200px;
  background: linear-gradient(
    270deg,
    rgba(31, 62, 122, 0) 0%,
    rgba(31, 62, 122, 0.35) 21%,
    #1f3e7a 100%
  );
  border-radius: 0px 0px 0px 0px;
  opacity: 0.85;
  width: 502px;
  height: 100%;
  margin-left: 14px;
  .title {
    font-size: 14px;
    margin-top: 10px;
    width: 502px;
    height: 28.6px;
    background: url('@/assets/images/task/task-num-total.png') no-repeat center / 100% 100%;
    color: #CFEAFF;
    padding-left: 44px;
    line-height: 8px;
  }
  .chart {
    width: 100%;
    height: 100%;
    height: 200px;
  }
}
</style>
</style>