wy 1 rok temu
rodzic
commit
7399a20269
3 zmienionych plików z 25 dodań i 9 usunięć
  1. 2 0
      src/main.js
  2. 15 1
      src/utils/zk.js
  3. 8 8
      src/views/equipment-monitoring/index.vue

+ 2 - 0
src/main.js

@@ -14,6 +14,7 @@ import './permission' // permission control
 import * as filters from './filters' // global filters
 import moment from "moment"
 import {minix} from '@/utils/minix'
+import * as zk from '@/utils/zk'
 //表格宽度自适应
 import AFTableColumn from 'af-table-column'
 import "@/utils/dislocation.js"
@@ -28,6 +29,7 @@ Object.keys(filters).forEach(key => {
   Vue.filter(key, filters[key])
 })
 Vue.prototype.$moment = moment;
+Vue.prototype.$checks = zk;
 Vue.config.productionTip = false
 //引入flexible
 import './utils/flexible.js'

+ 15 - 1
src/utils/zk.js

@@ -266,4 +266,18 @@ export function DateToStr(date) {
         "-" +
         (day > 9 ? day : "0" + day)
     );
-}
+}
+/**
+* 保留指定小数位方法 默认保留两位小数
+*/
+export function KeepDecimals(num,len =2 ){
+    let numStr = typeof(num) == "number" ? `${num}` : num // 判断类型,统一转字符串处理
+    if(!numStr)return ''; // 空值return 空字符串
+    numStr=numStr.replace(/[^0-9.]/g,'') // 限制值只能为0-9和字符‘.’
+    let isDecimalIndex = numStr.indexOf('.') // 判断存不存在小数位
+    if(isDecimalIndex === -1)return `${Number(numStr)}` // 不存在小数位,返回处理后的数字
+    let integer = numStr.slice(0,isDecimalIndex) // 获取整数位
+    let Decimals = numStr.slice(isDecimalIndex+1) // 获取小数位
+    Decimals=Decimals.replace(/[^0-9]/g,'').slice(0,len) // 处理小数位中的无效字符,并截取指定长度
+    return `${Number(integer)}.${Decimals || ''}` // 组装数据。并在处理小数位事,将无效字符处理成空串
+}

+ 8 - 8
src/views/equipment-monitoring/index.vue

@@ -148,19 +148,19 @@
               <sub-title name="速度" statement="SPEED" />
               <div class="speed">
                 <div class="p">
-                  行走:<font>{{ robotInfoVo.xAxis || 0 }}</font>
+                  行走:<font>{{ this.$checks.KeepDecimals(robotInfoVo.xAxis,5)  || '0'}}</font>
                   <em>mm/s</em>
                 </div>
                 <div class="p">
-                  伸缩:<font>{{ robotInfoVo.yAxis || 0}}</font>
+                  伸缩:<font>{{ this.$checks.KeepDecimals(robotInfoVo.yAxis,5)  || '0'}}</font>
                   <em>mm/s</em>
                 </div>
                 <div class="p">
-                  举升:<font>{{ robotInfoVo.zAxis || 0 }}</font>
+                  举升:<font>{{ this.$checks.KeepDecimals(robotInfoVo.zAxis,5)  || '0'}}</font>
                   <em>mm/s</em>
                 </div>
                 <div class="p">
-                  旋转:<font>{{ robotInfoVo.rAxis|| 0}}</font>
+                  旋转:<font>{{ this.$checks.KeepDecimals(robotInfoVo.rAxis,5)  || '0'}}</font>
                   <em>mm/s</em>
                 </div>
               </div>
@@ -169,19 +169,19 @@
               <sub-title name="位置" statement="POSITION" />
               <div class="speed">
                 <div class="p">
-                  行走:<font>{{ robotInfoVo.xDpmt || 0}}</font>
+                  行走:<font>{{ this.$checks.KeepDecimals(robotInfoVo.xDpmt,5)  || '0'}}</font>
                   <em>mm</em>
                 </div>
                 <div class="p">
-                  伸缩:<font>{{ robotInfoVo.yDpmt || 0}}</font>
+                  伸缩:<font>{{ this.$checks.KeepDecimals(robotInfoVo.yDpmt,5)  || '0'}}</font>
                   <em>mm</em>
                 </div>
                 <div class="p">
-                  举升:<font>{{ robotInfoVo.zDpmt|| 0 }}</font>
+                  举升:<font>{{ this.$checks.KeepDecimals(robotInfoVo.zDpmt,5)  || '0'}}</font>
                   <em>mm</em>
                 </div>
                 <div class="p">
-                  旋转:<font>{{ robotInfoVo.rDpmt || 0}}</font>
+                  旋转:<font>{{ this.$checks.KeepDecimals(robotInfoVo.rDpmt,5)  || '0'}}</font>
                   <em>mm</em>
                 </div>
               </div>