feat: 打包上报弱网重试与语音播报优化

- 打包上报失败分流处理:401/403 静默、400(key 失效) 自动重查一次再重提、网络异常弹窗重传
- 新增打包上报失败重传弹窗,团单失败后保持核实状态,扫码/点击商品可重新上报
- 请求层新增默认 20s 超时与硬超时兜底(abort),防弱网下请求无限挂起
- queryPackOrder/packOrder/finishPack 支持透传 timeout,打包提交/结束显式 15s 超时
- 语音播报改为 FIFO 队列,不丢不截断,按真实时长设兜底(替代固定 5s)
- 散单预检通过后依次播报各商品打包要求;打包要求样式改为红底警示
- 版本号升至 1.0.42
This commit is contained in:
zm2000 2026-10-01 18:19:28 +08:00
parent dcbf6e3b1f
commit c64c11b2ef
4 changed files with 315 additions and 64 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "wms-worker-station", "name": "wms-worker-station",
"version": "1.0.41", "version": "1.0.42",
"description": "WMS仓库工作台(Android端 + 桌面端)", "description": "WMS仓库工作台(Android端 + 桌面端)",
"author": "tianbao", "author": "tianbao",
"main": "electron/main.js", "main": "electron/main.js",

View File

@ -156,12 +156,15 @@ export function removeWorkbenchMember(data: {
* - 散单 isSandan=1 附 order.intercept_flag/pack_flag;团购 isSandan=0 附 batch 波次信息 * - 散单 isSandan=1 附 order.intercept_flag/pack_flag;团购 isSandan=0 附 batch 波次信息
* - 另返回 order.wave_scope(波次范围:0=未分配 1=大团购 2=散单 3=小团购 4=单品单件) * - 另返回 order.wave_scope(波次范围:0=未分配 1=大团购 2=散单 3=小团购 4=单品单件)
*/ */
export function queryPackOrder(token: string, barcode: string) { export function queryPackOrder(
return request<ApiBody>( token: string,
'workbench.queryOrder', barcode: string,
{ token, barcode }, options?: RequestOptions
{ skipAuth: true } ) {
) return request<ApiBody>('workbench.queryOrder', { token, barcode }, {
skipAuth: true,
...options,
})
} }
/** /**
@ -190,14 +193,20 @@ export function packOrder(data: {
id?: number | null id?: number | null
real_name?: string real_name?: string
}> }>
}) { }, options?: RequestOptions) {
return request<ApiBody>('workbench.packOrder', data, { skipAuth: true }) return request<ApiBody>('workbench.packOrder', data, {
skipAuth: true,
...options,
})
} }
/** /**
* 工作台打包完成(免登录、免鉴权,以工作台 token 鉴权) * 工作台打包完成(免登录、免鉴权,以工作台 token 鉴权)
* - 入参 token(工作台 token);结束该工作台最后一个未结束的打包任务并回写订单打包状态 * - 入参 token(工作台 token);结束该工作台最后一个未结束的打包任务并回写订单打包状态
*/ */
export function finishPack(token: string) { export function finishPack(token: string, options?: RequestOptions) {
return request<ApiBody>('workbench.finishPack', { token }, { skipAuth: true }) return request<ApiBody>('workbench.finishPack', { token }, {
skipAuth: true,
...options,
})
} }

View File

@ -119,6 +119,13 @@ function handleUnauthorized() {
}, 5000) }, 5000)
} }
// 默认请求超时(毫秒):弱网/断网时避免请求无限挂起
const DEFAULT_TIMEOUT_MS = 20000
// 硬超时兜底:在 uni.request 的 timeout 之上再多等这些毫秒,
// 到点后主动 abort 并结算,确保 Promise 必定 settle
// (部分安卓 WebView / 弱网下 uni.request 的 timeout 可能不触发)
const HARD_TIMEOUT_EXTRA_MS = 2000
export function request<T = ApiBody>( export function request<T = ApiBody>(
method: string, method: string,
data?: Record<string, unknown>, data?: Record<string, unknown>,
@ -126,8 +133,24 @@ export function request<T = ApiBody>(
): AbortablePromise<T> { ): AbortablePromise<T> {
const url = buildRequestUrl(method) const url = buildRequestUrl(method)
const authHeader = options?.skipAuth ? {} : getAuthHeader() const authHeader = options?.skipAuth ? {} : getAuthHeader()
const timeoutMs = options?.timeout != null ? options.timeout : DEFAULT_TIMEOUT_MS
let requestTask: ReturnType<typeof uni.request> | null = null let requestTask: ReturnType<typeof uni.request> | null = null
let hardTimeoutTimer: ReturnType<typeof setTimeout> | null = null
let settled = false
// 成功/失败/硬超时三方只结算一次,避免重复 resolve/reject
const settle = (fn: () => void) => {
if (settled) {
return
}
settled = true
if (hardTimeoutTimer) {
clearTimeout(hardTimeoutTimer)
hardTimeoutTimer = null
}
fn()
}
const promise: AbortablePromise<T> = new Promise<T>((resolve, reject) => { const promise: AbortablePromise<T> = new Promise<T>((resolve, reject) => {
const requestOptions: UniApp.RequestOptions = { const requestOptions: UniApp.RequestOptions = {
@ -139,6 +162,7 @@ export function request<T = ApiBody>(
...options?.header, ...options?.header,
}, },
data: data ?? {}, data: data ?? {},
timeout: timeoutMs,
success: (res) => { success: (res) => {
const body = res.data as any const body = res.data as any
// 鉴权请求返回 401(令牌无效/过期)→ 清 token 回登录页 // 鉴权请求返回 401(令牌无效/过期)→ 清 token 回登录页
@ -150,18 +174,29 @@ export function request<T = ApiBody>(
) { ) {
handleUnauthorized() handleUnauthorized()
} }
resolve(body as T) settle(() => resolve(body as T))
}, },
fail: (err) => { fail: (err) => {
reject(err) settle(() => reject(err))
}, },
} }
if (options?.timeout != null) {
requestOptions.timeout = options.timeout
}
requestTask = uni.request(requestOptions) requestTask = uni.request(requestOptions)
// 硬超时兜底:到点后主动 abort 并以超时错误结算
hardTimeoutTimer = setTimeout(() => {
try {
if (requestTask && typeof requestTask.abort === 'function') {
requestTask.abort()
}
} catch (err) {
// 忽略中断异常
}
const timeoutErr: any = new Error('网络超时,请稍后重试')
timeoutErr.errMsg = 'request:fail timeout'
timeoutErr.timedOut = true
settle(() => reject(timeoutErr))
}, timeoutMs + HARD_TIMEOUT_EXTRA_MS)
}) })
promise.abort = () => { promise.abort = () => {

View File

@ -56,6 +56,9 @@
</view> </view>
<view v-if="hasPackRecord" class="pack-card pack-wave"> <view v-if="hasPackRecord" class="pack-card pack-wave">
<view v-if="groupPackRetryReady" class="pack-retry-hint">
<text class="pack-retry-hint-text">打包上报失败,扫描商品条码或单击商品重新上报</text>
</view>
<view class="pack-wave-head" :class="{ 'pack-wave-head--blocked': orderBlocked }"> <view class="pack-wave-head" :class="{ 'pack-wave-head--blocked': orderBlocked }">
<text class="pack-card-title">{{ isSandan === 1 ? '运单' : '波次' }}</text> <text class="pack-card-title">{{ isSandan === 1 ? '运单' : '波次' }}</text>
<text class="pack-wave-no">{{ isSandan === 1 ? (currentWaybillCode || '暂无运单') : (currentWaveNo || '暂无波次') }}</text> <text class="pack-wave-no">{{ isSandan === 1 ? (currentWaybillCode || '暂无运单') : (currentWaveNo || '暂无波次') }}</text>
@ -332,6 +335,22 @@
</view> </view>
</view> </view>
<!-- 打包上报失败重试弹窗(弱网/超时/key 失效后弹出,可手动重新上传) -->
<view v-if="retryPopupOpen" class="op-mask">
<view class="op-dialog retry-popup">
<text class="retry-popup-title">打包上报失败</text>
<view class="retry-popup-text">{{ retryPopupText }}</view>
<view class="op-confirm-footer op-confirm-footer--equal">
<button class="op-btn op-btn--cancel" @click="closeRetryPopup">关闭</button>
<button
class="op-btn op-btn--primary"
:disabled="packReporting"
@click="handleRetryPackReport"
>{{ packReporting ? '重新上传中...' : '重新上传' }}</button>
</view>
</view>
</view>
<!-- 扫码诊断面板(隐藏入口:3 秒内连点标题 5 次) --> <!-- 扫码诊断面板(隐藏入口:3 秒内连点标题 5 次) -->
<scan-diag-panel :visible="diagPanelVisible" @close="diagPanelVisible = false" /> <scan-diag-panel :visible="diagPanelVisible" @close="diagPanelVisible = false" />
</view> </view>
@ -513,6 +532,11 @@ export default {
packStarted: false, packStarted: false,
packReporting: false, packReporting: false,
packFinishing: false, packFinishing: false,
// ---- 打包上报弱网重试 / key 失效自动重查 ----
retryPopupOpen: false,
retryPopupText: '',
packKeyRetryCount: 0,
groupPackRetryReady: false,
// ---- 商品图片预览 ---- // ---- 商品图片预览 ----
imagePreviewVisible: false, imagePreviewVisible: false,
imagePreviewList: [], imagePreviewList: [],
@ -532,9 +556,9 @@ export default {
ttsReady: false, ttsReady: false,
ttsPendingText: '', ttsPendingText: '',
voiceAudioContext: null, voiceAudioContext: null,
// 语音播报串行队列状态 // 语音播报串行队列状态(FIFO:不丢任何一条,按顺序播完)
voicePlaying: false, voicePlaying: false,
voicePendingText: '', voiceQueue: [],
voiceNextTimer: null, voiceNextTimer: null,
// ---- 波次范围 / 大团购打包时长闸门 ---- // ---- 波次范围 / 大团购打包时长闸门 ----
currentWaveScope: null, currentWaveScope: null,
@ -571,6 +595,9 @@ export default {
return Number(this.workbenchInfo?.status) === 1 return Number(this.workbenchInfo?.status) === 1
}, },
searchPlaceholder() { searchPlaceholder() {
if (this.groupPackRetryReady) {
return '扫描商品条码重新上报'
}
return this.workbenchMembers.length > 0 ? '扫描/输入运单号' : '请先扫描工牌登录' return this.workbenchMembers.length > 0 ? '扫描/输入运单号' : '请先扫描工牌登录'
}, },
topbarOperatorText() { topbarOperatorText() {
@ -630,9 +657,9 @@ export default {
orderBlockReason() { orderBlockReason() {
return this.checkOrderBlocked().reason return this.checkOrderBlocked().reason
}, },
// 大团购打包倒计时展示文案(mm:ss) // 大团购打包倒计时展示文案(mm:ss,秒四舍五入避免小数尾巴)
packWaitRemainingText() { packWaitRemainingText() {
const total = this.packWaitRemaining const total = Math.round(this.packWaitRemaining)
if (!total || total <= 0) { if (!total || total <= 0) {
return '' return ''
} }
@ -755,7 +782,8 @@ export default {
return return
} }
// 连续重复扫码限制:与上一次扫描内容一致时不执行任何操作 // 连续重复扫码限制:与上一次扫描内容一致时不执行任何操作
if (this.lastScannedCode === kw) { // 失败态豁免:打包上报失败(重传弹窗/团单补报待命)时允许重扫同一码触发重试
if (this.lastScannedCode === kw && !this.retryPopupOpen && !this.groupPackRetryReady) {
diagDrop('duplicate-consecutive', { code: kw }) diagDrop('duplicate-consecutive', { code: kw })
console.log('[packaging][scan] handlePackSearch skip: duplicate consecutive code =', kw) console.log('[packaging][scan] handlePackSearch skip: duplicate consecutive code =', kw)
this.keyword = '' this.keyword = ''
@ -787,7 +815,7 @@ export default {
this.isGroupOrder && this.isGroupOrder &&
this.precheckPassed && this.precheckPassed &&
this.detailList.length > 0 && this.detailList.length > 0 &&
!this.groupVerifyCompleted (!this.groupVerifyCompleted || this.groupPackRetryReady)
) { ) {
this.matchProductBarcode(kw) this.matchProductBarcode(kw)
return return
@ -961,6 +989,11 @@ export default {
return return
} }
// 新查询成功:复位打包上报重试状态(key 重查计数 / 团单补报标记)
this.packKeyRetryCount = 0
this.groupPackRetryReady = false
this.retryPopupOpen = false
const order = raw?.order && typeof raw.order === 'object' ? raw.order : {} const order = raw?.order && typeof raw.order === 'object' ? raw.order : {}
const express = raw?.express && typeof raw.express === 'object' ? raw.express : {} const express = raw?.express && typeof raw.express === 'object' ? raw.express : {}
const batch = raw?.batch && typeof raw.batch === 'object' ? raw.batch : {} const batch = raw?.batch && typeof raw.batch === 'object' ? raw.batch : {}
@ -1107,7 +1140,13 @@ export default {
} }
return return
} }
// 散单:预检通过立即自动上报开始打包 // 散单:预检通过,依次播报各商品打包要求后自动上报开始打包
this.detailList.forEach((item) => {
const req = item?.packingRequirements || ''
if (req) {
this.speak(req)
}
})
this.startPack() this.startPack()
}, },
matchProductBarcode(barcode) { matchProductBarcode(barcode) {
@ -1122,6 +1161,11 @@ export default {
this.keyword = '' this.keyword = ''
this.speak('数据一致') this.speak('数据一致')
uni.showToast({ title: '数据一致', icon: 'none', silentVoice: true }) uni.showToast({ title: '数据一致', icon: 'none', silentVoice: true })
// 团单上报失败后(groupPackRetryReady):再次扫码已核实商品即重新上报
if (this.groupPackRetryReady) {
this.retryPopupOpen = false
this.maybeAutoSubmitGroupPack()
}
return return
} }
// 按商品种类:扫 1 次即标记为已核实,无需扫满数量 // 按商品种类:扫 1 次即标记为已核实,无需扫满数量
@ -1129,7 +1173,8 @@ export default {
target.scannedQty = Number(target.qty) || 0 target.scannedQty = Number(target.qty) || 0
this.addScanRecord(barcode) this.addScanRecord(barcode)
this.keyword = '' this.keyword = ''
this.speak('数据一致') const req = target?.packingRequirements || ''
this.speak(req ? `数据一致,${req}` : '数据一致')
uni.showToast({ title: '数据一致', icon: 'none', silentVoice: true }) uni.showToast({ title: '数据一致', icon: 'none', silentVoice: true })
// 全部核实后自动开始打包 // 全部核实后自动开始打包
this.maybeAutoSubmitGroupPack() this.maybeAutoSubmitGroupPack()
@ -1159,6 +1204,12 @@ export default {
if (!item || !this.isGroupOrder) { if (!item || !this.isGroupOrder) {
return return
} }
// 打包上报失败后(groupPackRetryReady):点击商品行即重新上报,失败会再次弹重传弹窗
if (this.groupPackRetryReady) {
this.retryPopupOpen = false
this.maybeAutoSubmitGroupPack()
return
}
const reason = this.verifyBlockReason(item) const reason = this.verifyBlockReason(item)
if (reason) { if (reason) {
diagNote('免验-blocked', { reason, source: 'click', item: item?.name || item?.barcode || '' }) diagNote('免验-blocked', { reason, source: 'click', item: item?.name || item?.barcode || '' })
@ -1192,6 +1243,12 @@ export default {
if (!item || !this.isGroupOrder) { if (!item || !this.isGroupOrder) {
return return
} }
// 打包上报失败后(groupPackRetryReady):右键商品行同样重新上报
if (this.groupPackRetryReady) {
this.retryPopupOpen = false
this.maybeAutoSubmitGroupPack()
return
}
const reason = this.verifyBlockReason(item) const reason = this.verifyBlockReason(item)
if (reason) { if (reason) {
diagNote('免验-blocked', { reason, source: 'contextmenu', item: item?.name || item?.barcode || '' }) diagNote('免验-blocked', { reason, source: 'contextmenu', item: item?.name || item?.barcode || '' })
@ -1227,7 +1284,8 @@ export default {
// 直接标记为已核实(标绿),无需扫码 // 直接标记为已核实(标绿),无需扫码
item.scannedQty = total item.scannedQty = total
this.addScanRecord(`免验:${item.name || item.barcode || ''}`) this.addScanRecord(`免验:${item.name || item.barcode || ''}`)
this.speak('免验通过') const req = item?.packingRequirements || ''
this.speak(req ? `免验通过,${req}` : '免验通过')
uni.showToast({ title: `「${item.name || ''}」免验通过`, icon: 'none', silentVoice: true }) uni.showToast({ title: `「${item.name || ''}」免验通过`, icon: 'none', silentVoice: true })
// 全部核实后自动开始打包 // 全部核实后自动开始打包
this.maybeAutoSubmitGroupPack() this.maybeAutoSubmitGroupPack()
@ -1313,10 +1371,10 @@ export default {
reportPackOrder(status = 1) { reportPackOrder(status = 1) {
const token = this.getWorkbenchToken() const token = this.getWorkbenchToken()
if (!token) { if (!token) {
return Promise.reject(new Error('工作台登录已失效')) return Promise.reject(this.makePackError('工作台登录已失效', 401))
} }
if (!this.currentOrderKey) { if (!this.currentOrderKey) {
return Promise.reject(new Error('订单上下文缺失,请重新扫码查询')) return Promise.reject(this.makePackError('订单上下文缺失,请重新扫码查询', 400))
} }
const payload = { const payload = {
token: String(token), token: String(token),
@ -1340,27 +1398,39 @@ export default {
})) }))
: undefined, : undefined,
} }
return packOrder(payload).then((body) => { // 显式 15s 超时:弱网下不无限挂起(请求层另有硬超时兜底)
return packOrder(payload, { timeout: 15000 }).then((body) => {
const res = body?.data || body?.result || body const res = body?.data || body?.result || body
const raw = res && typeof res === 'object' && !Array.isArray(res) ? res : null const raw = res && typeof res === 'object' && !Array.isArray(res) ? res : null
const flag = body?.flag || raw?.flag || '' const flag = body?.flag || raw?.flag || ''
const bizCode = Number(body?.code ?? raw?.code ?? 0)
if (this.checkWorkbenchAuthExpired(body)) { if (this.checkWorkbenchAuthExpired(body)) {
throw new Error('工作台已解绑') throw this.makePackError('工作台已解绑', bizCode || 401)
} }
if (flag === 'failure') { if (flag === 'failure') {
throw new Error(body?.message || body?.msg || '打包上报失败') throw this.makePackError(body?.message || body?.msg || '打包上报失败', bizCode)
} }
return body return body
}) })
}, },
/** 构造带业务码的打包上报错误(code 用于区分 400 key 失效 / 网络异常) */
makePackError(message, code = 0) {
const err = new Error(message || '打包上报失败')
err.code = Number(code) || 0
return err
},
startPack() { startPack() {
if (this.packReporting || this.packStarted) { if (this.packReporting || this.packStarted) {
return return
} }
this.packReporting = true this.packReporting = true
uni.showLoading({ title: '打包提交中...', mask: true })
this.reportPackOrder(1) this.reportPackOrder(1)
.then((body) => { .then((body) => {
this.packStarted = true this.packStarted = true
// 上报成功后复位重试状态(key 重查计数 / 团单补报标记)
this.packKeyRetryCount = 0
this.groupPackRetryReady = false
// 大团购:按 packOrder 响应下发的倒计时字段启动「打包时长闸门」倒计时 // 大团购:按 packOrder 响应下发的倒计时字段启动「打包时长闸门」倒计时
this.applyPackCountdown(body) this.applyPackCountdown(body)
// 新打包提交成功后刷新今日打包统计(服务端为准) // 新打包提交成功后刷新今日打包统计(服务端为准)
@ -1371,12 +1441,93 @@ export default {
uni.showToast({ title: '开始打包', icon: 'none', silentVoice: true }) uni.showToast({ title: '开始打包', icon: 'none', silentVoice: true })
}) })
.catch((err) => { .catch((err) => {
uni.showToast({ title: err?.message || '打包上报失败', icon: 'none' }) this.handlePackReportFailure(err)
}) })
.finally(() => { .finally(() => {
this.packReporting = false this.packReporting = false
uni.hideLoading()
}) })
}, },
/**
* 打包上报失败分流:
* - 401/403 已由 checkWorkbenchAuthExpired 处理(清状态回登录页),不再弹窗
* - code=400(打包上下文 key 失效/过期)→ 自动重查一次拿新 key 再重提
* - 其它(网络超时/断网/服务端业务失败)→ 弹重传弹窗
*/
handlePackReportFailure(err) {
const code = Number(err?.code) || 0
if (code === 401 || code === 403) {
return
}
if (code === 400) {
this.retryQueryForNewKey(err)
return
}
this.openRetryPopup(err?.message || '打包上报失败')
},
/**
* key 失效自动重查一次:按最近查询条码重新拿 key 后再上报。
* 仅重试一次(packKeyRetryCount >= 1 后改弹重传弹窗,避免死循环)。
*/
retryQueryForNewKey(err) {
if (this.packKeyRetryCount >= 1) {
this.openRetryPopup(err?.message || '打包上报失败')
return
}
const code = this.currentOrderCode || this.lastScannedCode
const token = this.getWorkbenchToken()
if (!code || !token) {
this.openRetryPopup(err?.message || '打包上报失败')
return
}
this.packKeyRetryCount += 1
queryPackOrder(String(token), code, { timeout: 15000 })
.then((body) => {
if (this.checkWorkbenchAuthExpired(body)) {
return
}
const payload = body?.data || body?.result || body
const raw =
payload && typeof payload === 'object' && !Array.isArray(payload) ? payload : null
const flag = body?.flag || raw?.flag || ''
if (flag === 'failure') {
this.openRetryPopup('打包上下文已失效,请重新扫码查询')
return
}
// 重查成功:更新服务端缓存 key(订单信息以重查结果为准),重试上报
const key = this.pickInfoField(raw, body, ['key', 'order_key', 'orderKey']) || ''
if (key) {
this.currentOrderKey = key
}
this.startPack()
})
.catch(() => {
// 重查失败:复位计数,恢复「待重传」能力(弹窗重传/重扫可再次触发重查)
this.packKeyRetryCount = 0
this.openRetryPopup('网络异常,请稍后重试')
})
},
openRetryPopup(message) {
this.retryPopupOpen = true
this.retryPopupText = message || '打包上报失败'
// 团单:上报失败后保持核实状态,扫描商品条码/免验可重新上报
if (this.isGroupOrder) {
this.groupPackRetryReady = true
}
},
closeRetryPopup() {
this.retryPopupOpen = false
},
/** 重传弹窗「重新上传」:保持核实状态重新上报,失败会再次弹出 */
handleRetryPackReport() {
if (this.packReporting || this.packStarted) {
return
}
this.retryPopupOpen = false
// 重置 key 重查计数:本次手动重试允许重新走「400→自动重查一次」的恢复链路
this.packKeyRetryCount = 0
this.startPack()
},
/** /**
* 读取 packOrder 响应下发的倒计时字段(仅大团购 wave_scope=1 非 0): * 读取 packOrder 响应下发的倒计时字段(仅大团购 wave_scope=1 非 0):
* - pack_wait_seconds:需等待秒数 * - pack_wait_seconds:需等待秒数
@ -1441,7 +1592,7 @@ export default {
} }
this.packFinishing = true this.packFinishing = true
try { try {
const body = await finishPack(String(token)) const body = await finishPack(String(token), { timeout: 15000 })
if (this.checkWorkbenchAuthExpired(body)) { if (this.checkWorkbenchAuthExpired(body)) {
return return
} }
@ -1470,6 +1621,11 @@ export default {
this.sameOrderQuery = false this.sameOrderQuery = false
this.precheckPassed = false this.precheckPassed = false
this.packStarted = false this.packStarted = false
this.packReporting = false
this.packKeyRetryCount = 0
this.groupPackRetryReady = false
this.retryPopupOpen = false
this.retryPopupText = ''
// 波次范围与打包时长闸门倒计时复位 // 波次范围与打包时长闸门倒计时复位
this.currentWaveScope = null this.currentWaveScope = null
this.stopPackCountdown() this.stopPackCountdown()
@ -1481,25 +1637,18 @@ export default {
if (!str) { if (!str) {
return return
} }
// 正在播报:不打断当前音频,只保留最新一条待播(快速连扫时合并为最后一条) // FIFO:正在播报时按顺序排队,不丢任何一条
if (this.voicePlaying) { if (this.voicePlaying) {
this.voicePendingText = str this.voiceQueue.push(str)
console.log('[语音播报] 正在播报,暂存待播文本:', str) console.log('[语音播报] 正在播报,按顺序排队:', str, '待播队列长度:', this.voiceQueue.length)
return return
} }
this.voicePlaying = true this.voicePlaying = true
this.playSpeakText(str) this.playSpeakText(str)
}, },
normalizeSpeakText(text) { normalizeSpeakText(text) {
let str = String(text || '').trim() // 播报文本不做截断,完整播报(仅去除首尾空白)
if (!str) { return String(text || '').trim()
return ''
}
// 长文本缩减:语音播报过长很啰嗦,超过 12 字符截断并以“等”收尾
if (str.length > 12) {
str = str.slice(0, 12) + '等'
}
return str
}, },
/** /**
* 播报单条文本(串行队列执行单元) * 播报单条文本(串行队列执行单元)
@ -1531,10 +1680,9 @@ export default {
}) })
}, },
scheduleNextSpeak() { scheduleNextSpeak() {
const next = this.voicePendingText const next = this.voiceQueue.shift()
this.voicePendingText = ''
if (next) { if (next) {
console.log('[语音播报] 播放待播文本:', next) console.log('[语音播报] 播放下一条:', next, '待播队列剩余:', this.voiceQueue.length)
this.playSpeakText(next) this.playSpeakText(next)
} else { } else {
this.voicePlaying = false this.voicePlaying = false
@ -1547,14 +1695,9 @@ export default {
speakViaHttp(msg) { speakViaHttp(msg) {
return new Promise((resolve) => { return new Promise((resolve) => {
let settled = false let settled = false
let timeoutTimer = null
const finish = (ok) => { const finish = (ok) => {
if (!settled) { if (!settled) {
settled = true settled = true
if (timeoutTimer) {
clearTimeout(timeoutTimer)
timeoutTimer = null
}
resolve(ok) resolve(ok)
} }
} }
@ -1580,13 +1723,10 @@ export default {
this.downloadVoiceAudio(src) this.downloadVoiceAudio(src)
.then((localSrc) => { .then((localSrc) => {
this.playVoiceAudio(localSrc, finish) this.playVoiceAudio(localSrc, finish)
// 超时兜底:5 秒后仍未播放完成也视为完成,避免一直等待
timeoutTimer = setTimeout(() => finish(true), 5000)
}) })
.catch(() => { .catch(() => {
// 下载失败回退为直接播远程地址 // 下载失败回退为直接播远程地址
this.playVoiceAudio(src, finish) this.playVoiceAudio(src, finish)
timeoutTimer = setTimeout(() => finish(true), 5000)
}) })
} catch (e) { } catch (e) {
console.error('[语音播报] HTTP 接口解析异常:', e) console.error('[语音播报] HTTP 接口解析异常:', e)
@ -1633,6 +1773,18 @@ export default {
this.voiceAudioContext = audio this.voiceAudioContext = audio
let playStarted = false let playStarted = false
let finished = false let finished = false
let stallTimer = null
const finish = (ok) => {
if (finished) {
return
}
finished = true
if (stallTimer) {
clearTimeout(stallTimer)
stallTimer = null
}
onEnd(ok)
}
const doPlay = () => { const doPlay = () => {
if (playStarted || finished) { if (playStarted || finished) {
return return
@ -1643,23 +1795,26 @@ export default {
console.log('[语音播报] 音频已开始播放') console.log('[语音播报] 音频已开始播放')
} catch (e) { } catch (e) {
console.error('[语音播报] 音频播放异常:', e) console.error('[语音播报] 音频播放异常:', e)
onEnd(false) finish(false)
} }
} }
audio.onError((e) => { audio.onError((e) => {
finished = true
console.warn('[语音播报] 音频播放错误:', e) console.warn('[语音播报] 音频播放错误:', e)
onEnd(false) finish(false)
}) })
audio.onEnded(() => { audio.onEnded(() => {
finished = true
console.log('[语音播报] 播放结束,总时长:', audio.duration, 's,实际播到:', audio.currentTime, 's') console.log('[语音播报] 播放结束,总时长:', audio.duration, 's,实际播到:', audio.currentTime, 's')
onEnd(true) finish(true)
}) })
// 等缓冲就绪再播放:部分 Android 设备设置 src 后立即 play 会在缓冲不足时 // 等缓冲就绪再播放:部分 Android 设备设置 src 后立即 play 会在缓冲不足时
// 截断尾帧(末字丢失);onCanplay 后再播更稳,500ms 兜底防止事件不触发 // 截断尾帧(末字丢失);onCanplay 后再播更稳,500ms 兜底防止事件不触发
audio.onCanplay(() => { audio.onCanplay(() => {
console.log('[语音播报] 音频可播放,总时长:', audio.duration, 's,来源:', String(src).startsWith('http') ? '远程' : '本地') console.log('[语音播报] 音频可播放,总时长:', audio.duration, 's,来源:', String(src).startsWith('http') ? '远程' : '本地')
// 按真实时长设兜底(时长 + 3s 缓冲),替代固定 5s,避免长音频被中途截断
const dur = Number(audio.duration)
if (!stallTimer) {
stallTimer = setTimeout(() => finish(true), dur > 0 ? Math.ceil((dur + 3) * 1000) : 30000)
}
doPlay() doPlay()
}) })
audio.src = src audio.src = src
@ -1675,7 +1830,7 @@ export default {
this.voiceNextTimer = null this.voiceNextTimer = null
} }
this.voicePlaying = false this.voicePlaying = false
this.voicePendingText = '' this.voiceQueue = []
if (this.voiceAudioContext) { if (this.voiceAudioContext) {
try { try {
this.voiceAudioContext.stop() this.voiceAudioContext.stop()
@ -3851,6 +4006,24 @@ export default {
color: #d46b08; color: #d46b08;
} }
/* 打包上报失败提示条(弹窗关闭后常驻概要卡片顶部,红底红字) */
.pack-retry-hint {
margin-bottom: 0.1rem;
background-color: #fdecec;
border: 0.01rem solid #f5c2c2;
border-radius: 0.08rem;
padding: 0.08rem 0.15rem;
box-sizing: border-box;
display: flex;
align-items: center;
}
.pack-retry-hint-text {
font-size: 0.21rem;
font-weight: 600;
color: var(--wms-danger-strong);
}
/* 搜索输入框 */ /* 搜索输入框 */
.pack-search { .pack-search {
background-color: var(--wms-card-bg); background-color: var(--wms-card-bg);
@ -4135,9 +4308,14 @@ export default {
/* 打包要求 */ /* 打包要求 */
.pack-detail-info-req { .pack-detail-info-req {
font-size: 0.22rem; font-size: 0.22rem;
color: var(--wms-primary); color: var(--wms-danger-strong);
word-break: break-all; word-break: break-all;
margin-top: 0.04rem; margin-top: 0.04rem;
background-color: #fef0f0;
padding: 0.03rem 0.1rem;
border-radius: 0.06rem;
align-self: flex-start;
max-width: 100%;
} }
.pack-item-img-wrap { .pack-item-img-wrap {
@ -4217,7 +4395,8 @@ export default {
} }
.pack-detail-row--scanned .pack-detail-info-req { .pack-detail-row--scanned .pack-detail-info-req {
color: var(--wms-white); color: var(--wms-danger-strong);
background-color: #fef0f0;
} }
/* 今日打包 */ /* 今日打包 */
@ -4564,6 +4743,34 @@ export default {
flex: 1; flex: 1;
} }
/* 打包上报失败重试弹窗 */
.retry-popup {
width: 5.57rem;
text-align: center;
}
.retry-popup-title {
display: block;
font-size: 0.3rem;
font-weight: 600;
color: var(--wms-danger-strong);
text-align: center;
margin-bottom: 0.2rem;
}
.retry-popup-text {
display: block;
padding: 0.16rem 0.2rem;
margin-bottom: 0.05rem;
font-size: 0.23rem;
line-height: 1.55;
color: #666;
background-color: #f5f6f8;
border-radius: 0.1rem;
text-align: left;
word-break: break-all;
}
/* 商品图片预览弹窗 */ /* 商品图片预览弹窗 */
.img-preview-mask { .img-preview-mask {
position: fixed; position: fixed;