| | |
| | | isSubmitting: false, |
| | | palletGroupedBarcodes: {}, |
| | | |
| | | // é³é¢é
ç½® |
| | | audioConfig: { |
| | | successPath: '/assets/audio/success.mp3', // å¯¹åº public ä¸çè·¯å¾ |
| | | errorPath: '/assets/audio/error.mp3' |
| | | }, |
| | | // ç¼åé³é¢å®ä¾ï¼é¿å
éå¤å建 |
| | | successAudio: null, |
| | | errorAudio: null, |
| | | |
| | | totalStockSum: 0, |
| | | totalStockCount: 0, |
| | | uniqueUnit: '', |
| | |
| | | // ç¡®ä¿ç»ä»¶éæ¯æ¶ç§»é¤çå¬ |
| | | this.removeKeyPressListener(); |
| | | this.clearAllTimers(); |
| | | |
| | | this.removeKeyPressListener(); |
| | | this.clearAllTimers(); |
| | | |
| | | //鿝é³é¢å®ä¾ |
| | | this.successAudio = null; |
| | | this.errorAudio = null; |
| | | }, |
| | | |
| | | methods: { |
| | | |
| | | /** |
| | | * åå§åé³é¢å®ä¾ï¼æå è½½ï¼åªåå»ºä¸æ¬¡ï¼ |
| | | * @param {String} type - é³é¢ç±»åï¼success/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 - é³é¢ç±»åï¼success/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) { |
| | |
| | | this.error = `æ¡ç ${currentBarcode} 已被å½åæçç»çï¼è¯·å¿é夿ä½`; |
| | | this.barcode = ''; |
| | | this.focusBarcodeInput(); |
| | | this.playErrorAudio(); |
| | | return; |
| | | } |
| | | |
| | |
| | | .then(valid => { |
| | | if (!valid) { |
| | | this.isSubmitting = false; |
| | | this.playErrorAudio(); |
| | | return; |
| | | } |
| | | |
| | |
| | | this.scanCode = ''; |
| | | this.isScanning = false; |
| | | |
| | | this.playSuccessAudio(); |
| | | |
| | | setTimeout(() => { |
| | | this.focusBarcodeInput(); |
| | | }, 100); |