Browse Source

优化排序

kukuasir@vip.qq.com 1 year ago
parent
commit
1286ae7355
2 changed files with 51 additions and 43 deletions
  1. 49 41
      src/js/sort.js
  2. 2 2
      src/views/equip-management/report/list.vue

+ 49 - 41
src/js/sort.js

@@ -1,8 +1,15 @@
 /** 根据盒子属性进行排序(比较最大值) */
 export function sortBoxList(data, sort) {
   return data.sort(function(obj1, obj2) {
-    let val1 = obj1.runStatus == 1 ? obj1[sort.prop] : -99;
-    let val2 = obj2.runStatus == 1 ? obj2[sort.prop] : -99;
+    let val1 = -99;
+    let val2 = -99;
+    if (sort.prop == "runStatus") {
+      val1 = obj1[sort.prop];
+      val2 = obj2[sort.prop];
+    } else {
+      val1 = obj1.runStatus == 1 ? obj1[sort.prop] : -99;
+      val2 = obj2.runStatus == 1 ? obj2[sort.prop] : -99;
+    }
     if (val1 < val2) {
       return sort.order === "descending" ? 1 : -1;
     } else if (val1 > val2) {
@@ -16,12 +23,10 @@ export function sortBoxList(data, sort) {
 /** 根据主机属性进行排序(比较最大值) */
 export function sortBoxListByHost(data, sort) {
   let comparedProp = sort.prop;
-  if (
-    sort.prop == "host_su_temp" ||
-    sort.prop == "host_re_temp" ||
-    sort.prop == "host_temp_diff"
-  ) {
+  if (sort.prop == "host_su_temp" || sort.prop == "host_re_temp" || sort.prop == "host_temp_diff") {
     comparedProp = 'colorval_' + sort.prop;
+  } else {
+    comparedProp = sort.prop;
   }
   for (let i = 0; i < data.length; i++) {
     const box = data[i];
@@ -29,13 +34,14 @@ export function sortBoxListByHost(data, sort) {
     const hostCtrl = box.hostCtrl || [];
     for (let j = 0; j < hostCtrl.length; j++) {
       const hp = hostCtrl[j];
-      if (
-        hp[comparedProp] > maxVal &&
-        box.runStatus == 1 &&
-        hp.host_su_temp &&
-        hp.host_re_temp
-      ) {
-        maxVal = hp[comparedProp];
+      if (comparedProp === sort.prop) {
+        if (hp[comparedProp] > maxVal && box.runStatus == 1) {
+          maxVal = hp[comparedProp];
+        }
+      } else {
+        if (hp[comparedProp] > maxVal && hp[sort.prop] && box.runStatus == 1) {
+          maxVal = hp[comparedProp];
+        }
       }
     }
     box["max_" + sort.prop] = maxVal;
@@ -46,12 +52,10 @@ export function sortBoxListByHost(data, sort) {
 /** 根据新风机属性进行排序(比较最大值) */
 export function sortBoxListByNewTrend(data, sort) {
   let comparedProp = sort.prop;
-  if (
-    sort.prop == "nt_in_temp" ||
-    sort.prop == "nt_in_humidity" ||
-    sort.prop == "nt_dew_point"
-  ) {
+  if (sort.prop == "nt_in_temp" || sort.prop == "nt_in_humidity" || sort.prop == "nt_dew_point") {
     comparedProp = "colorval_" + sort.prop;
+  } else {
+    comparedProp = sort.prop;
   }
   // 先计算最大值
   for (let i = 0; i < data.length; i++) {
@@ -60,8 +64,14 @@ export function sortBoxListByNewTrend(data, sort) {
     const newTrendCtrl = box.newTrendCtrl || [];
     for (let j = 0; j < newTrendCtrl.length; j++) {
       const dh = newTrendCtrl[j];
-      if (dh[comparedProp] > maxVal && box.runStatus == 1) {
-        maxVal = dh[comparedProp];
+      if (comparedProp === sort.prop) {
+        if (dh[comparedProp] > maxVal && box.runStatus == 1) {
+          maxVal = dh[comparedProp];
+        }
+      } else {
+        if (dh[comparedProp] > maxVal && box.runStatus == 1 && dh[sort.prop]) {
+          maxVal = dh[comparedProp];
+        }
       }
     }
     box["max_" + sort.prop] = maxVal;
@@ -72,11 +82,7 @@ export function sortBoxListByNewTrend(data, sort) {
 /** 根据换热站属性进行排序(比较最大值) */
 export function sortBoxListByHeatExchange(data, sort) {
   let comparedProp = sort.prop;
-  if (
-    sort.prop == "hex_su_temp" ||
-    sort.prop == "hex_re_temp" ||
-    sort.prop == "hex_temp_diff"
-  ) {
+  if (sort.prop == "hex_su_temp" || sort.prop == "hex_re_temp" || sort.prop == "hex_temp_diff") {
     comparedProp = "colorval_" + sort.prop;
   }
   // 先计算最大值
@@ -86,8 +92,14 @@ export function sortBoxListByHeatExchange(data, sort) {
     const heatExchangeCtrl = box.hex || [];
     for (let j = 0; j < heatExchangeCtrl.length; j++) {
       const hex = heatExchangeCtrl[j];
-      if (hex[comparedProp] > maxVal && box.runStatus == 1) {
-        maxVal = hex[comparedProp];
+      if (comparedProp === sort.prop) {
+        if (hex[comparedProp] > maxVal && box.runStatus == 1) {
+          maxVal = hex[comparedProp];
+        }
+      } else {
+        if (hex[comparedProp] > maxVal && box.runStatus == 1 && hex[sort.prop]) {
+          maxVal = hex[comparedProp];
+        }
       }
     }
     box["max_" + sort.prop] = maxVal;
@@ -101,21 +113,17 @@ export function sortBoxListByEnd(data, sort) {
     const box = data[i];
     const endCtrl = box.end || [];
     // 末端的通讯异常数量比较特殊,需要累加起来计算
-    if (sort.prop === "end_exception_num" && box.runStatus == 1) {
-      let total_end_exception_num = 0;
-      for (let j = 0; j < endCtrl.length; j++) {
-        total_end_exception_num += endCtrl[j].end_exception_num;
-      }
-      box.max_end_exception_num = total_end_exception_num;
-    } else {
-      let maxVal = -99;
-      for (let j = 0; j < endCtrl.length; j++) {
-        const end = endCtrl[j];
-        if (end[sort.prop] > maxVal && box.runStatus == 1) {
-          maxVal = end[sort.prop];
+    // 其他参数不参数与排序
+    if (box.runStatus == 1) {
+      if (sort.prop === "end_exception_num") {
+        let total_end_exception_num = 0;
+        for (let j = 0; j < endCtrl.length; j++) {
+          total_end_exception_num += endCtrl[j].end_exception_num;
         }
+        box.max_end_exception_num = total_end_exception_num;
       }
-      box["max_" + sort.prop] = maxVal;
+    } else {
+      box.max_end_exception_num = -1;
     }
   }
   return _sortData(data, sort);

+ 2 - 2
src/views/equip-management/report/list.vue

@@ -138,8 +138,8 @@
 					<el-table-column prop="runMode" label="运行模式" align="center" width="120" fixed sortable="custom">
 						<template slot-scope="scope">
 							<span class="el-table-tag"
-								:style="{ background: scope.row.runStatus == 2 ? '' : runModeMap[scope.row.runMode].color }">
-								{{ scope.row.runStatus == 2 ? '/' : runModeMap[scope.row.runMode].label }}
+								:style="{ background: scope.row.runStatus != 1 ? '' : runModeMap[scope.row.runMode].color }">
+								{{ scope.row.runStatus != 1 ? '/' : runModeMap[scope.row.runMode].label }}
 							</span>
 						</template>
 					</el-table-column>