kukuasir@vip.qq.com 1 year ago
parent
commit
f0a7d52559
2 changed files with 62 additions and 30 deletions
  1. 20 0
      src/js/common.js
  2. 42 30
      src/js/sort.js

+ 20 - 0
src/js/common.js

@@ -255,6 +255,25 @@ const endCols = [
   // }
 ];
 
+// 需要参与运算的数字类型属性
+const calcFloatProps = [
+  "host_su_temp",
+  "host_re_temp",
+  "host_temp_diff",
+  "nt_in_temp",
+  "nt_in_humidity",
+  "nt_dew_point",
+  "hex_su_temp",
+  "hex_re_temp",
+  "hex_temp_diff",
+  "end_min_temp",
+  "end_min_humidity",
+  "end_min_dew_point",
+  "end_max_temp",
+  "end_max_humidity",
+  "end_max_dew_point",
+];
+
 /**
  * 取最大单机数
  */
@@ -414,6 +433,7 @@ export default {
   newTrendCols,
   heatExchangeCols,
   endCols,
+  calcFloatProps,
   calcMaxStandaloneCnt,
   calcEndMinAndMaxValue,
   getArgsColor,

+ 42 - 30
src/js/sort.js

@@ -1,90 +1,102 @@
+import define from "./common.js";
+
 /** 根据主机属性进行排序(比较最大值) */
 export function sortBoxListByHost(data, sort) {
   // 先计算最大值
   for (let i = 0; i < data.length; i++) {
-    const box = data[i]
-    const hostCtrl = box.hostCtrl || []
-    let maxVal = 0
+    const box = data[i];
+    const hostCtrl = box.hostCtrl || [];
+    let maxVal = 0;
     for (let j = 0; j < hostCtrl.length; j++) {
-      const hp = hostCtrl[j]
-      if (hp[sort.prop] > maxVal) {
-        maxVal = hp[sort.prop]
+      const hp = hostCtrl[j];
+      if (_isFloat(sort.prop)) {
+        if (hp[sort.prop] > maxVal && box.runStatus == 1) {
+          maxVal = hp[sort.prop];
+        }
+      } else {
+        // TODO:
       }
     }
-    box["max_" + sort.prop] = maxVal
+    box["max_" + sort.prop] = maxVal;
     console.log(
       `盒子[${box.boxName}]的${"max_" + sort.prop}值为: ${
         box["max_" + sort.prop]
       }`
     );
   }
-  return _sortData(data, sort)
+  return _sortData(data, sort);
 }
 
 /** 根据新风机属性进行排序(比较最大值) */
 export function sortBoxListByNewTrend(data, sort) {
   // 先计算最大值
   for (let i = 0; i < data.length; i++) {
-    const box = data[i]
+    const box = data[i];
     const newTrendCtrl = box.newTrendCtrl || [];
-    let maxVal = 0
+    let maxVal = 0;
     for (let j = 0; j < newTrendCtrl.length; j++) {
-      const dh = newTrendCtrl[j]
+      const dh = newTrendCtrl[j];
       if (dh[sort.prop] > maxVal) {
-        maxVal = dh[sort.prop]
+        maxVal = dh[sort.prop];
       }
     }
-    box["max_" + sort.prop] = maxVal
+    box["max_" + sort.prop] = maxVal;
   }
-  return _sortData(data, sort)
+  return _sortData(data, sort);
 }
 
 /** 根据换热站属性进行排序(比较最大值) */
 export function sortBoxListByHeatExchange(data, sort) {
   // 先计算最大值
   for (let i = 0; i < data.length; i++) {
-    const box = data[i]
+    const box = data[i];
     const heatExchangeCtrl = box.hex || [];
-    let maxVal = 0
+    let maxVal = 0;
     for (let j = 0; j < heatExchangeCtrl.length; j++) {
-      const hex = heatExchangeCtrl[j]
+      const hex = heatExchangeCtrl[j];
       if (hex[sort.prop] > maxVal) {
         maxVal = hex[sort.prop];
       }
     }
-    box["max_" + sort.prop] = maxVal
+    box["max_" + sort.prop] = maxVal;
   }
-  return _sortData(data, sort)
+  return _sortData(data, sort);
 }
 
 /** 根据面板属性进行排序(比较最大值) */
 export function sortBoxListByEnd(data, sort) {
   // 先计算最大值
   for (let i = 0; i < data.length; i++) {
-    const box = data[i]
+    const box = data[i];
     const endCtrl = box.end || [];
-    let maxVal = 0
+    let maxVal = 0;
     for (let j = 0; j < endCtrl.length; j++) {
-      const end = endCtrl[j]
+      const end = endCtrl[j];
       if (end[sort.prop] > maxVal) {
         maxVal = end[sort.prop];
       }
     }
-    box["max_" + sort.prop] = maxVal
+    box["max_" + sort.prop] = maxVal;
   }
-  return _sortData(data, sort)
+  return _sortData(data, sort);
 }
 
+// 数据排序
 function _sortData(data, sort) {
   return data.sort(function(obj1, obj2) {
-    let val1 = obj1["max_" + sort.prop]
-    let val2 = obj2["max_" + sort.prop]
+    let val1 = obj1["max_" + sort.prop];
+    let val2 = obj2["max_" + sort.prop];
     if (val1 < val2) {
-      return sort.order === "descending" ? 1 : -1
+      return sort.order === "descending" ? 1 : -1;
     } else if (val1 > val2) {
-      return sort.order === "descending" ? -1 : 1
+      return sort.order === "descending" ? -1 : 1;
     } else {
-      return 0
+      return 0;
     }
-  })
+  });
+}
+
+// 是否为float类型
+function _isFloat(prop) {
+  return define.calcFloatProps.includes(prop);
 }