修改复核模块
This commit is contained in:
parent
2e934c02b5
commit
b5f366cdbb
@ -1,3 +1,6 @@
|
||||
const VOICE_API_URL = 'http://tbdata.gztbyc.com/voice/';
|
||||
const VOICE_API_PATH = 'http://tbdata.gztbyc.com';
|
||||
|
||||
class VoiceBroadcastManager {
|
||||
constructor() {
|
||||
this.tts = null;
|
||||
@ -5,6 +8,7 @@ class VoiceBroadcastManager {
|
||||
this.initListener = null;
|
||||
this.lastText = '';
|
||||
this.lastSpeakAt = 0;
|
||||
this.audio = null;
|
||||
}
|
||||
|
||||
isSupported() {
|
||||
@ -121,6 +125,48 @@ class VoiceBroadcastManager {
|
||||
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 = {}) {
|
||||
const content = String(text || '').trim();
|
||||
if (!content) {
|
||||
@ -133,6 +179,15 @@ class VoiceBroadcastManager {
|
||||
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()) {
|
||||
const nativeResult = await this.speakByNative(content, options);
|
||||
if (nativeResult) {
|
||||
@ -142,42 +197,42 @@ class VoiceBroadcastManager {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 尝试 Android TTS
|
||||
const ready = await this.ensureReady();
|
||||
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}`;
|
||||
|
||||
if (ready && this.tts) {
|
||||
try {
|
||||
this.tts.speak(normalizedContent, queueMode, null, utteranceId);
|
||||
} catch (error) {
|
||||
this.tts.speak(normalizedContent, queueMode, null);
|
||||
}
|
||||
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);
|
||||
|
||||
this.lastText = content;
|
||||
this.lastSpeakAt = Date.now();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('[VoiceBroadcast] 语音播报失败:', error);
|
||||
return false;
|
||||
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 {
|
||||
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() {
|
||||
|
||||
@ -300,7 +300,10 @@ import voice from '@/core/utils/voice';
|
||||
return candidates.includes(code);
|
||||
});
|
||||
|
||||
if (matchIndex < 0) return false;
|
||||
if (matchIndex < 0) {
|
||||
voice.speak('无记录');
|
||||
return false;
|
||||
}
|
||||
|
||||
this.currentGoodsIndex = matchIndex;
|
||||
const matchedItem = this.goodsList[matchIndex];
|
||||
@ -318,7 +321,14 @@ import voice from '@/core/utils/voice';
|
||||
|
||||
// 更新已扫数量
|
||||
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) {
|
||||
@ -373,7 +383,7 @@ import voice from '@/core/utils/voice';
|
||||
// 标记当前商品条码匹配
|
||||
this.$emit('barcodeMatched', matchId);
|
||||
uni.showToast({ title: `已标记为已复核(${planQty}/${planQty})`, icon: 'success' });
|
||||
voice.speak(`${skuName}已标记为已复核`);
|
||||
voice.speak('数据一致');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@ -922,10 +922,10 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
this.printStationId = String(matched.id);
|
||||
this.printStationName = String(matched.name || '--');
|
||||
uni.showToast({ title: `已绑定打印台:${matched.name}`, icon: 'success' });
|
||||
this.speakVoice(`${matched.name}已绑定`);
|
||||
this.speakVoice('已绑定打印台');
|
||||
} else {
|
||||
uni.showToast({ title: '未匹配到打印台', icon: 'none' });
|
||||
this.speakVoice('未匹配到打印台');
|
||||
this.speakVoice('未绑定打印台');
|
||||
}
|
||||
},
|
||||
handlePrintStationInput(value) {
|
||||
@ -1091,7 +1091,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
if (!matched) {
|
||||
uni.showToast({ title: '条码不匹配', icon: 'none' });
|
||||
uni.vibrateShort({ type: 'medium' });
|
||||
this.speakVoice('条码不匹配');
|
||||
this.speakVoice('无记录');
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1207,7 +1207,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
if (!matched) {
|
||||
uni.showToast({ title: '条码不匹配', icon: 'none' });
|
||||
uni.vibrateShort({ type: 'medium' });
|
||||
this.speakVoice('条码不匹配');
|
||||
this.speakVoice('无记录');
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1257,7 +1257,6 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
// 数量回归1
|
||||
this.scanQuantity = 1;
|
||||
this.saveSettings();
|
||||
this.speakVoice('已清空');
|
||||
},
|
||||
async handleRefreshTask() {
|
||||
if (!this.taskId) {
|
||||
@ -1351,6 +1350,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
stocks: waveStocks,
|
||||
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(),
|
||||
firstWaybillNo: String(wave?.first_waybill_no || wave?.firstWaybillNo || '').trim(),
|
||||
suggestedPkg: wave?.suggested_package_material || wave?.suggestedPkg || null,
|
||||
list: subList
|
||||
};
|
||||
@ -1503,7 +1503,6 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
title: `共匹配 ${flatList.length} 条订单`,
|
||||
icon: 'none'
|
||||
});
|
||||
this.speakVoice(`共匹配${flatList.length}条订单`);
|
||||
}
|
||||
// 自动选中订单:输入搜索选第一个,任务刷新选最后一个
|
||||
this.$nextTick(() => {
|
||||
@ -1557,7 +1556,6 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
title: `共匹配 ${this.orderList.length} 个波次`,
|
||||
icon: 'none'
|
||||
});
|
||||
this.speakVoice(`共匹配${this.orderList.length}个波次`);
|
||||
}
|
||||
// 自动选中波次:输入搜索选第一个,任务刷新选最后一个
|
||||
this.$nextTick(() => {
|
||||
@ -1787,7 +1785,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
orderId: Number(item.id || item.orderId || 0),
|
||||
waveId: String(item?.waveId ?? item?.id ?? '').trim(),
|
||||
waveNo: String(item.waveNo || '--'),
|
||||
waybillNo: String(item?.firstWaybillNo || item.waybillNo || '--'),
|
||||
waybillNo: String(item?.firstWaybillNo || item.waybillNo || ''),
|
||||
matchType: '',
|
||||
recheckStatus: String(item.recheckStatus || '').toLowerCase(),
|
||||
pickerName: String(this.scanPickerName || item.pickerName || '--'),
|
||||
@ -1803,6 +1801,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
printStationName: String(this.printStationName || ''),
|
||||
boxNo: String(item.boxNo || ''),
|
||||
isPrinted: !!item.isPrinted,
|
||||
unprintedCount: Number(item?.unprintedCount ?? 0),
|
||||
orderCount: Number(item?.orderCount ?? 0),
|
||||
listType: String(this.listType || ''),
|
||||
itemsWeight: Number(item?.itemsWeight ?? 0),
|
||||
suggestedPkg: item?.suggestedPkg || null
|
||||
@ -1815,8 +1815,14 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
this.listExpanded = false;
|
||||
|
||||
// 先打印后复核:进入详情时自动触发未打印订单的打印
|
||||
if (this.printMode === 'printFirst' && !item.isPrinted && this.printStationId) {
|
||||
this.autoPrintOrder(item);
|
||||
if (this.printMode === 'printFirst' && this.printStationId) {
|
||||
const isGroup = this.listType === 'group';
|
||||
const isAlreadyPrinted = isGroup
|
||||
? (item.unprintedCount || 0) === 0 && (item.orderCount || 0) > 0
|
||||
: !!item.isPrinted;
|
||||
if (!isAlreadyPrinted) {
|
||||
this.autoPrintOrder(item);
|
||||
}
|
||||
}
|
||||
},
|
||||
backToList() {
|
||||
@ -1859,14 +1865,20 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
listType: this.detailInfo.listType
|
||||
});
|
||||
// 先复核后打印:复核完成后发送未打印订单的打印
|
||||
if (this.printMode === 'reviewFirst' && !this.detailInfo?.isPrinted && this.printStationId) {
|
||||
this.autoPrintOrder(this.detailInfo);
|
||||
if (this.printMode === 'reviewFirst' && this.printStationId) {
|
||||
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) {
|
||||
this.requestScanOrder(this.keyword, true);
|
||||
}
|
||||
this.speakVoice('已确认复核');
|
||||
this.speakVoice('发货成功');
|
||||
return true;
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
@ -1929,6 +1941,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
this.scannedPackageId = String(matched.id || '');
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '包材匹配成功:' + (matched.material_name || trimmed), icon: 'success' });
|
||||
this.speakVoice('数据一致');
|
||||
} else if (list.length > 0) {
|
||||
// 没有精确匹配,但有模糊结果:取第一条
|
||||
const first = list[0];
|
||||
@ -1937,10 +1950,12 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
this.scannedPackageId = String(first.id || '');
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '匹配到包材:' + (first.material_name || trimmed), icon: 'success' });
|
||||
this.speakVoice('数据一致');
|
||||
} else {
|
||||
this.scannedPackageMaterial = null;
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '无记录', icon: 'none' });
|
||||
this.speakVoice('无记录');
|
||||
}
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
@ -1970,14 +1985,14 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
let packageCode = '';
|
||||
if (this.scannedPackageCode) {
|
||||
packageCode = this.scannedPackageId || this.scannedPackageCode;
|
||||
} else if (this.suggestedPkg?.code) {
|
||||
packageCode = this.suggestedPkg.code;
|
||||
} else if (this.suggestedPkg?.id) {
|
||||
packageCode = this.suggestedPkg.id;
|
||||
}
|
||||
if (packageCode && waybillNo) {
|
||||
try {
|
||||
await this.$http('order.bindExpressPackageMaterialByWaybill', {
|
||||
waybill_code: waybillNo,
|
||||
package_material_code: packageCode
|
||||
package_material_id: packageCode
|
||||
});
|
||||
} catch (pkgErr) {
|
||||
console.warn('[weigh] 包材绑定失败(不阻塞):', pkgErr);
|
||||
@ -2636,16 +2651,19 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
.weigh-ref-row {
|
||||
text-align: center;
|
||||
margin-bottom: 16rpx;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.weigh-ref-label {
|
||||
font-size: 28rpx;
|
||||
font-size: 32rpx;
|
||||
color: #909399;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.weigh-ref-value {
|
||||
color: #2979ff;
|
||||
font-weight: 500;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.weigh-row {
|
||||
@ -2705,8 +2723,9 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
|
||||
}
|
||||
|
||||
.weigh-ref-spec {
|
||||
font-size: 24rpx;
|
||||
font-size: 28rpx;
|
||||
color: #c0c4cc;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.weigh-unit {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user