Browse Source

feat: compatibility processing

nova message, user event and monitor reset
Casper Dai 2 years ago
parent
commit
ce2b8539ba

+ 1 - 1
src/layout/components/Notify.vue

@@ -59,7 +59,7 @@ export default {
   computed: {
     ...mapGetters(['userId']),
     topic () {
-      return `${this.userId}/user/event`
+      return `user/event/${this.userId}`
     },
     title () {
       if (this.msgData.length > 5) {

+ 10 - 2
src/utils/adapter/nova.js

@@ -20,7 +20,8 @@ export const Power = {
 // nova自身支持类型配置,此时需固定类型,例如屏电源统一为【屏体电源】
 export const RELAY_KEY = -1
 
-export const RELEASE_MULTI = 'ReleaseLinkMultiFunctionCard' // 释放占用
+export const LINK_MULTI = 'LinkMultiFunctionCard' // 开启上报
+export const RELEASE_MULTI = 'ReleaseMultiFunctionCard' // 停止上报
 
 export const GET_POWER_STATUS = 'GetRealtimePowerSwitchStatusAsync' // 9.2.2.1、获取电源实时状态获取
 export const SET_POWER_STATUS = 'SetManualPowerSwitchStatusAsync' // 9.2.3.2、设置多功能卡电源开关状态
@@ -216,7 +217,14 @@ function parseMessage (message) {
       message: message.data
     }
   }
-  const data = message.data ? JSON.parse(message.data.replaceAll("'", '"')) : {}
+  const data = message.data ? JSON.parse(message.data.replaceAll("'", '"')) : null
+  if (!data) {
+    return {
+      success: false,
+      message: '无解析内容'
+    }
+  }
+
   if (data.logined === false) {
     return {
       success: false,

+ 58 - 0
src/views/device/detail/components/Anolg/components/BoxOperation.vue

@@ -0,0 +1,58 @@
+<template>
+  <div class="l-flex--col u-font-size--sm">
+    <div class="c-sibling-item--v u-bold">播控器操作</div>
+    <div class="c-sibling-item--v l-grid--info mini">
+      <div
+        class="o-button"
+        @click="onTriggerLink"
+      >
+        开启多功能卡数据上报
+      </div>
+      <div
+        class="o-button"
+        @click="onTriggerRelease"
+      >
+        停止多功能卡数据上报
+      </div>
+    </div>
+  </div>
+</template>
+
+<script>
+import { publish } from '@/utils/mqtt'
+import {
+  LINK_MULTI,
+  RELEASE_MULTI
+} from '@/utils/adapter/nova'
+
+export default {
+  name: 'AnolgBoxStatus',
+  props: {
+    device: {
+      type: Object,
+      required: true
+    }
+  },
+  methods: {
+    onTriggerLink () {
+      this.onTrigger(LINK_MULTI)
+    },
+    onTriggerRelease () {
+      this.onTrigger(RELEASE_MULTI)
+    },
+    onTrigger (topic) {
+      publish(`${this.device.productId}/${this.device.id}/${topic}`, JSON.stringify({
+        messageId: `${this.device.id}_${Math.random().toString(16).slice(2)}`,
+        timestamp: `${Date.now()}`,
+        function: '',
+        inputs: '[]'
+      }), true).then(() => {
+        this.$message({
+          type: 'success',
+          message: '触发成功'
+        })
+      })
+    }
+  }
+}
+</script>

+ 7 - 1
src/views/device/detail/components/Anolg/index.vue

@@ -16,6 +16,10 @@
       class="c-sibling-item--v far"
       :device-id="deviceId"
     />
+    <box-operation
+      class="c-sibling-item--v far"
+      :device="device"
+    />
   </div>
 </template>
 
@@ -24,6 +28,7 @@ import Temperature from './components/Temperature.vue'
 import Deviation from './components/Deviation.vue'
 import BoxStatus from './components/BoxStatus.vue'
 import Monitor from './components/Monitor.vue'
+import BoxOperation from './components/BoxOperation.vue'
 
 export default {
   name: 'Anolg',
@@ -31,7 +36,8 @@ export default {
     Temperature,
     Deviation,
     BoxStatus,
-    Monitor
+    Monitor,
+    BoxOperation
   },
   props: {
     device: {

+ 2 - 7
src/views/device/detail/components/DeviceInvoke/MultifunctionCardPowerSwitch.vue

@@ -105,7 +105,6 @@ import {
 } from '@/utils/adapter'
 import {
   Status,
-  RELEASE_MULTI,
   GET_POWER_STATUS,
   SET_POWER_STATUS,
   GET_POWER_TIMING,
@@ -167,8 +166,7 @@ export default {
         list: this.getPowers,
         buttons: [
           { label: '一键开启', on: this.onSwitchOpen },
-          { label: '一键关闭', on: this.onSwitchClose },
-          { label: '停止上报', render: () => this.isSuperAdmin, on: this.onRelease }
+          { label: '一键关闭', on: this.onSwitchClose }
         ],
         cols: [
           { label: '设备', render: ({ portIndex }) => portIndex === RELAY_KEY ? '播控盒' : '控电设备' },
@@ -232,7 +230,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['isSuperAdmin', 'account']),
+    ...mapGetters(['account']),
     powerStatusTip () {
       switch (this.powerStatus) {
         case Status.OK:
@@ -1088,9 +1086,6 @@ export default {
       this.hasChanged = true
       this.$tasks.splice(index, 1)
       this.$refs.table.pageTo()
-    },
-    onRelease () {
-      this.sendTopic(RELEASE_MULTI)
     }
   }
 }

+ 5 - 5
src/views/device/detail/monitor.js

@@ -113,15 +113,15 @@ export function send (topic, message) {
 export function reset (type) {
   const inst = types.get(type)
   if (inst?.reset) {
-    let value = void 0
+    let val = void 0
     if (inst.default) {
-      const { val, ...options } = inst.default()
-      value = val
+      const { value, ...options } = inst.default()
+      val = value
       Object.assign(inst, options)
     }
-    updateType(inst, value)
+    updateType(inst, val)
     inst.cbs.forEach(cb => {
-      cb(value, inst)
+      cb(val, inst)
     })
   }
 }