Browse Source

排序优化

kukuasir@vip.qq.com 1 year ago
parent
commit
5a4890f229
2 changed files with 66 additions and 42 deletions
  1. 43 9
      src/js/sort.js
  2. 23 33
      src/views/equip-management/report/list.vue

+ 43 - 9
src/js/sort.js

@@ -1,5 +1,20 @@
 /** 根据盒子属性进行排序(比较最大值) */
-export function sortBoxList(data, sort) {
+export function sortBoxListById(data) {
+  return data.sort(function(obj1, obj2) {
+    let val1 = obj1.box_create_time;
+    let val2 = obj2.box_create_time;
+    if (val1 < val2) {
+      return -1;
+    } else if (val1 > val2) {
+      return 1;
+    } else {
+      return 0;
+    }
+  });
+}
+
+/** 根据盒子属性进行排序(比较最大值) */
+export function sortBoxListBySystem(data, sort) {
   return data.sort(function(obj1, obj2) {
     let val1 = -99;
     let val2 = -99;
@@ -23,8 +38,12 @@ 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") {
-    comparedProp = 'colorval_' + sort.prop;
+  if (
+    sort.prop == "host_su_temp" ||
+    sort.prop == "host_re_temp" ||
+    sort.prop == "host_temp_diff"
+  ) {
+    comparedProp = "colorval_" + sort.prop;
   } else {
     comparedProp = sort.prop;
   }
@@ -52,7 +71,11 @@ 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;
@@ -82,7 +105,11 @@ 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;
   }
   // 先计算最大值
@@ -97,7 +124,11 @@ export function sortBoxListByHeatExchange(data, sort) {
           maxVal = hex[comparedProp];
         }
       } else {
-        if (hex[comparedProp] > maxVal && box.runStatus == 1 && hex[sort.prop]) {
+        if (
+          hex[comparedProp] > maxVal &&
+          box.runStatus == 1 &&
+          hex[sort.prop]
+        ) {
           maxVal = hex[comparedProp];
         }
       }
@@ -127,8 +158,7 @@ export function sortBoxListByEnd(data, sort) {
       } else {
         box.max_end_exception_num = -1;
       }
-    }
-    else {
+    } else {
       let maxVal = -99;
       for (let j = 0; j < endCtrl.length; j++) {
         const end = endCtrl[j];
@@ -137,7 +167,11 @@ export function sortBoxListByEnd(data, sort) {
             maxVal = end[comparedProp];
           }
         } else {
-          if (end[comparedProp] > maxVal && box.runStatus == 1 && end[sort.prop]) {
+          if (
+            end[comparedProp] > maxVal &&
+            box.runStatus == 1 &&
+            end[sort.prop]
+          ) {
             maxVal = end[comparedProp];
           }
         }

+ 23 - 33
src/views/equip-management/report/list.vue

@@ -413,7 +413,8 @@ import PopEndInfo from './PopEndInfo.vue';
 import { listBox, listArgs } from '../../../js/api.js';
 import { expandAllNodes, mergeTableRows } from '../../../js/merge.js';
 import {
-	sortBoxList,
+	sortBoxListById,
+	sortBoxListBySystem,
 	sortBoxListByHost,
 	sortBoxListByNewTrend,
 	sortBoxListByHeatExchange,
@@ -643,25 +644,15 @@ export default {
 		handleSortChanged(val) {
 			console.log('val is: ',val)
 			this.queryParams.page_index = 1;
-			this.prop = val.prop
-			this.order = val.order
-			if (val.order != null){
-				console.log('val.order != null',this.order,this.prop)
-				if (this.dataSource && this.dataSource.length > 0) {
-					define.setPropColorVal(this.dataSource, this.argsList);
-					this.sortDataSource(val);
-					this.genTableData();
-				} else {
-					this.getBoxList(val);
-				}
-			}else{
-				console.log('val.order == null',this.order,this.prop)
-				console.log('无排序条件,重新拉取数据')
-				this.queryParams.page_index = 1;
-				this.getBoxList();
-				//this.getBoxList(val);
+			this.prop = val.prop;
+			this.order = val.order;
+			if (this.dataSource && this.dataSource.length > 0) {
+				define.setPropColorVal(this.dataSource, this.argsList);
+				this.sortDataSource(val);
+				this.genTableData();
+			} else {
+				this.getBoxList(val);
 			}
-
 		},
 		debug(val) {
 			console.log('val is', val)
@@ -839,21 +830,20 @@ export default {
 			this.dataSource = filterData;
 		},
 		sortDataSource(sort) {
-			console.log('sort is: ',sort)
-			// 先排序
-			if (!sort || !sort.prop.length) {
-				return;
-			}
-			if (sort.prop.indexOf('host_') >= 0) {
-				return sortBoxListByHost(this.dataSource, sort);
-			} else if (sort.prop.indexOf('nt_') >= 0) {
-				return sortBoxListByNewTrend(this.dataSource, sort);
-			} else if (sort.prop.indexOf('hex_') >= 0) {
-				return sortBoxListByHeatExchange(this.dataSource, sort);
-			} else if (sort.prop.indexOf('end_') >= 0) {
-				return sortBoxListByEnd(this.dataSource, sort);
+			if (sort && sort.order && sort.prop) {
+				if (sort.prop.indexOf('host_') >= 0) {
+					return sortBoxListByHost(this.dataSource, sort);
+				} else if (sort.prop.indexOf('nt_') >= 0) {
+					return sortBoxListByNewTrend(this.dataSource, sort);
+				} else if (sort.prop.indexOf('hex_') >= 0) {
+					return sortBoxListByHeatExchange(this.dataSource, sort);
+				} else if (sort.prop.indexOf('end_') >= 0) {
+					return sortBoxListByEnd(this.dataSource, sort);
+				} else {
+					return sortBoxListBySystem(this.dataSource, sort);
+				}
 			} else {
-				return sortBoxList(this.dataSource, sort);
+				return sortBoxListById(this.dataSource);
 			}
 		},
 		/** 生成tableData */