Browse Source

feat: 环境控制指标计算

珍珍 2 weeks ago
parent
commit
87b6f979f5
1 changed files with 29 additions and 37 deletions
  1. 29 37
      src/views/pac/entranceScreen.vue

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

@@ -228,44 +228,36 @@ export default defineComponent({
         }
       },
       checkLevel(value, name) {
-        let levelTxt = "";
-        let valueNum = parseFloat(value);
-        if (name == "humidity") {
-          if (valueNum < 30) {
-            levelTxt = "干燥";
-          } else if (valueNum > 70) {
-            levelTxt = "潮湿";
-          } else {
-            levelTxt = "健康";
-          }
-        } else if (name == "pm25") {
-          if (valueNum >= 0 && valueNum < 35) {
-            levelTxt = "健康";
-          } else if (valueNum >= 35 && valueNum <= 75) {
-            levelTxt = "良";
-          } else if (valueNum > 75 && valueNum <= 115) {
-            levelTxt = "轻度污染";
-          } else if (valueNum > 115 && valueNum <= 150) {
-            levelTxt = "中度污染";
-          } else if (valueNum > 150 && valueNum <= 250) {
-            levelTxt = "重度污染";
-          } else if (valueNum > 250) {
-            levelTxt = "严重污染";
-          }
-          console.log("levelTxt==", levelTxt);
-        } else if (name == "hcho") {
-          if (valueNum <= 0.1) {
-            levelTxt = "健康";
-          } else {
-            levelTxt = "超标";
-          }
-        }
+      let objList = {
+        humidity: {
+          range: [30, 70],
+          text: ['干燥', '健康', '潮湿'],
+        },
+        co2: {
+          range: [800, 1000, 1500],
+          text: ['健康', '达标', '略高', '超标'],
+        },
+        pm25: {
+          range: [35, 75, 115, 150, 250],
+          text: ['健康', '良', '轻度污染', '中度污染', '重度污染', '严重污染'],
+        },
+        hcho: {
+          range: [0.1],
+          text: ['健康', '超标'],
+        },
+        temper: {
+          range: [20, 24],
+          text: ['偏冷', '舒适', '偏热'],
+        },
+      };
+      let sortArr = [value, ...objList[name].range].sort((a, b) => {
+        return a - b;
+      });
 
-        let obj = {
-          levelTxt: levelTxt,
-        };
-        return obj;
-      },
+      let level = sortArr.findIndex((item) => item === value);
+      let levelTxt = objList[name].text[level];
+      return { level, levelTxt };
+    },
       timeInit() {
         this.time1 = setInterval(() => {
           this.getWeatherInfo();