无人机管理后台前端(已迁走)
罗广辉
2025-12-05 42e7814f816bedba1a0ef8e8f8fb3df1f495c9db
src/views/device/airport.vue
@@ -26,18 +26,18 @@
      <template #firmware_status="{ row }">
        <div v-if="row.firmware_status == 1" class="onlineStatus1">
          <el-tag type="info">无需升级</el-tag>
          <el-tag type="primary" effect="dark" class="active-element" @click="rollFirmware(row)">版本管理</el-tag>
<!--          <el-tag type="primary" effect="dark" class="active-element" @click="rollFirmware(row)">版本管理</el-tag>-->
          <!-- <div style="background-color: #f1f1f1; border-radius: 4px">无需升级</div> -->
        </div>
        <div v-if="row.firmware_status == 2" class="onlineStatus1">
          <!-- <el-tag type="success" effect="dark" class="active-element" @click="updateFirmware(row)"
            >升级固件</el-tag
          > -->
          <el-tag type="primary" effect="dark" class="active-element" @click="rollFirmware(row)">版本管理</el-tag>
<!--          <el-tag type="primary" effect="dark" class="active-element" @click="rollFirmware(row)">版本管理</el-tag>-->
          <!-- <div @click="updateFirmware(row)" class="firmware_status">升级固件</div> -->
        </div>
        <div v-if="row.firmware_status == 3" class="onlineStatus">
          <el-tag type="success" effect="dark" class="active-element" @click="updateFirmware(row)">一致性升级</el-tag>
<!--          <el-tag type="success" effect="dark" class="active-element" @click="updateFirmware(row)">一致性升级</el-tag>-->
          <!-- <div @click="updateFirmware(row)" class="firmware_status">一致性升级</div> -->
        </div>
        <div v-if="row.firmware_status == 4" class="onlineStatus">
@@ -64,31 +64,33 @@
            </el-icon>更多</el-button>
          <template #dropdown v-if="scope.row.domain == 3">
            <el-dropdown-menu teleported>
              <el-dropdown-item command="a">
                <el-button type="primary" text icon="el-icon-paperclip" v-if="permission.oss_set"
              <el-dropdown-item command="a" v-if="permission.oss_set">
                <el-button type="primary" text icon="el-icon-paperclip"
                  @click.stop="handleOpenOssSet(scope.row, scope.index)">存储配置</el-button>
              </el-dropdown-item>
              <el-dropdown-item command="b">
                <el-button type="primary" text icon="el-icon-share" v-if="permission.per_share && scope.row.domain == 3"
              <el-dropdown-item command="b" v-if="permission.per_share && scope.row.domain == 3">
                <el-button type="primary" text icon="el-icon-share"
                  @click.stop="handleOpenDevicePerShare(scope.row, scope.index)">机场授权</el-button>
              </el-dropdown-item>
              <el-dropdown-item command="c"> <el-button type="primary" text icon="el-icon-position"
                  :disabled="!scope.row.status" v-if="permission.rang_con && scope.row.domain == 3"
              <el-dropdown-item command="c" v-if="permission.rang_con && scope.row.domain == 3">
                <el-button type="primary" text icon="el-icon-position"
                  :disabled="!scope.row.status"
                  @click.stop="handleOpenRemoteDebugging(scope.row, scope.index)">远程调试</el-button>
              </el-dropdown-item>
              <el-dropdown-item command="d"><el-button type="primary" text icon="el-icon-collection"
                  v-if="permission.fly_device_offline" @click.stop="rollFirmware(scope.row)">固件版本管理</el-button>
              <el-dropdown-item command="d" v-if="permission.fly_device_offline">
                <el-button type="primary" text icon="el-icon-collection"
                   @click.stop="rollFirmware(scope.row)">固件版本管理</el-button>
              </el-dropdown-item>
              <el-dropdown-item command="d" v-if="!scope.row.status">
                <el-button type="primary" text icon="el-icon-collection" @click.stop="dockNotLine(scope.row)">
                  {{ scope.row.hidden_flag === 1 ? '设备上线' : '设备下线' }}
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item command="e"><el-button type="primary" text icon="el-icon-document-delete"
                  v-if="permission.fly_device_offline && scope.row.mode_code !==0" @click.stop="handleDeviceOffline(scope.row)">注销</el-button>
              <el-dropdown-item command="e" v-if="permission.fly_device_offline && scope.row.mode_code !==0">
                <el-button type="primary" text icon="el-icon-document-delete" @click.stop="handleDeviceOffline(scope.row)">注销</el-button>
              </el-dropdown-item>
              <el-dropdown-item command="e">
                <el-button type="primary" text icon="el-icon-document-delete" v-if="permission.fly_device_offline"
              <el-dropdown-item command="e" v-if="permission.fly_device_offline">
                <el-button type="primary" text icon="el-icon-document-delete"
                  :disabled="scope.row.dem_status === 1" @click.stop="handleStatus(scope.row)">
                  {{ scope.row.dem_status === 0 ? '初始化地形' : (scope.row.dem_status === 1 ? '初始化中' : '更新地形') }}
                </el-button>
@@ -297,6 +299,7 @@
      rollFirmVersion: '',
      firmList: [],
      rollFirmwareBox: false,
      isUpdateDrone: {},
      // 用于记录已经创建的websocket,防止重复创建
      webSocketIdSet: new Set(),
      // 用于保存多组websocket
@@ -407,7 +410,46 @@
              },
            ],
          },
          {
            label: '设备状态',
            prop: 'mode_code',
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            labelWidth: 145,
            searchSpan: 4,
            search: true,
            type: 'select',
            dicData: [
              { label: '在线', value: 0 },
              { label: '离线', value: -1 },
              { label: '远程调试', value: 2 },
              { label: '现场调试', value: 1 },
              { label: '固件升级中', value: 3 }
            ],
            slot: true,
            width: 110,
            rules: [
              {
                required: true,
                message: '请输入机场状态',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '固件升级',
            prop: 'firmware_status',
            labelWidth: 145,
            width: 100,
            // hide: true,
            viewDisabled: true,
            addDisabled: true,
            editDisplay: false, //编辑显示
            addDisplay: false,
            viewDisplay: false,
          },
          {
            label: '4G增强',
            prop: 'link_workmode',
@@ -502,35 +544,7 @@
            labelWidth: 145,
            width: 110,
          },
          {
            label: '设备状态',
            prop: 'mode_code',
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            labelWidth: 145,
            searchSpan: 4,
            search: true,
            type: 'select',
            dicData: [
              { label: '在线', value: 0 },
              { label: '离线', value: -1 },
              { label: '远程调试', value: 2 },
              { label: '现场调试', value: 1 },
              { label: '固件升级中', value: 3 }
            ],
            slot: true,
            width: 110,
            rules: [
              {
                required: true,
                message: '请输入机场状态',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '设备SN',
            prop: 'device_sn',
@@ -625,18 +639,6 @@
            labelWidth: 145,
            width: 110,
            editDisplay: false, //编辑显示
          },
          {
            label: '固件升级',
            prop: 'firmware_status',
            labelWidth: 145,
            width: 100,
            hide: true,
            viewDisabled: true,
            addDisabled: true,
            editDisplay: false, //编辑显示
            addDisplay: false,
            viewDisplay: false,
          },
          {
            label: '所属部门',
@@ -867,21 +869,33 @@
      websocket?.initSocket()
    },
    async messageHandler(payload) {
      if (!payload) {
      let loadData = JSON.parse(payload)
      if (!loadData) {
        return
      }
      if (payload.biz_code != 'ota_progress') {
      if (loadData.biz_code != 'ota_progress') {
        return
      }
      var data = payload.data
      this.data.forEach(e => {
        if (e.device_sn == data.sn && data.output.status == 'in_progress') {
          e.firmware_progress = data.output.progress.percent
      console.log(loadData.data.output.progress.percent, '6666')
      // if(loadData.data.output.progress.percent < 10) {
      //   this.onLoad(this.page)
      // }
      this.data.forEach((e, index) => {
        if ((e.device_sn == loadData.data.sn || e.child_sn == loadData.data.sn) && loadData.data.output.status == 'in_progress') {
          e.firmware_progress = loadData.data.output.progress.percent
          if (e.children[0]) {
            e.children[0].firmware_progress = loadData.data.output.progress.percent;
          }
          console.log('是否更新中2',e.children[0])
        }
        if (e.device_sn == data.sn && data.output.status == 'ok') {
        if ((e.device_sn == loadData.data.sn || e.child_sn == loadData.data.sn) && loadData.data.output.status == 'ok') {
          // 升级完成修改状态
          e.firmware_status = 1
          if (e.children[0]) {
            e.children[0].firmware_status = 1
          }
          const webscoket = this.websocketMap.get(e.workspace_id)
          // 关闭
          webscoket?.close()
@@ -890,6 +904,7 @@
          this.webSocketIdSet.delete(e.workspace_id)
        }
      })
      // this.$forceUpdate()
    },
    init() {
      (this.page = {
@@ -998,6 +1013,7 @@
    },
    // 版本回退点击事件
    rollFirmware(row) {
      console.log(this.data,row, '打印看看值')
      if (row.status == 0) {
        this.$message({
          type: 'warning',
@@ -1017,6 +1033,7 @@
      }
      var that = this
      this.rollFirmwareBox = true
      this.isUpdateDrone = row
      const param = {
        device_name: row.device_name,
      }
@@ -1122,6 +1139,7 @@
          // 需要改变的版本号和无人机版本号如果是一致,进行单独的机场升级/回滚操作
        }
      }
      ota(that.firmwareInfo.workspaceId, arr).then(res => {
        that.firmwareVersion = ''
        that.firmwareInfo = {}
@@ -1130,8 +1148,25 @@
          type: 'success',
          message: '操作成功!',
        })
        this.onLoad(this.page)
        done()
        // 此处需分是无人机升级还是机巢升级版本
        console.log('看看是无人机更新还是机场更新',that.isUpdateDrone)
        if(that.isUpdateDrone.domain == 3) {
          this.onLoad(this.page)
        } else {
          console.log(111)
          this.data.map(item => {
            if(item.workspace_id === that.isUpdateDrone.workspace_id) {
              item.firmware_status = 2
              item.mode_code = 3
              item.children[0].mode_code = 0
              item.children[0].firmware_status = 4
              this.connectWebSocket(item)
              console.log('无人机更新中',item)
            }
          })
        }
        // 获取保存的 resolve 函数===== 此处需要更新子集塞入父级
        // done()
      })
    },
    // 升级固件按钮事件
@@ -1370,25 +1405,25 @@
          this.$refs.crud.toggleSelection()
        })
    },
    async getFullAreaCode(areaCode) {
      console.log('getFullAreaCode', areaCode)
      if (!areaCode) return ''
      const code = areaCode.toString()
      if (code.includes(',')) return code
      if (code.endsWith('0000000000')) {
        return code
      } else if (code.endsWith('00000000') && !code.endsWith('0000000000')) {
        const provinceCode = code.substring(0, 2) + '0000000000'
        return `${provinceCode},${code}`
      } else {
        const provinceCode = code.substring(0, 2) + '0000000000'
        const cityCode = code.substring(0, 4) + '00000000'
        return `${provinceCode},${cityCode},${code}`
      }
    },
    // async getFullAreaCode(areaCode) {
    //   console.log('getFullAreaCode', areaCode)
    //   if (!areaCode) return ''
    //
    //   const code = areaCode.toString()
    //
    //   if (code.includes(',')) return code
    //
    //   if (code.endsWith('0000000000')) {
    //     return code
    //   } else if (code.endsWith('00000000') && !code.endsWith('0000000000')) {
    //     const provinceCode = code.substring(0, 2) + '0000000000'
    //     return `${provinceCode},${code}`
    //   } else {
    //     const provinceCode = code.substring(0, 2) + '0000000000'
    //     const cityCode = code.substring(0, 4) + '00000000'
    //     return `${provinceCode},${cityCode},${code}`
    //   }
    // },
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        getDetail(this.form.id).then(async res => {
@@ -1441,12 +1476,17 @@
        this.page.total = data.total
        data.records.forEach(e => {
          e['hasChildren'] = e.has_children
          if (e.firmware_status == 4) {
          if (e.firmware_status == 4 || e.mode_code === 3) {
            console.log('监听了没')// 机巢升级 firmware_status === 4
            this.connectWebSocket(e)
          }
          e.duration_of_insurance = [e?.insure_start_time?.slice(0, 10) || '', e?.insure_expired_time?.slice(0, 10) || '']
        })
        this.data = data.records
        this.data = data.records.map(item => ({
          ...item,
          firmware_progress: 0
        }));
        console.log('2222',this.data)
        this.loading = false
        this.selectionClear()
      })
@@ -1458,7 +1498,10 @@
        childSn: tree.child_sn,
      }
      getList(1, 10, params).then(res => {
        const data = res.data.data.records
        const data = res.data.data.records.map(item =>({
          ...item,
          firmware_progress: 0
        }))
        data.forEach(e => {
          e.duration_of_insurance = [e?.insure_start_time?.slice(0, 10) || '', e?.insure_expired_time?.slice(0, 10) || '']
        })