xieb
2023-09-13 3667807a7b7418efc090ee3fa6a6b734bc3080bf
src/pages/page-pilot/pilot-home.vue
@@ -67,7 +67,7 @@
            <span style="color: #737373">{{ device.data.gateway_sn }}</span>
          </a-col>
        </a-row>
        <a-row style="border-bottom: 1px solid #f4f8f9; height: 45px;" align="middle" v-if="device.data.online_status">
        <a-row style="border-bottom: 1px solid #f4f8f9; height: 45px;" align="middle" v-if="device.data.online_status && device.data.sn">
          <a-col :span="1"></a-col>
          <a-col :span="9">Aircraft Sn</a-col>
          <a-col :span="13" class="flex-align-end flex-column" >
@@ -79,7 +79,7 @@
        <span class="ml5" style="color: #939393;">Settings</span>
      </div>
      <div class="fz16" style="background-color: white; border-radius: 4px;">
        <a-row v-if="device.data.online_status" style="border-bottom: 1px solid #f4f8f9; height: 45px;" align="middle" @click="bindingDevice">
        <a-row v-if="device.data.online_status && device.data.sn" style="border-bottom: 1px solid #f4f8f9; height: 45px;" align="middle" @click="bindingDevice">
          <a-col :span="1"></a-col>
          <a-col :span="11">
            Device Binding
@@ -130,9 +130,8 @@
import cloudapi from '/@/assets/icons/cloudapi.png'
import { RightOutlined, CloudOutlined, CloudSyncOutlined, SyncOutlined } from '@ant-design/icons-vue'
import { useMyStore } from '/@/store'
import ReconnectingWebSocket from 'reconnecting-websocket'
import websocket from '/@/api/websocket'
import { DeviceStatus } from '/@/types/device'
import { useConnectWebSocket } from '/@/hooks/use-connect-websocket'
const root = getRoot()
const gatewayState = ref<boolean>(localStorage.getItem(ELocalStorageKey.GatewayOnline) === 'true')
@@ -151,7 +150,7 @@
const components = apiPilot.init()
const exitVisible = ref(false)
const drawerVisible = ref(false)
let minitor = -1
let minitor: any
interface DeviceInfoData {
  data: DeviceStatus
@@ -166,7 +165,7 @@
    bound_status: false,
    model: '',
    gateway_sn: EStatusValue.DISCONNECT,
    domain: ''
    domain: -1
  }
})
const bindParam: BindBody = {
@@ -211,8 +210,10 @@
const store = useMyStore()
const wsGetMsg = async (res: any) => {
  const payload = JSON.parse(res.data)
const messageHandler = async (payload: any) => {
  if (!payload) {
    return
  }
  switch (payload.biz_code) {
    case EBizCode.DeviceOnline: {
      console.info('online: ', payload)
@@ -241,26 +242,34 @@
      break
  }
}
let bindNum: number
let socket: ReconnectingWebSocket
// 监听ws 消息
useConnectWebSocket(messageHandler)
let bindNum: any
onMounted(() => {
  apiPilot.onBackClickReg()
  apiPilot.onStopPlatform()
  const oldDevice = localStorage.getItem(ELocalStorageKey.Device)
  if (oldDevice) {
    device.data = JSON.parse(oldDevice)
  }
  window.connectCallback = (arg: any) => {
    connectCallback(arg)
  }
  window.wsConnectCallback = (arg: any) => {
    wsConnectCallback(arg)
  }
  device.data.gateway_sn = apiPilot.getRemoteControllerSN()
  if (device.data.gateway_sn === EStatusValue.DISCONNECT.toString()) {
    message.warn('Data is not available, please restart the remote control.')
    return
  }
  const oldDevice = localStorage.getItem(ELocalStorageKey.Device)
  if (oldDevice) {
    device.data = JSON.parse(oldDevice)
  }
  device.data.sn = apiPilot.getAircraftSN()
  getDeviceInfo()
  socket = websocket.init(wsGetMsg)
  const isLoaded = apiPilot.isComponentLoaded(EComponentName.Thing)
  if (isLoaded) {
@@ -283,7 +292,7 @@
    // thing
    const param: ThingParam = {
      host: res.data.mqtt_addr,
      username: username.value,
      username: res.data.mqtt_username,
      password: res.data.mqtt_password,
      connectCallback: 'connectCallback'
    }
@@ -294,16 +303,6 @@
    bindParam.user_id = res.data.user_id
    bindParam.workspace_id = res.data.workspace_id
  })
  window.connectCallback = arg => {
    connectCallback(arg)
  }
  window.wsConnectCallback = arg => {
    wsConnectCallback(arg)
  }
})
onUnmounted(() => {
  socket.close()
})
const connectCallback = async (arg: any) => {
@@ -333,6 +332,11 @@
    apiPilot.loadComponent(EComponentName.Mission, {})
    bindNum = setInterval(() => {
      if (!bindParam.device_sn) {
        device.data.gateway_sn = apiPilot.getRemoteControllerSN()
        bindParam.device_sn = device.data.gateway_sn
        return
      }
      bindDevice(bindParam).then(bindRes => {
        if (bindRes.code !== 0) {
          message.error(bindRes.message)
@@ -483,7 +487,7 @@
}
function getDeviceInfo () {
  if (device.data.sn === EStatusValue.DISCONNECT) {
  if (!device.data.sn || device.data.sn === EStatusValue.DISCONNECT) {
    return
  }
  getDeviceBySn(bindParam.workspace_id, device.data.sn).then(res => {