66 lines
4.2 KiB
Markdown
66 lines
4.2 KiB
Markdown
# WMS 工作台(wms_worker_station)
|
||
|
||
## 真机调试热更新(dev:adb)
|
||
|
||
`npm run dev:adb` 一条命令完成真机调试闭环:
|
||
|
||
1. 自动列出所有 ADB 设备(多台时交互选择,单台自动选中)
|
||
2. 进程常驻,监听 `src/` 与原生工程源码(`simpleDemo/src/main/java`、`AndroidManifest.xml`)
|
||
3. 保存文件后自动:`build:app` → 离线打包(gradle 增量) → `adb install -r` → 启动应用(约 20 秒/轮)
|
||
4. **真机 console 实时打印到终端**(含视图层 renderjs)
|
||
|
||
可选参数:
|
||
- `npm run dev:adb -- --no-launch`:重装后不自动启动应用
|
||
- `npm run dev:adb -- --adb=D:\path\to\adb.exe`:自定义 adb 路径(默认自动探测 SDK)
|
||
|
||
console 转发原理(release 包 console 默认不进 logcat):
|
||
- 逻辑层:`src/main.js` 接管 `console.*` 与 uni-app 内部日志 `uni.__log__`(编译后的 console.log 走它),转发到 logcat tag `UniConsole`
|
||
- 视图层:`src/render-common/viewport-fix.js` 的 `installConsoleForward()`,各页 renderjs 调用,tag `UniViewConsole`
|
||
|
||
注意:不要 watch `simpleDemo/src/main/assets` 与 `res`(构建注入产物),否则构建自触发死循环(已在脚本中排除)。
|
||
|
||
## ⚠️ 真机坑:登录页 reLaunch 到打包模式白屏(切后台回前台才恢复)
|
||
|
||
### 现象
|
||
- 真机(RK3288 工控机 / Android 7.1.2,系统 WebView = Chromium 52)上,从登录页 `uni.reLaunch` 到打包模式页(`/pages/packaging/index`)后**整个页面白屏**;
|
||
- 按 Home 退后台再切回前台,页面恢复正常显示;
|
||
- 服务层逻辑正常执行(页面 onLoad/onShow/mounted 都跑了,toast/语音也正常),只有渲染层白屏。
|
||
|
||
### 根因
|
||
- reLaunch 创建的新页面 WebView 初始**视口为 0×0**(`window.innerWidth/innerHeight` 都是 0,`document.body` 尺寸 0×0);
|
||
- 全局 CSS 的 `html { font-size: min(5.2734375vw, 7.91015625vh) }` 依赖视口,视口为 0 时 fontSize 计算为 **0px**;
|
||
- 本项目全站用 rem 布局,fontSize=0 → 所有 rem 尺寸归零 → 白屏;
|
||
- 切后台回前台时 Activity resume 触发原生重排,视口恢复(961×640 CSS 像素,dpr=2 对应物理 1920×1280),页面随即正常。
|
||
|
||
### 诊断方法(重要,后续排查类似问题照此做)
|
||
- **renderjs 的 `console.log` 在 release 包里拿不到**(不会输出到 logcat);
|
||
- 必须用原生日志:`plus.android.importClass('android.util.Log').i('TAG', msg)`,然后 `adb logcat | grep TAG`;
|
||
- 轮询观察视口:`setInterval` 里打印 `window.innerWidth + 'x' + window.innerHeight` 与 `document.documentElement.style.fontSize / getComputedStyle(...).fontSize`。
|
||
|
||
### 修复(已落地,公共逻辑抽离到 `src/render-common/viewport-fix.js`)
|
||
- 在页面 renderjs 的 `mounted` 里 `import { installZeroViewportFix } from '../../render-common/viewport-fix.js'` 并调用一次,检测视口 0×0 时强制原生 Activity 重排自愈;
|
||
- 新页面接入示例:
|
||
|
||
```js
|
||
// 页面 .vue 内的 renderjs 模块
|
||
<script module="remInject" lang="renderjs">
|
||
import { installZeroViewportFix } from '../../render-common/viewport-fix.js'
|
||
|
||
export default {
|
||
mounted() {
|
||
// #ifdef APP-PLUS
|
||
installZeroViewportFix() // 视口自愈(0×0 → requestLayout+invalidate)
|
||
return // 注意:APP 端 renderjs 不覆盖 fontSize,rem 由 App.vue 全局 CSS 承担
|
||
// #endif
|
||
// H5 端 rem 逻辑...
|
||
},
|
||
}
|
||
</script>
|
||
```
|
||
|
||
### 后续开发注意
|
||
1. **不要**在页面 renderjs 的 APP 端覆盖 `html` fontSize(真机 rem 统一由 `App.vue` 全局纯 CSS 承担,renderjs 覆盖会导致字号/布局异常);
|
||
2. **不要**在新页面 WebView 创建早期(onLoad)调用 `plus.screen.lockOrientation` / `plus.webview.currentWebview().setStyle` 等 native 操作——实测无效且会触发 `AdaUniWebView` 的 `ViewOptions.updateViewData` NPE。横屏由 `manifest.json` 的全局 `screenOrientation` 配置承担,打包页的 lockLandscape 已因此移除;
|
||
3. 若新增页面在真机出现同样白屏,按上面的示例接入 `installZeroViewportFix` 即可;
|
||
4. 排查白屏类问题先看**视口尺寸**(renderjs 里打 Log),而不是猜字体/样式——0×0 视口下 CSS 的 vw/vh 全部失效是这类白屏的典型特征。
|