6d009f08368f93713c1ebeca6acde4163042faa4..11072628a309086e8dd77f6203abbd0d41ef85d6
2025-10-23 罗广辉
feat: 调整喊话广播
110726 diff | tree
2025-10-23 罗广辉
feat: 配置内嵌权限
59b961 diff | tree
2 files modified
79 ■■■■ changed files
src/components/WebViewPlus.vue 6 ●●●●● patch | view | raw | blame | history
src/subPackages/droneConsole/index.vue 73 ●●●●● patch | view | raw | blame | history
src/components/WebViewPlus.vue
@@ -1,11 +1,12 @@
<template>
  <web-view :src="src" @message="viewMessage" />
  <web-view :src="src" @message="viewMessage" :allow="allow"/>
</template>
<script setup>
const allow = "accelerometer;ambient-light-sensor;autoplay;battery;camera;clipboard-read;clipboard-write;cross-origin-isolated;display-capture;document-domain;encrypted-media;execution-while-not-rendered;execution-while-out-of-viewport;fullscreen;gamepad;geolocation;gyroscope;hid;idle-detection;local-fonts;magnetometer;microphone;midi;payment;picture-in-picture;publickey-credentials-get;screen-wake-lock;serial;speaker-selection;storage-access;sync-xhr;usb;web-share;xr-spatial-tracking"
const src = defineModel("src");
const emit = defineEmits(["webMessage"]);
function viewMessage(event) {
  messageFun({
    data: {
@@ -16,6 +17,7 @@
    },
  });
}
// WEB_INVOKE_APPSERVICE
function messageFun(e) {
  if (e.data.type === "WEB_INVOKE_APPSERVICE") {
src/subPackages/droneConsole/index.vue
@@ -11,57 +11,16 @@
import {useUserStore} from "@/store/index.js";
const wayLineJodInfoId = ref(null)
const startState = ref('0')
let recorder
const soundVideoName = ref('') // 喊话名称
soundVideoName.value = `${dayjs().format('YYYYMMDDHHmmss')}实时喊话`
const droneHornState = ref('0')
const updateKey = ref(0)
const uNotifyRef = ref(null)
const viewUrl = computed(() => {
  return getWebViewUrl('/DroneConsole', {
    wayLineJodInfoId: wayLineJodInfoId.value,
    startState: startState.value,
    droneHornState: droneHornState.value,
    updateKey: updateKey.value
  })
})
function onPostMessage(data) {
  if (data.type === 'record') {
    startState.value = '1'
    recorder = new Recorder({
      sampleBits: 16, // 采样位数,支持8或16,默认16
      sampleRate: 16000, // 采样率,支持11025、16000、22050、24000、44100、48000
      numChannels: 1, // 声道,支持1或2,默认1
    })
    nextTick(() => {
      recorder.start().then(() => {
        recorder.onprocess = duration => {
        }
      })
    })
  } else if (data.type === 'stopRecord') {
    startState.value = '2'
    recorder.stop()
  } else if (data.type === 'trialListening') {
    recorder.play()
  } else if (data.type === 'resetRecording') {
    startState.value = '0'
    droneHornState.value = '0'
    recorder?.destroy().then(() => {
      recorder = null // 释放资源
    })
  } else if (data.type === 'pushToDrone') {
    pushToDrone(data)
  } else if (data.type === 'saveSound') {
    saveSound(data)
  }
}
// 文件上传demo
const {VITE_API_BASE_URL} = getEnvObj()
function uploadUtil(options) {
  const {formData, file, url} = options
  return new Promise((resolve, reject) => {
@@ -99,39 +58,17 @@
// 保存喊话至广播列表内
function saveSound(data) {
  const file = new File([recorder.getWAVBlob()], '.wav')
  const recorder = 'xxx'
  const file = new File([recorder?.getWAVBlob()], '.wav')
  uploadUtil({
    file,
    formData: {
      fileName: data.soundName,
      sn: data.dockSn
      fileName: 'xxx',
      sn: 'xxx',
    },
    url: '/drone-device-core/speak/api/v1/uploadSpeak'
  }).then(res => {
    showToast('保存成功')
  })
}
// 无人机开始喊话
function pushToDrone(data) {
  const wavBlob = recorder.getWAVBlob()
  const file = new File([wavBlob], new Date().getTime() + '.wav')
  uploadUtil({
    file,
    formData: {
      name: data.soundName,
      sn: data.dockSn,
      psdk_index: 2,
      volumn: 100,
    },
    url: '/drone-device-core/speak/api/v1/startVoice'
  }).then(res => {
    droneHornState.value = '1'
    showToast('播放成功')
  }).catch(() => {
    droneHornState.value = '0'
  }).finally(() => {
    updateKey.value += 1
  })
}