feat: 大团购打包时长闸门、无任务自动登出与加急退回提示

packMode.vue:
- 新增大团购打包时长闸门倒计时条:packOrder 返回 wait_seconds/start_time 后展示,归零自动隐藏;恢复进行中任务时续上倒计时
- 扫描其它波次订单返回「打包时长不足」时,保留当前订单上下文不覆盖,提示后允许继续扫描本波次
- 打包上报携带波次范围 wave_scope 字段
- 新增 30 分钟无新打包任务自动登出:自动结束最后打包任务、下线全部成员、清空本地状态(不退出打包模式页面)

returnRecord.vue:
- 新增加急退回订单提示条,并针对加急订单优化语音播报(成功「加急订单,登记成功」、幂等「加急订单,已登记」)
This commit is contained in:
zm2000 2026-09-24 14:22:59 +08:00
parent 11e8fa2ed4
commit 2eb9cbfc1b
2 changed files with 266 additions and 12 deletions

View File

@ -28,6 +28,12 @@
<view class="content">
<!-- ============ 已绑定态 ============ -->
<template v-if="bound">
<!-- 大团购打包时长闸门倒计时:packOrder 返回 wait_seconds/start_time 后展示,归零自动隐藏 -->
<view v-if="packWaitActive" class="pack-wait-bar">
<u-icon name="clock-fill" size="34rpx" color="#e6a23c"></u-icon>
<text class="pack-wait-bar__text">大团购打包倒计时</text>
<text class="pack-wait-bar__time">{{ packWaitText }}</text>
</view>
<!-- 订单查询 -->
<view class="order-query-card">
<view class="order-query__scan-line">
@ -387,6 +393,8 @@
<script>
// 工作台在线成员列表本地缓存 key(服务端 getWorkbenchInfo 返回 members[] 时同步并缓存,重进时据此恢复)
const MEMBER_STORAGE_KEY = 'workbenchMembers'
// 无新打包任务自动登出:超过该时长(毫秒)自动结束最后打包任务并下线全部成员(不退出打包模式页面,只下线成员)
const IDLE_AUTO_LOGOUT_MS = 30 * 60 * 1000
export default {
data() {
@ -401,6 +409,8 @@ export default {
workbenchType: '',
infoRefreshing: false, // 进入后刷新工作台信息请求防重入锁
bcastHealTimer: null, // 广播监听自愈定时器(onShow 延迟重新注册用)
idleLogoutTimer: null, // 无新打包任务自动登出定时器(setTimeout 句柄)
idleLoggingOut: false, // 自动登出防重入标志
// 当前操作员列表(工作台成员,本地保存 bindMember 返回的成员行 id,支持多人)
boundOperators: [],
// 工作台在线成员列表(以服务端 getWorkbenchInfo 返回的 members[] 为权威,绑定/下线后静默重拉同步)
@ -430,6 +440,11 @@ export default {
activePackIdentity: '', // 当前「打包中」订单唯一标识:团单为 wave_no,散单为 waybill_code(重复查单去重用)
activePackIsSandan: null, // 当前「打包中」订单类型:true=散单 / false=团单 / null=无进行中任务(重复查单需类型一致)
packRestored: false, // 重进后从服务端恢复的「打包中」态(跳过拦截/已打包/预检,直接展示进行中任务)
packWaitSeconds: 0, // 大团购打包时长闸门:packOrder 返回的需等待总秒数(0=无需等待)
packStartTime: 0, // 大团购打包时长闸门:packOrder 返回的开始打包毫秒时间戳(0=无需等待)
packWaitRemain: 0, // 大团购打包时长闸门:剩余等待秒数(倒计时展示,<=0 隐藏)
packWaitTimer: null, // 大团购打包时长闸门:倒计时 interval 句柄
packWaveScope: null, // 当前「打包中」任务波次范围(0=未分配 1=大团购 2=散单 3=小团购 4=单品单件)
// 团购核实:商品行已扫计数(key=商品行id/序号 → 已扫次数),达 plan_qty 视为已核实
groupVerified: {},
groupSubmitting: false, // 团购提交开始打包防重入
@ -658,6 +673,18 @@ export default {
.map(m => String((m && m.user_name) || '').trim())
.filter(Boolean);
return names.length ? names.join('、') : '--';
},
// 大团购打包时长闸门:倒计时是否进行中(剩余秒数 > 0 时展示)
packWaitActive() {
return this.packWaitRemain > 0;
},
// 大团购打包时长闸门:倒计时文案 mm:ss
packWaitText() {
if (!this.packWaitActive) return '';
const total = this.packWaitRemain;
const m = Math.floor(total / 60);
const s = total % 60;
return `${m}:${s < 10 ? '0' : ''}${s}`;
}
},
onLoad(options) {
@ -704,13 +731,20 @@ export default {
}
});
}, 1200);
// 页面重新显示:重启无新打包任务自动登出计时(仅已绑定工作台时生效)
if (this.bound) {
this.scheduleIdleAutoLogout();
}
},
onHide() {
this.clearBcastHealTimer();
this.clearIdleAutoLogoutTimer();
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.clearBcastHealTimer();
this.clearIdleAutoLogoutTimer();
this.clearPackWaitTimer();
this.safeDispatchBroadcast('stop');
},
methods: {
@ -734,6 +768,67 @@ export default {
this.bcastHealTimer = null;
}
},
// 无新打包任务自动登出:重新计时(开始新打包 / 绑定成员 / 页面显示时调用)
scheduleIdleAutoLogout() {
this.clearIdleAutoLogoutTimer();
this.idleLogoutTimer = setTimeout(() => {
this.idleLogoutTimer = null;
this.autoLogoutForIdle();
}, IDLE_AUTO_LOGOUT_MS);
},
// 清除无新打包任务自动登出定时器
clearIdleAutoLogoutTimer() {
if (this.idleLogoutTimer) {
clearTimeout(this.idleLogoutTimer);
this.idleLogoutTimer = null;
}
},
// 超时触发:结束最后打包任务 → 下线全部成员 → 清空工作台,等待下一批操作员重新绑定(不退出打包模式页面)
async autoLogoutForIdle() {
if (this.idleLoggingOut) return;
this.idleLoggingOut = true;
try {
// 1. 结束最后打包任务(无进行中任务则跳过)
if (this.hasActivePack) {
const fr = await this.requestFinishPack();
if (fr && fr.expired) return;
}
// 2. 下线全部在线操作员(removeMember 支持 ids 数组),失败不阻断
const list = Array.isArray(this.workbenchMembers) ? this.workbenchMembers : [];
const ids = list.map((m) => Number(m && m.id)).filter((id) => id > 0);
if (ids.length) {
const token = String(this.workbenchToken || '').trim();
if (!token) {
this.exitWorkbench(true);
return;
}
try {
const res = await this.$http('workbench.removeMember', { ids, token });
const bizCode = Number(res?.code);
// 401/403:工作台已解绑,被动退出回登录页
if (bizCode === 401 || bizCode === 403) {
this.exitWorkbench(true);
return;
}
} catch (error) {
// 失败不阻断
}
}
// 3. 清空本地成员列表与打包数据,防止残留给下一批操作员
this.workbenchMembers = [];
this.boundOperators = [];
try { uni.removeStorageSync(MEMBER_STORAGE_KEY); } catch (e) {}
try { uni.removeStorageSync('workbenchOperators'); } catch (e) {}
this.clearPackState();
// 4. 静默重拉工作台信息,成员列表以服务端为准
this.fetchWorkbenchInfo({ silent: true });
// 5. 语音 + 提示
this.speakText('已结束打包并下线全部成员');
uni.showToast({ title: '长时间无新打包任务,已自动下线', icon: 'none' });
} finally {
this.idleLoggingOut = false;
}
},
// 扫码内容去重:扫码枪偶发「内容重复/尾段不完整」输出(如 abcabc → abc、abcab → abc),避免重复查询
dedupeRepeatedScan(code) {
const s = String(code || '').replace(/\s+/g, '');
@ -1058,6 +1153,15 @@ export default {
const identity = this.orderIdentity(result);
return !!identity && identity === this.activePackIdentity;
},
// 波次范围:从当前查询结果订单行取 wave_scope(0=未分配 1=大团购 2=散单 3=小团购 4=单品单件),缺省返回 null
orderWaveScope() {
const r = this.orderQueryResult;
if (!r || typeof r !== 'object') return null;
const order = r.order || {};
const raw = order.wave_scope ?? order.waveScope ?? r.wave_scope ?? r.waveScope;
if (raw === undefined || raw === null || raw === '') return null;
return Number(raw);
},
// 按运单号条码查询订单(workbench.queryOrder)
async queryOrder(barcode) {
const code = String(barcode || '').trim();
@ -1074,6 +1178,8 @@ export default {
return;
}
if (this.orderQuerying) return;
// 保存上一次查询结果:大团购打包时长闸门拦截「打包时长不足」时恢复展示,保持当前打包任务上下文
const previousResult = this.orderQueryResult;
this.orderQuerying = true;
this.orderQueryState = 'loading';
this.orderQueryResult = null;
@ -1086,8 +1192,20 @@ export default {
if (invalid) {
// 401:工作台 token 失效,退出工作台模式并清除 token 回登录页
if (this.handleWorkbenchAuthExpired(res?.code)) return;
const msg = String(res?.message || res?.msg || '');
// 大团购打包时长闸门:进行中的大团购任务未到等待时长时,扫描其它波次订单返回「打包时长不足」;
// 保持当前订单上下文不被覆盖,提示后允许继续扫描本波次订单
if (msg.indexOf('打包时长不足') !== -1) {
this.orderQueryState = previousResult ? 'success' : 'error';
this.orderQueryResult = previousResult;
this.orderQueryError = previousResult ? '' : msg;
this.orderBarcode = '';
this.speakText('打包时长不足');
uni.showToast({ title: '打包时长不足', icon: 'none', duration: 4000 });
return;
}
this.orderQueryState = 'error';
this.orderQueryError = res?.message || '查询失败,请重试';
this.orderQueryError = msg || '查询失败,请重试';
this.speakText('无记录');
return;
}
@ -1272,10 +1390,16 @@ export default {
this.packReporting = true;
uni.showLoading({ title: '打包上报中...', mask: true });
try {
// 波次范围 wave_scope(0=未分配 1=大团购 2=散单 3=小团购 4=单品单件):
// 上报查询结果中的订单行值,服务端复查(非法/缺省时兜底订单行值)
const waveScope = this.orderWaveScope();
const payload = {
key: packKey,
token
};
if (waveScope !== null && waveScope !== undefined) {
payload.wave_scope = waveScope;
}
// toastAfter=false:失败提示由本方法自行控制
const res = await this.$http('workbench.packOrder', payload, '', false);
@ -1291,15 +1415,26 @@ export default {
uni.showToast({ title: res?.message || '打包上报失败', icon: 'none' });
return false;
}
console.log('[packMode] 打包上报成功:', res?.data || res);
const data = (res && typeof res === 'object' && res.data && typeof res.data === 'object') ? res.data : res;
console.log('[packMode] 打包上报成功:', data || res);
// 记录存在未结束打包任务:退出工作台/解绑操作员前将自动上报打包完成
this.hasActivePack = true;
// 记录当前「打包中」订单标识与类型,重复扫描同一订单时保持打包中、不重复上报
this.activePackIdentity = this.orderIdentity(this.orderQueryResult);
this.activePackIsSandan = this.orderQueryIsSandan;
// 大团购打包时长闸门:packOrder 响应下发倒计时字段(非大团购波次均为 0)
const respWaveScope = data?.wave_scope ?? data?.waveScope;
this.packWaveScope = (respWaveScope !== undefined && respWaveScope !== null && respWaveScope !== '')
? Number(respWaveScope)
: waveScope;
const waitSeconds = Number(data?.pack_wait_seconds ?? data?.packWaitSeconds) || 0;
const startTime = Number(data?.pack_start_time ?? data?.packStartTime) || 0;
this.startPackWaitCountdown(waitSeconds, startTime);
uni.showToast({ title: '已开始打包', icon: 'success' });
// 开始打包成功后刷新今日打包统计(以服务端为准)
this.loadTodayPackStat();
// 有新打包任务:重置 30 分钟无新任务自动登出计时
this.scheduleIdleAutoLogout();
return true;
} catch (error) {
console.error('[packMode] 打包上报失败:', error);
@ -1333,6 +1468,8 @@ export default {
this.hasActivePack = false;
this.activePackIdentity = '';
this.activePackIsSandan = null;
// 打包任务结束:清除大团购打包时长闸门倒计时
this.clearPackWait();
}
return {
ok: true,
@ -1747,6 +1884,8 @@ export default {
this.speakText(`${name} 绑定成功`);
// 绑定后静默重拉工作台信息,成员列表以服务端为准
this.fetchWorkbenchInfo({ silent: true });
// 重新绑定成员后重启无新任务自动登出计时
this.scheduleIdleAutoLogout();
return { ok: true, member };
} catch (error) {
console.error('[packMode] 绑定操作员失败:', error);
@ -1883,6 +2022,8 @@ export default {
const fr = await this.requestFinishPack();
if (fr && fr.expired) return { ok: false, expired: true };
this.clearPackState();
// 全员已下线:停止无新任务自动登出计时(重新绑定后由 doBindOperator 重启)
this.clearIdleAutoLogoutTimer();
}
if (!silent) {
uni.showToast({ title: opts.toastText || '操作员已移除', icon: 'success' });
@ -1919,6 +2060,50 @@ export default {
this.activePackIdentity = '';
this.activePackIsSandan = null;
this.packRestored = false;
this.clearPackWait();
},
// 启动大团购打包时长闸门倒计时(waitSeconds>0 且 startTime>0 时启动,否则清除)
startPackWaitCountdown(waitSeconds, startTime) {
this.clearPackWaitTimer();
const ws = Number(waitSeconds) || 0;
const st = Number(startTime) || 0;
this.packWaitSeconds = ws;
this.packStartTime = st;
if (ws > 0 && st > 0) {
this.updatePackWaitRemain();
this.packWaitTimer = setInterval(() => {
this.updatePackWaitRemain();
if (this.packWaitRemain <= 0) {
this.clearPackWaitTimer();
}
}, 1000);
} else {
this.packWaitRemain = 0;
}
},
// 刷新倒计时剩余秒数(remaining = waitSeconds - 已过去秒数)
updatePackWaitRemain() {
if (this.packWaitSeconds <= 0 || this.packStartTime <= 0) {
this.packWaitRemain = 0;
return;
}
const elapsed = Math.floor((Date.now() - this.packStartTime) / 1000);
this.packWaitRemain = Math.max(0, this.packWaitSeconds - elapsed);
},
// 清除倒计时定时器(页面卸载/任务结束时调用,避免 interval 泄漏)
clearPackWaitTimer() {
if (this.packWaitTimer) {
clearInterval(this.packWaitTimer);
this.packWaitTimer = null;
}
},
// 清空大团购打包时长闸门倒计时状态(打包任务结束 / 清空打包状态时调用)
clearPackWait() {
this.clearPackWaitTimer();
this.packWaitSeconds = 0;
this.packStartTime = 0;
this.packWaitRemain = 0;
this.packWaveScope = null;
},
// 读取本地已绑定信息(wblc 免登录 / 绑定成功均写入 storage)
loadBound(options) {
@ -2033,6 +2218,16 @@ export default {
this.activePackIdentity = this.orderIdentity(this.orderQueryResult);
this.activePackIsSandan = this.orderQueryIsSandan;
this.packRestored = true; // 跳过拦截/已打包/预检,展示进行中任务
// 恢复大团购打包时长闸门倒计时(服务端在恢复响应中下发 wait_seconds/start_time 时续上倒计时)
const rawWait = raw?.pack_wait_seconds ?? raw?.packWaitSeconds ?? wave?.pack_wait_seconds ?? wave?.packWaitSeconds;
const rawStart = raw?.pack_start_time ?? raw?.packStartTime ?? wave?.pack_start_time ?? wave?.packStartTime;
if ((Number(rawWait) || 0) > 0 && (Number(rawStart) || 0) > 0) {
this.startPackWaitCountdown(rawWait, rawStart);
}
const rawScope = raw?.wave_scope ?? raw?.waveScope ?? wave?.wave_scope ?? wave?.waveScope;
if (rawScope !== undefined && rawScope !== null && rawScope !== '') {
this.packWaveScope = Number(rawScope);
}
console.log('[packMode] 恢复进行中打包任务:', { isSandan, waveNo, waybill, items: mappedItems.length });
},
// 重新拉取工作台信息:进入打包模式时校验本地工作台 token 并刷新工作台信息
@ -2156,6 +2351,7 @@ export default {
},
// 清除工作台 token 并返回登录页:工作台会话(主 token 即工作台 token)时一并清除主登录态
async exitWorkbench(withToast = false) {
this.clearIdleAutoLogoutTimer();
const wbToken = String(uni.getStorageSync('workbenchToken') || '').trim();
const mainToken = String(uni.getStorageSync('token') || '').trim();
uni.removeStorageSync('workbenchToken');
@ -2322,6 +2518,33 @@ export default {
overflow: hidden;
}
/* 大团购打包时长闸门倒计时条 */
.pack-wait-bar {
margin-top: 16rpx;
background: #fdf6ec;
border: 2rpx solid #f3d19e;
border-radius: 16rpx;
padding: 16rpx 20rpx;
box-sizing: border-box;
display: flex;
align-items: center;
flex-shrink: 0;
}
.pack-wait-bar__text {
font-size: 30rpx;
color: #b88230;
margin-left: 10rpx;
}
.pack-wait-bar__time {
font-size: 34rpx;
font-weight: bold;
color: #e6a23c;
margin-left: 8rpx;
font-variant-numeric: tabular-nums;
}
/* 已绑定态顶部工作台卡并入 header,以下旧样式不再使用 */
.state-card {
background: #ffffff;

View File

@ -68,6 +68,11 @@
</view>
</view>
<!-- 加急提示 -->
<view class="urgent-tip" v-show="showResult && isUrgent">
<text class="urgent-tip-text">⚠ 加急订单,请优先处理</text>
</view>
<!-- 30日幂等提示 -->
<view class="duplicated-tip" v-show="showResult && result.duplicated">
<text class="duplicated-tip-text">30日内已登记,本次沿用首次登记记录</text>
@ -104,6 +109,10 @@ import voice from '@/core/utils/voice';
isOriginal() {
return !!(this.result && this.result.is_original_return);
},
// 是否加急退回(wms_return_query_log 中同仓库同运单号存在记录时为 true)
isUrgent() {
return !!(this.result && this.result.is_urgent);
},
// 货主合约货主备注名称(wms_store_warehouse.store_remask,非原单退回时为空)
storeRemark() {
return (this.result && this.result.store_remark) ? String(this.result.store_remark) : '';
@ -341,15 +350,18 @@ import voice from '@/core/utils/voice';
this.scanCount += 1;
}
this.clearInputIfSame(waybillCode, remark);
if (this.result.duplicated) {
uni.showToast({ title: '30日内已登记', icon: 'none' });
this.speakVoice('已登记');
} else if (this.result.is_original_return) {
uni.showToast({ title: '原单退回登记成功', icon: 'success' });
this.speakVoice('登记成功');
} else {
uni.showToast({ title: '退件登记成功', icon: 'success' });
this.speakVoice('登记成功');
// 加急订单优先播报:成功「加急订单,登记成功」、幂等「加急订单,已登记」,避免与普通语音串扰
const urgentSuccessVoiceText = '加急订单,登记成功';
const urgentDuplicatedVoiceText = '加急订单,已登记';
if (this.result.duplicated) {
uni.showToast({ title: '30日内已登记', icon: 'none' });
this.speakVoice(this.isUrgent ? urgentDuplicatedVoiceText : '已登记');
} else if (this.result.is_original_return) {
uni.showToast({ title: '原单退回登记成功', icon: 'success' });
this.speakVoice(this.isUrgent ? urgentSuccessVoiceText : '登记成功');
} else {
uni.showToast({ title: '退件登记成功', icon: 'success' });
this.speakVoice(this.isUrgent ? urgentSuccessVoiceText : '登记成功');
}
},
/**
@ -570,9 +582,28 @@ import voice from '@/core/utils/voice';
}
}
/* ===== 加急提示 ===== */
.urgent-tip {
margin: 0 24rpx 16rpx;
padding: 24rpx 24rpx;
display: flex;
align-items: center;
justify-content: center;
background: #ffccc7;
border-radius: 12rpx;
border: 1rpx solid #ffa39e;
.urgent-tip-text {
font-size: 45rpx;
color: #f5222d;
font-weight: bold;
text-align: center;
}
}
/* ===== 30日幂等提示 ===== */
.duplicated-tip {
margin: 0 24rpx;
margin: 0 24rpx 16rpx;
padding: 20rpx 24rpx;
display: flex;
align-items: center;