kukuasir@vip.qq.com 1 year ago
parent
commit
7f5d67e813
3 changed files with 239 additions and 52 deletions
  1. 164 22
      src/js/common.js
  2. 33 9
      src/js/sort.js
  3. 42 21
      src/views/equip-management/report/list.vue

+ 164 - 22
src/js/common.js

@@ -365,26 +365,164 @@ export function calcEndMinAndMaxValue(standalone) {
 }
 
 /**
- * 函数:通过数组描述执行表达式,得到变量对应的颜色
+ * 对每个字段设置颜色值
  */
-function getArgsColor(argsList, runMode, val) {
-  let evalString = "";
+function setPropColorVal(data, argsList) {
+  const hpArgsList = argsList.filter((a) => a.En.indexOf("host_") == 0);
+  const dhArgsList = argsList.filter((a) => a.En.indexOf("nt_") == 0);
+  const hexArgsList = argsList.filter((a) => a.En.indexOf("hex_") == 0);
+  const cbArgsList = argsList.filter((a) => a.En.indexOf("end_") == 0);
+  for (let i = 0; i < data.length; i++) {
+    const box = data[i];
+
+    // 主机
+    const hostCtrl = box.hostCtrl || [];
+    for (let j = 0; j < hostCtrl.length; j++) {
+      const hp = hostCtrl[j];
+      // 供水温度
+      hp["colorval_host_su_temp"] = runCodeInArgsList(
+        box.runMode,
+        hp,
+        "host_su_temp",
+        hpArgsList
+      );
+      // 回水温度
+      hp["colorval_host_re_temp"] = runCodeInArgsList(
+        box.runMode,
+        hp,
+        "host_re_temp",
+        hpArgsList
+      );
+      // 温差
+      hp["colorval_host_temp_diff"] = runCodeInArgsList(
+        box.runMode,
+        hp,
+        "host_temp_diff",
+        hpArgsList
+      );
+    }
+
+    // 新风机
+    const newTrendCtrl = box.newTrendCtrl || [];
+    for (let j = 0; j < newTrendCtrl.length; j++) {
+      const dh = newTrendCtrl[j];
+      // 送风温度
+      dh["colorval_nt_in_temp"] = runCodeInArgsList(
+        box.runMode,
+        dh,
+        "nt_in_temp",
+        dhArgsList
+      );
+      // 送风湿度
+      dh["colorval_nt_in_humidity"] = runCodeInArgsList(
+        box.runMode,
+        dh,
+        "nt_in_humidity",
+        dhArgsList
+      );
+      // 送风露点
+      dh["colorval_nt_dew_point"] = runCodeInArgsList(
+        box.runMode,
+        dh,
+        "nt_dew_point",
+        dhArgsList
+      );
+    }
+
+    // 换热站
+    const heatExchangeCtrl = box.hex || [];
+    for (let j = 0; j < heatExchangeCtrl.length; j++) {
+      const hex = heatExchangeCtrl[j];
+      // 供水温度
+      hex["colorval_hex_su_temp"] = runCodeInArgsList(
+        box.runMode,
+        hex,
+        "hex_su_temp",
+        hexArgsList
+      );
+      // 供水温度
+      hex["colorval_hex_re_temp"] = runCodeInArgsList(
+        box.runMode,
+        hex,
+        "hex_re_temp",
+        hexArgsList
+      );
+      // 温差
+      hex["colorval_hex_temp_diff"] = runCodeInArgsList(
+        box.runMode,
+        hex,
+        "hex_temp_diff",
+        hexArgsList
+      );
+    }
+
+    // 末端
+    const endCtrl = box.end || [];
+    for (let j = 0; j < endCtrl.length; j++) {
+      const end = endCtrl[j];
+      // 最低室内温度
+      end["colorval_end_min_temp"] = runCodeInArgsList(
+        box.runMode,
+        end,
+        "end_min_temp",
+        cbArgsList
+      );
+      // 最低室内湿度
+      end["colorval_end_min_humidity"] = runCodeInArgsList(
+        box.runMode,
+        end,
+        "end_min_humidity",
+        cbArgsList
+      );
+      // 最低室内露点
+      end["colorval_end_min_dew_point"] = runCodeInArgsList(
+        box.runMode,
+        end,
+        "end_min_dew_point",
+        cbArgsList
+      );
+      // 最高室内温度
+      end["colorval_end_max_temp"] = runCodeInArgsList(
+        box.runMode,
+        end,
+        "end_max_temp",
+        cbArgsList
+      );
+      // 最高室内湿度
+      end["colorval_end_max_humidity"] = runCodeInArgsList(
+        box.runMode,
+        end,
+        "end_max_humidity",
+        cbArgsList
+      );
+      // 最高室内露点
+      end["colorval_end_max_dew_point"] = runCodeInArgsList(
+        box.runMode,
+        end,
+        "end_max_dew_point",
+        cbArgsList
+      );
+    }
+  }
+}
+
+/**
+ * 使用eval()方法执行判断
+ */
+function runCodeInArgsList(runMode, row, prop, argsList) {
+  argsList = argsList.filter((a) => a.En === prop);
+
+  var colorVal = 0;
+  var evalString = "";
   if (argsList.length <= 0) {
     return evalString;
   }
 
-  var color = "";
   // 先找出条件中有模式的数组跟无模式的数组
   // 先拼接带有模式的数组, 再组合一下无模式的数组
-  let runModeArgs = argsList.filter((args) => args.RunMode > 0);
-  let noneRunModeArgs = argsList.filter((args) => args.RunMode <= 0);
-  runModeArgs.forEach((args) => {
-    evalString += `if (runMode==${args.RunMode}) {color=val${args.Action}${args.Threshold}`;
-    if (args.Action2.length && args.Threshold2 > 0) {
-      evalString += `||val${args.Action2}${args.Threshold2}`;
-    }
-    evalString += `?'yellow':''} else `;
-  });
+  const val = row[prop];
+  const runModeArgs = argsList.filter((args) => args.RunMode > 0);
+  const noneRunModeArgs = argsList.filter((args) => args.RunMode <= 0);
   if (noneRunModeArgs.length > 0) {
     let tmp = "if (";
     noneRunModeArgs.forEach((args) => {
@@ -392,19 +530,22 @@ function getArgsColor(argsList, runMode, val) {
       tmp += "||";
     });
     tmp = tmp.substring(0, tmp.length - 2);
-    tmp += `) {color='yellow'} else {color=''}`;
+    tmp += `) {colorVal=1} else {colorVal=0}`;
     evalString += tmp;
   } else {
+    runModeArgs.forEach((args) => {
+      evalString += `if (runMode==${args.RunMode}) {colorVal=(val${args.Action}${args.Threshold}`;
+      if (args.Action2.length) {
+        evalString += `||val${args.Action2}${args.Threshold2})`;
+      } else {
+        evalString += ')';
+      }
+      evalString += `?1:0} else `;
+    });
     evalString = evalString.substring(0, evalString.length - 5);
   }
-
-  // if (argsList[0].En === "host_temp_diff") {
-  //   console.log(">>> evalString: ", evalString);
-  // }
-
-  // 执行命令
   eval(evalString);
-  return color;
+  return colorVal;
 }
 
 /**
@@ -487,7 +628,8 @@ export default {
   filterHostCtrl,
   calcMaxStandaloneCnt,
   calcEndMinAndMaxValue,
-  getArgsColor,
+  setPropColorVal,
+  runCodeInArgsList,
   formatData,
   getCbOrder,
 };

+ 33 - 9
src/js/sort.js

@@ -15,19 +15,27 @@ 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;
+  }
   for (let i = 0; i < data.length; i++) {
     const box = data[i];
-    const hostCtrl = box.hostCtrl || [];
     let maxVal = -99;
+    const hostCtrl = box.hostCtrl || [];
     for (let j = 0; j < hostCtrl.length; j++) {
       const hp = hostCtrl[j];
       if (
-        hp[sort.prop] > maxVal &&
+        hp[comparedProp] > maxVal &&
         box.runStatus == 1 &&
         hp.host_su_temp &&
         hp.host_re_temp
       ) {
-        maxVal = hp[sort.prop];
+        maxVal = hp[comparedProp];
       }
     }
     box["max_" + sort.prop] = maxVal;
@@ -37,15 +45,23 @@ 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"
+  ) {
+    comparedProp = "colorval_" + sort.prop;
+  }
   // 先计算最大值
   for (let i = 0; i < data.length; i++) {
     const box = data[i];
-    const newTrendCtrl = box.newTrendCtrl || [];
     let maxVal = -99;
+    const newTrendCtrl = box.newTrendCtrl || [];
     for (let j = 0; j < newTrendCtrl.length; j++) {
       const dh = newTrendCtrl[j];
-      if (dh[sort.prop] > maxVal && box.runStatus == 1) {
-        maxVal = dh[sort.prop];
+      if (dh[comparedProp] > maxVal && box.runStatus == 1) {
+        maxVal = dh[comparedProp];
       }
     }
     box["max_" + sort.prop] = maxVal;
@@ -55,15 +71,23 @@ 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"
+  ) {
+    comparedProp = "colorval_" + sort.prop;
+  }
   // 先计算最大值
   for (let i = 0; i < data.length; i++) {
     const box = data[i];
-    const heatExchangeCtrl = box.hex || [];
     let maxVal = -99;
+    const heatExchangeCtrl = box.hex || [];
     for (let j = 0; j < heatExchangeCtrl.length; j++) {
       const hex = heatExchangeCtrl[j];
-      if (hex[sort.prop] > maxVal && box.runStatus == 1) {
-        maxVal = hex[sort.prop];
+      if (hex[comparedProp] > maxVal && box.runStatus == 1) {
+        maxVal = hex[comparedProp];
       }
     }
     box["max_" + sort.prop] = maxVal;

+ 42 - 21
src/views/equip-management/report/list.vue

@@ -610,7 +610,7 @@ export default {
 	},
 	created() {
 		this.getBoxList();
-		this.getArgsList();
+		// this.getArgsList();
 	},
 	methods: {
 		renderHeader(h, { column, $index }, type) {
@@ -646,10 +646,16 @@ export default {
 			)
 		},
 		handleSortChanged(val) {
-			// console.log('handleSortChanged:', val)
+			this.queryParams.page_index = 1;
 			this.prop = val.prop
 			this.order = val.order
-			this.getBoxList(val);
+			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)
@@ -716,24 +722,40 @@ export default {
 				background: 'rgba(0, 0, 0, 0.8)',
 				target: document.querySelector('#container')
 			});
-			var params = {
-				box_name: this.queryParams.box_name,
-				online_status: this.queryParams.online_status,
-				run_mode: this.queryParams.run_mode,
-				province: this.operateSubjectForm.province,
-				city: this.operateSubjectForm.city,
-				prop: this.prop,
-				order: this.order,
-			};
-			listBox(params).then(resp => {
+
+			// 先获取条件参数
+			listArgs().then(resp => {
 				let data = resp.data || {};
-				let result = data.result || {};
-				this.filterOriginData(result.data || []);
-				this.sortDataSource(sort);
-				this.genTableData(true);
-				loading.close();
+				this.argsList = data.result || [];
+
+				// 再获取盒子列表数据
+				var params = {
+					box_name: this.queryParams.box_name,
+					online_status: this.queryParams.online_status,
+					run_mode: this.queryParams.run_mode,
+					province: this.operateSubjectForm.province,
+					city: this.operateSubjectForm.city,
+					prop: this.prop,
+					order: this.order,
+				};
+				listBox(params).then(resp => {
+					let data = resp.data || {};
+					let result = data.result || {};
+					const originData = result.data || [];
+					// 根据条件筛选有效数据
+					this.filterOriginData(originData);
+					// 对每个字段设置颜色值
+					define.setPropColorVal(this.dataSource, this.argsList);
+					// 根据属性排序
+					this.sortDataSource(sort);
+					// 分页并合并单元格
+					this.genTableData();
+					loading.close();
+				}).catch(err => {
+					console.log('[reportList]请求错误: ', err);
+				});
 			}).catch(err => {
-				console.log('[reportList]请求错误: ', err);
+				console.log('[args/list]请求错误: ', err);
 			});
 		},
 		/** 获取指标数据 */
@@ -884,8 +906,7 @@ export default {
 			if (!scope.row[prop]) {
 				return '';
 			} else {
-				let argsItems = this.argsList.filter(a => a.En === prop);
-				return define.getArgsColor(argsItems, scope.row.runMode, scope.row[prop]);
+				return scope.row['colorval_' + prop] > 0 ? 'yellow' : '';
 			}
 		},
 		/** 搜索 */