From 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Mon, 21 Apr 2025 18:29:09 +0800
Subject: [PATCH] fix: 天气显示

---
 src/views/TaskManage/TaskTop/TaskIndustry.vue |  138 ++++++++++++++++++++-------------------------
 1 files changed, 62 insertions(+), 76 deletions(-)

diff --git a/src/views/TaskManage/TaskTop/TaskIndustry.vue b/src/views/TaskManage/TaskTop/TaskIndustry.vue
index 47968cf..e27b5df 100644
--- a/src/views/TaskManage/TaskTop/TaskIndustry.vue
+++ b/src/views/TaskManage/TaskTop/TaskIndustry.vue
@@ -1,17 +1,20 @@
-<!-- 业务统计 -->
+<!-- 任务算法统计 -->
  <template>
-  <!-- <common-title title="行业统计" :style="{ marginLeft: pxToRem(14) }"></common-title> -->
   <div class="task-industry">
+    <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 { industryJobNumPieChart } from '@/api/home/task';
+import useEchartsResize from '@/hooks/useEchartsResize';
+import { useStore } from 'vuex';
+
+const store = useStore();
 const chartRef = ref(null);
-let chart = null;
+let { chart } = useEchartsResize(chartRef);
 
 const option = {
   tooltip: {
@@ -21,112 +24,95 @@
   legend: {
     orient: 'horizontal',
     left: 'center',
-    bottom: '5%',
+    bottom: '2%',
     textStyle: {
-      color: '#fff',
+      color: '#6B90B5',
       fontSize: 12
     },
-    itemWidth: 10,
-    itemHeight: 10,
-    itemGap: 10,
-    formatter: function(name) {
-      let data = option.series[0].data;
-      let total = 0;
-      let tarValue = 0;
-      for (let i = 0; i < data.length; i++) {
-        total += data[i].value;
-        if (data[i].name === name) {
-          tarValue = data[i].value;
-        }
-      }
-      let percentage = ((tarValue / total) * 100).toFixed(1);
-      return `${name} ${percentage}%`;
-    }
+    itemWidth: 2,        // 减小图例标记的宽度
+    itemHeight: 3,       // 减小图例标记的高度
+    itemGap: 8,          // 减小图例项之间的间距
+    formatter: '{name}'  // 简化图例文本
   },
   series: [
     {
       name: '行业统计',
       type: 'pie',
-      radius: '60%',
-      center: ['35%', '50%'],
-      itemStyle: {
-        borderRadius: 4,
-        borderColor: 'rgba(255,255,255,0.2)',
-        borderWidth: 1
-      },
+      roseType: 'radius',
+      radius: ['20%', '70%'],
+      center: ['50%', '45%'],
+      data: [],
+      // [
+      //   { name: '国土类', value: 0, itemStyle: { color: '#3D7FFF' } },
+      //   { name: '城管类', value: 0, itemStyle: { color: '#8277E9' } },
+      //   { name: '消防类', value: 0, itemStyle: { color: '#FFB77E' } },
+      //   { name: '林业类', value: 0, itemStyle: { color: '#44D7B6' } },
+      //   { name: '公安类', value: 0, itemStyle: { color: '#62F4FF' } }
+      // ],
       label: {
         show: true,
-        position: 'inside',
+        position: 'outside',
         formatter: '{c}',
         fontSize: 12,
         color: '#fff'
       },
       labelLine: {
-        show: false
-      },
-      emphasis: {
-        scale: true,
-        scaleSize: 10
+        show: true,
+        length: 5,
+        length2: 8,
+        lineStyle: {
+          color: '#fff'
+        }
       }
     }
   ]
 };
 
 // 获取行业统计数据
-const getIndustryJobNumPieChart = () => {
-  industryJobNumPieChart().then(res => {
+const getIndustryJobNumPieChart = (value) => {
+  industryJobNumPieChart(value).then(res => {
     if (res.data.code !== 0) return;
-    const data = res.data.data.map(item => ({
-      name: item.name,
-      value: item.value,
-      itemStyle: {
-        color: getRandomColor()
-      }
-    }));
-    option.series[0].data = data;
-    chart.setOption(option);
+    option.series[0].data = res.data.data;
+    // forEach(item => {
+    //   const matchData = res.data.data.find(d => d.name === item.name);
+    //   if (matchData) {
+    //     item.value = matchData.value;
+    //   }
+    // });
+    chart.value.setOption(option);
   });
 };
 
-// 生成随机颜色
-const getRandomColor = () => {
-  const colors = ['#1890FF', '#36CBCB', '#4ECB73', '#FBD437', '#F2637B', '#975FE5'];
-  return colors[Math.floor(Math.random() * colors.length)];
-};
+// 添加监听
+watch(() => store.state.task.taskSearchParams, (newVal) => {
+  if (newVal) {
+    getIndustryJobNumPieChart(newVal);
+  }
+}, { deep: true });
 
 onMounted(() => {
-  chart = echarts.init(chartRef.value);
-  getIndustryJobNumPieChart();
-  
-  window.addEventListener('resize', () => {
-    chart?.resize();
-  });
-});
-
-onUnmounted(() => {
-  window.removeEventListener('resize', chart?.resize);
-  chart?.dispose();
+  getIndustryJobNumPieChart({date_enum: 'TODAY'});
 });
 </script>
 
 <style lang="scss" scoped>
 .task-industry {
   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: 244px;
+  height: 100%;
+  .title {
+    margin-top: 10px;
+    width: 244px;
+    height: 26px;
+    background: url('@/assets/images/task/title.png') no-repeat center / 100% 100%;
+    color: #CFEAFF;
+    padding-left: 38px;
+    line-height: 8px;
+    font-size: 14px;
+  }
   .chart {
     width: 100%;
-    height: 100%;
+    height: 200px;
   }
 }
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.3