修改登录、打包模式页面
This commit is contained in:
parent
e3f3c7af09
commit
d1476fce83
@ -94,7 +94,7 @@
|
||||
</view>
|
||||
</block>
|
||||
<block v-else>
|
||||
<text class="wb-tip-top">在已登录的工作台管理端扫描二维码或输入绑定码,即可完成本机与工作台的绑定登录</text>
|
||||
<text class="wb-tip-top">工作台尚未绑定,请在PDA使用绑定工作台界面扫码绑定</text>
|
||||
<view class="wb-code-box">
|
||||
<image
|
||||
v-if="workbenchQrImage"
|
||||
@ -108,7 +108,6 @@
|
||||
</view>
|
||||
<text v-if="workbenchBindCode" class="wb-code-text">绑定码:{{ workbenchBindCode }}</text>
|
||||
<text class="wb-tip-bottom">{{ workbenchStatus }}</text>
|
||||
<text v-if="workbenchClientCode" class="wb-client-hint">客户端编码:{{ workbenchClientCode }}</text>
|
||||
<button class="wb-refresh-btn" :disabled="workbenchLoading" @click="handleWorkbenchRefresh">
|
||||
刷新绑定码
|
||||
</button>
|
||||
@ -192,6 +191,7 @@ export default {
|
||||
workbenchPollTimer: null,
|
||||
workbenchPollInterval: 1500,
|
||||
workbenchRequestTimeout: 120000,
|
||||
autoEnterPackTimer: null,
|
||||
}
|
||||
},
|
||||
onUnload() {
|
||||
@ -203,6 +203,7 @@ export default {
|
||||
this.clearScanFocusResumeTimer()
|
||||
this.clearKeyboardSuppressTimers()
|
||||
this.clearHiddenRefocusTimer()
|
||||
this.clearAutoEnterPackTimer()
|
||||
this.scanBadgeSubmitting = false
|
||||
},
|
||||
onReady() {
|
||||
@ -222,6 +223,7 @@ export default {
|
||||
this.suppressSoftKeyboardBurst()
|
||||
this.scheduleScanInputFocus(320)
|
||||
this.resumeWorkbenchFlow()
|
||||
this.autoEnterPackMode()
|
||||
},
|
||||
onHide() {
|
||||
this.pageActive = false
|
||||
@ -233,6 +235,7 @@ export default {
|
||||
this.clearHiddenScanTimer()
|
||||
this.clearPlusKeyTimer()
|
||||
this.clearHiddenRefocusTimer()
|
||||
this.clearAutoEnterPackTimer()
|
||||
this.scanHiddenFocused = false
|
||||
this.scanInputFocus = false
|
||||
},
|
||||
@ -1034,11 +1037,43 @@ export default {
|
||||
})
|
||||
}, 300)
|
||||
},
|
||||
enterStoredWorkbench() {
|
||||
clearAutoEnterPackTimer() {
|
||||
if (this.autoEnterPackTimer) {
|
||||
clearTimeout(this.autoEnterPackTimer)
|
||||
this.autoEnterPackTimer = null
|
||||
}
|
||||
},
|
||||
autoEnterPackMode() {
|
||||
if (!this.isPageActive()) {
|
||||
return
|
||||
}
|
||||
if (this.workbenchLoggedIn) {
|
||||
return
|
||||
}
|
||||
const storedToken = uni.getStorageSync('workbench_token')
|
||||
if (!storedToken) {
|
||||
return
|
||||
}
|
||||
this.hasStoredWorkbench = true
|
||||
this.clearAutoEnterPackTimer()
|
||||
// 延迟 500ms,期间再次确认 token 未被清除后再进入打包模式
|
||||
this.autoEnterPackTimer = setTimeout(() => {
|
||||
this.autoEnterPackTimer = null
|
||||
if (!this.isPageActive()) {
|
||||
return
|
||||
}
|
||||
const token = uni.getStorageSync('workbench_token')
|
||||
if (!token) {
|
||||
this.hasStoredWorkbench = false
|
||||
return
|
||||
}
|
||||
this.doEnterPackMode(token)
|
||||
}, 500)
|
||||
},
|
||||
doEnterPackMode(storedToken) {
|
||||
if (!this.isPageActive()) {
|
||||
return
|
||||
}
|
||||
if (!storedToken) {
|
||||
this.hasStoredWorkbench = false
|
||||
this.chooseRebindWorkbench()
|
||||
@ -1067,6 +1102,13 @@ export default {
|
||||
})
|
||||
}, 250)
|
||||
},
|
||||
enterStoredWorkbench() {
|
||||
if (!this.isPageActive()) {
|
||||
return
|
||||
}
|
||||
const storedToken = uni.getStorageSync('workbench_token')
|
||||
this.doEnterPackMode(storedToken)
|
||||
},
|
||||
chooseRebindWorkbench() {
|
||||
if (!this.isPageActive()) {
|
||||
return
|
||||
|
||||
@ -41,6 +41,7 @@
|
||||
:focus="searchFocus"
|
||||
:adjust-position="false"
|
||||
confirm-type="search"
|
||||
@input="handleSearchInput"
|
||||
@confirm="handlePackSearch"
|
||||
@focus="handleSearchFocus"
|
||||
@blur="handleSearchBlur"
|
||||
@ -70,7 +71,7 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="hasPackRecord" class="pack-card pack-detail">
|
||||
<view v-if="showPackDetail" class="pack-card pack-detail">
|
||||
<view class="pack-detail-title">
|
||||
<text class="pack-card-title">商品明细</text>
|
||||
<text
|
||||
@ -118,6 +119,10 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="orderBlocked" class="pack-card pack-blocked">
|
||||
<text class="pack-blocked-text">{{ orderBlockReason }}</text>
|
||||
</view>
|
||||
|
||||
<view v-if="!hasPackRecord" class="pack-left-empty">
|
||||
<text class="pack-left-empty-text">暂无打包记录</text>
|
||||
<text class="pack-left-empty-sub">扫码运单号开始打包</text>
|
||||
@ -233,7 +238,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 移除操作员确认弹窗 -->
|
||||
<view v-if="removeConfirmVisible" class="op-mask" @click="closeRemoveConfirm">
|
||||
<view v-if="removeConfirmVisible" class="op-mask">
|
||||
<view class="op-dialog op-dialog--confirm" @click.stop>
|
||||
<view class="op-dialog-head">
|
||||
<text class="op-dialog-title">移除操作员</text>
|
||||
@ -317,6 +322,21 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 退出工作台确认弹窗 -->
|
||||
<view v-if="logoutConfirmVisible" class="op-mask">
|
||||
<view class="op-dialog op-dialog--confirm logout-dialog" @click.stop>
|
||||
<view class="op-dialog-head">
|
||||
<text class="op-dialog-title">退出工作台模式</text>
|
||||
<text class="op-dialog-close" @click="closeLogoutConfirm">×</text>
|
||||
</view>
|
||||
<view class="op-confirm-content">退出后将清除本地工作台登录记录,需要重新扫码登录才能进入打包模式</view>
|
||||
<view class="op-confirm-footer op-confirm-footer--equal">
|
||||
<button class="op-btn op-btn--cancel" @click="closeLogoutConfirm">取消</button>
|
||||
<button class="op-btn op-btn--danger" @click="confirmLogout">退出</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -340,6 +360,11 @@ const SCAN_MIN_LENGTH = 2
|
||||
const SCAN_BURST_MAX_GAP = 100
|
||||
// 已绑定操作员本地缓存 key(后端暂未提供查询成员接口时,刷新后据此恢复显示)
|
||||
const MEMBER_STORAGE_KEY = 'workbenchMember'
|
||||
// 今日打包统计本地缓存 key(前端自行记录,按天存储,跨天重置)
|
||||
const TODAY_PACK_STORAGE_KEY = 'todayPackStat'
|
||||
// 语音播报:HTTP 语音接口(参考 WMS_PDA voice.js,不依赖平板系统中文语音包)
|
||||
const VOICE_API_URL = 'http://tbdata.gztbyc.com/voice/'
|
||||
const VOICE_API_PATH = 'http://tbdata.gztbyc.com'
|
||||
|
||||
export default {
|
||||
name: 'PackagingPage',
|
||||
@ -380,6 +405,7 @@ export default {
|
||||
scanFocusResumeTimer: null,
|
||||
scanKeyboardSuppressTimers: [],
|
||||
scanHiddenFocused: false,
|
||||
scanInputIdleTimer: null,
|
||||
lastSubmittedScan: { code: '', at: 0 },
|
||||
// ---- 绑定操作员(工作台成员)----
|
||||
operatorDialogVisible: false,
|
||||
@ -399,6 +425,7 @@ export default {
|
||||
noBarcodeReviewVisible: false,
|
||||
noBarcodeReviewTarget: null,
|
||||
cancelVerifyPopupOpen: false,
|
||||
logoutConfirmVisible: false,
|
||||
// ---- 打包流程(预检/上报/完成)----
|
||||
currentOrderCode: '',
|
||||
currentWaybillCode: '',
|
||||
@ -422,6 +449,11 @@ export default {
|
||||
previewTouchOriginY: 0,
|
||||
previewPinchStartDistance: 0,
|
||||
previewPinchStartScale: 1,
|
||||
// ---- 语音播报(HTTP 接口优先 + Android 原生 TTS + Web Speech 降级)----
|
||||
ttsEngine: null,
|
||||
ttsReady: false,
|
||||
ttsPendingText: '',
|
||||
voiceAudioContext: null,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -488,6 +520,17 @@ export default {
|
||||
hasPackRecord() {
|
||||
return !!(this.currentOrderRaw || this.currentOrderCode || this.detailList.length > 0)
|
||||
},
|
||||
// 订单是否被禁止打包(命中即隐藏商品明细)
|
||||
orderBlocked() {
|
||||
return this.checkOrderBlocked().blocked
|
||||
},
|
||||
// 商品明细显示条件:已绑定操作员 + 查询成功 + 订单未被禁止打包
|
||||
showPackDetail() {
|
||||
return !!(this.workbenchMember && this.hasPackRecord && !this.orderBlocked)
|
||||
},
|
||||
orderBlockReason() {
|
||||
return this.checkOrderBlocked().reason
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
groupVerifiedCount(val) {
|
||||
@ -508,6 +551,7 @@ export default {
|
||||
return
|
||||
}
|
||||
this.restoreWorkbenchMember()
|
||||
this.loadTodayPackStat()
|
||||
this.loadWorkbenchInfo()
|
||||
},
|
||||
onShow() {
|
||||
@ -566,6 +610,7 @@ export default {
|
||||
console.log('[packaging][query] queryPackOrderByCode code =', code)
|
||||
// 未绑定操作员时禁止查询订单,避免绕过绑定流程直接查询
|
||||
if (!this.workbenchMember) {
|
||||
this.speak('未绑定操作员')
|
||||
uni.showToast({ title: '请先绑定操作员', icon: 'none' })
|
||||
return
|
||||
}
|
||||
@ -599,10 +644,12 @@ export default {
|
||||
const flag = body?.flag || raw?.flag || ''
|
||||
const bizCode = body?.code ?? raw?.code ?? null
|
||||
if (Number(bizCode) === 401) {
|
||||
this.speak('无记录')
|
||||
this.handleWorkbenchAuthExpired()
|
||||
return
|
||||
}
|
||||
if (flag === 'failure') {
|
||||
this.speak('无记录')
|
||||
uni.showToast({
|
||||
title: body?.message || body?.msg || '未找到对应订单',
|
||||
icon: 'none',
|
||||
@ -610,6 +657,7 @@ export default {
|
||||
return
|
||||
}
|
||||
if (Number(bizCode) === 403) {
|
||||
this.speak('无记录')
|
||||
uni.showToast({ title: '工作台登录已失效,请重新登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
@ -699,7 +747,7 @@ export default {
|
||||
// ---- 预检与分流 ----
|
||||
const precheck = this.packPrecheck()
|
||||
if (!precheck.ok) {
|
||||
this.speak(precheck.reason)
|
||||
this.speak(precheck.speakText)
|
||||
uni.showToast({ title: precheck.reason, icon: 'none' })
|
||||
return
|
||||
}
|
||||
@ -775,6 +823,7 @@ export default {
|
||||
return
|
||||
}
|
||||
target.scannedQty = total
|
||||
this.speak('数据一致')
|
||||
uni.showToast({ title: `已将「${target.name || ''}」标记为已扫`, icon: 'none' })
|
||||
this.closeNoBarcodeReview()
|
||||
},
|
||||
@ -797,37 +846,50 @@ export default {
|
||||
* - 团单:未复核 / 已打包(pack_status≠none),不判拦截
|
||||
*/
|
||||
packPrecheck() {
|
||||
const { blocked, reason, speakText } = this.checkOrderBlocked()
|
||||
return blocked ? { ok: false, reason, speakText } : { ok: true }
|
||||
},
|
||||
/**
|
||||
* 订单禁止打包判断(命中即隐藏商品明细)
|
||||
* - 未复核:recheck_status 非空且不是 fin/finished/1
|
||||
* - 已打包:散单 pack_flag===1;团单 pack_status 非空且非 none
|
||||
* - 拦截:仅散单 intercept_flag===1
|
||||
* speakText 为语音文案,reason 为界面提示文案(两者可能不同)
|
||||
*/
|
||||
checkOrderBlocked() {
|
||||
const raw = this.currentOrderRaw
|
||||
if (!raw) {
|
||||
return { blocked: false, reason: '', speakText: '' }
|
||||
}
|
||||
const order =
|
||||
this.currentOrderRaw?.order && typeof this.currentOrderRaw.order === 'object'
|
||||
? this.currentOrderRaw.order
|
||||
: {}
|
||||
raw.order && typeof raw.order === 'object' ? raw.order : {}
|
||||
const batch =
|
||||
this.currentOrderRaw?.batch && typeof this.currentOrderRaw.batch === 'object'
|
||||
? this.currentOrderRaw.batch
|
||||
: {}
|
||||
raw.batch && typeof raw.batch === 'object' ? raw.batch : {}
|
||||
if (this.isGroupOrder) {
|
||||
// 团单:未复核 → 已打包
|
||||
const recheckStatus = order?.recheck_status ?? order?.recheckStatus ?? ''
|
||||
if (recheckStatus && String(recheckStatus) !== 'fin') {
|
||||
return { ok: false, reason: '订单未复核,禁止打包' }
|
||||
if (recheckStatus && !['fin', 'finished', '1'].includes(String(recheckStatus))) {
|
||||
return { blocked: true, reason: '订单未复核,禁止打包', speakText: '订单未复核,禁止打包' }
|
||||
}
|
||||
const packStatus =
|
||||
order?.pack_status ?? order?.packStatus ?? batch?.pack_status ?? batch?.packStatus ?? ''
|
||||
if (packStatus && String(packStatus) !== 'none') {
|
||||
return { ok: false, reason: '订单已打包,禁止重复打包' }
|
||||
return { blocked: true, reason: '订单已打包,禁止打包', speakText: '已打包' }
|
||||
}
|
||||
return { ok: true }
|
||||
return { blocked: false, reason: '', speakText: '' }
|
||||
}
|
||||
// 散单:拦截 → 未复核 → 已打包
|
||||
if (Number(order?.intercept_flag) === 1) {
|
||||
return { ok: false, reason: '订单已拦截,禁止打包' }
|
||||
return { blocked: true, reason: '订单已拦截,禁止打包', speakText: '订单已拦截,禁止打包' }
|
||||
}
|
||||
const recheckStatus = order?.recheck_status ?? order?.recheckStatus ?? ''
|
||||
if (recheckStatus && String(recheckStatus) !== 'fin') {
|
||||
return { ok: false, reason: '订单未复核,禁止打包' }
|
||||
if (recheckStatus && !['fin', 'finished', '1'].includes(String(recheckStatus))) {
|
||||
return { blocked: true, reason: '订单未复核,禁止打包', speakText: '订单未复核,禁止打包' }
|
||||
}
|
||||
if (Number(order?.pack_flag) === 1) {
|
||||
return { ok: false, reason: '订单已打包,禁止重复打包' }
|
||||
return { blocked: true, reason: '订单已打包,禁止打包', speakText: '已打包' }
|
||||
}
|
||||
return { ok: true }
|
||||
return { blocked: false, reason: '', speakText: '' }
|
||||
},
|
||||
/**
|
||||
* 上报开始打包(复用 workbench.packOrder,status=1)
|
||||
@ -870,6 +932,7 @@ export default {
|
||||
this.reportPackOrder(1)
|
||||
.then(() => {
|
||||
this.packStarted = true
|
||||
this.recordTodayPack()
|
||||
this.speak('开始打包')
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -891,7 +954,6 @@ export default {
|
||||
try {
|
||||
await finishPack(String(token))
|
||||
this.packStarted = false
|
||||
this.speak('打包完成')
|
||||
} catch (e) {
|
||||
// 失败不阻断
|
||||
} finally {
|
||||
@ -914,17 +976,240 @@ export default {
|
||||
this.packStarted = false
|
||||
},
|
||||
speak(text) {
|
||||
console.log('[语音播报] speak 入口:', String(text))
|
||||
const str = String(text || '').trim()
|
||||
if (!str) {
|
||||
return
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
// 优先 HTTP 语音接口(平板缺中文语音包时仍可发声),失败再走本地 TTS / Web Speech
|
||||
this.speakViaHttp(str).then((ok) => {
|
||||
console.log('[语音播报] HTTP 语音接口结果:', ok)
|
||||
if (!ok) {
|
||||
this.speakViaTtsOrWebSpeech(str)
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifndef APP-PLUS
|
||||
this.speakViaTtsOrWebSpeech(str)
|
||||
// #endif
|
||||
},
|
||||
speakViaHttp(msg) {
|
||||
return new Promise((resolve) => {
|
||||
let settled = false
|
||||
const finish = (ok) => {
|
||||
if (!settled) {
|
||||
settled = true
|
||||
resolve(ok)
|
||||
}
|
||||
}
|
||||
uni.request({
|
||||
url: VOICE_API_URL + encodeURIComponent(msg),
|
||||
method: 'GET',
|
||||
timeout: 3000,
|
||||
header: { 'content-type': 'text/xml; charset=utf-8' },
|
||||
success: (res) => {
|
||||
try {
|
||||
const audioPath = res?.data?.audio
|
||||
if (!audioPath) {
|
||||
console.warn('[语音播报] HTTP 接口未返回 audio 字段:', JSON.stringify(res?.data || res))
|
||||
finish(false)
|
||||
return
|
||||
}
|
||||
const src = VOICE_API_PATH + audioPath
|
||||
console.log('[语音播报] HTTP 音频地址:', src)
|
||||
this.playVoiceAudio(src, finish)
|
||||
// 超时兜底:5 秒后仍未播放完成也视为完成,避免一直等待
|
||||
setTimeout(() => finish(true), 5000)
|
||||
} catch (e) {
|
||||
console.error('[语音播报] HTTP 接口解析异常:', e)
|
||||
finish(false)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.warn('[语音播报] HTTP 语音接口请求失败:', err)
|
||||
finish(false)
|
||||
},
|
||||
})
|
||||
})
|
||||
},
|
||||
playVoiceAudio(src, onEnd) {
|
||||
try {
|
||||
if (this.voiceAudioContext) {
|
||||
try {
|
||||
this.voiceAudioContext.destroy()
|
||||
} catch (e) {
|
||||
// 忽略旧实例销毁异常
|
||||
}
|
||||
this.voiceAudioContext = null
|
||||
}
|
||||
const audio = uni.createInnerAudioContext()
|
||||
this.voiceAudioContext = audio
|
||||
audio.onError((e) => {
|
||||
console.warn('[语音播报] 音频播放错误:', e)
|
||||
onEnd(false)
|
||||
})
|
||||
audio.onEnded(() => {
|
||||
onEnd(true)
|
||||
})
|
||||
audio.src = src
|
||||
audio.play()
|
||||
console.log('[语音播报] 音频已开始播放')
|
||||
} catch (e) {
|
||||
console.error('[语音播报] 创建音频上下文异常:', e)
|
||||
onEnd(false)
|
||||
}
|
||||
},
|
||||
destroyVoiceAudio() {
|
||||
if (this.voiceAudioContext) {
|
||||
try {
|
||||
this.voiceAudioContext.stop()
|
||||
this.voiceAudioContext.destroy()
|
||||
} catch (e) {
|
||||
// 忽略
|
||||
}
|
||||
this.voiceAudioContext = null
|
||||
}
|
||||
},
|
||||
speakViaTtsOrWebSpeech(text) {
|
||||
const str = String(text)
|
||||
// #ifdef APP-PLUS
|
||||
console.log(
|
||||
'[语音播报] APP-PLUS 分支:',
|
||||
JSON.stringify({ hasEngine: !!this.ttsEngine, ttsReady: this.ttsReady, text: str })
|
||||
)
|
||||
if (this.ttsEngine) {
|
||||
if (this.ttsReady) {
|
||||
const ok = this.speakNativeTts(str)
|
||||
console.log('[语音播报] speakNativeTts 返回:', ok)
|
||||
} else {
|
||||
// 引擎未就绪:只保留最后一条待播文本
|
||||
this.ttsPendingText = str
|
||||
console.log('[语音播报] 引擎未就绪,暂存待播文本:', str)
|
||||
}
|
||||
return
|
||||
}
|
||||
console.log('[语音播报] 无 TTS 引擎,回退 Web Speech')
|
||||
// #endif
|
||||
this.speakViaWebSpeech(str)
|
||||
},
|
||||
speakViaWebSpeech(text) {
|
||||
console.log(
|
||||
'[语音播报] Web Speech 分支:',
|
||||
JSON.stringify({
|
||||
hasWindow: typeof window !== 'undefined',
|
||||
hasSpeechSynthesis: typeof window !== 'undefined' && !!window.speechSynthesis,
|
||||
text: String(text),
|
||||
})
|
||||
)
|
||||
try {
|
||||
if (typeof window !== 'undefined' && window.speechSynthesis) {
|
||||
window.speechSynthesis.cancel()
|
||||
const utterance = new SpeechSynthesisUtterance(String(text))
|
||||
utterance.lang = 'zh-CN'
|
||||
window.speechSynthesis.speak(utterance)
|
||||
console.log('[语音播报] Web Speech 已调用 speak')
|
||||
} else {
|
||||
console.warn('[语音播报] window.speechSynthesis 不可用,无法用 Web Speech 播报')
|
||||
}
|
||||
} catch (e) {
|
||||
// 语音不可用时静默忽略
|
||||
console.error('[语音播报] Web Speech 异常:', e)
|
||||
}
|
||||
},
|
||||
initNativeTts() {
|
||||
// #ifdef APP-PLUS
|
||||
console.log(
|
||||
'[语音播报] initNativeTts 开始:',
|
||||
JSON.stringify({ hasPlus: typeof plus !== 'undefined', hasAndroid: !!(plus && plus.android) })
|
||||
)
|
||||
if (typeof plus === 'undefined' || !plus.android) {
|
||||
console.warn('[语音播报] plus.android 不可用,无法初始化原生 TTS')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const vm = this
|
||||
const TextToSpeech = plus.android.importClass('android.speech.tts.TextToSpeech')
|
||||
const Locale = plus.android.importClass('java.util.Locale')
|
||||
console.log('[语音播报] 已导入 TextToSpeech / Locale 类')
|
||||
const OnInitListener = plus.android.implements(
|
||||
'android.speech.tts.TextToSpeech$OnInitListener',
|
||||
{
|
||||
onInit: function (status) {
|
||||
console.log('[语音播报] onInit 回调 status:', status)
|
||||
// status === 0 表示 TTS 初始化成功(TextToSpeech.SUCCESS)
|
||||
if (status !== 0 || !vm.ttsEngine) {
|
||||
vm.ttsReady = false
|
||||
console.warn('[语音播报] TTS 初始化失败或引擎为空:', { status, hasEngine: !!vm.ttsEngine })
|
||||
return
|
||||
}
|
||||
// 设置中文语音;返回值 >= 0 表示该语言可用
|
||||
const langResult = vm.ttsEngine.setLanguage(Locale.CHINA)
|
||||
console.log('[语音播报] setLanguage(Locale.CHINA) 返回:', langResult)
|
||||
if (langResult >= 0) {
|
||||
vm.ttsReady = true
|
||||
console.log('[语音播报] TTS 就绪,ttsReady=true')
|
||||
if (vm.ttsPendingText) {
|
||||
const pending = vm.ttsPendingText
|
||||
vm.ttsPendingText = ''
|
||||
console.log('[语音播报] 补播暂存文本:', pending)
|
||||
vm.speakNativeTts(pending)
|
||||
}
|
||||
} else {
|
||||
vm.ttsReady = false
|
||||
console.warn('[语音播报] 中文语音包不可用(-1缺数据/-2不支持),需安装中文 TTS 语音数据')
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
this.ttsEngine = new TextToSpeech(plus.android.runtimeMainActivity(), OnInitListener)
|
||||
console.log('[语音播报] TextToSpeech 实例已创建:', !!this.ttsEngine)
|
||||
} catch (e) {
|
||||
this.ttsEngine = null
|
||||
this.ttsReady = false
|
||||
console.error('[语音播报] initNativeTts 异常:', e)
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
speakNativeTts(text) {
|
||||
// #ifdef APP-PLUS
|
||||
console.log(
|
||||
'[语音播报] speakNativeTts 调用:',
|
||||
JSON.stringify({ hasEngine: !!this.ttsEngine, ttsReady: this.ttsReady, text: String(text) })
|
||||
)
|
||||
if (!this.ttsEngine || !this.ttsReady) {
|
||||
console.warn('[语音播报] speakNativeTts 跳过:引擎未就绪')
|
||||
return false
|
||||
}
|
||||
try {
|
||||
const TextToSpeech = plus.android.importClass('android.speech.tts.TextToSpeech')
|
||||
// QUEUE_FLUSH = 0:清空队列后立即播报当前文本
|
||||
this.ttsEngine.speak(String(text), TextToSpeech.QUEUE_FLUSH, null)
|
||||
console.log('[语音播报] 原生 TTS speak 已调用')
|
||||
return true
|
||||
} catch (e) {
|
||||
console.error('[语音播报] 原生 TTS speak 异常:', e)
|
||||
return false
|
||||
}
|
||||
// #endif
|
||||
return false
|
||||
},
|
||||
shutdownNativeTts() {
|
||||
// #ifdef APP-PLUS
|
||||
console.log('[语音播报] shutdownNativeTts:', { hasEngine: !!this.ttsEngine })
|
||||
if (this.ttsEngine) {
|
||||
try {
|
||||
this.ttsEngine.stop()
|
||||
this.ttsEngine.shutdown()
|
||||
console.log('[语音播报] 原生 TTS 已 stop + shutdown')
|
||||
} catch (e) {
|
||||
console.error('[语音播报] 释放 TTS 异常:', e)
|
||||
}
|
||||
this.ttsEngine = null
|
||||
this.ttsReady = false
|
||||
this.ttsPendingText = ''
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
previewItemImage(item) {
|
||||
const urls =
|
||||
Array.isArray(item?.images) && item.images.length > 0
|
||||
@ -1050,6 +1335,27 @@ export default {
|
||||
activateSearchInput() {
|
||||
this.searchFocus = true
|
||||
},
|
||||
handleSearchInput() {
|
||||
// 真机(APP-PLUS)扫码枪走 IME 注入文本、无 DOM keydown 字符,
|
||||
// 停止输入 1000ms 视为一次完整扫码自动查询(@confirm 仍可即时查询)
|
||||
if (!this.isPageActive() || !this.isAppPlus()) {
|
||||
return
|
||||
}
|
||||
const code = String(this.keyword || '').trim()
|
||||
this.clearScanInputIdleTimer()
|
||||
if (!code) {
|
||||
return
|
||||
}
|
||||
this.scanInputIdleTimer = setTimeout(() => {
|
||||
if (!this.isPageActive()) {
|
||||
return
|
||||
}
|
||||
if (!String(this.keyword || '').trim()) {
|
||||
return
|
||||
}
|
||||
this.handlePackSearch()
|
||||
}, 1000)
|
||||
},
|
||||
clearKeyword() {
|
||||
this.keyword = ''
|
||||
this.scanBurstConfirmed = false
|
||||
@ -1166,8 +1472,13 @@ export default {
|
||||
return false
|
||||
// #endif
|
||||
},
|
||||
hasDomKeyboardSupport() {
|
||||
return typeof window !== 'undefined' || typeof document !== 'undefined'
|
||||
},
|
||||
setupScanCaptureMode() {
|
||||
this.enableHiddenInputCapture = this.isRealDevice()
|
||||
// 真机扫码枪走 IME 注入文本(无 DOM keydown 字符)、隐藏 input 会丢字,
|
||||
// 且隐藏 input 聚焦会反复弹出软键盘;改为可见搜索框直接接收扫码(与登录页一致)
|
||||
this.enableHiddenInputCapture = !this.hasDomKeyboardSupport()
|
||||
},
|
||||
isRealDevice() {
|
||||
// #ifdef APP-PLUS
|
||||
@ -1414,8 +1725,8 @@ export default {
|
||||
return
|
||||
}
|
||||
if (!this.enableHiddenInputCapture) {
|
||||
// 无隐藏捕获:不再抢占/隐藏软键盘,避免点击操作时软键盘反复弹收
|
||||
this.scanInputFocus = false
|
||||
this.suppressSoftKeyboardBurst()
|
||||
return
|
||||
}
|
||||
if (!this.scanInputFocus) {
|
||||
@ -1540,6 +1851,51 @@ export default {
|
||||
this.scanRecords = this.scanRecords.slice(0, 50)
|
||||
}
|
||||
},
|
||||
getTodayKey() {
|
||||
const d = new Date()
|
||||
const pad = (n) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
|
||||
},
|
||||
loadTodayPackStat() {
|
||||
try {
|
||||
const cached = uni.getStorageSync(TODAY_PACK_STORAGE_KEY)
|
||||
const today = this.getTodayKey()
|
||||
if (cached && typeof cached === 'object' && cached.date === today) {
|
||||
this.todayOrderCount = Number(cached.orderCount) || 0
|
||||
this.todayProductCount = Number(cached.productCount) || 0
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略:读取失败按无记录处理
|
||||
}
|
||||
this.todayOrderCount = 0
|
||||
this.todayProductCount = 0
|
||||
},
|
||||
recordTodayPack() {
|
||||
const today = this.getTodayKey()
|
||||
// 跨天或首次:先归零
|
||||
try {
|
||||
const cached = uni.getStorageSync(TODAY_PACK_STORAGE_KEY)
|
||||
if (!(cached && typeof cached === 'object' && cached.date === today)) {
|
||||
this.todayOrderCount = 0
|
||||
this.todayProductCount = 0
|
||||
}
|
||||
} catch (e) {
|
||||
this.todayOrderCount = 0
|
||||
this.todayProductCount = 0
|
||||
}
|
||||
this.todayOrderCount += 1
|
||||
this.todayProductCount += Number(this.productCount) || 0
|
||||
try {
|
||||
uni.setStorageSync(TODAY_PACK_STORAGE_KEY, {
|
||||
date: today,
|
||||
orderCount: this.todayOrderCount,
|
||||
productCount: this.todayProductCount,
|
||||
})
|
||||
} catch (e) {
|
||||
// 忽略:存储失败不影响界面展示
|
||||
}
|
||||
},
|
||||
clearPlusKeyTimer() {
|
||||
if (this.plusKeyTimer) {
|
||||
clearTimeout(this.plusKeyTimer)
|
||||
@ -1564,6 +1920,12 @@ export default {
|
||||
this.scanFocusResumeTimer = null
|
||||
}
|
||||
},
|
||||
clearScanInputIdleTimer() {
|
||||
if (this.scanInputIdleTimer) {
|
||||
clearTimeout(this.scanInputIdleTimer)
|
||||
this.scanInputIdleTimer = null
|
||||
}
|
||||
},
|
||||
clearKeyboardSuppressTimers() {
|
||||
this.scanKeyboardSuppressTimers.forEach((timer) => clearTimeout(timer))
|
||||
this.scanKeyboardSuppressTimers = []
|
||||
@ -1574,6 +1936,7 @@ export default {
|
||||
this.clearHiddenScanTimer()
|
||||
this.clearPlusKeyTimer()
|
||||
this.clearHiddenRefocusTimer()
|
||||
this.clearScanInputIdleTimer()
|
||||
if (this.scanTimer) {
|
||||
clearTimeout(this.scanTimer)
|
||||
this.scanTimer = null
|
||||
@ -1666,11 +2029,13 @@ export default {
|
||||
}
|
||||
if (flag === 'failure' || Number(bizCode) === 404) {
|
||||
this.operatorResult = null
|
||||
this.speak('未绑定操作员')
|
||||
uni.showToast({ title: '未找到该用户', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (Number(bizCode) === 400) {
|
||||
this.operatorResult = null
|
||||
this.speak('未绑定操作员')
|
||||
uni.showToast({ title: '临时码不能为空', icon: 'none' })
|
||||
return
|
||||
}
|
||||
@ -1726,6 +2091,7 @@ export default {
|
||||
return
|
||||
}
|
||||
if (flag === 'failure') {
|
||||
this.speak('绑定失败,请点击绑定重试')
|
||||
if (Number(bizCode) === 403) {
|
||||
uni.showToast({ title: '工作台不存在或 token 无效', icon: 'none' })
|
||||
} else {
|
||||
@ -1743,6 +2109,7 @@ export default {
|
||||
uni.setStorageSync(MEMBER_STORAGE_KEY, this.workbenchMember)
|
||||
// 清空主搜索框(未绑定时扫码内容为临时码,绑定后应清空)
|
||||
this.keyword = ''
|
||||
this.speak('绑定成功')
|
||||
uni.showToast({ title: '绑定成功', icon: 'none' })
|
||||
// 绑定成功后关闭弹窗
|
||||
this.closeOperatorDialog()
|
||||
@ -1784,16 +2151,19 @@ export default {
|
||||
const token = this.getWorkbenchToken()
|
||||
if (!token) {
|
||||
if (!silent) {
|
||||
this.exitToLogin('工作台登录已失效,请重新登录', { clearStored: true })
|
||||
this.exitToLogin('工作台登录已失效,请重新登录')
|
||||
}
|
||||
return
|
||||
return 'expired'
|
||||
}
|
||||
if (this.operatorRemoving) {
|
||||
return
|
||||
return 'failed'
|
||||
}
|
||||
// 1. 先上报打包完成
|
||||
await this.ensurePackFinishedBeforeLeave()
|
||||
this.operatorRemoving = true
|
||||
if (!silent) {
|
||||
uni.showLoading({ title: '移除中...', mask: true })
|
||||
}
|
||||
await this.ensurePackFinishedBeforeLeave()
|
||||
try {
|
||||
const body = await removeWorkbenchMember({
|
||||
ids: [Number(memberId)],
|
||||
@ -1805,17 +2175,18 @@ export default {
|
||||
const flag = body?.flag || raw?.flag || ''
|
||||
const bizCode = body?.code ?? raw?.code ?? null
|
||||
if (Number(bizCode) === 401) {
|
||||
// 401:token 失效,统一回登录页(静默场景交由退出流程处理)
|
||||
// 401:token 失效,统一回登录页
|
||||
if (!silent) {
|
||||
this.handleWorkbenchAuthExpired()
|
||||
}
|
||||
return
|
||||
return 'expired'
|
||||
}
|
||||
if (flag === 'failure') {
|
||||
if (!silent) {
|
||||
this.speak('移除失败')
|
||||
uni.showToast({ title: body?.message || body?.msg || '移除失败', icon: 'none' })
|
||||
}
|
||||
return
|
||||
return 'failed'
|
||||
}
|
||||
const removed = Number(raw?.removed ?? body?.removed ?? 0)
|
||||
if (removed > 0) {
|
||||
@ -1828,18 +2199,27 @@ export default {
|
||||
this.operatorResult = null
|
||||
this.operatorSearched = false
|
||||
if (!silent) {
|
||||
this.speak('已移除操作员')
|
||||
this.speak('移除成功')
|
||||
uni.showToast({ title: '已移除操作员', icon: 'none' })
|
||||
}
|
||||
} else if (!silent) {
|
||||
return 'success'
|
||||
}
|
||||
if (!silent) {
|
||||
this.speak('移除失败')
|
||||
uni.showToast({ title: '未找到可移除的成员', icon: 'none' })
|
||||
}
|
||||
return 'failed'
|
||||
} catch (e) {
|
||||
if (!silent) {
|
||||
this.speak('移除失败')
|
||||
uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' })
|
||||
}
|
||||
return 'failed'
|
||||
} finally {
|
||||
this.operatorRemoving = false
|
||||
if (!silent) {
|
||||
uni.hideLoading()
|
||||
}
|
||||
}
|
||||
},
|
||||
pickInfoField(raw, body, keys) {
|
||||
@ -1911,7 +2291,7 @@ export default {
|
||||
this.workbenchInfo = null
|
||||
this.infoError = '工作台不存在或 token 无效'
|
||||
// token 已失效:清除本地保存的工作台会话,回到登录页重新绑定
|
||||
this.exitToLogin(this.infoError, { clearStored: true })
|
||||
this.exitToLogin('工作台登录已失效,请重新登录')
|
||||
return
|
||||
}
|
||||
const info = {
|
||||
@ -1947,22 +2327,25 @@ export default {
|
||||
* 工作台 token 失效(401):清除本地会话与操作员缓存,回到登录页
|
||||
*/
|
||||
handleWorkbenchAuthExpired() {
|
||||
this.workbenchMember = null
|
||||
uni.removeStorageSync(MEMBER_STORAGE_KEY)
|
||||
this.exitToLogin('工作台登录已失效,请重新登录', { clearStored: true })
|
||||
this.exitToLogin('工作台登录已失效,请重新登录')
|
||||
},
|
||||
exitToLogin(message, options = {}) {
|
||||
const { clearStored = false } = options
|
||||
exitToLogin(message) {
|
||||
if (message) {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
uni.removeStorageSync('token')
|
||||
// 主动退出默认保留 workbench_token,登录页工作台 Tab 可一键再次进入打包模式
|
||||
if (clearStored) {
|
||||
uni.removeStorageSync('workbench_token')
|
||||
const wbToken = uni.getStorageSync('workbench_token')
|
||||
const mainToken = uni.getStorageSync('token')
|
||||
// 清理工作台会话与操作员缓存
|
||||
uni.removeStorageSync('workbench_token')
|
||||
uni.removeStorageSync('workbench_id')
|
||||
uni.removeStorageSync(MEMBER_STORAGE_KEY)
|
||||
this.workbenchMember = null
|
||||
// 主登录态一致性判断:一致(工作台会话即主登录态)→ 清主 token;不一致 → 保留主登录态
|
||||
if (wbToken && wbToken === mainToken) {
|
||||
uni.removeStorageSync('token')
|
||||
}
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
@ -1975,22 +2358,26 @@ export default {
|
||||
await this.ensurePackFinishedBeforeLeave()
|
||||
// 2. 静默解绑操作员(操作员归属当前工作台),失败不阻断
|
||||
if (this.workbenchMember && this.workbenchMember.id) {
|
||||
await this.doRemoveOperator(this.workbenchMember.id, { silent: true })
|
||||
const result = await this.doRemoveOperator(this.workbenchMember.id, { silent: true })
|
||||
// 401 已失效:被动退出,提示并回登录页
|
||||
if (result === 'expired') {
|
||||
this.exitToLogin('工作台登录已失效,请重新登录')
|
||||
return
|
||||
}
|
||||
}
|
||||
// 3. 清除会话回登录页
|
||||
this.exitToLogin('已退出登录')
|
||||
// 3. 清除会话回登录页(主动退出不再额外弹 toast)
|
||||
this.exitToLogin('')
|
||||
},
|
||||
handleLogout() {
|
||||
// 退出前二次确认;工作台登出仅清理本地会话,不调用 user.logout 接口
|
||||
uni.showModal({
|
||||
title: '退出',
|
||||
content: '确认退出当前工作台?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.finishLogout()
|
||||
}
|
||||
},
|
||||
})
|
||||
this.logoutConfirmVisible = true
|
||||
},
|
||||
closeLogoutConfirm() {
|
||||
this.logoutConfirmVisible = false
|
||||
},
|
||||
confirmLogout() {
|
||||
this.logoutConfirmVisible = false
|
||||
this.finishLogout()
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
@ -2000,6 +2387,7 @@ export default {
|
||||
this.attachGlobalKeyboardListener()
|
||||
this.suppressSoftKeyboardBurst()
|
||||
this.scheduleScanInputFocus(260)
|
||||
this.initNativeTts()
|
||||
// 页面进入即聚焦搜索框(H5 无隐藏捕获时)
|
||||
this.$nextTick(() => {
|
||||
if (!this.enableHiddenInputCapture) {
|
||||
@ -2009,6 +2397,8 @@ export default {
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.pageActive = false
|
||||
this.shutdownNativeTts()
|
||||
this.destroyVoiceAudio()
|
||||
this.removePlusKeyboardListener()
|
||||
this.removeGlobalKeyboardListener()
|
||||
this.clearScanTimers()
|
||||
@ -2384,6 +2774,20 @@ export default {
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.pack-blocked {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
margin-top: 12rpx;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.pack-blocked-text {
|
||||
font-size: 64rpx;
|
||||
color: #e64340;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.pack-detail-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@ -2888,6 +3292,11 @@ export default {
|
||||
width: 680rpx;
|
||||
}
|
||||
|
||||
/* 退出工作台确认弹窗(宽度更大) */
|
||||
.logout-dialog {
|
||||
width: 900rpx;
|
||||
}
|
||||
|
||||
.op-confirm-content {
|
||||
font-size: 40rpx;
|
||||
color: #333;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user