浏览代码

工作统计修改

cuiHe 11 月之前
父节点
当前提交
5b34037c5e
共有 4 个文件被更改,包括 92 次插入18 次删除
  1. 1 0
      .eslintrc.js
  2. 1 3
      src/layout/sidebar.vue
  3. 31 8
      src/utils/tools.ts
  4. 59 7
      src/views/big-screen/single.vue

+ 1 - 0
.eslintrc.js

@@ -25,6 +25,7 @@
     "getM_S": true,
     "h": true,
     "inject": true,
+    "isNullOrEmpty": true,
     "isProxy": true,
     "isReactive": true,
     "isReadonly": true,

+ 1 - 3
src/layout/sidebar.vue

@@ -93,7 +93,7 @@
   import { useSidebarStore } from '../store/sidebar'
   import { useRoute } from 'vue-router'
   import { menuList, equipmentMenu } from '@/router/menu'
-  import { useMqtt, useQuery } from '@/utils/hooks'
+  import { useQuery } from '@/utils/hooks'
   import { fetchDeviceInfo } from '@/api/deviceAuthorize'
   const route = useRoute()
   const router = useRouter()
@@ -137,8 +137,6 @@
     })
     sidebar.setEquipmentId(useQuery('id'))
     getDeviceInfo(id)
-    // 挂载全局mqtt
-    useMqtt()
   })
   const onRoutes = computed(() => {
     return route.path

+ 31 - 8
src/utils/tools.ts

@@ -1,4 +1,5 @@
 import '../../public/mqtt/dist/mqtt.min'
+import { MqttClient } from './mqtt/types'
 declare const window: any
 var _mqttMessageCallback: any = null
 
@@ -37,21 +38,21 @@ export const onUnsubscribe = (topic: string) => {
  * 实时数据
  */
 export const useMqtt = () => {
-  const userInfo = JSON.parse(localStorage.getItem('gdyt_user') as string)
+  const userInfo = JSON.parse(localStorage.getItem('user') as string)
   const { userId, securityCode } = userInfo
   const { mqtt } = window as any
   const mqttOptions = {
     clean: true,
     connectTimeout: 10000,
-    port: 80,
+    port: 443,
     clientId: `2${Date.now()}`, //提取到配置文件
     username: `${userId}`, //提取到配置文件
     password: securityCode //提取到配置文件
   }
   console.log(mqttOptions)
   if (window.client == null) {
-    //console.log('初始化mqtt')
-    window.client = mqtt.connect('ws://cloud-mqtt.gd-yt.cn/mqtt', mqttOptions)
+    console.log('初始化mqtt')
+    window.client = mqtt.connect('wss://mqtt.hldcloud.cn/mqtt', mqttOptions)
   }
   window.client.on('connect', () => {
     console.log('mqtt连接成功')
@@ -151,20 +152,42 @@ export function formatGears(gear: any) {
 
 /** value值,  translate 系数*/
 export const formatValue = (value: any, translate: any) => {
-  if (value == null) return '--'
-  if (value == "闭合" || value == "开启") {
+  if (isNullOrEmpty(value)) {
+    return ''
+  }
+  if (value === "闭合" || value === "开启") {
     return value
   }
 
   let num = parseFloat(value) * translate;
   let surplus = num % 1;
   if (surplus != 0.0) {
-    return (Math.floor(num * 100) / 100).toFixed(2)
+    return ((num * 100) / 100).toFixed(2)
   } else {
     //无小数
-    return parseInt(num.toString());
+    return parseInt(num.toString()).toString();
+  }
+
+}
+
+/**
+ * null或者空字符串
+ * @param v 
+ * @returns 
+ */
+export function isNullOrEmpty(v: any) {
+  if (v === null || v === '' || v === undefined) {
+    return true
   }
 
+  if (typeof v === 'object') {
+    if (Array.isArray(v)) {
+      return v.length === 0
+    } else {
+      return Object.keys(v).length === 0
+    }
+  }
+  return false
 }
 
 //解析档位

+ 59 - 7
src/views/big-screen/single.vue

@@ -204,6 +204,7 @@
     </div>
     <div class="right">
       <div class="right_top">
+
           <div style="display: flex;justify-content: space-between;align-items: center;">
               <div style="display: flex;align-items: center;">
                 <div style="width: 8px;height: 8px;background-color: #02803A;margin-right: 15px;" />
@@ -212,7 +213,7 @@
                 </span>
               </div>
               <span style="margin-top: 5px;color: #608BF3;font-size: 18px;font-family: Alibaba-PuHuiTi-R;">
-                {{ dutyCycleData.currentDuration }}
+                {{ currentDurationData.value }}
               </span>
           </div>
           <div style="display: flex;justify-content: space-between;align-items: center;border-top:0.5px solid #152844;">
@@ -223,7 +224,7 @@
                 </span>
               </div>
               <span style="margin-top: 5px;color: #608BF3;font-size: 18px;font-family: Alibaba-PuHuiTi-R;">
-                {{ dutyCycleData.totalDuration }}
+                {{ totalDurationData.value }}
               </span>
           </div>
           <div style="display: flex;justify-content: space-between;align-items: center;border-top:0.5px solid #152844;">
@@ -234,7 +235,7 @@
                 </span>
               </div>
               <span style="margin-top: 5px;color: #608BF3;font-size: 18px;font-family: Alibaba-PuHuiTi-R;">
-                {{ dutyCycleData.totalCount+' 次' }}
+                {{ totalCountData.value+' 次' }}
               </span>
           </div>
       </div>
@@ -396,8 +397,12 @@
   const hoistSwitchVariablesData: any = ref([])
   //总配电变量
   const otherSwitchData: any = ref([])
+  //本次工作
+  const currentDurationData: any = ref({})
+  //累计工作
+  const totalDurationData: any = ref({})
   //工作循环
-  const dutyCycleData: any = ref({})
+  const totalCountData: any = ref({})
   //报警集合
   const alarmRecordArr: any = ref([]);
 
@@ -510,8 +515,12 @@
     hoistSwitchVariablesData.value = chunkArray(hoistData.value.switchVariables,12)
     //总配电开关量
     otherSwitchData.value = chunkArray(deviceData.value.otherSwitchData,6)
-    //工作云环
-    dutyCycleData.value = deviceData.value.dutyCycle
+    //本次工作
+    currentDurationData.value = deviceData.value.dutyCycle.currentDuration
+    //累计工作
+    totalDurationData.value = deviceData.value.dutyCycle.totalDuration
+    //工作循环
+    totalCountData.value = deviceData.value.dutyCycle.totalCount
     //获取报警信息
     const record = await getAlertRecordsByDevice({ deviceId: deviceId.value, maxCount: 10 })
     alarmRecordArr.value = record
@@ -708,6 +717,32 @@
               }
             });
           }
+          //本次工作
+          const currentDuration = currentDurationData.value
+          if(currentDuration){
+            if (currentDuration.code == Code) {
+                let value = formatValue(Value, currentDuration.translate)  
+                currentDuration.value = evaluateFormula(value, currentDuration.formula)
+                return
+            }
+          }
+          //累计工作
+          const totalDuration = totalDurationData.value
+          if(totalDuration){
+            if (totalDuration.code == Code) {
+                let value = formatValue(Value, totalDuration.translate)  
+                totalDuration.value = evaluateFormula(value, totalDuration.formula)
+                return
+            }
+          }
+          //工作循环
+          const totalCount = totalCountData.value
+          if(totalCount){
+            if (totalCount.code == Code) {
+                totalCount.value = formatValue(Value, totalCount.translate)
+                return
+            }
+          }
       })
   }
 
@@ -719,8 +754,25 @@
     router.go(-1)
   }
 
+  const evaluateFormula = (value: any, formula: any) => {
+    if (formula == null || formula == undefined || formula === '') {
+      return value
+    }
+    //函数模板
+    const array = formula.split(",")
+    //字符串模本
+    var templete = array[0]
+    const formulaArray = array.slice(1)
+    formulaArray.forEach((item: any, index: number) => {
+      const func = item.replace("{Value}", value)
+      const result = eval(func)
+      templete = templete.replace(`{${index}}`, Math.floor(parseFloat(result)))
+    })
+    return templete
+  }
+
   const formatStr = (value:string) => {
-    return value.replace('大车','').replace('副小车','').replace('主起升','').replace('配电','')
+    return value.replace('大车','').replace('副小车','').replace('主起升','').replace('配电','').replace('起升','').replace('小车','')
   }
 </script>