From d1476fce83e051b6ccd0df58a52f7c3896c11c91 Mon Sep 17 00:00:00 2001 From: zm2000 <18386612143@163.com> Date: Mon, 14 Sep 2026 18:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95=E3=80=81?= =?UTF-8?q?=E6=89=93=E5=8C=85=E6=A8=A1=E5=BC=8F=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/login/login.vue | 48 +++- src/pages/packaging/index.vue | 515 ++++++++++++++++++++++++++++++---- 2 files changed, 507 insertions(+), 56 deletions(-) diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index 74ac77f..e898996 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -94,7 +94,7 @@ - 在已登录的工作台管理端扫描二维码或输入绑定码,即可完成本机与工作台的绑定登录 + 工作台尚未绑定,请在PDA使用绑定工作台界面扫码绑定 绑定码:{{ workbenchBindCode }} {{ workbenchStatus }} - 客户端编码:{{ workbenchClientCode }} @@ -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 diff --git a/src/pages/packaging/index.vue b/src/pages/packaging/index.vue index 7eff22c..48e4a59 100644 --- a/src/pages/packaging/index.vue +++ b/src/pages/packaging/index.vue @@ -41,6 +41,7 @@ :focus="searchFocus" :adjust-position="false" confirm-type="search" + @input="handleSearchInput" @confirm="handlePackSearch" @focus="handleSearchFocus" @blur="handleSearchBlur" @@ -70,7 +71,7 @@ - + 商品明细 + + {{ orderBlockReason }} + + 暂无打包记录 扫码运单号开始打包 @@ -233,7 +238,7 @@ - + 移除操作员 @@ -317,6 +322,21 @@ + + + + + + 退出工作台模式 + × + + 退出后将清除本地工作台登录记录,需要重新扫码登录才能进入打包模式 + + + + + + @@ -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;