Explorar o código

feat: receiving card status cache

Casper Dai hai 1 ano
pai
achega
ee42dd43bd

+ 10 - 1
src/api/device.js

@@ -583,7 +583,7 @@ export function getDeviceAttentionList (options) {
   })
 }
 
-export function getStatusReport (id, options) {
+export function getMultiCardStatusReport (id, options) {
   return request({
     url: '/device/screenPower/latestStatusReport',
     method: 'POST',
@@ -592,6 +592,15 @@ export function getStatusReport (id, options) {
   })
 }
 
+export function getReceivingCardStatusReport (id, options) {
+  return request({
+    url: '/device/receiverCard/cacheData',
+    method: 'GET',
+    params: { deviceId: id },
+    ...options
+  })
+}
+
 export function getDevicesWithPower (params, options) {
   return request({
     url: '/device/bond/multiFunction/list',

+ 25 - 7
src/utils/adapter/monitor.js

@@ -1,23 +1,26 @@
-import { ThirdPartyDevice } from '@/constant'
+import { ThirdPartyDevice } from '@/constant.js'
 import {
   WillTopic,
   createClient,
   decodePayload
 } from '@/utils/mqtt'
-import { transformPercentVolumeToLevelVolume } from '@/utils/control/volume'
-import { getStatusReport } from '@/api/device'
-import { getThirdPartyDevicesByThirdPartyDevice } from '@/api/mesh'
+import { transformPercentVolumeToLevelVolume } from '@/utils/control/volume.js'
+import {
+  getMultiCardStatusReport,
+  getReceivingCardStatusReport
+} from '@/api/device.js'
+import { getThirdPartyDevicesByThirdPartyDevice } from '@/api/mesh.js'
 import {
   Status,
   Power
-} from './constant'
+} from './constant.js'
 import {
   GET_POWER_STATUS,
   GET_RECEIVER_INFO,
   parseCachePower,
   getPowerStatusByMessage,
   getReceivingCardStatusByMessage
-} from './nova'
+} from './nova.js'
 
 export const TIMEOUT_MILLISECOND = 120000
 export const EXPIRED_MILLISECOND = 300000
@@ -358,7 +361,7 @@ function startTask () {
   fetching = true
   console.log('monitor task', queue.size)
   const ids = [...queue]
-  getStatusReport(ids, { background: true, custom: true }).then(
+  getMultiCardStatusReport(ids, { background: true, custom: true }).then(
     async ({ data }) => {
       const map = {}
       data.forEach(item => {
@@ -437,3 +440,18 @@ function startTask () {
     setTimeout(flush, 500)
   })
 }
+
+export function getReceivingCardStatusFromServer (id) {
+  getReceivingCardStatusReport(id, { background: true, custom: true }).then(res => {
+    if (res.data && getCacheById(id)[ThirdPartyDevice.RECEIVING_CARD].status !== Status.LOADING) {
+      const message = JSON.parse(res.data)
+      const data = getReceivingCardStatusByMessage(message)
+      if (data.success) {
+        emit(id, ThirdPartyDevice.RECEIVING_CARD, {
+          timestamp: message.timestamp,
+          ...data.data
+        })
+      }
+    }
+  })
+}

+ 8 - 14
src/views/device/detail/components/DeviceExternal/components/ReceivingCard.vue

@@ -5,7 +5,9 @@
       @click="getTopology"
     />
     <template v-else-if="!loading && !topology">
-      <div class="u-color--black u-font-size--md u-bold u-text--center">未配置拓扑图或拓扑图异常,请联系管理员</div>
+      <div class="u-color--black u-font-size--md u-bold u-text--center">
+        未配置拓扑图或拓扑图异常,请联系管理员
+      </div>
     </template>
     <template v-else>
       <div
@@ -42,11 +44,11 @@
 
 <script>
 import { ThirdPartyDevice } from '@/constant'
-import { publish } from '@/utils/mqtt'
 import {
+  Status,
   addListener,
   removeListener,
-  triggerReceivingCardTopologyReporting
+  getReceivingCardStatusFromServer
 } from '@/utils/adapter'
 import { getThirdPartyDevicesByThirdPartyDevice } from '@/api/mesh'
 import { getReceivingCardTopology } from '@/api/external'
@@ -98,18 +100,10 @@ export default {
       if (!key || key === ThirdPartyDevice.RECEIVING_CARD) {
         console.log('monitor topology', value)
         this.receivers = value[ThirdPartyDevice.RECEIVING_CARD].receivers
+        if (value[ThirdPartyDevice.RECEIVING_CARD].status === Status.LOADING) {
+          getReceivingCardStatusFromServer(this.device.id)
+        }
       }
-      // this.setTopology(value.topology)
-    },
-    setTopology (data) {
-      if (this.topology) {
-        return
-      }
-      if (!data) {
-        triggerReceivingCardTopologyReporting(publish, this.device)
-        return
-      }
-      this.transfromTopology(data.ports)
     },
     getTopology () {
       if (this.$instId) {