Browse Source

feat: 环境信息图片更换

珍珍 2 weeks ago
parent
commit
81b9ae33e7
1 changed files with 50 additions and 29 deletions
  1. 50 29
      src/views/pac/entranceScreen.vue

+ 50 - 29
src/views/pac/entranceScreen.vue

@@ -5,6 +5,7 @@
         <img class="logo" :src="parseImgUrl('pac', 'logo.svg')" />
         <img
           class="weather-icon"
+          v-show="outWeather.imgname"
           :src="parseImgUrl('pac', 'weather/' + outWeather.imgname)"
         />
         <div class="wether-info">
@@ -51,6 +52,7 @@ import {
 } from "vue";
 import { parseImgUrl, setQueryConfig } from "@/utils";
 import { getWeatherNew, getPacSpaceInfo } from "@/apis/envmonitor";
+import { setInterval, clearInterval } from "timers";
 export default defineComponent({
   components: {},
   setup(props) {
@@ -95,6 +97,8 @@ export default defineComponent({
     const proxyData = reactive({
       envlist: envlist,
       parseImgUrl: parseImgUrl,
+      time1: "",
+      time2: "",
       params: {
         spaceId: "Sp31010600032517f22f3d6a4c71b18cab24c444d362",
         pubname: "sagacarepad",
@@ -102,63 +106,66 @@ export default defineComponent({
       },
       outWeather: {},
       getWeatherIconByText(text) {
-        let imgname = "晴.png";
+        let imgname = "晴.svg";
         if (text.indexOf("晴") > -1) {
-          imgname = "晴.png";
+          imgname = "晴.svg";
         } else if (text.indexOf("雨") > -1) {
-          imgname = "大雨.png";
+          imgname = "大雨.svg";
         } else if (text.indexOf("阴") > -1 || text.indexOf("云") > -1) {
-          imgname = "阴.png";
+          imgname = "阴.svg";
         } else if (text.indexOf("霾") > -1) {
-          imgname = "雾.png";
+          imgname = "雾.svg";
         } else if (text.indexOf("雾") > -1) {
-          imgname = "雾.png";
+          imgname = "雾.svg";
         } else if (text.indexOf("风") > -1) {
-          imgname = "风.png";
+          imgname = "风.svg";
         } else if (text.indexOf("雷") > -1) {
-          imgname = "雷阵雨.png";
+          imgname = "雷阵雨.svg";
         }
         return imgname;
       },
       getWeatherIconByCode(code) {
         let imgname = "";
         if (code <= 3) {
-          imgname = "晴.png";
+          imgname = "晴.svg";
         } else if (code <= 8) {
-          imgname = "多云.png";
+          imgname = "多云.svg";
         } else if (code <= 9) {
-          imgname = "阴.png";
+          imgname = "阴.svg";
         } else if (code <= 10) {
-          imgname = "阵雨.png";
+          imgname = "阵雨.svg";
         } else if (code <= 12) {
-          imgname = "雷阵雨.png";
+          imgname = "雷阵雨.svg";
         } else if (code <= 13) {
-          imgname = "小雨.png";
+          imgname = "小雨.svg";
         } else if (code <= 15) {
-          imgname = "大雨.png";
+          imgname = "大雨.svg";
         } else if (code <= 18) {
-          imgname = "暴雨.png";
+          imgname = "暴雨.svg";
         } else if (code <= 19) {
           // 冻雨
-          imgname = "小雨.png";
+          imgname = "小雨.svg";
         } else if (code <= 20) {
-          imgname = "雨夹雪.png";
-        } else if (code <= 25) {
-          imgname = "雪.png";
+          imgname = "雨夹雪.svg";
+        }  else if (code <= 23) {
+          imgname = "小雪.svg";
+        }
+        else if (code <= 25) {
+          imgname = "大雪.svg";
         } else if (code <= 29) {
-          imgname = "阴.png";
+          imgname = "阴.svg";
         } else if (code <= 31) {
-          imgname = "雾.png";
+          imgname = "雾.svg";
         } else if (code <= 35) {
-          imgname = "风.png";
+          imgname = "风.svg";
         } else if (code <= 36) {
-          imgname = "龙卷风.png";
+          imgname = "龙卷风.svg";
         } else if (code <= 37) {
           // 冷
-          imgname = "阴.png";
+          imgname = "阴.svg";
         } else if (code <= 38) {
           // 热
-          imgname = "晴.png";
+          imgname = "晴.svg";
         }
         return imgname;
       },
@@ -182,7 +189,9 @@ export default defineComponent({
         const str = setQueryConfig(proxyData.params);
         getPacSpaceInfo({ criteria: proxyData.params }).then((res) => {
           const content = (res && res.content) || [];
-          proxyData.formatSpaceInfo(content);
+          if (content && content.length) {
+            proxyData.formatSpaceInfo(content);
+          }
         });
       },
       formatSpaceInfo(content = []) {
@@ -214,7 +223,7 @@ export default defineComponent({
             proxyData.envlist[3].num = item.humidity;
           } else {
             proxyData.envlist[3].num = "--";
-            proxyData.envlist[3].levelTxt = "";
+            // proxyData.envlist[3].levelTxt = "";
           }
         }
       },
@@ -257,11 +266,23 @@ export default defineComponent({
         };
         return obj;
       },
+      timeInit() {
+        this.time1 = setInterval(() => {
+          this.getWeatherInfo();
+        }, 300000);
+        this.time12 = setInterval(() => {
+          this.getSpaceInfo();
+        }, 300000);
+      },
+    });
+    onBeforeUnmount(() => {
+      clearInterval(this.time1);
+      clearInterval(this.time1);
     });
-    onBeforeUnmount(() => {});
     onMounted(() => {
       proxyData.getWeatherInfo();
       proxyData.getSpaceInfo();
+      proxyData.timeInit();
     });
     return {
       ...toRefs(proxyData),