fix: 恢复打包页视口自愈并完善统计/提示逻辑
- 修复渲染复发: renderjs 恢复 installZeroViewportFix/installConsoleForward 调用(510ee6c 后丢失导致白屏复发),viewport-fix 增加每次尝试与恢复日志 - 打包页搜索框默认隐藏,标题栏 2 秒内连续点击 5 次切换显隐 - 今日打包统计改为服务端 getWorkbenchCount(团购波次/团购订单/散单/团散/均件数) - 语音播报与 Toast 超长文本截断(语音>12字符、失败文案>24字符) - 白屏排查实验代码(lockLandscape/setFullscreenStyle 当前为空壳、WMSPage 生命周期日志)
This commit is contained in:
parent
510ee6c326
commit
f393523bf0
@ -143,12 +143,24 @@
|
||||
<text class="pack-card-title">今日打包</text>
|
||||
<view class="pack-today-stats">
|
||||
<view class="pack-stat">
|
||||
<text class="pack-stat-num">{{ todayOrderCount }}</text>
|
||||
<text class="pack-stat-label">单数</text>
|
||||
<text class="pack-stat-num">{{ todayWaveCount }}</text>
|
||||
<text class="pack-stat-label">团购波次</text>
|
||||
</view>
|
||||
<view class="pack-stat">
|
||||
<text class="pack-stat-num">{{ todayProductCount }}</text>
|
||||
<text class="pack-stat-label">商品数</text>
|
||||
<text class="pack-stat-num">{{ todayGroupOrderCount }}</text>
|
||||
<text class="pack-stat-label">团购订单</text>
|
||||
</view>
|
||||
<view class="pack-stat">
|
||||
<text class="pack-stat-num">{{ todaySingleCount }}</text>
|
||||
<text class="pack-stat-label">散单</text>
|
||||
</view>
|
||||
<view v-if="isPersonalWorkbench && todayRatio !== null" class="pack-stat">
|
||||
<text class="pack-stat-num">{{ todayRatio }}</text>
|
||||
<text class="pack-stat-label">团散</text>
|
||||
</view>
|
||||
<view v-if="isPersonalWorkbench" class="pack-stat">
|
||||
<text class="pack-stat-num">{{ todayAvgPiece ?? '—' }}</text>
|
||||
<text class="pack-stat-label">均件数</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -301,6 +313,7 @@
|
||||
<script>
|
||||
import {
|
||||
getWorkbenchInfo,
|
||||
getWorkbenchCount,
|
||||
queryUserByToken,
|
||||
bindWorkbenchMember,
|
||||
removeWorkbenchMember,
|
||||
@ -337,8 +350,6 @@ const ANDROID_PUNCT_MAP = {
|
||||
}
|
||||
// 已绑定操作员本地缓存 key(后端暂未提供查询成员接口时,刷新后据此恢复显示)
|
||||
const MEMBER_STORAGE_KEY = 'workbenchMember'
|
||||
// 今日打包统计本地缓存 key(前端自行记录,按天存储,跨天重置)
|
||||
const TODAY_PACK_STORAGE_KEY = 'todayPackStat'
|
||||
// 扫描记录本地缓存 key(最多 50 条,出入栈:最新在前、超限丢最旧)
|
||||
const SCAN_RECORDS_STORAGE_KEY = 'packScanRecords'
|
||||
// 无新打包任务自动退出:超过该时长(毫秒)自动登出所有成员并结束最后打包任务
|
||||
@ -361,8 +372,11 @@ export default {
|
||||
packageMaterialName: '',
|
||||
productCount: 0,
|
||||
detailList: [],
|
||||
todayOrderCount: 0,
|
||||
todayProductCount: 0,
|
||||
todayWaveCount: 0,
|
||||
todaySingleCount: 0,
|
||||
todayGroupOrderCount: 0,
|
||||
todayRatio: null,
|
||||
todayAvgPiece: null,
|
||||
scanRecords: [],
|
||||
// ---- 广播扫描(扫码枪全局键盘监听,移植自 order/index.vue)----
|
||||
searchFocus: false,
|
||||
@ -511,6 +525,10 @@ export default {
|
||||
hasPackRecord() {
|
||||
return !!(this.currentOrderRaw || this.currentOrderCode || this.detailList.length > 0)
|
||||
},
|
||||
// 是否个人工作台(type=personal 展示团散/均件数,group 展示团购订单数)
|
||||
isPersonalWorkbench() {
|
||||
return this.workbenchInfo?.type === 'personal'
|
||||
},
|
||||
// 订单是否被禁止打包(命中即隐藏商品明细)
|
||||
orderBlocked() {
|
||||
return this.checkOrderBlocked().blocked
|
||||
@ -529,6 +547,9 @@ export default {
|
||||
},
|
||||
},
|
||||
onLoad() {
|
||||
// #ifdef APP-PLUS
|
||||
plus.android.importClass('android.util.Log').i('WMSPage', 'onLoad')
|
||||
// #endif
|
||||
// 简单守卫:无 token 时回到登录页
|
||||
if (!uni.getStorageSync('token')) {
|
||||
uni.reLaunch({
|
||||
@ -538,12 +559,31 @@ export default {
|
||||
}
|
||||
this.restoreWorkbenchMembers()
|
||||
this.restoreScanRecords()
|
||||
this.lockLandscape()
|
||||
this.loadTodayPackStat()
|
||||
this.loadWorkbenchInfo()
|
||||
},
|
||||
onReady() {
|
||||
this.lockLandscape()
|
||||
setTimeout(() => {
|
||||
this.lockLandscape()
|
||||
}, 500)
|
||||
},
|
||||
onShow() {
|
||||
// #ifdef APP-PLUS
|
||||
plus.android.importClass('android.util.Log').i('WMSPage', 'onShow')
|
||||
// #endif
|
||||
try {
|
||||
this.pageActive = true
|
||||
this.lockLandscape()
|
||||
// 多时间点重试全屏重排:覆盖 WebView 尺寸错乱白屏场景
|
||||
;[300, 800, 2000].forEach((delay) => {
|
||||
setTimeout(() => {
|
||||
if (this.pageActive) {
|
||||
this.setFullscreenStyle()
|
||||
}
|
||||
}, delay)
|
||||
})
|
||||
this.attachPlusKeyboardListener()
|
||||
this.attachGlobalKeyboardListener()
|
||||
this.startScanWatchdog()
|
||||
@ -562,6 +602,41 @@ export default {
|
||||
this.clearIdleAutoLogoutTimer()
|
||||
},
|
||||
methods: {
|
||||
// 强制锁定横屏 + 全屏重排:
|
||||
// 实验:暂时禁用所有 native 调用,验证白屏是否与 lockOrientation/setStyle 相关。
|
||||
lockLandscape() {
|
||||
// #ifdef APP-PLUS
|
||||
try {
|
||||
const screen = plus && plus.screen
|
||||
if (screen && typeof screen.lockOrientation === 'function') {
|
||||
// screen.lockOrientation('landscape')
|
||||
}
|
||||
// this.setFullscreenStyle()
|
||||
return true
|
||||
} catch (e) {
|
||||
console.error('[packaging] lockLandscape 异常:', e)
|
||||
}
|
||||
// #endif
|
||||
return false
|
||||
},
|
||||
// 仅修正 WebView 全屏边距(不触发方向事件,可安全重复调用)
|
||||
setFullscreenStyle() {
|
||||
// 【临时实验】禁用 setStyle native 调用,对照验证白屏元凶
|
||||
return
|
||||
// #ifdef APP-PLUS
|
||||
try {
|
||||
if (typeof plus !== 'undefined' && plus.webview) {
|
||||
const wv = plus.webview.currentWebview()
|
||||
if (wv && typeof wv.setStyle === 'function') {
|
||||
wv.setStyle({ top: '0px', bottom: '0px', left: '0px', right: '0px' })
|
||||
console.log('[packaging] webview setStyle fullscreen done')
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[packaging] setFullscreenStyle 异常:', e)
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
handlePackSearch() {
|
||||
const kw = this.dedupeRepeatedScan(String(this.keyword || '').trim())
|
||||
if (!kw) {
|
||||
@ -724,8 +799,10 @@ export default {
|
||||
}
|
||||
if (flag === 'failure') {
|
||||
this.speak('无记录')
|
||||
// 后端失败文案可能含条码等长文本,过长时用简短提示代替
|
||||
const failMsg = body?.message || body?.msg || '未找到对应订单'
|
||||
uni.showToast({
|
||||
title: body?.message || body?.msg || '未找到对应订单',
|
||||
title: String(failMsg).length > 24 ? '未找到对应订单' : failMsg,
|
||||
icon: 'none',
|
||||
})
|
||||
return
|
||||
@ -989,7 +1066,8 @@ export default {
|
||||
this.reportPackOrder(1)
|
||||
.then(() => {
|
||||
this.packStarted = true
|
||||
this.recordTodayPack()
|
||||
// 新打包提交成功后刷新今日打包统计(服务端为准)
|
||||
this.loadTodayPackStat()
|
||||
// 有新打包任务:重置 30 分钟无新任务自动登出计时
|
||||
this.scheduleIdleAutoLogout()
|
||||
this.speak('开始打包')
|
||||
@ -1041,10 +1119,14 @@ export default {
|
||||
},
|
||||
speak(text) {
|
||||
console.log('[语音播报] speak 入口:', String(text))
|
||||
const str = String(text || '').trim()
|
||||
let str = String(text || '').trim()
|
||||
if (!str) {
|
||||
return
|
||||
}
|
||||
// 长文本缩减:语音播报过长很啰嗦,超过 12 字符截断并以“等”收尾
|
||||
if (str.length > 12) {
|
||||
str = str.slice(0, 12) + '等'
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
// 优先 HTTP 语音接口(平板缺中文语音包时仍可发声),失败再走本地 TTS / Web Speech
|
||||
this.speakViaHttp(str).then((ok) => {
|
||||
@ -2156,50 +2238,32 @@ export default {
|
||||
// 存储失败不阻断扫描流程
|
||||
}
|
||||
},
|
||||
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) {
|
||||
// 忽略:读取失败按无记录处理
|
||||
const token = this.getWorkbenchToken()
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
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,
|
||||
// 今日打包统计以服务端 workbench.getWorkbenchCount 为准
|
||||
getWorkbenchCount(String(token))
|
||||
.then((body) => {
|
||||
if (this.checkWorkbenchAuthExpired(body)) {
|
||||
return
|
||||
}
|
||||
const payload = body?.data || body?.result || body
|
||||
const raw =
|
||||
payload && typeof payload === 'object' && !Array.isArray(payload) ? payload : null
|
||||
if (!raw) {
|
||||
return
|
||||
}
|
||||
this.todayWaveCount = Number(raw.group_wave_count) || 0
|
||||
this.todaySingleCount = Number(raw.single_order_count) || 0
|
||||
this.todayGroupOrderCount = Number(raw.group_order_count) || 0
|
||||
this.todayRatio = raw.group_single_ratio ?? null
|
||||
this.todayAvgPiece = raw.avg_piece_count ?? null
|
||||
})
|
||||
.catch(() => {
|
||||
// 静默:统计失败不影响打包流程
|
||||
})
|
||||
} catch (e) {
|
||||
// 忽略:存储失败不影响界面展示
|
||||
}
|
||||
},
|
||||
clearPlusKeyTimer() {
|
||||
if (this.plusKeyTimer) {
|
||||
@ -2822,6 +2886,9 @@ export default {
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
// #ifdef APP-PLUS
|
||||
plus.android.importClass('android.util.Log').i('WMSPage', 'mounted')
|
||||
// #endif
|
||||
try {
|
||||
// 广播扫描:plus.key(Android 原生 keycode)+ DOM 全局 keydown + 隐藏 input(关闭)
|
||||
this.setupScanCaptureMode()
|
||||
@ -2857,10 +2924,19 @@ export default {
|
||||
installConsoleForward()
|
||||
// 真机修复(RK3288/Android7 实测):reLaunch 后新页面 WebView 视口可能为 0×0,
|
||||
// CSS 的 vw/vh 随之计算为 0 → html fontSize=0 → 所有 rem 尺寸归零 → 白屏;
|
||||
// 切后台回前台能恢复(Activity resume 时原生重排)。检测到 0×0 视口时强制原生重排自愈。
|
||||
// 公共逻辑见 src/render-common/viewport-fix.js,新页面照此接入即可。
|
||||
// 已对照验证:移除自愈白屏复现,本修复必需保留。
|
||||
// 检测到 0×0 视口时强制原生 decorView 重排自愈。公共逻辑见 src/render-common/viewport-fix.js。
|
||||
// 已对照验证:移除自愈白屏复现,此调用必需保留。
|
||||
installZeroViewportFix()
|
||||
try {
|
||||
const Log = plus.android.importClass('android.util.Log')
|
||||
Log.i('WMSView', 'renderjs mounted, body=' + (document.body ? document.body.clientWidth + 'x' + document.body.clientHeight : 'null') + ', inner=' + window.innerWidth + 'x' + window.innerHeight + ', fontSize=' + (document.documentElement.style ? document.documentElement.style.fontSize : 'na'))
|
||||
setTimeout(() => {
|
||||
Log.i('WMSView', 'renderjs t+2s, body=' + (document.body ? document.body.clientWidth + 'x' + document.body.clientHeight : 'null') + ', inner=' + window.innerWidth + 'x' + window.innerHeight + ', fontSize=' + (document.documentElement.style ? document.documentElement.style.fontSize : 'na'))
|
||||
}, 2000)
|
||||
} catch (e) {
|
||||
const Log2 = plus.android.importClass('android.util.Log')
|
||||
Log2.i('WMSView', 'renderjs err=' + e)
|
||||
}
|
||||
// 真机 rem 由 App.vue 全局纯 CSS(html { font-size: min(3.515625vw, 5.2734375vh) },0.675 系数)承担,
|
||||
// renderjs 不再覆盖,避免与 CSS 方案互相覆盖导致白屏/抖动
|
||||
return
|
||||
|
||||
@ -69,16 +69,26 @@ export function installZeroViewportFix(options = {}) {
|
||||
const interval = options.interval || 400
|
||||
const startDelay = options.startDelay || 300
|
||||
let attempts = 0
|
||||
const log = (msg) => {
|
||||
try {
|
||||
plus.android.importClass('android.util.Log').i('WMSView', msg)
|
||||
} catch (e) {
|
||||
// 日志失败不阻断
|
||||
}
|
||||
}
|
||||
|
||||
const fix = () => {
|
||||
// 视口已恢复则停止
|
||||
if (window.innerWidth > 0 && window.innerHeight > 0) {
|
||||
log('viewport-fix ok: inner=' + window.innerWidth + 'x' + window.innerHeight + ', attempts=' + attempts)
|
||||
return
|
||||
}
|
||||
attempts++
|
||||
if (attempts > maxAttempts) {
|
||||
log('viewport-fix give up: inner=' + window.innerWidth + 'x' + window.innerHeight + ', attempts=' + attempts)
|
||||
return
|
||||
}
|
||||
log('viewport-fix attempt=' + attempts + ': inner=' + window.innerWidth + 'x' + window.innerHeight)
|
||||
try {
|
||||
const main = plus.android.runtimeMainActivity()
|
||||
const win = plus.android.invoke(main, 'getWindow')
|
||||
@ -87,6 +97,7 @@ export function installZeroViewportFix(options = {}) {
|
||||
plus.android.invoke(decor, 'invalidate')
|
||||
} catch (e) {
|
||||
// 重排失败不阻断,等待系统侧恢复(切后台回前台仍可恢复)
|
||||
log('viewport-fix err: ' + (e && e.message ? e.message : e))
|
||||
}
|
||||
setTimeout(fix, interval)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user