feat(packaging): 大团购打包时长闸门与打包生产地址强制注入
- 打包页接入波次范围 wave_scope(0=未分配 1=大团购 2=散单 3=小团购 4=单品单件): queryOrder 读入 order.wave_scope,packOrder 上报 wave_scope(非法/缺省服务端兜底) - 大团购(wave_scope=1)packOrder 响应下发 pack_wait_seconds/pack_start_time, 启动打包时长闸门倒计时并在搜索框上方展示;扫描其他波次返回「打包时长不足」时提示并放行本波次 - 打包页新增拣货人(picker_name)展示 - 修复语音播报末字被截断:TTS 文本末尾补句号留停顿,音频 onCanplay 后再播放 + 500ms 兜底 - 打包脚本强制生产地址:新增 scripts/build-apk.cjs(强制编译 + 注入生产域名 + 产物地址校验), 避免开发地址(192.168.11.56)被打进生产 APK;dev-adb 改用 android:pack:raw 避免重复编译 - 版本号 1.0.28 -> 1.0.32
This commit is contained in:
parent
c057cbdad2
commit
47130fbf53
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wms-worker-station",
|
"name": "wms-worker-station",
|
||||||
"version": "1.0.28",
|
"version": "1.0.32",
|
||||||
"description": "WMS仓库工作台桌面端",
|
"description": "WMS仓库工作台桌面端",
|
||||||
"author": "tianbao",
|
"author": "tianbao",
|
||||||
"main": "electron/main.js",
|
"main": "electron/main.js",
|
||||||
@ -13,9 +13,10 @@
|
|||||||
"build:h5": "uni build --mode electron",
|
"build:h5": "uni build --mode electron",
|
||||||
"build:app": "uni build -p app",
|
"build:app": "uni build -p app",
|
||||||
"build:exe": "node scripts/build-exe.cjs",
|
"build:exe": "node scripts/build-exe.cjs",
|
||||||
"build:apk": "npm run build:app && npm run android:pack",
|
"build:apk": "node scripts/build-apk.cjs",
|
||||||
"android:prepare": "node android-offline/prepare.cjs",
|
"android:prepare": "node android-offline/prepare.cjs",
|
||||||
"android:pack": "powershell -NoProfile -ExecutionPolicy Bypass -File android-offline/pack.ps1",
|
"android:pack": "node scripts/build-apk.cjs",
|
||||||
|
"android:pack:raw": "powershell -NoProfile -ExecutionPolicy Bypass -File android-offline/pack.ps1",
|
||||||
"start:electron": "electron electron/main.js"
|
"start:electron": "electron electron/main.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
110
scripts/build-apk.cjs
Normal file
110
scripts/build-apk.cjs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/**
|
||||||
|
* Android APK 一键打包(强制生产环境)。
|
||||||
|
*
|
||||||
|
* 背景:曾出现「开发地址(192.168.11.56)被打进生产 APK」的事故,根因有三:
|
||||||
|
* 1) 旧版 env.js 无条件读 VITE_API_BASE_URL(来自 .env.local),没有生产判断;
|
||||||
|
* 2) Vite 的 .env.local 在所有 mode(含 production)都会加载;
|
||||||
|
* 3) HBuilderX/外部编辑器会回退文件,使 env.js 的修复被覆盖。
|
||||||
|
*
|
||||||
|
* 本脚本用三重保障兜底,确保生产 APK 绝不携带开发地址:
|
||||||
|
* 1. 强制重新编译(build:app,避免使用陈旧 dist/build/app);
|
||||||
|
* 2. 编译期注入生产地址:NODE_ENV=production(使 env.js 走 PROD 分支)
|
||||||
|
* + VITE_API_BASE_URL 覆盖为生产域名(Vite loadEnv 中 process.env 会无条件
|
||||||
|
* 覆盖 .env.local,因此即使 env.js 被回退成旧逻辑也不会拿到开发地址);
|
||||||
|
* 3. 产物防御性校验:dist/build/app 必须包含生产域名、不得包含开发地址,否则中止。
|
||||||
|
*
|
||||||
|
* 用法:
|
||||||
|
* npm run android:pack # 编译 + 打包 + 发布上传(pack.ps1 默认行为)
|
||||||
|
* npm run android:pack -- -NoUpload # 编译 + 打包,跳过发布上传
|
||||||
|
* npm run build:apk # 同 android:pack
|
||||||
|
*/
|
||||||
|
const { spawnSync } = require('child_process')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
const ROOT = path.resolve(__dirname, '..')
|
||||||
|
const APP_BUILD_DIR = path.join(ROOT, 'dist', 'build', 'app')
|
||||||
|
|
||||||
|
// 与 env.js 中 PROD_API_BASE 保持一致
|
||||||
|
const PROD_API_BASE = 'https://qimen.wms.gztbyc.com'
|
||||||
|
const PROD_HOST = 'qimen.wms.gztbyc.com'
|
||||||
|
const DEV_HOSTS = ['192.168.11.56', '127.0.0.1']
|
||||||
|
|
||||||
|
const log = (...args) => console.log('[build-apk]', ...args)
|
||||||
|
|
||||||
|
function run(cmd, args, opts = {}) {
|
||||||
|
log(`$ ${cmd} ${args.join(' ')}`)
|
||||||
|
const res = spawnSync(cmd, args, {
|
||||||
|
cwd: opts.cwd || ROOT,
|
||||||
|
stdio: 'inherit',
|
||||||
|
env: { ...process.env, ...(opts.env || {}) },
|
||||||
|
shell: process.platform === 'win32',
|
||||||
|
})
|
||||||
|
return res.status === 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectJsFiles(dir, out = []) {
|
||||||
|
if (!fs.existsSync(dir)) return out
|
||||||
|
for (const name of fs.readdirSync(dir)) {
|
||||||
|
const full = path.join(dir, name)
|
||||||
|
const stat = fs.statSync(full)
|
||||||
|
if (stat.isDirectory()) collectJsFiles(full, out)
|
||||||
|
else if (/\.js$/.test(name)) out.push(full)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- step 1: 强制生产编译 ----------
|
||||||
|
log('step 1/3: build:app(强制生产模式 + 注入生产地址)...')
|
||||||
|
if (
|
||||||
|
!run('npm', ['run', 'build:app'], {
|
||||||
|
env: {
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
VITE_API_BASE_URL: PROD_API_BASE,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
console.error('[build-apk] ✗ build:app 失败,终止')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- step 2: 产物地址防御性校验 ----------
|
||||||
|
log('step 2/3: 校验产物接口地址 ...')
|
||||||
|
const jsFiles = collectJsFiles(APP_BUILD_DIR)
|
||||||
|
if (!jsFiles.length) {
|
||||||
|
console.error(`[build-apk] ✗ 未找到 App 构建产物: ${APP_BUILD_DIR}`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
const badFiles = []
|
||||||
|
let hasProd = false
|
||||||
|
for (const file of jsFiles) {
|
||||||
|
const content = fs.readFileSync(file, 'utf-8')
|
||||||
|
if (content.includes(PROD_HOST)) hasProd = true
|
||||||
|
for (const host of DEV_HOSTS) {
|
||||||
|
if (content.includes(host)) {
|
||||||
|
badFiles.push(`${path.relative(APP_BUILD_DIR, file)}(含 ${host})`)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (badFiles.length) {
|
||||||
|
console.error('[build-apk] ✗ 产物中检测到开发地址,已终止打包:')
|
||||||
|
badFiles.forEach((f) => console.error(' - ' + f))
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
if (!hasProd) {
|
||||||
|
console.error(`[build-apk] ✗ 产物中未检测到生产域名 ${PROD_HOST},已终止打包`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
log('✓ 地址校验通过:已注入生产域名,无开发地址')
|
||||||
|
|
||||||
|
// ---------- step 3: 离线打包(参数透传) ----------
|
||||||
|
const extraArgs = process.argv.slice(2)
|
||||||
|
const packArgs = ['run', 'android:pack:raw']
|
||||||
|
if (extraArgs.length) packArgs.push('--', ...extraArgs)
|
||||||
|
log(`step 3/3: android:pack:raw${extraArgs.length ? ' ' + extraArgs.join(' ') : ''} ...`)
|
||||||
|
if (!run('npm', packArgs)) {
|
||||||
|
console.error('[build-apk] ✗ android:pack:raw 失败')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
log('✓ 打包完成')
|
||||||
@ -214,8 +214,9 @@ async function buildAndInstall(serial, trigger) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// 2. 离线打包(prepare + gradle 增量 + 复制 APK),跳过发布上传
|
// 2. 离线打包(prepare + gradle 增量 + 复制 APK),跳过发布上传
|
||||||
if (!run('npm', ['run', 'android:pack', '--', '-NoUpload'])) {
|
// 用 android:pack:raw 直接打包,避免重复编译(本脚本已在上面跑 build:app)
|
||||||
log('✗ android:pack 失败,跳过安装')
|
if (!run('npm', ['run', 'android:pack:raw', '--', '-NoUpload'])) {
|
||||||
|
log('✗ android:pack:raw 失败,跳过安装')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// 3. 定位 APK
|
// 3. 定位 APK
|
||||||
|
|||||||
@ -134,6 +134,7 @@ export function removeWorkbenchMember(data: {
|
|||||||
* - 返回 data.key:服务端缓存的订单上下文 key(开始打包时回传给 workbench.packOrder),
|
* - 返回 data.key:服务端缓存的订单上下文 key(开始打包时回传给 workbench.packOrder),
|
||||||
* 其余返回字段仅用于展示,不再作为打包参数回传
|
* 其余返回字段仅用于展示,不再作为打包参数回传
|
||||||
* - 散单 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=单品单件)
|
||||||
*/
|
*/
|
||||||
export function queryPackOrder(token: string, barcode: string) {
|
export function queryPackOrder(token: string, barcode: string) {
|
||||||
return request<ApiBody>(
|
return request<ApiBody>(
|
||||||
@ -149,6 +150,8 @@ export function queryPackOrder(token: string, barcode: string) {
|
|||||||
* 仓库与工作台由服务端从 token 解析注入
|
* 仓库与工作台由服务端从 token 解析注入
|
||||||
* - 订单数据由服务端按 key 从查询时缓存的上下文中解析,客户端不再回传订单信息
|
* - 订单数据由服务端按 key 从查询时缓存的上下文中解析,客户端不再回传订单信息
|
||||||
* - 散单按 order_id、团购按 wave_no 去重后创建打包任务(wms_pack_task)
|
* - 散单按 order_id、团购按 wave_no 去重后创建打包任务(wms_pack_task)
|
||||||
|
* - 大团购(wave_scope=1)响应附 pack_wait_seconds(需等待秒数)与 pack_start_time(开始打包毫秒时间戳)
|
||||||
|
* 供前端倒计时;其他波次两字段均为 0
|
||||||
*/
|
*/
|
||||||
export function packOrder(data: {
|
export function packOrder(data: {
|
||||||
token: string
|
token: string
|
||||||
@ -157,6 +160,11 @@ export function packOrder(data: {
|
|||||||
status?: number
|
status?: number
|
||||||
/** 打包时间(Unix 秒,后端按秒转 datetime) */
|
/** 打包时间(Unix 秒,后端按秒转 datetime) */
|
||||||
pack_time?: number
|
pack_time?: number
|
||||||
|
/**
|
||||||
|
* 波次范围:0=未分配 1=大团购 2=散单 3=小团购 4=单品单件
|
||||||
|
* (queryOrder 下发,服务端复查:上报值非法/缺省时兜底订单行值)
|
||||||
|
*/
|
||||||
|
wave_scope?: number | null
|
||||||
users?: Array<{
|
users?: Array<{
|
||||||
wms_account_id?: number | null
|
wms_account_id?: number | null
|
||||||
id?: number | null
|
id?: number | null
|
||||||
|
|||||||
@ -36,6 +36,9 @@
|
|||||||
<view v-else class="pack-layout">
|
<view v-else class="pack-layout">
|
||||||
<!-- 左面板 65% -->
|
<!-- 左面板 65% -->
|
||||||
<view class="pack-left">
|
<view class="pack-left">
|
||||||
|
<view v-if="packStarted && packWaitRemaining > 0" class="pack-countdown-bar">
|
||||||
|
<text class="pack-countdown-bar-text">大团购打包倒计时 {{ packWaitRemainingText }}</text>
|
||||||
|
</view>
|
||||||
<view class="pack-search">
|
<view class="pack-search">
|
||||||
<input
|
<input
|
||||||
class="pack-search-input"
|
class="pack-search-input"
|
||||||
@ -68,6 +71,10 @@
|
|||||||
<text class="pack-meta-label">包材</text>
|
<text class="pack-meta-label">包材</text>
|
||||||
<text class="pack-meta-value">{{ packageMaterialName || '—' }}</text>
|
<text class="pack-meta-value">{{ packageMaterialName || '—' }}</text>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="pack-meta-item">
|
||||||
|
<text class="pack-meta-label">拣货</text>
|
||||||
|
<text class="pack-meta-value">{{ pickerName || '—' }}</text>
|
||||||
|
</view>
|
||||||
<view class="pack-meta-item">
|
<view class="pack-meta-item">
|
||||||
<text class="pack-meta-label">商品总数</text>
|
<text class="pack-meta-label">商品总数</text>
|
||||||
<text class="pack-meta-value">{{ productCount }}</text>
|
<text class="pack-meta-value">{{ productCount }}</text>
|
||||||
@ -370,6 +377,7 @@ export default {
|
|||||||
waveTotalOrders: '',
|
waveTotalOrders: '',
|
||||||
storeRemark: '',
|
storeRemark: '',
|
||||||
packageMaterialName: '',
|
packageMaterialName: '',
|
||||||
|
pickerName: '',
|
||||||
productCount: 0,
|
productCount: 0,
|
||||||
detailList: [],
|
detailList: [],
|
||||||
todayWaveCount: 0,
|
todayWaveCount: 0,
|
||||||
@ -468,6 +476,12 @@ export default {
|
|||||||
voicePlaying: false,
|
voicePlaying: false,
|
||||||
voicePendingText: '',
|
voicePendingText: '',
|
||||||
voiceNextTimer: null,
|
voiceNextTimer: null,
|
||||||
|
// ---- 波次范围 / 大团购打包时长闸门 ----
|
||||||
|
currentWaveScope: null,
|
||||||
|
packWaitSeconds: 0,
|
||||||
|
packStartTime: 0,
|
||||||
|
packWaitRemaining: 0,
|
||||||
|
packCountdownTimer: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -556,6 +570,16 @@ export default {
|
|||||||
orderBlockReason() {
|
orderBlockReason() {
|
||||||
return this.checkOrderBlocked().reason
|
return this.checkOrderBlocked().reason
|
||||||
},
|
},
|
||||||
|
// 大团购打包倒计时展示文案(mm:ss)
|
||||||
|
packWaitRemainingText() {
|
||||||
|
const total = this.packWaitRemaining
|
||||||
|
if (!total || total <= 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
const mins = Math.floor(total / 60)
|
||||||
|
const secs = total % 60
|
||||||
|
return `${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`
|
||||||
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
groupVerifiedCount(val) {
|
groupVerifiedCount(val) {
|
||||||
@ -790,6 +814,10 @@ export default {
|
|||||||
}
|
}
|
||||||
const isGroup = Number(order?.pack_mode) === 2
|
const isGroup = Number(order?.pack_mode) === 2
|
||||||
this.isSandan = isGroup ? 0 : 1
|
this.isSandan = isGroup ? 0 : 1
|
||||||
|
this.currentWaveScope =
|
||||||
|
order?.wave_scope !== undefined && order?.wave_scope !== null && order?.wave_scope !== ''
|
||||||
|
? Number(order?.wave_scope)
|
||||||
|
: null
|
||||||
this.currentWaveNo = wave?.wave_no || order?.wave_no || ''
|
this.currentWaveNo = wave?.wave_no || order?.wave_no || ''
|
||||||
this.currentWaybillCode = order?.waybill_code || order?.barcode || ''
|
this.currentWaybillCode = order?.waybill_code || order?.barcode || ''
|
||||||
this.currentDeliveryOrderCode = order?.delivery_order_code || ''
|
this.currentDeliveryOrderCode = order?.delivery_order_code || ''
|
||||||
@ -807,6 +835,20 @@ export default {
|
|||||||
})
|
})
|
||||||
this.precheckPassed = true
|
this.precheckPassed = true
|
||||||
this.packStarted = true
|
this.packStarted = true
|
||||||
|
// 恢复进行中的大团购打包时长闸门倒计时(若服务端随任务下发倒计时字段)
|
||||||
|
const restoreWait = Number(
|
||||||
|
this.pickInfoField(order, {}, ['pack_wait_seconds', 'packWaitSeconds']) ||
|
||||||
|
this.pickInfoField(wave, {}, ['pack_wait_seconds', 'packWaitSeconds']) ||
|
||||||
|
0
|
||||||
|
)
|
||||||
|
const restoreStart = Number(
|
||||||
|
this.pickInfoField(order, {}, ['pack_start_time', 'packStartTime']) ||
|
||||||
|
this.pickInfoField(wave, {}, ['pack_start_time', 'packStartTime']) ||
|
||||||
|
0
|
||||||
|
)
|
||||||
|
if (restoreWait > 0 && restoreStart > 0) {
|
||||||
|
this.startPackCountdown(restoreWait, restoreStart)
|
||||||
|
}
|
||||||
console.log(
|
console.log(
|
||||||
'[packaging][restore] 恢复进行中的打包任务',
|
'[packaging][restore] 恢复进行中的打包任务',
|
||||||
this.currentWaveNo || this.currentWaybillCode || this.currentDeliveryOrderCode
|
this.currentWaveNo || this.currentWaybillCode || this.currentDeliveryOrderCode
|
||||||
@ -822,9 +864,17 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (flag === 'failure') {
|
if (flag === 'failure') {
|
||||||
this.speak('无记录')
|
|
||||||
// 后端失败文案可能含条码等长文本,过长时用简短提示代替
|
// 后端失败文案可能含条码等长文本,过长时用简短提示代替
|
||||||
const failMsg = body?.message || body?.msg || '未找到对应订单'
|
const failMsg = body?.message || body?.msg || '未找到对应订单'
|
||||||
|
// 大团购打包时长闸门:存在进行中的 wave_scope=1 打包任务且未到时,
|
||||||
|
// 扫描本波次以外的订单会返回「打包时长不足」;按该文案提示并允许继续扫描本波次订单
|
||||||
|
if (String(failMsg).indexOf('打包时长不足') >= 0) {
|
||||||
|
this.lastScannedCode = ''
|
||||||
|
this.speak('打包时长不足')
|
||||||
|
uni.showToast({ title: '打包时长不足', icon: 'none', silentVoice: true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.speak('无记录')
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: String(failMsg).length > 24 ? '未找到对应订单' : failMsg,
|
title: String(failMsg).length > 24 ? '未找到对应订单' : failMsg,
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
@ -849,6 +899,18 @@ export default {
|
|||||||
const newIsGroup = rawSandan !== '' && Number(rawSandan) === 0
|
const newIsGroup = rawSandan !== '' && Number(rawSandan) === 0
|
||||||
this.isSandan = rawSandan === '' ? null : Number(rawSandan)
|
this.isSandan = rawSandan === '' ? null : Number(rawSandan)
|
||||||
|
|
||||||
|
// 波次范围:0=未分配 1=大团购 2=散单 3=小团购 4=单品单件
|
||||||
|
// (服务端在 queryOrder 下发 order.wave_scope,开始打包时回传 packOrder)
|
||||||
|
let waveScope = null
|
||||||
|
for (const src of [order, raw, batch]) {
|
||||||
|
const v = this.pickInfoField(src, {}, ['wave_scope', 'waveScope'])
|
||||||
|
if (v !== '' && v !== undefined && v !== null) {
|
||||||
|
waveScope = Number(v)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.currentWaveScope = waveScope
|
||||||
|
|
||||||
// 与正在打包的订单对比:团单比波次号、散单比运单号;一致即重复查询同一单
|
// 与正在打包的订单对比:团单比波次号、散单比运单号;一致即重复查询同一单
|
||||||
const newWaveNo =
|
const newWaveNo =
|
||||||
this.pickInfoField(batch, {}, ['wave_no', 'waveNo']) ||
|
this.pickInfoField(batch, {}, ['wave_no', 'waveNo']) ||
|
||||||
@ -911,6 +973,9 @@ export default {
|
|||||||
'packageMaterialName',
|
'packageMaterialName',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
// 拣货人
|
||||||
|
this.pickerName = this.pickInfoField(order, {}, ['picker_name', 'pickerName'])
|
||||||
|
|
||||||
// 商品数量:优先 order.items_total,兜底 items plan_qty 求和
|
// 商品数量:优先 order.items_total,兜底 items plan_qty 求和
|
||||||
let productCount = Number(order?.items_total)
|
let productCount = Number(order?.items_total)
|
||||||
if (!productCount) {
|
if (!productCount) {
|
||||||
@ -1103,6 +1168,11 @@ export default {
|
|||||||
status,
|
status,
|
||||||
// 打包时间:Unix 秒(后端按秒转 datetime,传毫秒会导致 start_time 年份溢出报错)
|
// 打包时间:Unix 秒(后端按秒转 datetime,传毫秒会导致 start_time 年份溢出报错)
|
||||||
pack_time: Math.floor(Date.now() / 1000),
|
pack_time: Math.floor(Date.now() / 1000),
|
||||||
|
// 波次范围(queryOrder 下发,服务端复查:上报值非法/缺省时兜底订单行值)
|
||||||
|
wave_scope:
|
||||||
|
this.currentWaveScope !== null && this.currentWaveScope !== undefined
|
||||||
|
? Number(this.currentWaveScope)
|
||||||
|
: undefined,
|
||||||
// 上报当前在线操作员(workbench.packOrder 的 users 参数,支持多人)
|
// 上报当前在线操作员(workbench.packOrder 的 users 参数,支持多人)
|
||||||
users:
|
users:
|
||||||
this.workbenchMembers.length > 0
|
this.workbenchMembers.length > 0
|
||||||
@ -1132,8 +1202,10 @@ export default {
|
|||||||
}
|
}
|
||||||
this.packReporting = true
|
this.packReporting = true
|
||||||
this.reportPackOrder(1)
|
this.reportPackOrder(1)
|
||||||
.then(() => {
|
.then((body) => {
|
||||||
this.packStarted = true
|
this.packStarted = true
|
||||||
|
// 大团购:按 packOrder 响应下发的倒计时字段启动「打包时长闸门」倒计时
|
||||||
|
this.applyPackCountdown(body)
|
||||||
// 新打包提交成功后刷新今日打包统计(服务端为准)
|
// 新打包提交成功后刷新今日打包统计(服务端为准)
|
||||||
this.loadTodayPackStat()
|
this.loadTodayPackStat()
|
||||||
// 有新打包任务:重置 30 分钟无新任务自动登出计时
|
// 有新打包任务:重置 30 分钟无新任务自动登出计时
|
||||||
@ -1148,6 +1220,60 @@ export default {
|
|||||||
this.packReporting = false
|
this.packReporting = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 读取 packOrder 响应下发的倒计时字段(仅大团购 wave_scope=1 非 0):
|
||||||
|
* - pack_wait_seconds:需等待秒数
|
||||||
|
* - pack_start_time:开始打包毫秒时间戳
|
||||||
|
* 其余波次两字段均为 0,不启动倒计时。
|
||||||
|
*/
|
||||||
|
applyPackCountdown(body) {
|
||||||
|
const payload = body?.data || body?.result || body
|
||||||
|
const raw =
|
||||||
|
payload && typeof payload === 'object' && !Array.isArray(payload) ? payload : null
|
||||||
|
const waitSeconds = Number(
|
||||||
|
this.pickInfoField(raw, body, ['pack_wait_seconds', 'packWaitSeconds']) || 0
|
||||||
|
)
|
||||||
|
const startTime = Number(
|
||||||
|
this.pickInfoField(raw, body, ['pack_start_time', 'packStartTime']) || 0
|
||||||
|
)
|
||||||
|
if (waitSeconds > 0 && startTime > 0) {
|
||||||
|
this.startPackCountdown(waitSeconds, startTime)
|
||||||
|
} else {
|
||||||
|
this.stopPackCountdown()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** 启动打包时长闸门倒计时(1 秒刷新一次,到 0 自动停止) */
|
||||||
|
startPackCountdown(waitSeconds, startTime) {
|
||||||
|
this.stopPackCountdown()
|
||||||
|
this.packWaitSeconds = Number(waitSeconds) || 0
|
||||||
|
this.packStartTime = Number(startTime) || 0
|
||||||
|
this.updatePackWaitRemaining()
|
||||||
|
if (this.packWaitRemaining <= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.packCountdownTimer = setInterval(() => {
|
||||||
|
this.updatePackWaitRemaining()
|
||||||
|
if (this.packWaitRemaining <= 0) {
|
||||||
|
this.stopPackCountdown()
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
},
|
||||||
|
/** 根据 pack_start_time 与 pack_wait_seconds 重算剩余秒数 */
|
||||||
|
updatePackWaitRemaining() {
|
||||||
|
const elapsed =
|
||||||
|
this.packStartTime > 0 ? Math.floor((Date.now() - this.packStartTime) / 1000) : 0
|
||||||
|
this.packWaitRemaining = Math.max(0, (this.packWaitSeconds || 0) - elapsed)
|
||||||
|
},
|
||||||
|
/** 停止并复位打包时长闸门倒计时 */
|
||||||
|
stopPackCountdown() {
|
||||||
|
if (this.packCountdownTimer) {
|
||||||
|
clearInterval(this.packCountdownTimer)
|
||||||
|
this.packCountdownTimer = null
|
||||||
|
}
|
||||||
|
this.packWaitSeconds = 0
|
||||||
|
this.packStartTime = 0
|
||||||
|
this.packWaitRemaining = 0
|
||||||
|
},
|
||||||
handleSubmitGroupPack() {
|
handleSubmitGroupPack() {
|
||||||
this.startPack()
|
this.startPack()
|
||||||
},
|
},
|
||||||
@ -1176,6 +1302,7 @@ export default {
|
|||||||
this.waveTotalOrders = ''
|
this.waveTotalOrders = ''
|
||||||
this.storeRemark = ''
|
this.storeRemark = ''
|
||||||
this.packageMaterialName = ''
|
this.packageMaterialName = ''
|
||||||
|
this.pickerName = ''
|
||||||
this.productCount = 0
|
this.productCount = 0
|
||||||
this.isSandan = null
|
this.isSandan = null
|
||||||
this.currentOrderCode = ''
|
this.currentOrderCode = ''
|
||||||
@ -1186,6 +1313,9 @@ export default {
|
|||||||
this.sameOrderQuery = false
|
this.sameOrderQuery = false
|
||||||
this.precheckPassed = false
|
this.precheckPassed = false
|
||||||
this.packStarted = false
|
this.packStarted = false
|
||||||
|
// 波次范围与打包时长闸门倒计时复位
|
||||||
|
this.currentWaveScope = null
|
||||||
|
this.stopPackCountdown()
|
||||||
},
|
},
|
||||||
speak(text) {
|
speak(text) {
|
||||||
const str = this.normalizeSpeakText(text)
|
const str = this.normalizeSpeakText(text)
|
||||||
@ -1265,8 +1395,11 @@ export default {
|
|||||||
resolve(ok)
|
resolve(ok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 末字补一个句号:让 TTS 在最后一个字后生成停顿,避免部分 Android 设备
|
||||||
|
// 播放 HTTP 音频时解码丢尾帧,导致最后一个字(如“包”)被截断
|
||||||
|
const ttsText = String(msg) + '。'
|
||||||
uni.request({
|
uni.request({
|
||||||
url: VOICE_API_URL + encodeURIComponent(msg),
|
url: VOICE_API_URL + encodeURIComponent(ttsText),
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
timeout: 3000,
|
timeout: 3000,
|
||||||
header: { 'content-type': 'text/xml; charset=utf-8' },
|
header: { 'content-type': 'text/xml; charset=utf-8' },
|
||||||
@ -1307,16 +1440,35 @@ export default {
|
|||||||
}
|
}
|
||||||
const audio = uni.createInnerAudioContext()
|
const audio = uni.createInnerAudioContext()
|
||||||
this.voiceAudioContext = audio
|
this.voiceAudioContext = audio
|
||||||
|
let playStarted = false
|
||||||
|
let finished = false
|
||||||
|
const doPlay = () => {
|
||||||
|
if (playStarted || finished) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
playStarted = true
|
||||||
|
try {
|
||||||
|
audio.play()
|
||||||
|
console.log('[语音播报] 音频已开始播放')
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[语音播报] 音频播放异常:', e)
|
||||||
|
onEnd(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
audio.onError((e) => {
|
audio.onError((e) => {
|
||||||
|
finished = true
|
||||||
console.warn('[语音播报] 音频播放错误:', e)
|
console.warn('[语音播报] 音频播放错误:', e)
|
||||||
onEnd(false)
|
onEnd(false)
|
||||||
})
|
})
|
||||||
audio.onEnded(() => {
|
audio.onEnded(() => {
|
||||||
|
finished = true
|
||||||
onEnd(true)
|
onEnd(true)
|
||||||
})
|
})
|
||||||
|
// 等缓冲就绪再播放:部分 Android 设备设置 src 后立即 play 会在缓冲不足时
|
||||||
|
// 截断尾帧(末字丢失);onCanplay 后再播更稳,500ms 兜底防止事件不触发
|
||||||
|
audio.onCanplay(doPlay)
|
||||||
audio.src = src
|
audio.src = src
|
||||||
audio.play()
|
setTimeout(doPlay, 500)
|
||||||
console.log('[语音播报] 音频已开始播放')
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[语音播报] 创建音频上下文异常:', e)
|
console.error('[语音播报] 创建音频上下文异常:', e)
|
||||||
onEnd(false)
|
onEnd(false)
|
||||||
@ -3033,6 +3185,7 @@ export default {
|
|||||||
this.removePlusKeyboardListener()
|
this.removePlusKeyboardListener()
|
||||||
this.removeGlobalKeyboardListener()
|
this.removeGlobalKeyboardListener()
|
||||||
this.clearScanTimers()
|
this.clearScanTimers()
|
||||||
|
this.stopPackCountdown()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -3364,6 +3517,24 @@ export default {
|
|||||||
margin-bottom: 0.256rem;
|
margin-bottom: 0.256rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 大团购打包倒计时条(搜索框上方) */
|
||||||
|
.pack-countdown-bar {
|
||||||
|
margin-bottom: 0.205rem;
|
||||||
|
background-color: #fff7e6;
|
||||||
|
border: 0.026rem solid #ffd591;
|
||||||
|
border-radius: 0.41rem;
|
||||||
|
padding: 0.128rem 0.512rem;
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pack-countdown-bar-text {
|
||||||
|
font-size: 0.768rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #d46b08;
|
||||||
|
}
|
||||||
|
|
||||||
/* 搜索输入框 */
|
/* 搜索输入框 */
|
||||||
.pack-search {
|
.pack-search {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
@ -3448,7 +3619,9 @@ export default {
|
|||||||
/* 货主 / 包材 / 商品总数 */
|
/* 货主 / 包材 / 商品总数 */
|
||||||
.pack-meta-line {
|
.pack-meta-line {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
gap: 0.307rem 1.229rem;
|
||||||
margin-top: 0.307rem;
|
margin-top: 0.307rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3459,10 +3632,6 @@ export default {
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pack-meta-item + .pack-meta-item {
|
|
||||||
margin-left: 1.229rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pack-meta-label {
|
.pack-meta-label {
|
||||||
font-size: 0.717rem;
|
font-size: 0.717rem;
|
||||||
color: #888;
|
color: #888;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user