From 7635213630830c4cbb9ff6ada69ba9b5c8a35d42 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Thu, 03 Apr 2025 11:05:34 +0800
Subject: [PATCH] feat: 地图居中点调整

---
 src/views/Home/components/HomeRight/EventOverview.vue |  341 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 270 insertions(+), 71 deletions(-)

diff --git a/src/views/Home/components/HomeRight/EventOverview.vue b/src/views/Home/components/HomeRight/EventOverview.vue
index 20d1dfc..effefdf 100644
--- a/src/views/Home/components/HomeRight/EventOverview.vue
+++ b/src/views/Home/components/HomeRight/EventOverview.vue
@@ -1,6 +1,55 @@
+<template>
+  <CommonTitle title="事件概况" />
+  <div :style="{ marginLeft: pxToRem(14) }">
+    <div class="eventOverview">
+      <div class="overviewData">
+        <div class="totalBox">
+          <div class="totalNumber">{{ eventTotal }}</div>
+          <div class="totalLabel">总事件数</div>
+        </div>
+        <div class="contentBox">
+          <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="timeArr" @change="timeChange" />
+
+      <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 deviceList"
+          :key="item.value"
+          :label="item.label"
+          :value="item.value"
+        />
+      </el-select>
+      <div class="completion">
+        <img class="completion-left-img" :src="completionLeft" alt="" />
+        <div class="completion-text">事件类型完成率情况</div>
+        <div class="completion-separator"></div>
+        <img class="completion-left-img" :src="completionLeft" alt="" />
+      </div>
+
+      <div class="chart" ref="echartsRef"></div>
+    </div>
+  </div>
+</template>
 <script setup>
 import CommonTitle from '@/components/CommonTitle.vue';
-import { pxToRem } from '@/utils/rem';
 import overviewImg1 from '@/assets/images/home/homeRight/overview1.png';
 import overviewImg2 from '@/assets/images/home/homeRight/overview2.png';
 import overviewImg3 from '@/assets/images/home/homeRight/overview3.png';
@@ -8,80 +57,215 @@
 import overviewImg5 from '@/assets/images/home/homeRight/overview5.png';
 import overviewImg6 from '@/assets/images/home/homeRight/overview6.png';
 import completionLeft from '@/assets/images/home/homeRight/completionLeft.png';
+import * as echarts from 'echarts';
+import CommonDateTime from '@/components/CommonDateTime.vue';
+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 echartsOption = {
+  tooltip: {
+    trigger: 'axis',
+    axisPointer: {
+      type: 'shadow',
+    },
+  },
+  grid: {
+    top: '5%',
+    left: 0,
+    right: 0,
+    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: [],
+  },
+  yAxis: [
+    {
+      type: 'value',
+      axisLabel: {
+        interval: 0, // 显示所有标签
+        color: '#FFFFFF',
+        fontFamily: 'Source Han Sans CN, Source Han Sans CN',
+        fontWeight: 400,
+        fontSize: 10,
+      },
+      axisLine: {
+        lineStyle: {
+          color: '#ffffff',
+        },
+      },
+      splitLine: {
+        lineStyle: {
+          color: 'rgba(255, 255, 255, 0.1)',
+          type: 'dashed', // 设置为虚线
+        },
+      },
+    },
+  ],
+  series: [],
+};
+
+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 value = ref('');
+const seriesObj = {};
+eventTypeList.value.forEach(item => {
+  seriesObj[item.status] = {
+    type: 'bar',
+    stack: 'Ad',
+    emphasis: {
+      focus: 'series',
+    },
+    name: item.name,
+    itemStyle: { color: item.color },
+    data: [],
+  };
+});
+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 options = [
-  {
-    value: 'Option1',
-    label: 'Option1',
-  },
-  {
-    value: 'Option2',
-    label: 'Option2',
-  },
-  {
-    value: 'Option3',
-    label: 'Option3',
-  },
-  {
-    value: 'Option4',
-    label: 'Option4',
-  },
-  {
-    value: 'Option5',
-    label: 'Option5',
-  },
-];
+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 => {
+      eventTypeList.value.forEach(item1 => {
+        if (item1.name === item.name) {
+          item1.value = item.num;
+        }
+      });
+    });
+  });
+};
+
+// 获取事件概括数据
+const getData = () => {
+  getTypeData();
+  getBarChartData();
+};
+
+onMounted(() => {
+  chart = echarts.init(echartsRef.value);
+  window.addEventListener('resize', () => {
+    chart.resize();
+  });
+  getJobEventTotal().then(res => {
+    eventTotal.value = res?.data?.data || 0;
+  });
+  getData();
+  getTableList();
+});
 </script>
-
-<template>
-  <CommonTitle title="事件概况" />
-  <div :style="{ marginLeft: pxToRem(14) }">
-    <div class="eventOverview">
-      <div class="overviewData">
-        <div class="totalBox">
-          <div class="totalNumber">8096</div>
-          <div class="totalLabel">总事件数</div>
-        </div>
-        <div class="contentBox">
-          <div class="overviewItem" v-for="item in list" :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>
-
-      <el-select class="homeRightSelect" v-model="value" placeholder="请选择" size="large">
-        <el-option
-          v-for="item in options"
-          :key="item.value"
-          :label="item.label"
-          :value="item.value"
-        />
-      </el-select>
-
-      <div class="completion">
-        <img class="completion-left-img" :src="completionLeft" />
-        <div class="completion-text">事件类型完成率情况</div>
-        <div class="completion-separator"></div>
-        <img class="completion-left-img" :src="completionLeft" />
-      </div>
-
-      <div class="chart">
-        <div class="chart-text">echarts柱状图</div>
-      </div>
-    </div>
-  </div>
-</template>
 
 <style scoped lang="scss">
 .homeRightSelect {
@@ -91,6 +275,7 @@
     .el-select__wrapper {
       background: linear-gradient(90deg, #195bad 0%, rgba(25, 91, 173, 0) 100%);
       min-height: 28px;
+      height: 28px;
       box-shadow: none;
       border: 1px solid #306fca;
     }
@@ -98,6 +283,7 @@
     .el-select__placeholder {
       font-family: Microsoft YaHei, Microsoft YaHei, serif;
       color: #ffffff;
+      font-size: 14px;
     }
   }
 }
@@ -119,6 +305,11 @@
   flex-direction: column;
   align-items: center;
 
+  .dateTime {
+    width: 356px;
+    margin: 15px 0 8px 0;
+  }
+
   .overviewData {
     width: 360px;
     height: 122px;
@@ -129,6 +320,8 @@
     padding-left: 11px;
 
     .totalBox {
+      width: 77px;
+
       .totalNumber {
         font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
         font-weight: 400;
@@ -189,6 +382,7 @@
     justify-content: space-between;
     width: 356px;
     height: 23px;
+    margin-top: 16px;
 
     &--left-img {
       width: 16px;
@@ -210,5 +404,10 @@
       opacity: 0.2;
     }
   }
+
+  .chart {
+    width: 356px;
+    height: 190px;
+  }
 }
 </style>

--
Gitblit v1.9.3