From ed7e34dfde7797eb983a2ac9541fbd01ac3d8c3a Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Thu, 15 May 2025 10:16:05 +0800
Subject: [PATCH] feat:设备统计样式调整

---
 src/views/wel/components/statistics.vue |  456 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 283 insertions(+), 173 deletions(-)

diff --git a/src/views/wel/components/statistics.vue b/src/views/wel/components/statistics.vue
index c168948..7e17f8a 100644
--- a/src/views/wel/components/statistics.vue
+++ b/src/views/wel/components/statistics.vue
@@ -9,7 +9,10 @@
         <img src="/src/assets/images/workbench/st2.png" alt="" />
       </div>
     </div>
-    <div class="grid-container1">
+    <!-- <div
+      class="grid-container"
+      v-if="permission.device_statistics_four && !permission.device_statistics_six"
+    >
       <div v-for="(item, index) in Object.keys(newtitleData)" :key="index" class="device-card">
         <div class="device-title">
           <img :src="test[item].img" :alt="newtitleData[item].name" />
@@ -20,16 +23,173 @@
           </div>
         </div>
         <div class="status-list">
-          <div v-for="(status, statusIndex) in newtitleData[item].status_map" :key="statusIndex" class="status-item"
-            :class="getStatusStyle(test[item]?.name, statusIndex)"
-            :style="{ color: getStatusColor(test[item]?.name, statusIndex) }">
-            <span class="indicator" :style="{
-              backgroundColor: getStatusBackground(test[item]?.name, statusIndex),
-              color: getStatusColor(test[item]?.name, statusIndex),
-            }"></span>
-            <span class="label">{{ getStatusLabel(test[item]?.name, statusIndex) }}</span>
-            <span class="count">{{ status }} {{ test[item]?.name === '无人机' ? '架' : '个' }}</span>
+          <template v-if="test[item]?.name == '机巢' || test[item]?.name == '无人机'">
+            <div
+              v-for="statusKey in [4, 0, -1]"
+              :key="statusKey"
+              class="status-item"
+              :class="getStatusStyle(test[item]?.name, statusKey)"
+              :style="{ color: getStatusColor(test[item]?.name, statusKey) }"
+            >
+              <span
+                class="indicator"
+                :style="{
+                  backgroundColor: getStatusBackground(test[item]?.name, statusKey),
+                  color: getStatusColor(test[item]?.name, statusKey),
+                }"
+              ></span>
+              <span class="label">{{ getStatusLabel(test[item]?.name, statusKey) }}</span>
+              <span class="count">
+                {{ newtitleData[item].status_map[statusKey] }}
+                {{ test[item]?.name === '无人机' ? '架' : '个' }}
+              </span>
+            </div>
+          </template>
+          <template v-else-if="test[item]?.name == '监控设备'">
+            <div
+              v-for="statusKey in [1, 0]"
+              :key="statusKey"
+              class="status-item"
+              :class="getStatusStyle(test[item]?.name, statusKey)"
+              :style="{ color: getStatusColor(test[item]?.name, statusKey) }"
+            >
+              <span
+                class="indicator"
+                :style="{
+                  backgroundColor: getStatusBackground(test[item]?.name, statusKey),
+                  color: getStatusColor(test[item]?.name, statusKey),
+                }"
+              ></span>
+              <span class="label">{{ getStatusLabel(test[item]?.name, statusKey) }}</span>
+              <span class="count">
+                {{ newtitleData[item].status_map[statusKey] }}
+                {{ test[item]?.name === '无人机' ? '架' : '个' }}
+              </span>
+            </div>
+          </template>
+
+          <template v-else>
+            <div
+              v-for="(status, statusIndex) in newtitleData[item].status_map"
+              :key="statusIndex"
+              class="status-item"
+              :class="getStatusStyle(test[item]?.name, statusIndex)"
+              :style="{ color: getStatusColor(test[item]?.name, statusIndex) }"
+            >
+              <span
+                class="indicator"
+                :style="{
+                  backgroundColor: getStatusBackground(test[item]?.name, statusIndex),
+                  color: getStatusColor(test[item]?.name, statusIndex),
+                }"
+              ></span>
+              <span class="label">{{ getStatusLabel(test[item]?.name, statusIndex) }}</span>
+              <span class="count"
+                >{{ status }} {{ test[item]?.name === '无人机' ? '架' : '个' }}</span
+              >
+            </div>
+          </template>
+        </div>
+      </div>
+    </div> -->
+    <div class="grid-container">
+      <div v-for="(item, index) in Object.keys(newtitleData)" :key="index" class="device-card">
+        <div class="device-title">
+          <img :src="test[item].img" :alt="newtitleData[item].name" />
+          <div class="itemcenter">
+            <div>{{ test[item]?.name || '--' }}</div>
+            <span class="shu">{{ newtitleData[item].total_num }}</span>
+            <span>个</span>
           </div>
+        </div>
+        <div class="status-list">
+          <template v-if="test[item]?.name == '机巢' || test[item]?.name == '无人机'">
+            <div
+              v-for="statusKey in [4, 0, -1]"
+              :key="statusKey"
+              class="status-item"
+              :class="getStatusStyle(test[item]?.name, statusKey)"
+              :style="{ color: getStatusColor(test[item]?.name, statusKey) }"
+            >
+              <span
+                class="indicator"
+                :style="{
+                  backgroundColor: getStatusBackground(test[item]?.name, statusKey),
+                  color: getStatusColor(test[item]?.name, statusKey),
+                }"
+              ></span>
+              <span class="label">{{ getStatusLabel(test[item]?.name, statusKey) }}</span>
+              <span class="count">
+                {{ newtitleData[item].status_map[statusKey] }}
+                {{ test[item]?.name === '无人机' ? '架' : '个' }}
+              </span>
+            </div>
+          </template>
+          <template v-else-if="test[item]?.name == '监控设备'">
+            <div
+              v-for="statusKey in [1, 0]"
+              :key="statusKey"
+              class="status-item"
+              :class="getStatusStyle(test[item]?.name, statusKey)"
+              :style="{ color: getStatusColor(test[item]?.name, statusKey) }"
+            >
+              <span
+                class="indicator"
+                :style="{
+                  backgroundColor: getStatusBackground(test[item]?.name, statusKey),
+                  color: getStatusColor(test[item]?.name, statusKey),
+                }"
+              ></span>
+              <span class="label">{{ getStatusLabel(test[item]?.name, statusKey) }}</span>
+              <span class="count">
+                {{ newtitleData[item].status_map[statusKey] }}
+                {{ test[item]?.name === '无人机' ? '架' : '个' }}
+              </span>
+            </div>
+          </template>
+          <template v-else-if="test[item]?.name == '机巢保险'">
+            <div
+              v-for="statusKey in [1, 0]"
+              :key="statusKey"
+              class="status-item"
+              :class="getStatusStyle(test[item]?.name, statusKey)"
+              :style="{ color: getStatusColor(test[item]?.name, statusKey) }"
+            >
+              <span
+                class="indicator"
+                :style="{
+                  backgroundColor: getStatusBackground(test[item]?.name, statusKey),
+                  color: getStatusColor(test[item]?.name, statusKey),
+                }"
+              ></span>
+              <span class="label">{{ getStatusLabel(test[item]?.name, statusKey) }}</span>
+              <span class="count">
+                {{ newtitleData[item].status_map[statusKey] }}
+                {{ test[item]?.name === '无人机' ? '架' : '个' }}
+              </span>
+            </div>
+          </template>
+          <template v-else>
+            <div
+              v-for="(status, statusIndex) in newtitleData[item].status_map"
+              :key="statusIndex"
+              class="status-item"
+              :class="getStatusStyle(test[item]?.name, statusIndex)"
+              :style="{ color: getStatusColor(test[item]?.name, statusIndex) }"
+            >
+              <span
+                class="indicator"
+                :style="{
+                  backgroundColor: getStatusBackground(test[item]?.name, statusIndex),
+                  color: getStatusColor(test[item]?.name, statusIndex),
+                }"
+              ></span>
+              <span class="label">{{ getStatusLabel(test[item]?.name, statusIndex) }}</span>
+              <span class="count"
+                >{{ status }} {{ test[item]?.name === '无人机' ? '架' : '个' }}</span
+              >
+            </div>
+          </template>
         </div>
       </div>
     </div>
@@ -37,65 +197,31 @@
 </template>
 
 <script setup>
-import { useStore } from 'vuex'
-import { computed } from 'vue'
-import titleImg1 from '@/assets/images/workbench/st3.png'
-import titleImg2 from '@/assets/images/workbench/st4.png'
-import titleImg3 from '@/assets/images/workbench/st5.png'
-import titleImg4 from '@/assets/images/workbench/st6.png'
-import titleImg5 from '@/assets/images/workbench/st8.png'
-import titleImg6 from '@/assets/images/workbench/st9.png'
-import { getStatics } from '@/api/home/index'
-const store = useStore()
-// Object.key;
-// 运维人员:1912328766238597121
-// 政企专员:1912467025014923265
+import { useStore } from 'vuex';
+import { computed } from 'vue';
+import titleImg1 from '@/assets/images/workbench/st3.png';
+import titleImg2 from '@/assets/images/workbench/st4.png';
+import titleImg3 from '@/assets/images/workbench/st8.png';
+import titleImg4 from '@/assets/images/workbench/st5.png';
+import titleImg5 from '@/assets/images/workbench/st6.png';
+import titleImg6 from '@/assets/images/workbench/st9.png';
+import { getStatics } from '@/api/home/index';
+import { useRouter } from 'vue-router';
+const router = useRouter();
+const store = useStore();
 const refresh = () => {
-  getStaticsList()
-}
+  getStaticsList();
+};
 const jumppage = () => {
-  console.log('跳转')
+  router.push({
+    path: '/device/index',
+  });
+};
+const userInfo = computed(() => store.getters.userInfo);
+const permission = computed(() => store.getters.permission);
 
-}
-const userInfo = computed(() => store.getters.userInfo)
-const permission = computed(() => store.getters.permission)
+const newtitleData = ref({});
 
-console.log(permission, 'permission')
-const newtitleData = ref({})
-const titleData = ref([
-  {
-    img: titleImg1,
-    name: '机巢',
-    total_num: 52,
-    working: 0,
-    leisure: 0,
-    offline: 0,
-  },
-  {
-    img: titleImg2,
-    name: '无人机',
-    total_num: 52,
-    working: 0,
-    leisure: 0,
-    offline: 0,
-  },
-  {
-    img: titleImg3,
-    name: '监控设备',
-    total_num: 52,
-    working: 0,
-    leisure: 0,
-    offline: 0,
-  },
-  {
-    img: titleImg4,
-    name: '移动机巢',
-    total_num: 52,
-    working: 0,
-    leisure: 0,
-    offline: 0,
-  },
-])
 const test = {
   no_move_list: {
     name: '机巢',
@@ -106,7 +232,7 @@
     img: titleImg2,
   },
   flow_type_list: {
-    name: '机巢流量',
+    name: '无人机流量',
     img: titleImg3,
   },
   monitor_list: {
@@ -122,25 +248,30 @@
     name: '机巢保险',
     img: titleImg6,
   },
-}
+};
 const statusSelect = {
-  0: '空闲中',
   4: '作业中',
+  0: '空闲中',
   '-1': '离线中',
-}
+};
 const flowStatus = {
-  0: '流量无忧',
-  1: '流量到期',
-  2: '流量不足',
-}
+  0: '无忧',
+  1: '到期',
+  2: '不足',
+};
 const monitorStatus = {
   0: '离线中',
   1: '在线中',
-}
+};
+
 const insureStatus = {
   0: '临近到期',
   1: '正常期限',
-}
+};
+const moveListStatus = {
+  '-1': '离线中',
+  4: '在线中',
+};
 // 样式配置对象
 const statusStyles = {
   机巢保险: {
@@ -148,7 +279,7 @@
     1: { class: 'normal', color: '#1B94FF', background: '#1B94FF' },
   },
 
-  机巢流量: {
+  无人机流量: {
     0: { class: 'offline', color: '#11CE3E', background: '#11CE3E' },
     1: { class: 'flying', color: '#1B94FF', background: '#1B94FF' },
     2: { class: 'flying', color: '#7C8091', background: '#7C8091' },
@@ -157,71 +288,89 @@
     0: { class: 'offline', color: '#bababa', background: '#bababa' },
     1: { class: 'flying', color: '#1B94FF', background: '#1B94FF' },
   },
+  移动机巢: {
+    '-1': { class: 'offline', color: '#bababa', background: '#bababa' },
+    4: { class: 'flying', color: '#1B94FF', background: '#1B94FF' },
+  },
   // 默认样式配置
   default: {
     0: { class: 'warning', color: '#1b94ff', background: '#1b94ff' },
     4: { class: 'success', color: '#11ce3e', background: '#11ce3e' },
     '-1': { class: 'success', color: '#bababa', background: '#bababa' },
   },
-}
-const getStatusStyle = (name, statusIndex) => {
-  // 获取样式配置,优先使用名称专属配置
-  const styleConfig = statusStyles[name] || statusStyles.default
-  return styleConfig[statusIndex]?.class || ''
-}
+};
 
+const getStatusStyle = (name, statusIndex) => {
+  const styleConfig = statusStyles[name] || statusStyles.default;
+  return styleConfig[statusIndex]?.class || '';
+};
 const getStatusColor = (name, statusIndex) => {
-  // 获取颜色配置,优先使用名称专属配置
-  const styleConfig = statusStyles[name] || statusStyles.default
-  return styleConfig[statusIndex]?.color || '#333'
-}
-// 新增背景颜色获取方法
+  const styleConfig = statusStyles[name] || statusStyles.default;
+  return styleConfig[statusIndex]?.color || '#333';
+};
+//背景颜色获取方法
 const getStatusBackground = (name, statusIndex) => {
-  const styleConfig = statusStyles[name] || statusStyles.default
-  return (
-    styleConfig[statusIndex]?.background ||
-    styleConfig[statusIndex]?.color || // 降级使用字体颜色
-    '#F0F0F0'
-  ) // 最终默认颜色
-}
+  const styleConfig = statusStyles[name] || statusStyles.default;
+  return styleConfig[statusIndex]?.background || styleConfig[statusIndex]?.color || '#F0F0F0';
+};
 const getStatusLabel = (itemName, statusCode) => {
   switch (itemName) {
-    case '机巢流量':
-      return flowStatus[statusCode] || statusSelect[statusCode]
+    case '无人机流量':
+      return flowStatus[statusCode] || statusSelect[statusCode];
     case '监控设备':
-      return monitorStatus[statusCode] || statusSelect[statusCode]
+      return monitorStatus[statusCode] || statusSelect[statusCode];
     case '机巢保险':
-      return insureStatus[statusCode] || statusSelect[statusCode]
+      return insureStatus[statusCode] || statusSelect[statusCode];
+    case '移动机巢':
+      return moveListStatus[statusCode] || statusSelect[statusCode];
     default:
-      return statusSelect[statusCode] || `未知状态(${statusCode})`
+      return statusSelect[statusCode] || `未知状态(${statusCode})`;
   }
-}
+};
+// const px = {
+// '4':0,
+//   '0':1,
+//   '-1':2
+// }
+// const status_map = newtitleData.value.plant_list.status_map
+// newtitleData.value.plant_list.status_map = Object.entries(status_map).sort((a,b) => {
+//   return px[a[0]] - px[b[0]]
+// })
+// console.log(Object.entries(status_map).sort((a,b) => {
+//   return px[a[0]] - px[b[0]]
+// }));
 const getStaticsList = () => {
-  getStatics(userInfo.value.detail.areaCode,).then(res => {
-  console.log(permission, 111)
+  getStatics(userInfo.value.detail.areaCode).then(res => {
+    console.log('permission.value', permission.value);
+    console.log('设备', res.data.data);
     if (permission.value?.device_statistics_six) {
-      newtitleData.value = res.data.data
-      return
+      const { move_list, ...filteredData } = res.data.data;
+      newtitleData.value = filteredData;
+
+      return;
     }
 
     for (let key in res.data.data) {
-      if (permission.value?.device_statistics_four && (key === 'flow_type_list' ||
-        key === 'insure_list')) continue
-      newtitleData.value[key] = res.data.data[key]
+      if (
+        permission.value?.device_statistics_four &&
+        (key === 'flow_type_list' || key === 'insure_list')
+      )
+        continue;
+      newtitleData.value[key] = res.data.data[key];
     }
-  })
-}
+  });
+};
 
 const unitMap = {
   drone: '架',
   nest: '个',
   monitor: '个',
   mobile: '个',
-}
+};
 
 onMounted(() => {
-  getStaticsList()
-})
+  getStaticsList();
+});
 </script>
 
 <style scoped lang="scss">
@@ -230,7 +379,7 @@
   background: #ffffff;
   border-radius: 8px 8px 8px 8px;
   margin-bottom: 10px;
-
+  font-size: clamp(12px, 2vw, 24px);
   .title {
     padding: 14px 14px 0 21px;
     display: flex;
@@ -243,6 +392,10 @@
 
       span {
         margin-right: 4px;
+        font-weight: bold;
+        font-size: 16px;
+        color: #363636;
+        font-family: 'YouSheBiaoTiHei';
       }
 
       img {
@@ -257,14 +410,15 @@
 
   .grid-container {
     padding: 0 14px 0 21px;
-    display: grid;
-    grid-template-columns: repeat(4, 1fr);
-
+    // display: grid;
+    // grid-template-columns: repeat(4, 1fr);
+    display: flex;
+   justify-content: space-between;
     .device-card {
       display: flex;
-      flex-direction: column;
       align-items: center;
-
+      margin-top: 30px;
+      margin-left: 10px;
       .device-title {
         display: flex;
         align-items: center;
@@ -276,7 +430,7 @@
       }
 
       .itemcenter {
-        margin-left: 14px;
+        margin-left: 5px;
         font-weight: 400;
         font-size: 14px;
         color: #343434;
@@ -285,6 +439,10 @@
           font-weight: bold;
           font-size: 36px;
           color: #363636;
+          display: inline-block;
+          transform: skewX(-5deg);
+          font-family: 'YouSheBiaoTiHei';
+          // font-size: calc(12px + 0.5vw);
         }
 
         span {
@@ -298,7 +456,6 @@
     .status-list {
       display: grid;
       margin-left: 5px;
-
       .status-item {
         display: flex;
         align-items: center;
@@ -307,13 +464,11 @@
         font-size: 12px;
         gap: 10px;
         margin-bottom: 5px;
-
         .indicator {
           width: 6px;
           height: 6px;
           border-radius: 50%;
         }
-
         .label {
           flex: 1;
           // font-size: clamp(12px, 1vw, 14px);
@@ -324,36 +479,12 @@
           font-size: 14px;
           color: #7c8091;
         }
-
-        &.status-4 .indicator {
-          background: #11ce3e;
-        }
-
-        &.status-4 {
-          color: #11ce3e;
-        }
-
-        &.status-0 .indicator {
-          background: #1b94ff;
-        }
-
-        &.status-0 {
-          color: #1b94ff;
-        }
-
-        &.status--1 .indicator {
-          background: #bababa;
-        }
-
-        &.status--1 {
-          color: #bababa;
-        }
       }
     }
   }
 
   .grid-container1 {
-    padding: 0 14px 0 21px;
+    // padding: 0 14px 0 21px;
     display: grid;
     grid-template-columns: repeat(6, 1fr);
 
@@ -382,6 +513,9 @@
           font-weight: bold;
           font-size: 36px;
           color: #363636;
+          display: inline-block;
+          transform: skewX(-5deg);
+          font-family: 'YouSheBiaoTiHei';
         }
 
         span {
@@ -412,37 +546,13 @@
 
         .label {
           flex: 1;
-          // font-size: clamp(12px, 1vw, 14px);
+          font-size: clamp(12px, 1vw, 14px);
         }
 
         .count {
-          // font-size: clamp(14px, 1.1vw, 16px);
+          font-size: clamp(12px, 1.1vw, 16px);
           font-size: 14px;
           color: #7c8091;
-        }
-
-        &.status-4 .indicator {
-          background: #11ce3e;
-        }
-
-        &.status-4 {
-          color: #11ce3e;
-        }
-
-        &.status-0 .indicator {
-          background: #1b94ff;
-        }
-
-        &.status-0 {
-          color: #1b94ff;
-        }
-
-        &.status--1 .indicator {
-          background: #bababa;
-        }
-
-        &.status--1 {
-          color: #bababa;
         }
       }
     }

--
Gitblit v1.9.3