Jelajahi Sumber

Merge branch 'test' of http://110.41.163.243:9980/kd-aiot/kd-aiot-frontend into dev

yusheng 6 bulan lalu
induk
melakukan
93da89f831

+ 58 - 10
src/views/rulesManagement/releaseRules/components/experimentationProcess.vue

@@ -69,7 +69,10 @@
       <el-card class="box-card" v-show="editShow" style="width: 320px">
         <div slot="header" class="clearfix">
           <span>配置</span>
-          <el-button style="float: right; padding: 3px 0" type="text" @click="editShow = false"
+          <el-button
+            style="float: right; padding: 3px 0"
+            type="text"
+            @click="editShow = false"
             >关闭</el-button
           >
         </div>
@@ -180,6 +183,22 @@
           <el-option key="append" label="追加" value="append" />
           <el-option key="replace" label="替换" value="replace" />
         </el-select>
+        <el-input
+          v-model.number="domObj.units.decimalPlace"
+          placeholder="小数位"
+          size="mini"
+          style="width: 120px; margin-left: 8px; flex-shrink: 0"
+        >
+        </el-input>
+        <el-select
+          v-model="domObj.units.takeValueMethod"
+          placeholder="取值方法"
+          size="mini"
+          style="width: 100px; margin-left: 8px; flex-shrink: 0"
+        >
+          <el-option key="1" label="四舍五入" value="1" />
+          <el-option key="2" label="去尾" value="2" />
+        </el-select>
       </div>
 
       <!-- 已组装公式标签展示 -->
@@ -247,7 +266,7 @@
         editShow: false,
         visible: false,
         templateDivRef: '',
-        domObj: {},
+        domObj: { units: {} },
         idList: [],
         opSelectOptions: ['+', '-', '*', '/', '%', '(', ')'],
         equationUnit: {
@@ -267,6 +286,7 @@
       calculation() {
         this.getValue();
         let equation = [];
+
         this.list.forEach((item) => {
           equation.push({
             id: item.id,
@@ -275,32 +295,58 @@
         });
         equation.forEach((item) => {
           for (const key in item.equation) {
-            let data = this.getObjValue(); //每次计算都获取最新的值
+            let { data, units } = this.getObjValue(); //每次计算都获取最新的值
             let value = '';
             if (item.equation[key].length) {
               item.equation[key].forEach((equationItem) => {
-                if (equationItem.type == 'symbol') {
+                if (
+                  equationItem.type == 'symbol' ||
+                  equationItem.type == 'value'
+                ) {
                   value += equationItem.value;
                 } else if (equationItem.type == 'id') {
                   value += Number(data[equationItem.value]) || 0;
-                } else {
-                  value += equationItem.value;
                 }
               });
+              if (units[key]?.decimalPlace) {
+                if (units[key]?.takeValueMethod) {
+                  value =
+                    units[key]?.takeValueMethod == 1
+                      ? parseFloat(eval(value).toFixed(units[key].decimalPlace))
+                      : this.truncateToFixedManual(
+                          eval(value),
+                          units[key].decimalPlace
+                        );
+                } else {
+                  value = parseFloat(
+                    eval(value).toFixed(units[key].decimalPlace)
+                  );
+                }
+              } else {
+                value = parseFloat(eval(value).toFixed(2));
+              }
               if (this.$refs['customTextRef' + item.id][0]) {
                 this.$refs['customTextRef' + item.id][0].equationValue({
                   domId: key,
-                  value: eval(value)
+                  value
                 });
               }
             }
           }
         });
       },
+
+      truncateToFixedManual(num, decimalPlaces) {
+        let factor = Math.pow(10, decimalPlaces);
+        return Math.floor(num * factor) / factor;
+      },
       getObjValue() {
         this.getValue();
         let data = {};
+        let units = {};
         this.list.forEach((item) => {
+          units = { ...item.units, ...units };
+
           if (item.type == 'customText') {
             data = { ...item.valueObj, ...data };
           } else {
@@ -311,7 +357,7 @@
             });
           }
         });
-        return data || {};
+        return { data: data || {}, units: units || {} };
       },
 
       setEquation() {
@@ -414,7 +460,8 @@
               this.$refs['customTextRef' + item.id][0].init({
                 form: item.value,
                 valueObj: item.valueObj,
-                equation: item.equation
+                equation: item.equation,
+                units: item.units
               });
             });
           });
@@ -449,11 +496,12 @@
       },
       getValue() {
         this.list.forEach((item, index) => {
-          let { form, valueObj, equation } =
+          let { form, valueObj, equation, units } =
             this.$refs['customTextRef' + item.id][0].getValue();
           this.$set(this.list[index], 'value', form);
           this.$set(this.list[index], 'valueObj', valueObj);
           this.$set(this.list[index], 'equation', equation);
+          this.$set(this.list[index], 'units', units);
         });
         return this.list;
       }

+ 19 - 10
src/views/rulesManagement/releaseRules/components/templateDiv/customTable.vue

@@ -93,7 +93,7 @@
         domId: '',
         rightClickShow: false,
         columns: [],
-        // rows: [],
+        units: {},
         equation: {}
       };
     },
@@ -134,7 +134,8 @@
 
       // 方法:添加新行
       addRow(rowIndex, columnIndex) {
-        if (columnIndex > 0) { //不是第一列则需要合并单元格
+        if (columnIndex > 0) {
+          //不是第一列则需要合并单元格
           this.columns.forEach((item, newColumnIndex) => {
             let newRow = this.getInput();
             if (newColumnIndex < columnIndex) {
@@ -155,7 +156,7 @@
             }
             this.columns[newColumnIndex].splice(rowIndex + 1, 0, newRow);
           });
-        } else { 
+        } else {
           this.columns.forEach((item, index) => {
             let _rowIndex = rowIndex;
             if (item[rowIndex]?.rowspan > 1) {
@@ -169,7 +170,8 @@
       getPreventRowspan(columnIndex, rowIndex) {
         let preventRowspan = null;
         this.columns[columnIndex].forEach((item, newRowIndex) => {
-          if (newRowIndex < rowIndex && item.rowspan > 1) { //向上找到当前列合并过单元格的行
+          if (newRowIndex < rowIndex && item.rowspan > 1) {
+            //向上找到当前列合并过单元格的行
             preventRowspan = newRowIndex;
           }
         });
@@ -179,7 +181,8 @@
       // 方法:删除指定行
       removeRow(rowIndex) {
         this.columns.forEach((item, columnIndex) => {
-          if (item[rowIndex].rowspan == 0) { // 如果当前列,删除的这一行rowspan为0,则需要找到真正需要改变rowspan的行
+          if (item[rowIndex].rowspan == 0) {
+            // 如果当前列,删除的这一行rowspan为0,则需要找到真正需要改变rowspan的行
             let preventRowspanIndex = this.getPreventRowspan(
               columnIndex,
               rowIndex
@@ -191,17 +194,17 @@
                 this.columns[columnIndex][preventRowspanIndex].rowspan - 1
               );
             }
-          } else if (item[rowIndex].rowspan > 1) { //rowspan大于1,代表合并过单元格,需要吧值继承给下一行
+          } else if (item[rowIndex].rowspan > 1) {
+            //rowspan大于1,代表合并过单元格,需要吧值继承给下一行
             let data = item[rowIndex];
             data.rowspan--;
-            this.$set(this.columns[columnIndex], [rowIndex + 1], data); 
+            this.$set(this.columns[columnIndex], [rowIndex + 1], data);
           }
 
           item.splice(rowIndex, 1);
         });
       },
 
-
       calculation() {
         this.$emit('calculation');
       },
@@ -217,20 +220,25 @@
         return {
           form: null,
           equation: this.equation,
+          units: this.units,
           valueObj: {
             columns: this.columns
           }
         };
       },
-      init({ form, valueObj, equation }) {
+      init({ form, valueObj, equation, units }) {
         this.form = form;
         this.columns = valueObj.columns;
         this.equation = equation || {};
+        this.units = units || {};
       },
       editInputChange(domObj) {
         if (domObj.equation) {
           this.equation[this.domId] = domObj.equation;
         }
+        if (domObj.units) {
+          this.units[this.domId] = domObj.units;
+        }
         this.columns.forEach((item, index) => {
           let rowsIndex = item.findIndex((cells) => cells.id == this.domId);
           if (rowsIndex >= 0) {
@@ -255,7 +263,8 @@
             readonly: item.readonly,
             value: item.value,
             rowspan: item.rowspan,
-            equation: this.equation[item.id]
+            equation: this.equation[item.id],
+            units: this.units[item.id]||{}
           }
         });
       }

+ 10 - 3
src/views/rulesManagement/releaseRules/components/templateDiv/customText.vue

@@ -43,6 +43,7 @@
         form: null,
         valueObj: {},
         equation: {},
+        units: {},
         domId: '',
         rightClickShow: false
       };
@@ -113,7 +114,8 @@
         return {
           form: this.$refs[this.id].innerHTML,
           valueObj: data,
-          equation: this.equation
+          equation: this.equation,
+          units: this.units
         };
       },
       equationValue({ domId, value }) {
@@ -125,10 +127,11 @@
           }
         }
       },
-      init({ form, valueObj, equation }) {
+      init({ form, valueObj, equation, units }) {
         this.form = form;
         this.valueObj = valueObj;
         this.equation = equation || {};
+        this.units = units || {};
         this.$nextTick(() => {
           if (!this.edit) {
             let inputs = document.querySelectorAll('.templateInput');
@@ -152,6 +155,9 @@
         if (domObj.equation) {
           this.equation[domObj.id] = domObj.equation;
         }
+        if (domObj.units) {
+          this.units[domObj.id] = domObj.units;
+        }
         dom.id = domObj.id;
       },
       onRightClick(PointerEvent) {
@@ -185,7 +191,8 @@
               width: event.target.offsetWidth,
               id: event.target.id,
               readonly: event.target.readOnly ? 2 : 1,
-              equation: this.equation[this.domId]
+              equation: this.equation[this.domId],
+              units: this.units[this.domId]||{}
             }
           });
         }

+ 2 - 2
src/views/system/unifiedPortal/index.vue

@@ -25,12 +25,12 @@
                     <i
                       class="el-icon-delete"
                       @click="deleted(item)"
-                      v-if="$hasPermission('mian:system:delete')"
+                      v-if="$hasPermission('sys:system:delete')"
                     ></i>
                     <i
                       class="el-icon-edit"
                       @click="edit(item)"
-                      v-if="$hasPermission('mian:system:update')"
+                      v-if="$hasPermission('sys:system:update')"
                     ></i>
                   </div>
                   <div class="card-content">