forked from drone/command-center-dashboard

罗广辉
2025-04-01 d36bac3029c9ff3ea53da4b95618a4b19f855450
feat: 事件概况对接
4 files modified
1 files added
362 ■■■■ changed files
src/api/home/index.js 3 ●●●● patch | view | raw | blame | history
src/components/CommonDateTime.vue 11 ●●●●● patch | view | raw | blame | history
src/directive/selectLoad.js 13 ●●●●● patch | view | raw | blame | history
src/views/Home/components/HomeLeft/InspectionRaskDetails.vue 53 ●●●● patch | view | raw | blame | history
src/views/Home/components/HomeRight/EventOverview.vue 282 ●●●●● patch | view | raw | blame | history
src/api/home/index.js
@@ -9,10 +9,11 @@
};
// 巡检任务item数量
export const getJobStatistics = () => {
export const getJobStatistics = (data) => {
  return request({
    url: '/drone-device-core/wayline/waylineJobInfo/jobStatistics',
    method: 'post',
    data
  });
};
src/components/CommonDateTime.vue
@@ -8,13 +8,14 @@
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      @change="change"
      disabled
    />
    <div class="time-card">
      <div
        class="card-item"
        :class="item === checked ? 'active' : ''"
        v-for="(item, index) in timeList"
        @click="timeClick(item)"
        @click="timeClick(item,index)"
      >
        {{ timeListStr[index] }}
      </div>
@@ -32,6 +33,7 @@
let timeList = ['today', 'week', 'month', 'year'];
let timeListStr = ['今日', '本周', '本月', '本年'];
let timeListEnum = ['TODAY', 'CURRENT_WEEK', 'CURRENT_MONTH', 'CURRENT_YEAR'];
let checked = ref('today');
const getDateRange = unit => {
@@ -49,13 +51,14 @@
};
const change = value => {
  emit('change', value);
  // todo 我对接
  // emit('change', value);
};
let timeClick = item => {
let timeClick = (item,index) => {
  checked.value = item;
  model.value = dateRanges[item];
  emit('change', model.value);
  emit('change', dateRanges[item],timeListEnum[index]);
};
</script>
src/directive/selectLoad.js
New file
@@ -0,0 +1,13 @@
const selectLoad = {
  mounted(el, binding){
    const dom = document.querySelector('.' + binding.arg)
    const wrap = dom.querySelector('.el-scrollbar__wrap')
    wrap.addEventListener('scroll', function () {
      if (this.scrollHeight - this.scrollTop < this.clientHeight + 1) {
        binding.value()
      }
    })
  }
}
export default selectLoad
src/views/Home/components/HomeLeft/InspectionRaskDetails.vue
@@ -15,7 +15,7 @@
        </div>
      </div>
    </div>
    <CommonDateTime :style="{ top: pxToRem(19) }" v-model="newTime" @change="dateChange" />
    <CommonDateTime :style="{ top: pxToRem(19) }" v-model="newTime" @change="getData" />
    <div class="chart-container" ref="chartRef"></div>
  </div>
</template>
@@ -30,7 +30,6 @@
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' },
@@ -58,38 +57,7 @@
  },
  xAxis: {
    type: 'category',
    data: [
      '1',
      '2',
      '3',
      '4',
      '5',
      '6',
      '7',
      '8',
      '9',
      '10',
      '11',
      '12',
      '13',
      '14',
      '15',
      '16',
      '17',
      '18',
      '19',
      '20',
      '21',
      '22',
      '23',
      '24',
      '25',
      '26',
      '27',
      '28',
      '29',
      '30',
    ],
    data: ['1',],
    axisLine: {
      show: false, // 隐藏轴线
    },
@@ -122,10 +90,7 @@
    },
  },
  series: {
    data: [
      10, 15, 8, 20, 12, 18, 15, 22, 16, 19, 14, 17, 21, 13, 16, 18, 15, 20, 17, 22, 19, 16, 14, 18,
      21, 15, 17, 20, 16, 18,
    ],
    data: [10],
    type: 'bar',
    barWidth: '60%',
    itemStyle: {
@@ -141,14 +106,12 @@
  console.log('details');
};
const dateChange = value => {
  newTime.value = value;
  getData();
};
let chart = null;
const getData = () => {
// TODAY,CURRENT_WEEK,CURRENT_MONTH,CURRENT_YEAR
const getData = (value,date_enum) => {
  const params = {
    date_enum: 'TODAY',
    date_enum,
    // start_date: newTime.value[0],
    // end_date: newTime.value[1]
  };
@@ -181,7 +144,7 @@
  getTotalJobNum().then(res => {
    total.value = res.data?.data || 0;
  });
  getData();
  getData(newTime.value, 'TODAY');
});
</script>
src/views/Home/components/HomeRight/EventOverview.vue
@@ -4,21 +4,34 @@
    <div class="eventOverview">
      <div class="overviewData">
        <div class="totalBox">
          <div class="totalNumber">{{ total }}</div>
          <div class="totalNumber">{{ eventTotal }}</div>
          <div class="totalLabel">总事件数</div>
        </div>
        <div class="contentBox">
          <div class="overviewItem" v-for="item in list" :key="item.name">
          <div class="overviewItem" v-for="item in eventTypeList" :key="item.name">
            <div class="itemName"><img :src="item.img" alt="" />{{ item.name }}</div>
            <div class="itemValue" :style="{ color: item.color }">{{ item.value }}</div>
          </div>
        </div>
      </div>
      <CommonDateTime class="dateTime" v-model="newTime" @change="dateChange" />
      <CommonDateTime class="dateTime" v-model="timeArr" @change="timeChange" />
      <el-select class="homeRightSelect" v-model="value" placeholder="请选择" size="large">
      <el-select
        class="homeRightSelect"
        v-model="params.device_sn"
        placeholder="请选择"
        size="large"
        filterable
        :remote-method="remoteMethod"
        remote-show-suffix
        remote
        clearable
        popper-class="uavHomePopper"
        v-select-load:uavHomePopper="scrollEvent"
        @change="selectChange"
      >
        <el-option
          v-for="item in options"
          v-for="item in deviceList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
@@ -46,35 +59,12 @@
import completionLeft from '@/assets/images/home/homeRight/completionLeft.png';
import * as echarts from 'echarts';
import CommonDateTime from '@/components/CommonDateTime.vue';
import {
  getJobEventBrokerLine,
  getJobEventByStatus,
  getJobEventTotal,
  getJobNumBar,
  getJobStatistics,
} from '@/api/home';
import VSelectLoad from '@/directive/selectLoad';
import { getJobEventBrokerLine, getJobEventByStatus, getJobEventTotal } from '@/api/home';
import dayjs from 'dayjs';
import { selectDevicePage } from '@/api/home/machineNest';
const list = ref([
  { name: '待审核', value: 265, img: overviewImg1, color: '#FF8E8E' },
  { name: '待分拨', value: 266, img: overviewImg2, color: '#6FCAFF' },
  { name: '待处理', value: 262, img: overviewImg3, color: '#6FCAFF' },
  { name: '处理中', value: 262, img: overviewImg4, color: '#FFD509' },
  { name: '已完成', value: 246, img: overviewImg5, color: '#FF8E8E' },
  { name: '已完结', value: 262, img: overviewImg6, color: '#8EFFAC' },
]);
const value = ref('');
const echartsRef = ref(null);
const options = [
  {
    value: 'Option1',
    label: 'Option1',
  },
];
const currenDate = dayjs().format('YYYY-MM-DD');
const newTime = ref([currenDate, currenDate]);
const option = {
const echartsOption = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
@@ -88,20 +78,18 @@
    bottom: 0,
    containLabel: true,
  },
  xAxis: [
    {
      type: 'category',
      axisLabel: {
        rotate: -45, // 旋转角度
        interval: 0, // 显示所有标签
        color: '#FFFFFF',
        fontFamily: 'Source Han Sans CN, Source Han Sans CN',
        fontWeight: 400,
        fontSize: 10,
      },
      data: ['暴露垃圾', '占道', '暴露垃圾', '占道', '暴露垃圾', '占道', '暴露垃圾', '占道'],
  xAxis: {
    type: 'category',
    axisLabel: {
      rotate: -45, // 旋转角度
      interval: 0, // 显示所有标签
      color: '#FFFFFF',
      fontFamily: 'Source Han Sans CN, Source Han Sans CN',
      fontWeight: 400,
      fontSize: 10,
    },
  ],
    data: [],
  },
  yAxis: [
    {
      type: 'value',
@@ -125,103 +113,157 @@
      },
    },
  ],
  series: [
    {
      name: '待完成',
      type: 'bar',
      stack: 'Ad',
      emphasis: {
        focus: 'series',
      },
      itemStyle: {
        color: '#FF8E8E', // 设置颜色
      },
      data: [120, 132, 120, 132, 120, 132, 120, 132],
    },
    {
      name: '已完成',
      type: 'bar',
      stack: 'Ad',
      emphasis: {
        focus: 'series',
      },
      data: [120, 132, 120, 132, 120, 132, 120, 132],
    },
    {
      name: '已完成1',
      type: 'bar',
      stack: 'Ad',
      emphasis: {
        focus: 'series',
      },
      data: [120, 132, 120, 132, 120, 132, 120, 132],
    },
    {
      name: '已完成2',
      type: 'bar',
      stack: 'Ad',
      emphasis: {
        focus: 'series',
      },
      data: [120, 132, 120, 132, 120, 132, 120, 132],
    },
    {
      name: '完成率',
      type: 'line',
      itemStyle: {
        color: '#0CEBF7', // 设置颜色
      },
      lineStyle: {
        width: 2, // 线条宽度
        type: 'solid', // 线条类型
      },
      symbol: 'circle', // 数据点符号
      symbolSize: 6, // 数据点符号大小
      emphasis: {
        focus: 'series',
      },
      data: [50, 55, 60, 65, 70, 75, 80, 85], // 示例数据,根据实际完成率计算
    },
  ],
  series: [],
};
const total = ref(0);
const getData = () => {
  const params = {
    date_enum: 'TODAY',
    // start_date: newTime.value[0],
    // end_date: newTime.value[1]
const eventTypeList = ref([
  { name: '待审核', value: 0, img: overviewImg1, color: '#FF8E8E', status: '2' },
  { name: '待分拨', value: 0, img: overviewImg2, color: '#6FCAFF', status: '1' },
  { name: '待处理', value: 0, img: overviewImg3, color: '#6FCAFF', status: '0' },
  { name: '处理中', value: 0, img: overviewImg4, color: '#FFD509', status: '3' },
  { name: '已完成', value: 0, img: overviewImg5, color: '#FF8E8E', status: '4' },
  { name: '已完结', value: 0, img: overviewImg6, color: '#8EFFAC', status: '5' },
]);
const seriesObj = {};
eventTypeList.value.forEach(item => {
  seriesObj[item.status] = {
    type: 'bar',
    stack: 'Ad',
    emphasis: {
      focus: 'series',
    },
    name: item.name,
    itemStyle: { color: item.color },
    data: [],
  };
  getJobEventByStatus(params).then(res => {
});
const echartsRef = ref(null);
let chart = null;
const deviceList = ref([]);
const today = dayjs().format('YYYY-MM-DD');
const timeArr = ref([today, today]);
const completionRateSeries = {
  name: '完成率',
  type: 'line',
  itemStyle: {
    color: '#0CEBF7', // 设置颜色
  },
  lineStyle: {
    width: 2, // 线条宽度
    type: 'solid', // 线条类型
  },
  symbol: 'circle', // 数据点符号
  symbolSize: 6, // 数据点符号大小
  emphasis: {
    focus: 'series',
  },
  data: [], // 示例数据,根据实际完成率计算
};
const eventTotal = ref(0);
let deviceTotal = 0;
const devicePageParams = ref({
  current: 1,
  size: 10,
  total: 0,
  nickname: '',
});
const params = ref({
  date_enum: 'TODAY',
  device_sn: '',
  end_date: undefined,
  start_date: undefined,
});
// 远程查询
const remoteMethod = nickname => {
  devicePageParams.value.nickname = nickname;
  devicePageParams.value.current = 1;
  devicePageParams.value.size = 10;
  deviceList.value = [];
  getTableList();
};
// 滚动查询
const scrollEvent = () => {
  const { current, size } = devicePageParams.value;
  if (current * size < deviceTotal) {
    devicePageParams.value.current = current + 1;
    getTableList();
  }
};
// 机巢列表数据
const getTableList = async () => {
  const res = await selectDevicePage({ ...devicePageParams.value, type: 1 });
  const arr = res?.data?.data?.records || [];
  deviceList.value = deviceList.value.concat(
    arr.map(item => ({
      value: item.device_sn,
      label: item.nickname,
    }))
  );
  deviceTotal = res?.data?.data?.total || 0;
};
// 下拉变化
const selectChange = val => {
  getData();
};
// 时间变化
const timeChange = (value, date_enum) => {
  params.value = {
    ...params.value,
    date_enum,
  };
  getData();
};
// 获取柱状图数据
const getBarChartData = () => {
  getJobEventBrokerLine(params.value).then(res => {
    const list = res?.data?.data || [];
    echartsOption.xAxis.data = list.map(item => item.name);
    list.forEach(item => {
      item.data.forEach((item1, index) => {
        seriesObj[item1.status].data.push(item1.value);
      });
    });
    completionRateSeries.data = list.map(item => item.rate);
    echartsOption.series = Object.values(seriesObj);
    echartsOption.series.push(completionRateSeries);
    chart.setOption(echartsOption);
  });
};
//  事件类型数据
const getTypeData = () => {
  getJobEventByStatus(params.value).then(res => {
    const resList = res?.data?.data || [];
    resList.forEach(item => {
      list.value.forEach(item1 => {
      eventTypeList.value.forEach(item1 => {
        if (item1.name === item.name) {
          item1.value = item.num;
        }
      });
    });
  });
  // todo 未对接
  getJobEventBrokerLine(params).then(res => {});
};
const dateChange = value => {
  console.log(value);
  newTime.value = value;
  getData();
// 获取事件概括数据
const getData = () => {
  getTypeData();
  getBarChartData();
};
onMounted(() => {
  const chart = echarts.init(echartsRef.value);
  chart.setOption(option);
  chart = echarts.init(echartsRef.value);
  window.addEventListener('resize', () => {
    chart.resize();
  });
  getJobEventTotal().then(res => {
    total.value = res?.data?.data || 0;
    eventTotal.value = res?.data?.data || 0;
  });
  getData();
  getTableList();
});
</script>