forked from drone/command-center-dashboard

罗广辉
2025-04-02 e1699c4851f6ca397cd0ad1ff63f32c737654836
src/views/Home/components/HomeLeft/InspectionRaskDetails.vue
@@ -1,222 +1,225 @@
<!-- 巡检任务详情 -->
<template>
  <common-title title="巡检任务情况" :style="{ marginLeft: pxToRem(14) }" @details="detailsFun">
  </common-title>
  <div class="inspection-rask-details">
    <div class="inspection-num">
      <div class="total">
        <div class="value">{{ total }}</div>
        <div class="name">总任务数</div>
      </div>
      <div class="status">
        <div v-for="item in list">
          <div :style="{ color: item.color }" class="value">{{ jobStatistics[item.field] }}</div>
          <div class="name">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <CommonDateTime :style="{ top: pxToRem(19) }" v-model="newTime" @change="getData" />
    <div class="chart-container" ref="chartRef"></div>
  </div>
   <common-title title="巡检任务情况" :style="{ marginLeft: pxToRem(14) }" @details="detailsFun">
   </common-title>
   <div class="inspection-rask-details">
      <div class="inspection-num">
         <div class="total">
            <div class="value">{{ total }}</div>
            <div class="name">总任务数</div>
         </div>
         <div class="status">
            <div v-for="item in list">
               <div :style="{ color: item.color }" class="value">
                  {{ jobStatistics[item.field] }}
               </div>
               <div class="name">{{ item.name }}</div>
            </div>
         </div>
      </div>
      <CommonDateTime :style="{ top: pxToRem(19) }" v-model="newTime" @change="getData" />
      <div class="chart-container" ref="chartRef"></div>
   </div>
</template>
<script setup>
import * as echarts from 'echarts';
import { pxToRem } from '@/utils/rem';
import CommonTitle from '@/components/CommonTitle.vue';
import CommonDateTime from '@/components/CommonDateTime.vue';
import { getJobNumBar, getJobStatistics, getTotalJobNum } from '@/api/home';
import dayjs from 'dayjs';
import * as echarts from 'echarts'
import { pxToRem } from '@/utils/rem'
import CommonTitle from '@/components/CommonTitle.vue'
import CommonDateTime from '@/components/CommonDateTime.vue'
import { getJobNumBar, getJobStatistics, getTotalJobNum } from '@/api/home'
import dayjs from 'dayjs'
const currenDate = dayjs().format('YYYY-MM-DD');
const newTime = ref([currenDate, currenDate]);
const currenDate = dayjs().format('YYYY-MM-DD')
const newTime = ref([currenDate, currenDate])
const list = ref([
  { name: '计划执行', value: 89, color: '#FFFFFF', field: 'planned_executions' },
  { name: '执行中', value: 100, color: '#FFA768', field: 'running_num' },
  { name: '待执行', value: 66, color: '#FFE17E', field: 'pending_executions' },
  { name: '已执行', value: 10, color: '#8EFFAC', field: 'executed' },
  { name: '执行失败', value: 10, color: '#FF8E8E', field: 'failed_executions' },
]);
   { name: '计划执行', value: 89, color: '#FFFFFF', field: 'planned_executions' },
   { name: '执行中', value: 100, color: '#FFA768', field: 'running_num' },
   { name: '待执行', value: 66, color: '#FFE17E', field: 'pending_executions' },
   { name: '已执行', value: 10, color: '#8EFFAC', field: 'executed' },
   { name: '执行失败', value: 10, color: '#FF8E8E', field: 'failed_executions' },
])
const option = {
  grid: {
    top: '15%',
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true,
  },
  tooltip: {
    trigger: 'axis',
    backgroundColor: 'rgba(0,0,0,0.7)',
    borderColor: '#0070FF',
    borderWidth: 1,
    textStyle: {
      color: '#fff',
    },
    formatter: '{b}: {c}次',
  },
  xAxis: {
    type: 'category',
    data: ['1',],
    axisLine: {
      show: false, // 隐藏轴线
    },
    axisTick: {
      show: true,
      length: 2,
      lineStyle: {
        color: '#ffffff',
      },
    },
    axisLabel: {
      color: '#ffffff',
      margin: 8,
    },
  },
  yAxis: {
    type: 'value',
    axisLine: {
      lineStyle: {
        color: '#ffffff',
      },
    },
    axisLabel: {
      color: '#ffffff',
    },
    splitLine: {
      lineStyle: {
        color: 'rgba(255, 255, 255, 0.1)',
      },
    },
  },
  series: {
    data: [10],
    type: 'bar',
    barWidth: '60%',
    itemStyle: {
      color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
        { offset: 0, color: '#1EE7E7' },
        { offset: 1, color: 'rgba(0, 112, 255, 0.1)' },
      ]),
    },
  },
};
   grid: {
      top: '15%',
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true,
   },
   tooltip: {
      trigger: 'axis',
      backgroundColor: 'rgba(0,0,0,0.7)',
      borderColor: '#0070FF',
      borderWidth: 1,
      textStyle: {
         color: '#fff',
      },
      formatter: '{b}: {c}次',
   },
   xAxis: {
      type: 'category',
      data: ['1'],
      axisLine: {
         show: false, // 隐藏轴线
      },
      axisTick: {
         show: true,
         length: 2,
         lineStyle: {
            color: '#ffffff',
         },
      },
      axisLabel: {
         color: '#ffffff',
         margin: 8,
      },
   },
   yAxis: {
      type: 'value',
      axisLine: {
         lineStyle: {
            color: '#ffffff',
         },
      },
      axisLabel: {
         color: '#ffffff',
      },
      splitLine: {
         lineStyle: {
            color: 'rgba(255, 255, 255, 0.1)',
         },
      },
   },
   series: {
      data: [10],
      type: 'bar',
      barWidth: '60%',
      itemStyle: {
         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: '#1EE7E7' },
            { offset: 1, color: 'rgba(0, 112, 255, 0.1)' },
         ]),
      },
   },
}
const detailsFun = () => {
  console.log('details');
};
   console.log('details')
}
let chart = null;
let chart = null
// TODAY,CURRENT_WEEK,CURRENT_MONTH,CURRENT_YEAR
const getData = (value,date_enum) => {
  const params = {
    date_enum,
    // start_date: newTime.value[0],
    // end_date: newTime.value[1]
  };
  getJobStatistics(params).then(res => {
    jobStatistics.value = res.data?.data || {};
  });
  getJobNumBar(params).then(res => {
    option.xAxis.data = res.data?.data.map(item => item.name);
    option.series.data = res.data?.data.map(item => item.value);
    chart.setOption(option);
  });
};
const getData = (value, date_enum) => {
   const params = {
      date_enum,
      // start_date: newTime.value[0],
      // end_date: newTime.value[1]
   }
   getJobStatistics(params).then(res => {
      jobStatistics.value = res.data?.data || {}
   })
   getJobNumBar(params).then(res => {
      option.xAxis.data = res.data?.data.map(item => item.name)
      option.series.data = res.data?.data.map(item => item.value)
      chart.setOption(option)
   })
}
const chartRef = ref(null);
const total = ref(0);
const chartRef = ref(null)
const total = ref(0)
const jobStatistics = ref({
  planned_executions: 0,
  executed: 0,
  running_num: 0,
  failed_executions: 0,
  pending_executions: 0,
});
   planned_executions: 0,
   executed: 0,
   running_num: 0,
   failed_executions: 0,
   pending_executions: 0,
})
onMounted(() => {
  chart = echarts.init(chartRef.value);
  // 监听窗口大小变化
  window.addEventListener('resize', () => {
    chart.resize();
  });
  getTotalJobNum().then(res => {
    total.value = res.data?.data || 0;
  });
  getData(newTime.value, 'TODAY');
});
   chart = echarts.init(chartRef.value)
   // 监听窗口大小变化
   window.addEventListener('resize', () => {
      chart.resize()
   })
   getTotalJobNum().then(res => {
      total.value = res.data?.data || 0
   })
   getData(newTime.value, 'TODAY')
})
</script>
<style scoped lang="scss">
.inspection-rask-details {
  margin-left: 29px;
  padding: 16px 16px;
  width: 390px;
  height: 414px;
  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;
   margin-left: 29px;
   padding: 16px 16px;
   width: 390px;
   height: 414px;
   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;
  .inspection-num {
    background: url('@/assets/images/home/homeLeft/inspection-num.png') no-repeat center / 100% 100%;
    width: 360px;
    height: 118px;
    position: relative;
   .inspection-num {
      background: url('@/assets/images/home/homeLeft/inspection-num.png') no-repeat center / 100%
         100%;
      width: 360px;
      height: 118px;
      position: relative;
    .total {
      position: absolute;
      left: 34px;
      top: 44px;
      font-weight: 500;
      font-size: 14px;
      color: #ffffff;
      text-align: center;
      font-family: Source Han Sans CN, Source Han Sans CN;
      line-height: 19px;
      .total {
         position: absolute;
         left: 34px;
         top: 44px;
         font-weight: 500;
         font-size: 14px;
         color: #ffffff;
         text-align: center;
         font-family: Source Han Sans CN, Source Han Sans CN;
         line-height: 19px;
      .value {
        font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
        font-size: 26px;
      }
    }
         .value {
            font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
            font-size: 26px;
         }
      }
    .status {
      position: absolute;
      top: 8px;
      right: 10px;
      width: 200px;
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: flex-start;
      line-height: 22px;
      padding: 0 10px 10px 0;
      .status {
         position: absolute;
         top: 8px;
         right: 10px;
         width: 200px;
         display: flex;
         flex-wrap: wrap;
         gap: 8px;
         justify-content: flex-start;
         line-height: 22px;
         padding: 0 10px 10px 0;
      .name {
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 400;
        font-size: 14px;
        color: #ffffff;
      }
         .name {
            font-family: Source Han Sans CN, Source Han Sans CN;
            font-weight: 400;
            font-size: 14px;
            color: #ffffff;
         }
      .value {
        font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
        font-weight: 400;
        font-size: 26px;
      }
    }
  }
         .value {
            font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
            font-weight: 400;
            font-size: 26px;
         }
      }
   }
  .chart-container {
    width: 100%;
    height: 200px;
    margin-top: 20px;
  }
   .chart-container {
      width: 100%;
      height: 200px;
      margin-top: 20px;
   }
}
</style>