Browse Source

排序优化

kukuasir@vip.qq.com 1 year ago
parent
commit
ed21308058
2 changed files with 20 additions and 16 deletions
  1. 14 6
      src/js/sort.js
  2. 6 10
      src/views/equip-management/report/list.vue

+ 14 - 6
src/js/sort.js

@@ -1,4 +1,17 @@
-import define from "./common.js";
+/** 根据盒子属性进行排序(比较最大值) */
+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;
+    if (val1 < val2) {
+      return sort.order === "descending" ? 1 : -1;
+    } else if (val1 > val2) {
+      return sort.order === "descending" ? -1 : 1;
+    } else {
+      return 0;
+    }
+  });
+}
 
 /** 根据主机属性进行排序(比较最大值) */
 export function sortBoxListByHost(data, sort) {
@@ -98,8 +111,3 @@ function _sortData(data, sort) {
     }
   });
 }
-
-// 是否为float类型
-function _isFloat(prop) {
-  return define.calcFloatProps.includes(prop);
-}

+ 6 - 10
src/views/equip-management/report/list.vue

@@ -413,6 +413,7 @@ import PopEndInfo from './PopEndInfo.vue';
 import { listBox, listArgs } from '../../../js/api.js';
 import { expandAllNodes, mergeTableRows } from '../../../js/merge.js';
 import { 
+	sortBoxList,
 	sortBoxListByHost, 
 	sortBoxListByNewTrend,
 	sortBoxListByHeatExchange,
@@ -811,21 +812,16 @@ export default {
 			if (!sort || !sort.prop.length) {
 				return;
 			}
-			// 主机
 			if (sort.prop.indexOf('host_') >= 0) {
 				return sortBoxListByHost(this.dataSource, sort);
-			}
-			// 新风机
-			else if (sort.prop.indexOf('nt_') >= 0) {
+			} else if (sort.prop.indexOf('nt_') >= 0) {
 				return sortBoxListByNewTrend(this.dataSource, sort);
-			}
-			// 换热站
-			else if (sort.prop.indexOf('hex_') >= 0) {
+			} else if (sort.prop.indexOf('hex_') >= 0) {
 				return sortBoxListByHeatExchange(this.dataSource, sort);
-			}
-			// 末端
-			else if (sort.prop.indexOf('end_') >= 0) {
+			} else if (sort.prop.indexOf('end_') >= 0) {
 				return sortBoxListByEnd(this.dataSource, sort);
+			} else {
+				return sortBoxList(this.dataSource, sort);
 			}
 			// console.log("排序后的数据: ", this.dataSource);
 		},