From deb12fd2b06ccc821104aa475a8fb784c39dfb2c Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期一, 02 二月 2026 19:01:00 +0800
Subject: [PATCH] 添加音频播放和优化调拨明细查询方法

---
 项目代码/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue |  153 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 149 insertions(+), 4 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue"
index 85cfe01..2630979 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue"
@@ -175,7 +175,7 @@
 import http from '@/api/http.js';
 import VolBox from '@/components/basic/VolBox.vue';
 
-// 闃叉姈鍑芥暟淇濇寔涓嶅彉
+// 闃叉姈鍑芥暟
 function debounce(func, wait) {
   let timeout;
   return function () {
@@ -218,6 +218,15 @@
       isSubmitting: false,
       palletGroupedBarcodes: {},
 
+      // 闊抽閰嶇疆
+      audioConfig: {
+        successPath: '/assets/audio/success.mp3', // 瀵瑰簲 public 涓嬬殑璺緞
+        errorPath: '/assets/audio/error.mp3'
+     },
+      // 缂撳瓨闊抽瀹炰緥锛岄伩鍏嶉噸澶嶅垱寤�
+      successAudio: null,
+      errorAudio: null,
+
       totalStockSum: 0,
       totalStockCount: 0,
       uniqueUnit: '',
@@ -251,7 +260,11 @@
             trigger: 'change'
           }
         ]
-      }
+      },
+      
+      // 鏂板锛氶敭鐩樹簨浠剁洃鍚爣璁�
+      keyPressListenerAdded: false,
+      isDialogClosing: false
     }
   },
 
@@ -272,6 +285,26 @@
   },
   
   watch: {
+    // 鐩戝惉show鍙橀噺鍙樺寲
+    show(newVal) {
+      if (newVal === true) {
+        console.log('寮规鎵撳紑锛岄噸缃暟鎹�');
+        this.isDialogClosing = false;
+        this.resetData();
+        this.$nextTick(() => {
+          setTimeout(() => {
+            this.fetchUnpalletMaterialDetails();
+            this.addKeyPressListener(); // 娣诲姞閿洏浜嬩欢鐩戝惉
+          }, 300);
+        });
+      } else if (newVal === false && !this.isDialogClosing) {
+        console.log('寮规鍏抽棴锛岀Щ闄や簨浠剁洃鍚�');
+        this.isDialogClosing = true;
+        this.removeKeyPressListener(); // 绉婚櫎閿洏浜嬩欢鐩戝惉
+        this.resetData();
+      }
+    },
+    
     visible(newVal, oldVal) {
       this.palletVisible = newVal;
 
@@ -306,15 +339,109 @@
   },
   
   mounted() {
-    document.addEventListener('keypress', this.handleKeyPress);
+    // 涓嶅湪mounted鏃舵坊鍔犵洃鍚紝鍦ㄥ脊绐楁墦寮�鏃舵坊鍔�
   },
   
   beforeDestroy() {
-    document.removeEventListener('keypress', this.handleKeyPress);
+    // 纭繚缁勪欢閿�姣佹椂绉婚櫎鐩戝惉
+    this.removeKeyPressListener();
     this.clearAllTimers();
+
+     this.removeKeyPressListener();
+     this.clearAllTimers();
+  
+   //閿�姣侀煶棰戝疄渚�
+    this.successAudio = null;
+    this.errorAudio = null;
   },
   
   methods: {
+
+    /**
+   * 鍒濆鍖栭煶棰戝疄渚嬶紙鎳掑姞杞斤紝鍙垱寤轰竴娆★級
+   * @param {String} type - 闊抽绫诲瀷锛歴uccess/error
+   * @returns {Audio} 闊抽瀹炰緥
+   */
+  initAudioInstance(type) {
+    if (type === 'success' && this.successAudio) {
+      return this.successAudio;
+    }
+    if (type === 'error' && this.errorAudio) {
+      return this.errorAudio;
+    }
+    
+    const audioPath = type === 'success' 
+      ? this.audioConfig.successPath 
+      : this.audioConfig.errorPath;
+    
+    const audioInstance = new Audio(audioPath);
+    
+    // 缂撳瓨闊抽瀹炰緥
+    if (type === 'success') {
+      this.successAudio = audioInstance;
+    } else {
+      this.errorAudio = audioInstance;
+    }
+    
+    // 闊抽鍔犺浇澶辫触鍥炶皟锛堝彲閫夛紝鐢ㄤ簬璋冭瘯锛�
+    audioInstance.onerror = (err) => {
+      console.error(`銆�${type} 闊抽銆戝姞杞藉け璐, err);
+    };
+    
+    return audioInstance;
+  },
+  
+  /**
+   * 鎾斁闊抽
+   * @param {String} type - 闊抽绫诲瀷锛歴uccess/error
+   */
+  playAudio(type) {
+    try {
+      const audioInstance = this.initAudioInstance(type);
+      
+      // 閲嶇疆鎾斁杩涘害锛堥伩鍏嶉噸澶嶆挱鏀炬椂闊抽鏈粨鏉燂級
+      audioInstance.currentTime = 0;
+      
+      // 鎾斁闊抽锛堣繑鍥� Promise 澶勭悊鎾斁缁撴灉锛屽吋瀹归儴鍒嗘祻瑙堝櫒闄愬埗锛�
+      audioInstance.play().catch((err) => {
+        console.warn('闊抽鎾斁澶辫触锛堝彲鑳芥槸娴忚鍣ㄨ嚜鍔ㄦ挱鏀剧瓥鐣ラ檺鍒讹級', err);
+      });
+    } catch (err) {
+      console.error('鎾斁闊抽鏃跺彂鐢熷紓甯�', err);
+    }
+  },
+  
+  /**
+   * 鎾斁鎴愬姛闊抽
+   */
+  playSuccessAudio() {
+    this.playAudio('success');
+  },
+  
+  /**
+   * 鎾斁澶辫触闊抽
+   */
+  playErrorAudio() {
+    this.playAudio('error');
+  },
+    // 娣诲姞閿洏浜嬩欢鐩戝惉
+    addKeyPressListener() {
+      if (!this.keyPressListenerAdded) {
+        document.addEventListener('keypress', this.handleKeyPress);
+        this.keyPressListenerAdded = true;
+        console.log('閿洏浜嬩欢鐩戝惉宸叉坊鍔�');
+      }
+    },
+    
+    // 绉婚櫎閿洏浜嬩欢鐩戝惉
+    removeKeyPressListener() {
+      if (this.keyPressListenerAdded) {
+        document.removeEventListener('keypress', this.handleKeyPress);
+        this.keyPressListenerAdded = false;
+        console.log('閿洏浜嬩欢鐩戝惉宸茬Щ闄�');
+      }
+    },
+    
     open() {
       this.show = true;
       this.orderNo = "";
@@ -322,6 +449,13 @@
       this.initLocationTypes();
       this.initwarehouseTypes();
       this.fetchUnpalletMaterialDetails();
+      
+      // 寮圭獥鎵撳紑鏃舵坊鍔犻敭鐩樹簨浠剁洃鍚�
+      this.$nextTick(() => {
+        setTimeout(() => {
+          this.addKeyPressListener();
+        }, 100);
+      });
     },
     
     validateLocationType(rule, value, callback) {
@@ -529,6 +663,8 @@
     },
     
     handleDialogClose() {
+      // 鍏堢Щ闄ら敭鐩樹簨浠剁洃鍚�
+      this.removeKeyPressListener();
       this.show = false;
       this.resetData();
     },
@@ -665,6 +801,7 @@
         this.error = `鏉$爜 ${currentBarcode} 宸茶褰撳墠鎵樼洏缁勭洏锛岃鍕块噸澶嶆搷浣渀;
         this.barcode = '';
         this.focusBarcodeInput();
+        this.playErrorAudio();
         return;
       }
 
@@ -674,6 +811,7 @@
         .then(valid => {
           if (!valid) {
             this.isSubmitting = false;
+            this.playErrorAudio();
             return;
           }
           
@@ -740,6 +878,8 @@
           this.scanCode = '';
           this.isScanning = false;
 
+          this.playSuccessAudio();
+
           setTimeout(() => {
             this.focusBarcodeInput();
           }, 100);
@@ -797,6 +937,11 @@
 
     // 澶勭悊鎵爜鏋緭鍏�
     handleKeyPress(event) {
+      // 妫�鏌ュ脊绐楁槸鍚︽樉绀�
+      if (!this.show || this.isDialogClosing) {
+        return;
+      }
+      
       if (this.isManualInput || this.isSubmitting) {
         return;
       }

--
Gitblit v1.9.3