修改复核模块

This commit is contained in:
zm2000 2026-06-21 19:01:07 +08:00
parent 2e934c02b5
commit b5f366cdbb
3 changed files with 137 additions and 53 deletions

View File

@ -1,3 +1,6 @@
const VOICE_API_URL = 'http://tbdata.gztbyc.com/voice/';
const VOICE_API_PATH = 'http://tbdata.gztbyc.com';
class VoiceBroadcastManager { class VoiceBroadcastManager {
constructor() { constructor() {
this.tts = null; this.tts = null;
@ -5,6 +8,7 @@ class VoiceBroadcastManager {
this.initListener = null; this.initListener = null;
this.lastText = ''; this.lastText = '';
this.lastSpeakAt = 0; this.lastSpeakAt = 0;
this.audio = null;
} }
isSupported() { isSupported() {
@ -121,6 +125,48 @@ class VoiceBroadcastManager {
return this.initPromise; return this.initPromise;
} }
playByHttp(msg) {
return new Promise(resolve => {
uni.request({
url: VOICE_API_URL + msg,
method: 'GET',
timeout: 3000,
header: {
'content-type': 'text/xml; charset=utf-8'
},
success: res => {
const _src = VOICE_API_PATH + res.data.audio;
console.log('[VoiceHTTP] audio src:', _src);
// 每次重新创建 audio 实例,避免复用导致播放卡死
if (this.audio) {
this.audio.destroy();
}
const audio = uni.createInnerAudioContext();
this.audio = audio;
audio.onError(e => {
console.warn('[VoiceHTTP] audio error:', e);
resolve(false);
});
audio.onEnded(() => {
resolve(true);
});
audio.src = _src;
audio.play();
// 超时兜底:5秒后仍未触发 ended 也视为完成
setTimeout(() => resolve(true), 5000);
},
fail: err => {
console.warn('[VoiceHTTP] 请求语音失败:', err);
resolve(false);
}
});
});
}
play(msg) {
return this.playByHttp(msg);
}
async speak(text = '', options = {}) { async speak(text = '', options = {}) {
const content = String(text || '').trim(); const content = String(text || '').trim();
if (!content) { if (!content) {
@ -133,6 +179,15 @@ class VoiceBroadcastManager {
return false; return false;
} }
// 1. 优先 HTTP 语音接口
const httpResult = await this.playByHttp(content);
if (httpResult) {
this.lastText = content;
this.lastSpeakAt = Date.now();
return true;
}
// 2. 尝试原生语音播报
if (this.hasNativeSpeech()) { if (this.hasNativeSpeech()) {
const nativeResult = await this.speakByNative(content, options); const nativeResult = await this.speakByNative(content, options);
if (nativeResult) { if (nativeResult) {
@ -142,42 +197,42 @@ class VoiceBroadcastManager {
} }
} }
// 3. 尝试 Android TTS
const ready = await this.ensureReady(); const ready = await this.ensureReady();
if (!ready || !this.tts) { if (ready && this.tts) {
return false;
}
try {
const TextToSpeech = plus.android.importClass('android.speech.tts.TextToSpeech');
const queueMode = options.flush === false
? (typeof TextToSpeech.QUEUE_ADD === 'number' ? TextToSpeech.QUEUE_ADD : 1)
: (typeof TextToSpeech.QUEUE_FLUSH === 'number' ? TextToSpeech.QUEUE_FLUSH : 0);
const rate = Number(options.rate || 1);
const pitch = Number(options.pitch || 1);
if (typeof this.tts.setSpeechRate === 'function') {
this.tts.setSpeechRate(rate);
}
if (typeof this.tts.setPitch === 'function') {
this.tts.setPitch(pitch);
}
const normalizedContent = content.replace(/\s+/g, ' ');
const utteranceId = `voice_${now}`;
try { try {
this.tts.speak(normalizedContent, queueMode, null, utteranceId); const TextToSpeech = plus.android.importClass('android.speech.tts.TextToSpeech');
} catch (error) { const queueMode = options.flush === false
this.tts.speak(normalizedContent, queueMode, null); ? (typeof TextToSpeech.QUEUE_ADD === 'number' ? TextToSpeech.QUEUE_ADD : 1)
} : (typeof TextToSpeech.QUEUE_FLUSH === 'number' ? TextToSpeech.QUEUE_FLUSH : 0);
const rate = Number(options.rate || 1);
const pitch = Number(options.pitch || 1);
this.lastText = content; if (typeof this.tts.setSpeechRate === 'function') {
this.lastSpeakAt = Date.now(); this.tts.setSpeechRate(rate);
return true; }
} catch (error) { if (typeof this.tts.setPitch === 'function') {
console.error('[VoiceBroadcast] 语音播报失败:', error); this.tts.setPitch(pitch);
return false; }
const normalizedContent = content.replace(/\s+/g, ' ');
const utteranceId = `voice_${now}`;
try {
this.tts.speak(normalizedContent, queueMode, null, utteranceId);
} catch (error) {
this.tts.speak(normalizedContent, queueMode, null);
}
this.lastText = content;
this.lastSpeakAt = Date.now();
return true;
} catch (error) {
console.warn('[VoiceBroadcast] TTS 播报失败:', error);
}
} }
return false;
} }
stop() { stop() {

View File

@ -300,7 +300,10 @@ import voice from '@/core/utils/voice';
return candidates.includes(code); return candidates.includes(code);
}); });
if (matchIndex < 0) return false; if (matchIndex < 0) {
voice.speak('无记录');
return false;
}
this.currentGoodsIndex = matchIndex; this.currentGoodsIndex = matchIndex;
const matchedItem = this.goodsList[matchIndex]; const matchedItem = this.goodsList[matchIndex];
@ -318,7 +321,14 @@ import voice from '@/core/utils/voice';
// 更新已扫数量 // 更新已扫数量
this.$emit('updateScannedQty', matchIndex, newScanned); this.$emit('updateScannedQty', matchIndex, newScanned);
voice.speak(`${matchedItem?.skuName || '商品'}已扫${newScanned}${maxQty > 0 ? `共${maxQty}` : ''}`); // 所有商品都已完成扫描时才播报"数据一致"
const allDone = this.goodsList.every((item, idx) => {
const qty = idx === matchIndex ? newScanned : (item.scannedQty || 0);
return qty >= (item.planQty || 0);
});
if (allDone) {
voice.speak('数据一致');
}
// 已扫数量达到计划数量时,才标记为已匹配 // 已扫数量达到计划数量时,才标记为已匹配
if (newScanned >= maxQty) { if (newScanned >= maxQty) {
@ -373,7 +383,7 @@ import voice from '@/core/utils/voice';
// 标记当前商品条码匹配 // 标记当前商品条码匹配
this.$emit('barcodeMatched', matchId); this.$emit('barcodeMatched', matchId);
uni.showToast({ title: `已标记为已复核(${planQty}/${planQty})`, icon: 'success' }); uni.showToast({ title: `已标记为已复核(${planQty}/${planQty})`, icon: 'success' });
voice.speak(`${skuName}已标记为已复核`); voice.speak('数据一致');
} }
}); });
}, },

View File

@ -922,10 +922,10 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
this.printStationId = String(matched.id); this.printStationId = String(matched.id);
this.printStationName = String(matched.name || '--'); this.printStationName = String(matched.name || '--');
uni.showToast({ title: `已绑定打印台:${matched.name}`, icon: 'success' }); uni.showToast({ title: `已绑定打印台:${matched.name}`, icon: 'success' });
this.speakVoice(`${matched.name}已绑定`); this.speakVoice('已绑定打印台');
} else { } else {
uni.showToast({ title: '未匹配到打印台', icon: 'none' }); uni.showToast({ title: '未匹配到打印台', icon: 'none' });
this.speakVoice('未匹配到打印台'); this.speakVoice('未绑定打印台');
} }
}, },
handlePrintStationInput(value) { handlePrintStationInput(value) {
@ -1091,7 +1091,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
if (!matched) { if (!matched) {
uni.showToast({ title: '条码不匹配', icon: 'none' }); uni.showToast({ title: '条码不匹配', icon: 'none' });
uni.vibrateShort({ type: 'medium' }); uni.vibrateShort({ type: 'medium' });
this.speakVoice('条码不匹配'); this.speakVoice('无记录');
} }
return; return;
} }
@ -1207,7 +1207,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
if (!matched) { if (!matched) {
uni.showToast({ title: '条码不匹配', icon: 'none' }); uni.showToast({ title: '条码不匹配', icon: 'none' });
uni.vibrateShort({ type: 'medium' }); uni.vibrateShort({ type: 'medium' });
this.speakVoice('条码不匹配'); this.speakVoice('无记录');
} }
return; return;
} }
@ -1257,7 +1257,6 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
// 数量回归1 // 数量回归1
this.scanQuantity = 1; this.scanQuantity = 1;
this.saveSettings(); this.saveSettings();
this.speakVoice('已清空');
}, },
async handleRefreshTask() { async handleRefreshTask() {
if (!this.taskId) { if (!this.taskId) {
@ -1351,6 +1350,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
stocks: waveStocks, stocks: waveStocks,
orderIds: (Array.isArray(wave?.order_ids) ? wave.order_ids : Array.isArray(wave?.orderIds) ? wave.orderIds : []).map(id => Number(id)), orderIds: (Array.isArray(wave?.order_ids) ? wave.order_ids : Array.isArray(wave?.orderIds) ? wave.orderIds : []).map(id => Number(id)),
interceptStatus: String(wave?.intercept_status || wave?.interceptStatus || '').trim(), interceptStatus: String(wave?.intercept_status || wave?.interceptStatus || '').trim(),
firstWaybillNo: String(wave?.first_waybill_no || wave?.firstWaybillNo || '').trim(),
suggestedPkg: wave?.suggested_package_material || wave?.suggestedPkg || null, suggestedPkg: wave?.suggested_package_material || wave?.suggestedPkg || null,
list: subList list: subList
}; };
@ -1503,7 +1503,6 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
title: `共匹配 ${flatList.length} 条订单`, title: `共匹配 ${flatList.length} 条订单`,
icon: 'none' icon: 'none'
}); });
this.speakVoice(`共匹配${flatList.length}条订单`);
} }
// 自动选中订单:输入搜索选第一个,任务刷新选最后一个 // 自动选中订单:输入搜索选第一个,任务刷新选最后一个
this.$nextTick(() => { this.$nextTick(() => {
@ -1557,7 +1556,6 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
title: `共匹配 ${this.orderList.length} 个波次`, title: `共匹配 ${this.orderList.length} 个波次`,
icon: 'none' icon: 'none'
}); });
this.speakVoice(`共匹配${this.orderList.length}个波次`);
} }
// 自动选中波次:输入搜索选第一个,任务刷新选最后一个 // 自动选中波次:输入搜索选第一个,任务刷新选最后一个
this.$nextTick(() => { this.$nextTick(() => {
@ -1787,7 +1785,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
orderId: Number(item.id || item.orderId || 0), orderId: Number(item.id || item.orderId || 0),
waveId: String(item?.waveId ?? item?.id ?? '').trim(), waveId: String(item?.waveId ?? item?.id ?? '').trim(),
waveNo: String(item.waveNo || '--'), waveNo: String(item.waveNo || '--'),
waybillNo: String(item?.firstWaybillNo || item.waybillNo || '--'), waybillNo: String(item?.firstWaybillNo || item.waybillNo || ''),
matchType: '', matchType: '',
recheckStatus: String(item.recheckStatus || '').toLowerCase(), recheckStatus: String(item.recheckStatus || '').toLowerCase(),
pickerName: String(this.scanPickerName || item.pickerName || '--'), pickerName: String(this.scanPickerName || item.pickerName || '--'),
@ -1803,6 +1801,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
printStationName: String(this.printStationName || ''), printStationName: String(this.printStationName || ''),
boxNo: String(item.boxNo || ''), boxNo: String(item.boxNo || ''),
isPrinted: !!item.isPrinted, isPrinted: !!item.isPrinted,
unprintedCount: Number(item?.unprintedCount ?? 0),
orderCount: Number(item?.orderCount ?? 0),
listType: String(this.listType || ''), listType: String(this.listType || ''),
itemsWeight: Number(item?.itemsWeight ?? 0), itemsWeight: Number(item?.itemsWeight ?? 0),
suggestedPkg: item?.suggestedPkg || null suggestedPkg: item?.suggestedPkg || null
@ -1815,8 +1815,14 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
this.listExpanded = false; this.listExpanded = false;
// 先打印后复核:进入详情时自动触发未打印订单的打印 // 先打印后复核:进入详情时自动触发未打印订单的打印
if (this.printMode === 'printFirst' && !item.isPrinted && this.printStationId) { if (this.printMode === 'printFirst' && this.printStationId) {
this.autoPrintOrder(item); const isGroup = this.listType === 'group';
const isAlreadyPrinted = isGroup
? (item.unprintedCount || 0) === 0 && (item.orderCount || 0) > 0
: !!item.isPrinted;
if (!isAlreadyPrinted) {
this.autoPrintOrder(item);
}
} }
}, },
backToList() { backToList() {
@ -1859,14 +1865,20 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
listType: this.detailInfo.listType listType: this.detailInfo.listType
}); });
// 先复核后打印:复核完成后发送未打印订单的打印 // 先复核后打印:复核完成后发送未打印订单的打印
if (this.printMode === 'reviewFirst' && !this.detailInfo?.isPrinted && this.printStationId) { if (this.printMode === 'reviewFirst' && this.printStationId) {
this.autoPrintOrder(this.detailInfo); const isGroup = this.detailInfo?.listType === 'group';
const isAlreadyPrinted = isGroup
? (this.detailInfo?.unprintedCount || 0) === 0 && (this.detailInfo?.orderCount || 0) > 0
: !!this.detailInfo?.isPrinted;
if (!isAlreadyPrinted) {
this.autoPrintOrder(this.detailInfo);
}
} }
// 刷新订单列表数据 // 刷新订单列表数据
if (this.keyword) { if (this.keyword) {
this.requestScanOrder(this.keyword, true); this.requestScanOrder(this.keyword, true);
} }
this.speakVoice('已确认复核'); this.speakVoice('发货成功');
return true; return true;
} catch (error) { } catch (error) {
uni.hideLoading(); uni.hideLoading();
@ -1929,6 +1941,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
this.scannedPackageId = String(matched.id || ''); this.scannedPackageId = String(matched.id || '');
uni.hideLoading(); uni.hideLoading();
uni.showToast({ title: '包材匹配成功:' + (matched.material_name || trimmed), icon: 'success' }); uni.showToast({ title: '包材匹配成功:' + (matched.material_name || trimmed), icon: 'success' });
this.speakVoice('数据一致');
} else if (list.length > 0) { } else if (list.length > 0) {
// 没有精确匹配,但有模糊结果:取第一条 // 没有精确匹配,但有模糊结果:取第一条
const first = list[0]; const first = list[0];
@ -1937,10 +1950,12 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
this.scannedPackageId = String(first.id || ''); this.scannedPackageId = String(first.id || '');
uni.hideLoading(); uni.hideLoading();
uni.showToast({ title: '匹配到包材:' + (first.material_name || trimmed), icon: 'success' }); uni.showToast({ title: '匹配到包材:' + (first.material_name || trimmed), icon: 'success' });
this.speakVoice('数据一致');
} else { } else {
this.scannedPackageMaterial = null; this.scannedPackageMaterial = null;
uni.hideLoading(); uni.hideLoading();
uni.showToast({ title: '无记录', icon: 'none' }); uni.showToast({ title: '无记录', icon: 'none' });
this.speakVoice('无记录');
} }
} catch (error) { } catch (error) {
uni.hideLoading(); uni.hideLoading();
@ -1970,14 +1985,14 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
let packageCode = ''; let packageCode = '';
if (this.scannedPackageCode) { if (this.scannedPackageCode) {
packageCode = this.scannedPackageId || this.scannedPackageCode; packageCode = this.scannedPackageId || this.scannedPackageCode;
} else if (this.suggestedPkg?.code) { } else if (this.suggestedPkg?.id) {
packageCode = this.suggestedPkg.code; packageCode = this.suggestedPkg.id;
} }
if (packageCode && waybillNo) { if (packageCode && waybillNo) {
try { try {
await this.$http('order.bindExpressPackageMaterialByWaybill', { await this.$http('order.bindExpressPackageMaterialByWaybill', {
waybill_code: waybillNo, waybill_code: waybillNo,
package_material_code: packageCode package_material_id: packageCode
}); });
} catch (pkgErr) { } catch (pkgErr) {
console.warn('[weigh] 包材绑定失败(不阻塞):', pkgErr); console.warn('[weigh] 包材绑定失败(不阻塞):', pkgErr);
@ -2636,16 +2651,19 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
.weigh-ref-row { .weigh-ref-row {
text-align: center; text-align: center;
margin-bottom: 16rpx; margin-bottom: 16rpx;
word-break: break-all;
} }
.weigh-ref-label { .weigh-ref-label {
font-size: 28rpx; font-size: 32rpx;
color: #909399; color: #909399;
word-break: break-all;
} }
.weigh-ref-value { .weigh-ref-value {
color: #2979ff; color: #2979ff;
font-weight: 500; font-weight: 500;
font-size: 32rpx;
} }
.weigh-row { .weigh-row {
@ -2705,8 +2723,9 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
} }
.weigh-ref-spec { .weigh-ref-spec {
font-size: 24rpx; font-size: 28rpx;
color: #c0c4cc; color: #c0c4cc;
word-break: break-all;
} }
.weigh-unit { .weigh-unit {