Kaynağa Gözat

计件宝声音改成网页播放

zh 10 ay önce
ebeveyn
işleme
dd0df62a69
1 değiştirilmiş dosya ile 29 ekleme ve 47 silme
  1. 29 47
      src/views/piece/dashboard/index.vue

+ 29 - 47
src/views/piece/dashboard/index.vue

@@ -141,18 +141,14 @@
       </van-notice-bar>
     </van-dialog>
   </van-sticky>
-  <audio ref="errorAudio" controls hidden="true"  :src="errorPath" />
-  <audio ref="tipAudio" controls hidden="true"  :src="tipPath" />
-  <audio ref="repeatAudio" controls hidden="true"  :src="repeatPath" />
-  <audio ref="reLoginAudio" controls hidden="true"  :src="reLoginPath" />
-  <audio ref="scanErrorAudio" controls hidden="true"  :src="scanErrorPath" />
+  <audio ref="audioPlayer" controls hidden="true" />
 </template>
 
 <script setup>
 import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
 import { closeListener, openListener, scanInit } from '@/utils/keydownListener'
 import {
-  getVersionName, saveUserId, getUserId, saveMacAddress, listErrRecords, readMacAddress,
+  getVersionName, saveUserId, getUserId, checkUpdate, saveMacAddress, listErrRecords, readMacAddress,
   pageDelivery, addDelivery, isDeliveryNoExists, markAsPushed, getErrRecordsCount, removeUserId
 } from '@/utils/androidPiece'
 import { showLoadingToast, showNotify } from 'vant'
@@ -704,51 +700,37 @@ const _one_click_push = () => {
 }
 
 
-const errorPath = ref(new URL('@/assets/sounds/error.mp3', import.meta.url).href)
-const tipPath = ref(new URL('@/assets/sounds/tip.mp3', import.meta.url).href)
-const repeatPath = ref(new URL('@/assets/sounds/scanner_repeat.mp3', import.meta.url).href)
-const reLoginPath = ref(new URL('@/assets/sounds/relogin.mp3', import.meta.url).href)
-const scanErrorPath = ref(new URL('@/assets/sounds/scanner_error.mp3', import.meta.url).href)
-// 失败提示
-const errorAudio = ref(null)
-const scanError = () => {
-  // 本地链接
-  nextTick(() => {
-    errorAudio.value?.play()
-  })
-}
-// 成功提示
-const tipAudio = ref(null)
-const scanSuccess = () => {
-  // 本地链接
-  nextTick(() => {
-    tipAudio.value?.play()
-  })
-}
-// 重复扫描提示
-const repeatAudio = ref(null)
-const scanRepeat = () => {
-  // 本地链接
-  nextTick(() => {
-    repeatAudio.value?.play()
-  })
+const soundPaths = {
+  error: new URL('@/assets/sounds/error.mp3', import.meta.url).href,
+  tip: new URL('@/assets/sounds/tip.mp3', import.meta.url).href,
+  repeat: new URL('@/assets/sounds/scanner_repeat.mp3', import.meta.url).href,
+  reLogin: new URL('@/assets/sounds/relogin.mp3', import.meta.url).href,
+  scanError: new URL('@/assets/sounds/scanner_error.mp3', import.meta.url).href
 }
-// 重新登录提示语
-const reLoginAudio = ref(null)
-const reLoginTip = () => {
-  // 本地链接
-  nextTick(() => {
-    reLoginAudio.value?.play()
-  })
-}
-// 扫描错误提示
-const scanErrorAudio = ref(null)
-const scanErr = () => {
-  // 本地链接
+
+const audioPlayer = ref(null)
+
+// 统一播放函数
+const playSound = (type) => {
   nextTick(() => {
-    scanErrorAudio.value?.play()
+    if (!audioPlayer.value) return
+
+    // 避免音频重叠播放
+    audioPlayer.value.pause()
+    audioPlayer.value.currentTime = 0
+
+    // 设置对应音源并播放
+    audioPlayer.value.src = soundPaths[type]
+    audioPlayer.value.play()
   })
 }
+
+// 语义化播放方法
+const scanSuccess = () => playSound('tip')
+const scanError = () => playSound('error')  // 原errorAudio
+const scanRepeat = () => playSound('repeat')
+const reLoginTip = () => playSound('reLogin')
+const scanErr = () => playSound('scanError')  // 原scanErrorAudio
 </script>
 
 <style scoped lang="sass">