From 1a2fd5b971e3886cc4c4c9b977ad5a638314b3d6 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sat, 19 Sep 2026 14:51:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=93=E5=8C=85=E9=A1=B5=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E4=B8=8E=E5=85=A8=E5=B1=80=E8=AF=AD=E9=9F=B3=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 打包页:打包状态标记(packStarted)、长按/右键免核商品、展示包装要求、移除无条码复核弹窗 - 全局语音:拦截 uni.showToast 同步语音播报(方案迁移自散单项目),新增 core/voice.js - api:packOrder 增加 pack_time(Unix 秒)字段说明 --- src/api/index.ts | 1 + src/core/voice.js | 52 +++++++ src/main.js | 22 +++ src/pages/packaging/index.vue | 260 ++++++++++++++++++++++------------ 4 files changed, 242 insertions(+), 93 deletions(-) create mode 100644 src/core/voice.js diff --git a/src/api/index.ts b/src/api/index.ts index b38de8d..c224788 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -137,6 +137,7 @@ export function packOrder(data: { delivery_order_code: string wave_no?: string status?: number + /** 打包时间(Unix 秒,后端按秒转 datetime) */ pack_time?: number wave_total_orders?: number items_count?: number diff --git a/src/core/voice.js b/src/core/voice.js new file mode 100644 index 0000000..68fd9ed --- /dev/null +++ b/src/core/voice.js @@ -0,0 +1,52 @@ +/** + * 语音提示(移植自散单项目 js_sdk/baiduvoic) + * 播报文字:GET http://tbdata.gztbyc.com/voice/{msg} 返回 { audio },再用 innerAudioContext 播放 + */ +const VOICE_API = 'http://tbdata.gztbyc.com/voice/' +const VOICE_BASE = 'http://tbdata.gztbyc.com' + +let instance = null + +class Voice { + constructor() { + this.audio = uni.createInnerAudioContext() + this.audio.onError((e) => { + console.log('[voice] audio error:', e) + }) + } + + /** 仅播放语音(不弹 toast,避免与全局 showToast 拦截器互相递归) */ + play(msg) { + if (!msg) { + return + } + uni.request({ + url: VOICE_API + msg, + method: 'GET', + timeout: 3000, + header: { 'content-type': 'text/xml; charset=utf-8' }, + success: (res) => { + if (!res || !res.data || !res.data.audio) { + return + } + const src = VOICE_BASE + res.data.audio + this.audio.stop() + this.audio.src = src + this.audio.play() + }, + fail: (err) => { + console.log('[voice] request fail:', err) + }, + }) + } +} + +/** 获取语音单例(首次调用时初始化,确保 uni 运行时就绪) */ +export function getVoice() { + if (!instance) { + instance = new Voice() + } + return instance +} + +export default Voice diff --git a/src/main.js b/src/main.js index 4f645f0..51f6042 100644 --- a/src/main.js +++ b/src/main.js @@ -4,6 +4,28 @@ import { import App from "./App.vue"; import appEnv from './config/env' import { installNavGuard } from './core/nav-guard' +import { getVoice } from './core/voice' + +// 全局提示语音:所有 uni.showToast 同时语音播报(仓库作业场景,语音提示来自散单项目方案) +const originalShowToast = uni.showToast +uni.showToast = function (options) { + const title = typeof options === 'string' ? options : options && options.title + let result + try { + result = originalShowToast.call(uni, options) + } catch (error) { + // toast 异常时保持原行为 + } + if (title) { + try { + getVoice().play(title) + } catch (error) { + console.log('[voice] play fail:', error) + } + } + return result +} + export function createApp() { const app = createSSRApp(App); app.config.globalProperties.$env = appEnv diff --git a/src/pages/packaging/index.vue b/src/pages/packaging/index.vue index 7a46f46..1df0c23 100644 --- a/src/pages/packaging/index.vue +++ b/src/pages/packaging/index.vue @@ -53,9 +53,10 @@ - + {{ isSandan === 1 ? '运单' : '波次' }} {{ isSandan === 1 ? (currentWaybillCode || '暂无运单') : (currentWaveNo || '暂无波次') }} + 打包中 共{{ waveTotalOrders || 0 }}单 @@ -82,7 +83,8 @@ class="pack-order-type" :class="isGroupOrder ? 'pack-order-type--group' : 'pack-order-type--single'" >{{ isGroupOrder ? '团单' : '散单' }} - + 长按/右键商品行免验 + 已扫 {{ scannedKindCount }}/{{ totalKindCount }} 种 共{{ detailList.length }}项 @@ -95,6 +97,7 @@ class="pack-detail-row" :class="{ 'pack-detail-row--scanned': isGroupOrder && isItemScanned(item) }" @longpress="handleLongPressProduct(item)" + @contextmenu.prevent="handleLongPressProduct(item)" > {{ index + 1 }} @@ -113,6 +116,7 @@ {{ item.name }} 【{{ item.barcode }}】 + {{ item.packingRequirements }} - - - - - 无条码复核 - × - - 将「{{ (noBarcodeReviewTarget && noBarcodeReviewTarget.name) || '' }}」标记为已扫? - - - - - - - @@ -413,6 +402,7 @@ export default { scanHiddenFocused: false, scanInputIdleTimer: null, lastSubmittedScan: { code: '', at: 0 }, + lastScannedCode: '', // ---- 绑定操作员(工作台成员)---- operatorDialogVisible: false, badgeHandling: false, @@ -425,8 +415,6 @@ export default { orderQuerying: false, // ---- 打包订单类型 / 无条码复核 ---- isSandan: null, - noBarcodeReviewVisible: false, - noBarcodeReviewTarget: null, cancelVerifyPopupOpen: false, idleLogoutTimer: null, idleLoggingOut: false, @@ -537,12 +525,7 @@ export default { }, watch: { groupVerifiedCount(val) { - if (!this.isGroupOrder || !this.precheckPassed || this.packStarted || this.packReporting) { - return - } - if (this.totalKindCount > 0 && val >= this.totalKindCount) { - this.handleSubmitGroupPack() - } + this.maybeAutoSubmitGroupPack() }, }, onLoad() { @@ -619,6 +602,14 @@ export default { console.log('[packaging][scan] handlePackSearch skip: infoLoading =', this.infoLoading, 'infoError =', this.infoError) return } + // 连续重复扫码限制:与上一次扫描内容一致时不执行任何操作 + if (this.lastScannedCode === kw) { + console.log('[packaging][scan] handlePackSearch skip: duplicate consecutive code =', kw) + this.keyword = '' + this.scheduleScanInputFocus(150) + return + } + this.lastScannedCode = kw // 工牌码(base64 JSON 含 uuid):识别为操作员工牌,走工牌登录/下线切换 const badge = this.parseBadgeCode(kw) if (badge && badge.uuid) { @@ -630,29 +621,15 @@ export default { if (!this.workbenchMembers.length) { console.log('[packaging][scan] handlePackSearch -> 无成员且非工牌码,拦截') this.keyword = '' + this.lastScannedCode = '' this.speak('需要先登录') uni.showToast({ title: '需要先登录', icon: 'none' }) this.scheduleScanInputFocus(150) return } - // 已绑定:团单已进入核实态时,按核实进度决定扫码含义 + // 已绑定:团单等待复核中,所有条码输入均作为商品条码校验(切换订单请先取消核实) if (this.isGroupOrder && this.precheckPassed && this.detailList.length > 0) { - if (this.groupVerifiedCount === 0) { - // 尚未开始核实:先按商品条码匹配,匹配不到则视为新运单号切换订单 - const matched = this.detailList.some( - (item) => - (Array.isArray(item.barcodes) && item.barcodes.includes(kw)) || - item.barcode === kw - ) - if (matched) { - this.matchProductBarcode(kw) - } else { - this.queryPackOrderByCode(kw) - } - } else { - // 已开始核实:扫码内容按商品条码核实 - this.matchProductBarcode(kw) - } + this.matchProductBarcode(kw) return } // 已绑定:扫码运单号查询订单 @@ -683,12 +660,88 @@ export default { this.keyword = '' }) .catch(() => { + // 查询失败允许重扫同一码 + this.lastScannedCode = '' uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' }) }) .finally(() => { this.orderQuerying = false }) }, + /** + * 商品明细统一映射(queryOrder.items 与 getWorkbenchInfo.current_orders.items 共用) + */ + mapOrderItems(items) { + return items.map((it) => { + const rawBarcodes = Array.isArray(it?.barcodes) ? it.barcodes : [] + // barcodes 元素可能是对象 { id, barcode } 或字符串,兼容两种结构 + const firstBarcode = + rawBarcodes.length > 0 + ? typeof rawBarcodes[0] === 'object' && rawBarcodes[0] !== null + ? rawBarcodes[0].barcode || rawBarcodes[0].code || '' + : String(rawBarcodes[0]) + : '' + const images = this.extractImages(it) + const barcodeList = rawBarcodes + .map((bc) => + typeof bc === 'object' && bc !== null ? bc.barcode || bc.code || '' : String(bc) + ) + .filter((bc) => bc) + return { + name: it?.item_name || it?.item_code || '', + barcode: firstBarcode || it?.item_code || '', + barcodes: barcodeList.length > 0 ? barcodeList : firstBarcode ? [firstBarcode] : [], + qty: it?.plan_qty ?? '', + scannedQty: 0, + image: images[0] || '', + imageCount: images.length, + images, + // 打包要求(packing_requirements) + packingRequirements: it?.packing_requirements ?? it?.packingRequirements ?? '', + // 是否免验(need_recheck=Y 免验直接标绿;默认 N 需要核实) + needRecheck: String(it?.need_recheck ?? it?.needRecheck ?? 'N'), + } + }) + }, + /** + * 恢复进行中的打包任务(getWorkbenchInfo.current_wave / current_orders) + * - app 中途退出后重进:依据服务端当前任务恢复界面(打包中、商品明细全部标绿) + * - 本地已有订单上下文/打包状态时跳过,避免覆盖 + */ + restoreCurrentPackTask(raw) { + if (this.packStarted || this.hasPackRecord) { + return + } + const wave = + raw?.current_wave && typeof raw.current_wave === 'object' ? raw.current_wave : null + const orders = Array.isArray(raw?.current_orders) ? raw.current_orders : [] + const order = + orders.length > 0 && typeof orders[0] === 'object' ? orders[0] : null + if (!wave && !order) { + return + } + const isGroup = Number(order?.pack_mode) === 2 + this.isSandan = isGroup ? 0 : 1 + this.currentWaveNo = wave?.wave_no || order?.wave_no || '' + this.currentWaybillCode = order?.waybill_code || order?.barcode || '' + this.currentDeliveryOrderCode = order?.delivery_order_code || '' + this.waveTotalOrders = wave?.order_count ?? order?.order_count ?? '' + this.productCount = Number(wave?.items_total) || Number(order?.items_total) || 0 + this.currentOrderCode = + order?.waybill_code || this.currentWaveNo || order?.delivery_order_code || '' + const items = Array.isArray(order?.items) ? order.items : [] + this.detailList = this.mapOrderItems(items) + // 任务已在进行中:核实已完成,全部标绿;恢复打包中状态 + this.detailList.forEach((item) => { + item.scannedQty = Number(item.qty) || 0 + }) + this.precheckPassed = true + this.packStarted = true + console.log( + '[packaging][restore] 恢复进行中的打包任务', + this.currentWaveNo || this.currentWaybillCode || this.currentDeliveryOrderCode + ) + }, applyQueryResult(body, code) { const payload = body?.data || body?.result || body const raw = @@ -762,30 +815,12 @@ export default { this.productCount = productCount // 商品明细 - this.detailList = items.map((it) => { - const rawBarcodes = Array.isArray(it?.barcodes) ? it.barcodes : [] - // barcodes 元素可能是对象 { id, barcode } 或字符串,兼容两种结构 - const firstBarcode = - rawBarcodes.length > 0 - ? typeof rawBarcodes[0] === 'object' && rawBarcodes[0] !== null - ? rawBarcodes[0].barcode || rawBarcodes[0].code || '' - : String(rawBarcodes[0]) - : '' - const images = this.extractImages(it) - const barcodeList = rawBarcodes - .map((bc) => - typeof bc === 'object' && bc !== null ? bc.barcode || bc.code || '' : String(bc) - ) - .filter((bc) => bc) - return { - name: it?.item_name || it?.item_code || '', - barcode: firstBarcode || it?.item_code || '', - barcodes: barcodeList.length > 0 ? barcodeList : firstBarcode ? [firstBarcode] : [], - qty: it?.plan_qty ?? '', - scannedQty: 0, - image: images[0] || '', - imageCount: images.length, - images, + this.detailList = this.mapOrderItems(items) + + // 免验商品(need_recheck=Y)直接标记为已核实(标绿),无需扫码/长按 + this.detailList.forEach((item) => { + if (item.needRecheck === 'Y') { + item.scannedQty = Number(item.qty) || 0 } }) @@ -798,8 +833,8 @@ export default { } this.precheckPassed = true if (this.isGroupOrder) { - // 团单:无商品明细 = 无需核实,直接提交开始打包 - if (this.detailList.length === 0) { + // 团单:无商品明细 或 全部商品免验 = 无需核实,直接提交开始打包 + if (this.detailList.length === 0 || this.groupVerifiedCount >= this.totalKindCount) { this.handleSubmitGroupPack() } return @@ -826,6 +861,8 @@ export default { this.keyword = '' this.speak('数据一致') uni.showToast({ title: `${target.name || ''} 已核实`, icon: 'none' }) + // 全部核实后自动开始打包 + this.maybeAutoSubmitGroupPack() } else { this.speak('无记录') uni.showToast({ title: '条码与待核实商品不匹配', icon: 'none' }) @@ -841,36 +878,32 @@ export default { return } if (this.isItemScanned(item)) { - uni.showToast({ title: '该商品已全部扫码', icon: 'none' }) + uni.showToast({ title: '该商品已核实', icon: 'none' }) return } - this.noBarcodeReviewTarget = item - this.noBarcodeReviewVisible = true - }, - closeNoBarcodeReview() { - this.noBarcodeReviewVisible = false - this.noBarcodeReviewTarget = null - }, - confirmNoBarcodeReview() { - const target = this.noBarcodeReviewTarget - if (!target) { - this.closeNoBarcodeReview() - return - } - const total = Number(target.qty) || 0 + const total = Number(item.qty) || 0 if (total <= 0) { - uni.showToast({ title: '该商品无数量,无法标记', icon: 'none' }) + uni.showToast({ title: '该商品无数量,无法免验', icon: 'none' }) return } - if ((Number(target.scannedQty) || 0) >= total) { - uni.showToast({ title: '该商品已全部扫码', icon: 'none' }) - this.closeNoBarcodeReview() + // 长按免验:直接标记为已核实(标绿),无需扫码 + item.scannedQty = total + this.addScanRecord(`免验:${item.name || item.barcode || ''}`) + this.speak('免验通过') + uni.showToast({ title: `「${item.name || ''}」免验通过`, icon: 'none' }) + // 全部核实后自动开始打包 + this.maybeAutoSubmitGroupPack() + }, + /** + * 团单全部商品核实完成后自动开始打包(扫码核实/免验后调用,watcher 兼作兑底) + */ + maybeAutoSubmitGroupPack() { + if (!this.isGroupOrder || !this.precheckPassed || this.packStarted || this.packReporting) { return } - target.scannedQty = total - this.speak('数据一致') - uni.showToast({ title: `已将「${target.name || ''}」标记为已扫`, icon: 'none' }) - this.closeNoBarcodeReview() + if (this.totalKindCount > 0 && this.groupVerifiedCount >= this.totalKindCount) { + this.handleSubmitGroupPack() + } }, handleCancelGroupVerify() { this.cancelVerifyPopupOpen = true @@ -949,7 +982,8 @@ export default { delivery_order_code: this.currentDeliveryOrderCode || this.currentOrderCode || this.currentWaveNo || '', status, - pack_time: Date.now(), + // 打包时间:Unix 秒(后端按秒转 datetime,传毫秒会导致 start_time 年份溢出报错) + pack_time: Math.floor(Date.now() / 1000), wave_no: this.isGroupOrder && this.currentWaveNo ? this.currentWaveNo : undefined, items_count: this.totalKindCount || undefined, items_total: this.productCount || undefined, @@ -988,6 +1022,7 @@ export default { // 有新打包任务:重置 30 分钟无新任务自动登出计时 this.scheduleIdleAutoLogout() this.speak('开始打包') + uni.showToast({ title: '开始打包', icon: 'none' }) }) .catch((err) => { uni.showToast({ title: err?.message || '打包上报失败', icon: 'none' }) @@ -1019,6 +1054,7 @@ export default { }, clearPackState() { this.detailList = [] + this.lastScannedCode = '' this.currentWaveNo = '' this.waveTotalOrders = '' this.storeRemark = '' @@ -2379,7 +2415,9 @@ export default { this.doBindOperator(realName, userId) }) .catch(() => { + // 查询失败允许重扫同一码 this.keyword = '' + this.lastScannedCode = '' uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' }) }) .finally(() => { @@ -2676,6 +2714,8 @@ export default { this.workbenchMembers = members uni.setStorageSync(MEMBER_STORAGE_KEY, members) } + // 恢复进行中的打包任务(app 中途退出后重进) + this.restoreCurrentPackTask(raw) }) .catch(() => { if (silent) { @@ -3184,6 +3224,11 @@ export default { background-color: #2fbf71; } +/* 订单被拦截/未复核/已打包等禁止打包状态:运单/波次横幅标红 */ +.pack-wave-head--blocked { + background-color: #e64340; +} + .pack-wave-head .pack-card-title { margin-bottom: 0; color: #ffffff; @@ -3196,10 +3241,21 @@ export default { margin-left: 0.307rem; } +/* 打包中角标(开始打包后的明确反馈) */ +.pack-wave-status { + margin-left: auto; + font-size: 0.666rem; + line-height: 1.2; + color: #ffffff; + background-color: rgba(255, 255, 255, 0.25); + border-radius: 0.205rem; + padding: 0.102rem 0.307rem; +} + .pack-wave-count { font-size: 1.024rem; color: #ffffff; - margin-left: auto; + margin-left: 0.41rem; } /* 货主 / 包材 / 商品总数 */ @@ -3293,6 +3349,12 @@ export default { color: #2f7dff; } +.pack-verify-hint { + margin-left: 0.614rem; + font-size: 0.614rem; + color: #999; +} + .pack-verify-cancel-btn { margin: 0 0 0 auto; height: 1.434rem; @@ -3390,6 +3452,14 @@ export default { margin-top: 0.128rem; } +/* 打包要求 */ +.pack-detail-info-req { + font-size: 0.819rem; + color: #2f7dff; + word-break: break-all; + margin-top: 0.128rem; +} + .pack-item-img-wrap { position: relative; width: 2.56rem; @@ -3465,6 +3535,10 @@ export default { color: #ffffff; } +.pack-detail-row--scanned .pack-detail-info-req { + color: #ffffff; +} + /* 今日打包 */ .pack-today-stats { display: flex;