feat: 真机适配与调试工具链
- 修复 RK3288 真机 reLaunch 白屏: 新页面 WebView 视口 0×0 导致 CSS vw/vh 归零, renderjs 检测并强制原生重排自愈(公共逻辑 src/render-common/viewport-fix.js) - 移除打包页无效的 lockLandscape(锁屏由 manifest 全局配置承担, setStyle 曾触发 native NPE) - 新增 dev:adb 真机调试热更新脚本: 设备选择/文件监听自动构建重装/真机 console 实时打印 - console 转发 logcat: main.js 接管 uni.__log__ 与 console(UniConsole), 视图层 renderjs 转发(UniViewConsole) - Android 离线包: appid 切换为散单 __UNI__900BDC1 复用其 appKey; prepare.cjs 对齐 compilerVersion 消除版本不一致弹窗 - 新增开机自启 BootReceiver(BOOT_COMPLETED + QUICKBOOT_POWERON) - 启动时将系统音量调至最大(App.vue) - 文档: README 记录白屏踩坑与 dev:adb 用法
This commit is contained in:
parent
9ee6d7b986
commit
510ee6c326
4
.gitignore
vendored
4
.gitignore
vendored
@ -37,4 +37,6 @@ android-offline/HBuilder-Integrate-AS/**/build/
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
*.sw?
|
||||
# 构建注入的 App 资源(由 prepare.cjs 从 dist 拷贝,勿提交)
|
||||
android-offline/HBuilder-Integrate-AS/simpleDemo/src/main/assets/apps/__UNI__900BDC1/
|
||||
|
||||
65
README.md
65
README.md
@ -0,0 +1,65 @@
|
||||
# WMS 工作台(wms_worker_station)
|
||||
|
||||
## 真机调试热更新(dev:adb)
|
||||
|
||||
`npm run dev:adb` 一条命令完成真机调试闭环:
|
||||
|
||||
1. 自动列出所有 ADB 设备(多台时交互选择,单台自动选中)
|
||||
2. 进程常驻,监听 `src/` 与原生工程源码(`simpleDemo/src/main/java`、`AndroidManifest.xml`)
|
||||
3. 保存文件后自动:`build:app-plus` → 离线打包(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(3.515625vw, 5.2734375vh) }` 依赖视口,视口为 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 全部失效是这类白屏的典型特征。
|
||||
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowClearUserData="true"
|
||||
@ -44,6 +46,16 @@
|
||||
<meta-data
|
||||
android:name="dcloud_appkey"
|
||||
android:value="${dcloud_appkey}" />
|
||||
<!-- 开机自启:系统启动完成后自动拉起应用(见 BootReceiver.java) -->
|
||||
<receiver
|
||||
android:name=".BootReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 5.7 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 2.0 KiB |
@ -1,24 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>View</title>
|
||||
<link rel="icon" href="data:,">
|
||||
<link rel="stylesheet" href="app.css" />
|
||||
<script>var __uniConfig = {"globalStyle":{},"darkmode":false}</script>
|
||||
<script>
|
||||
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
||||
CSS.supports('top: constant(a)'))
|
||||
document.write(
|
||||
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="uni-app-view.umd.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -1,11 +0,0 @@
|
||||
|
||||
;(function(){
|
||||
let u=void 0,isReady=false,onReadyCallbacks=[],isServiceReady=false,onServiceReadyCallbacks=[];
|
||||
const __uniConfig = {"pages":[],"globalStyle":{"backgroundColor":"#F8F8F8","navigationBar":{"backgroundColor":"#F8F8F8","titleText":"wms_worker_station","type":"default","titleColor":"#000000"},"isNVue":false},"nvue":{"compiler":"uni-app","styleCompiler":"uni-app","flex-direction":"column"},"renderer":"auto","appname":"WMS工作台","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":true},"compilerVersion":"5.07","entryPagePath":"pages/login/login","entryPageQuery":"","realEntryPagePath":"","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000},"locales":{},"darkmode":false,"themeConfig":{}};
|
||||
const __uniRoutes = [{"path":"pages/login/login","meta":{"isQuit":true,"isEntry":true,"titleNView":false,"navigationBar":{"type":"default","style":"custom"},"isNVue":false}},{"path":"pages/index/index","meta":{"titleNView":false,"navigationBar":{"type":"default","style":"custom"},"isNVue":false}},{"path":"pages/order/index","meta":{"titleNView":false,"navigationBar":{"titleText":"订单复核1","type":"default","style":"custom"},"isNVue":false}},{"path":"pages/weighing/index","meta":{"titleNView":false,"navigationBar":{"titleText":"称重","type":"default","style":"custom"},"isNVue":false}},{"path":"pages/returns/index","meta":{"titleNView":false,"navigationBar":{"titleText":"退件","type":"default","style":"custom"},"isNVue":false}},{"path":"pages/packaging/index","meta":{"titleNView":false,"navigationBar":{"titleText":"打包模式","type":"default","style":"custom"},"isNVue":false}}].map(uniRoute=>(uniRoute.meta.route=uniRoute.path,__uniConfig.pages.push(uniRoute.path),uniRoute.path='/'+uniRoute.path,uniRoute));
|
||||
__uniConfig.styles=[];//styles
|
||||
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:16})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,global:u,window:u,document:u,frames:u,self:u,location:u,navigator:u,localStorage:u,history:u,Caches:u,screen:u,alert:u,confirm:u,prompt:u,fetch:u,XMLHttpRequest:u,WebSocket:u,webkit:u,print:u}}}});
|
||||
})();
|
||||
|
||||
@ -1 +0,0 @@
|
||||
(function(){})();
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,119 +0,0 @@
|
||||
{
|
||||
"@platforms": [
|
||||
"android",
|
||||
"iPhone",
|
||||
"iPad"
|
||||
],
|
||||
"id": "__UNI__F18BF9C",
|
||||
"name": "WMS工作台",
|
||||
"version": {
|
||||
"name": "1.0.1",
|
||||
"code": "101"
|
||||
},
|
||||
"description": "",
|
||||
"developer": {
|
||||
"name": "",
|
||||
"email": "",
|
||||
"url": ""
|
||||
},
|
||||
"permissions": {
|
||||
"UniNView": {
|
||||
"description": "UniNView原生渲染"
|
||||
}
|
||||
},
|
||||
"plus": {
|
||||
"useragent": {
|
||||
"value": "uni-app",
|
||||
"concatenate": true
|
||||
},
|
||||
"splashscreen": {
|
||||
"target": "id:1",
|
||||
"autoclose": true,
|
||||
"waiting": true,
|
||||
"delay": 0
|
||||
},
|
||||
"popGesture": "close",
|
||||
"launchwebview": {
|
||||
"render": "always",
|
||||
"id": "1",
|
||||
"kernel": "WKWebview"
|
||||
},
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"distribute": {
|
||||
"google": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.INTERNET\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||
],
|
||||
"abiFilters": [
|
||||
"x86",
|
||||
"armeabi-v7a",
|
||||
"arm64-v8a"
|
||||
]
|
||||
},
|
||||
"apple": {
|
||||
"dSYMs": false
|
||||
},
|
||||
"plugins": {
|
||||
"audio": {
|
||||
"mp3": {
|
||||
"description": "Android平台录音支持MP3格式文件"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"statusbar": {
|
||||
"immersed": "supportedDevice",
|
||||
"style": "dark",
|
||||
"background": "#F8F8F8"
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"allowsInlineMediaPlayback": true,
|
||||
"uni-app": {
|
||||
"control": "uni-v3",
|
||||
"vueVersion": "3",
|
||||
"compilerVersion": "5.07",
|
||||
"nvueCompiler": "uni-app",
|
||||
"renderer": "auto",
|
||||
"nvue": {
|
||||
"flex-direction": "column"
|
||||
},
|
||||
"nvueLaunchMode": "normal",
|
||||
"webView": {
|
||||
"minUserAgentVersion": "49.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"app-harmony": {
|
||||
"useragent": {
|
||||
"value": "uni-app",
|
||||
"concatenate": true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
}
|
||||
},
|
||||
"screenOrientation": [
|
||||
"landscape-primary",
|
||||
"landscape-secondary"
|
||||
],
|
||||
"launch_path": "__uniappview.html"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
.top-nav[data-v-a0b04150]{width:100%;margin-bottom:.75rem;padding:.5625rem .875rem;box-sizing:border-box;background-color:#2f7dff;display:flex;align-items:center;justify-content:space-between}.top-nav-logo[data-v-a0b04150]{width:7.5rem;height:2.8125rem;flex-shrink:0}.top-nav-right[data-v-a0b04150]{position:relative;margin-left:auto}.top-nav-menu-wrap[data-v-a0b04150]{display:flex;align-items:center;margin-left:1.125rem;gap:.4375rem;min-width:0}.top-nav-menu-item[data-v-a0b04150]{padding:.3125rem .5625rem;border-radius:.25rem}.top-nav-menu-item--active[data-v-a0b04150]{background-color:rgba(255,255,255,.24)}.top-nav-menu-text[data-v-a0b04150]{font-size:1rem;color:#fff;font-weight:500}.top-nav-user[data-v-a0b04150]{display:flex;align-items:center;gap:.3125rem;cursor:pointer}.top-nav-user-name[data-v-a0b04150]{color:#fff;font-size:1rem;line-height:1}.top-nav-mine-icon[data-v-a0b04150]{width:1.375rem;height:1.375rem;display:flex;flex-direction:column;align-items:center;justify-content:center;border-radius:31.21875rem;background-color:rgba(255,255,255,.2);box-sizing:border-box}.top-nav-mine-icon-head[data-v-a0b04150]{width:.375rem;height:.375rem;border:.0625rem solid #fff;border-radius:50%;box-sizing:border-box}.top-nav-mine-icon-body[data-v-a0b04150]{width:.625rem;height:.3125rem;margin-top:.125rem;border:.0625rem solid #fff;border-top:none;border-radius:0 0 .375rem .375rem;box-sizing:border-box}.popup-card[data-v-a0b04150]{position:absolute;right:0;top:2.1875rem;min-width:10.3125rem;background:#fff;border-radius:.375rem;box-shadow:0 .375rem 1rem rgba(0,0,0,.16);padding:.5rem;box-sizing:border-box;z-index:30}.popup-user-info[data-v-a0b04150]{max-height:10rem;overflow-y:auto}.popup-user-item[data-v-a0b04150]{padding:.375rem;border-radius:.25rem}.popup-user-item--current[data-v-a0b04150]{background-color:#edf4ff}.popup-user-text[data-v-a0b04150]{font-size:.875rem;color:#333}.popup-user-item--current .popup-user-text[data-v-a0b04150]{color:#2f7dff}.logout-btn[data-v-a0b04150]{margin-top:.5rem;height:1.875rem;line-height:1.875rem;font-size:.875rem}.close-btn[data-v-a0b04150]{margin-top:.3125rem;height:1.875rem;line-height:1.875rem;font-size:.875rem;background-color:#f5f7fb;color:#333}.switch-mask[data-v-a0b04150]{position:fixed;left:0;top:0;right:0;bottom:0;background-color:#f8f8f8;z-index:9999;pointer-events:none;opacity:0;visibility:hidden;transition:opacity .2s ease,visibility .2s ease}.switch-mask--active[data-v-a0b04150]{opacity:1;visibility:visible}.page{height:100%;min-height:0;display:flex;flex-direction:column;overflow:hidden;box-sizing:border-box;background-color:#f8f8f8}.page-main{flex:1;min-height:0;overflow-y:auto;padding:.25rem 1rem 1rem;box-sizing:border-box}.dynamic-view--returns{width:100%}.module-card{background-color:#fff;border-radius:.5rem;padding:1rem;box-sizing:border-box}.module-card-title{display:block;font-size:1rem;color:#333;font-weight:600;margin-bottom:.375rem}.module-card-desc{display:block;font-size:.8125rem;color:#888;line-height:1.5}
|
||||
@ -1 +0,0 @@
|
||||
.top-nav[data-v-a0b04150]{width:100%;margin-bottom:.75rem;padding:.5625rem .875rem;box-sizing:border-box;background-color:#2f7dff;display:flex;align-items:center;justify-content:space-between}.top-nav-logo[data-v-a0b04150]{width:7.5rem;height:2.8125rem;flex-shrink:0}.top-nav-right[data-v-a0b04150]{position:relative;margin-left:auto}.top-nav-menu-wrap[data-v-a0b04150]{display:flex;align-items:center;margin-left:1.125rem;gap:.4375rem;min-width:0}.top-nav-menu-item[data-v-a0b04150]{padding:.3125rem .5625rem;border-radius:.25rem}.top-nav-menu-item--active[data-v-a0b04150]{background-color:rgba(255,255,255,.24)}.top-nav-menu-text[data-v-a0b04150]{font-size:1rem;color:#fff;font-weight:500}.top-nav-user[data-v-a0b04150]{display:flex;align-items:center;gap:.3125rem;cursor:pointer}.top-nav-user-name[data-v-a0b04150]{color:#fff;font-size:1rem;line-height:1}.top-nav-mine-icon[data-v-a0b04150]{width:1.375rem;height:1.375rem;display:flex;flex-direction:column;align-items:center;justify-content:center;border-radius:31.21875rem;background-color:rgba(255,255,255,.2);box-sizing:border-box}.top-nav-mine-icon-head[data-v-a0b04150]{width:.375rem;height:.375rem;border:.0625rem solid #fff;border-radius:50%;box-sizing:border-box}.top-nav-mine-icon-body[data-v-a0b04150]{width:.625rem;height:.3125rem;margin-top:.125rem;border:.0625rem solid #fff;border-top:none;border-radius:0 0 .375rem .375rem;box-sizing:border-box}.popup-card[data-v-a0b04150]{position:absolute;right:0;top:2.1875rem;min-width:10.3125rem;background:#fff;border-radius:.375rem;box-shadow:0 .375rem 1rem rgba(0,0,0,.16);padding:.5rem;box-sizing:border-box;z-index:30}.popup-user-info[data-v-a0b04150]{max-height:10rem;overflow-y:auto}.popup-user-item[data-v-a0b04150]{padding:.375rem;border-radius:.25rem}.popup-user-item--current[data-v-a0b04150]{background-color:#edf4ff}.popup-user-text[data-v-a0b04150]{font-size:.875rem;color:#333}.popup-user-item--current .popup-user-text[data-v-a0b04150]{color:#2f7dff}.logout-btn[data-v-a0b04150]{margin-top:.5rem;height:1.875rem;line-height:1.875rem;font-size:.875rem}.close-btn[data-v-a0b04150]{margin-top:.3125rem;height:1.875rem;line-height:1.875rem;font-size:.875rem;background-color:#f5f7fb;color:#333}.switch-mask[data-v-a0b04150]{position:fixed;left:0;top:0;right:0;bottom:0;background-color:#f8f8f8;z-index:9999;pointer-events:none;opacity:0;visibility:hidden;transition:opacity .2s ease,visibility .2s ease}.switch-mask--active[data-v-a0b04150]{opacity:1;visibility:visible}.page{height:100%;min-height:0;display:flex;flex-direction:column;overflow:hidden;box-sizing:border-box;background-color:#f8f8f8}.page-main{flex:1;min-height:0;overflow-y:auto;padding:.25rem 1rem 1rem;box-sizing:border-box}.dynamic-view--catch-weight{width:100%}.module-card{background-color:#fff;border-radius:.5rem;padding:1rem;box-sizing:border-box}.module-card-title{display:block;font-size:1rem;color:#333;font-weight:600;margin-bottom:.375rem}.module-card-desc{display:block;font-size:.8125rem;color:#888;line-height:1.5}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 82 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.9 KiB |
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
||||
<hbuilder>
|
||||
<apps>
|
||||
<app appid="__UNI__F18BF9C" appver=""/>
|
||||
<app appid="__UNI__900BDC1" appver=""/>
|
||||
</apps>
|
||||
</hbuilder>
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package com.gztbyc.sandan;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* 开机自启:监听系统开机完成广播,自动拉起应用。
|
||||
* 说明:Android 3.1+ 要求应用至少被用户启动过一次后,BOOT_COMPLETED 才会送达。
|
||||
*/
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String ACTION_QUICKBOOT_POWERON = "android.intent.action.QUICKBOOT_POWERON";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent == null || intent.getAction() == null) {
|
||||
return;
|
||||
}
|
||||
final String action = intent.getAction();
|
||||
if (!Intent.ACTION_BOOT_COMPLETED.equals(action) && !ACTION_QUICKBOOT_POWERON.equals(action)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
if (launch != null) {
|
||||
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
context.startActivity(launch);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 启动失败不阻断系统广播
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,8 +27,8 @@ android-offline/
|
||||
|
||||
| 字段 | 说明 |
|
||||
|---|---|
|
||||
| `appId` | uni-app appid,已预填 `__UNI__F18BF9C` |
|
||||
| `appKey` | DCloud AppKey,到 https://dev.dcloud.net.cn 申请后填写 |
|
||||
| `appId` | uni-app appid,已预填 `__UNI__900BDC1`(与散单项目共用,复用其离线打包 Key) |
|
||||
| `appKey` | DCloud AppKey,与散单项目共用(散单在 dev.dcloud.net.cn 为 `__UNI__900BDC1` 申请),复用即可 |
|
||||
| `appName` | 应用名(安装后桌面显示名称) |
|
||||
| `packageName` | Android 包名(唯一标识,发布后不可改) |
|
||||
| `abis` | CPU 架构列表,默认 `["x86", "armeabi-v7a", "arm64-v8a"]` 三种全覆盖 |
|
||||
|
||||
@ -89,6 +89,27 @@ if (!wwwSource) {
|
||||
log(`✓ 拷贝 App 资源: ${path.relative(ROOT, wwwSource)} -> assets/apps/${config.appId}/www`)
|
||||
}
|
||||
|
||||
// ---------- 4.5 对齐编译器版本(隐藏"HTML5+ Runtime 版本不一致"提示) ----------
|
||||
// CLI 构建资源时写入的 compilerVersion(如 5.07)与离线 SDK Runtime 版本不一致时,
|
||||
// 启动会弹"本应用使用HBuilderX %s 编译,而手机端SDK版本是 %s"对话框。
|
||||
// 此处把 www 内 manifest.json / app-config-service.js 的 compilerVersion 对齐到
|
||||
// config/android.json 的 runtimeVersion(默认 5.24,与离线 SDK 一致),即可消除提示。
|
||||
const runtimeVersion = config.runtimeVersion || '5.24'
|
||||
function alignCompilerVersion (filePath) {
|
||||
try {
|
||||
if (!fs.existsSync(filePath)) return
|
||||
let text = fs.readFileSync(filePath, 'utf-8')
|
||||
const re = /"compilerVersion"\s*:\s*"[^"]*"/g
|
||||
text = text.replace(re, '"compilerVersion": "' + runtimeVersion + '"')
|
||||
fs.writeFileSync(filePath, text, 'utf-8')
|
||||
log(`✓ 对齐 compilerVersion -> ${runtimeVersion}: ${path.relative(ROOT, filePath)}`)
|
||||
} catch (e) {
|
||||
warn(`对齐 compilerVersion 失败 ${filePath}: ${e.message}`)
|
||||
}
|
||||
}
|
||||
alignCompilerVersion(path.join(wwwTarget, 'manifest.json'))
|
||||
alignCompilerVersion(path.join(wwwTarget, 'app-config-service.js'))
|
||||
|
||||
// ---------- 9. 覆盖图标与启动图 ----------
|
||||
function findResFiles(pattern) {
|
||||
const resDir = path.join(DEMO_DIR, 'src', 'main', 'res')
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
|
||||
`android.json` 字段说明:appId(uni-app appid)、appKey(dev.dcloud.net.cn 申请)、appName(应用名)、packageName(Android 包名)、abis(CPU 架构)、icon/splash(图标启动图路径,相对项目根)、wwwSource(可选:指定 App 资源目录,留空则自动用 dist/build/app 或 unpackage/resources)、signing(keystore 路径/密码)。
|
||||
|
||||
> ⚠️ **appKey 必须与 appId 严格匹配**,留空或填其他应用的 key 时,APK 启动会白屏提示“未配置appkey或配置错误”(5+ Runtime 启动校验)。本应用与散单项目共用包名/签名/appid(`__UNI__900BDC1`),因此直接复用散单已申请的离线打包 Key,无需再申请。若日后更换 appid/证书/包名,需到 https://dev.dcloud.net.cn → 应用详情 → Android → 离线打包 Key 管理重新申请(需填包名与证书 SHA-256 指纹)。
|
||||
|
||||
`deploy.json` 字段说明:android 段(APK 发布,`android:pack` 打包后自动 scp 上传)与 windows 段(exe 发布,`build:exe` 打包后自动 scp 上传),每段含 host(服务器 IP)、port(SSH 端口)、user(SSH 用户)、keyPath(SSH 私钥路径)、remoteDir(服务器上传目录:APK 与散单项目同为 worker_station,exe 为 worker_station_windows)、downloadUrlPrefix(下载 URL 前缀)、latestJsonName(latest.json 文件名)。跳过上传:`-NoUpload`(APK)/ `--no-upload`(exe)。
|
||||
|
||||
## 根目录其他配置
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"appId": "__UNI__F18BF9C",
|
||||
"appId": "__UNI__900BDC1",
|
||||
"appKey": "",
|
||||
"appName": "WMS工作台",
|
||||
"packageName": "com.gztbyc.sandan",
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
"build:app-plus": "uni build -p app",
|
||||
"android:prepare": "node android-offline/prepare.cjs",
|
||||
"android:pack": "powershell -NoProfile -ExecutionPolicy Bypass -File android-offline/pack.ps1",
|
||||
"dev:adb": "node scripts/dev-adb.cjs",
|
||||
"build:exe": "node scripts/build-exe.cjs"
|
||||
},
|
||||
"dependencies": {},
|
||||
|
||||
370
scripts/dev-adb.cjs
Normal file
370
scripts/dev-adb.cjs
Normal file
@ -0,0 +1,370 @@
|
||||
/**
|
||||
* ADB 真机调试(类热更新):
|
||||
* 1. 列出所有已连接设备,可选择目标设备(多台时交互选择,单台自动选中)
|
||||
* 2. 进程常驻,监听源码变更
|
||||
* 3. 变更后自动:build:app-plus → 离线打包(gradle 增量) → adb install -r → 启动应用
|
||||
*
|
||||
* 用法:
|
||||
* npm run dev:adb # 自动选唯一设备
|
||||
* npm run dev:adb -- --no-launch # 重装后不自动启动应用
|
||||
* npm run dev:adb -- --adb=adb路径 # 自定义 adb 路径
|
||||
*
|
||||
* 变更监听范围:
|
||||
* src/(uni-app 前端资源)
|
||||
* android-offline/HBuilder-Integrate-AS/simpleDemo/src/(原生工程:Manifest/Java/res)
|
||||
*/
|
||||
const { spawnSync, spawn } = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const readline = require('readline')
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..')
|
||||
|
||||
// ---------- adb 路径探测(PATH 里没有时从 SDK 目录找) ----------
|
||||
function detectAdb() {
|
||||
const arg = process.argv.find((a) => a.startsWith('--adb='))
|
||||
if (arg) {
|
||||
return arg.slice('--adb='.length)
|
||||
}
|
||||
if (process.env.ADB) {
|
||||
return process.env.ADB
|
||||
}
|
||||
const candidates = []
|
||||
const home = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || ''
|
||||
if (home) {
|
||||
candidates.push(path.join(home, 'platform-tools', process.platform === 'win32' ? 'adb.exe' : 'adb'))
|
||||
}
|
||||
if (process.env.LOCALAPPDATA) {
|
||||
candidates.push(path.join(process.env.LOCALAPPDATA, 'Android', 'Sdk', 'platform-tools', 'adb.exe'))
|
||||
}
|
||||
candidates.push(process.platform === 'win32' ? 'adb.exe' : 'adb')
|
||||
for (const c of candidates) {
|
||||
try {
|
||||
const res = spawnSync(c, ['version'], { encoding: 'utf-8' })
|
||||
if (res.status === 0 && /Android Debug Bridge/.test(res.stdout || '')) {
|
||||
return c
|
||||
}
|
||||
} catch (e) {
|
||||
// 继续
|
||||
}
|
||||
}
|
||||
return 'adb'
|
||||
}
|
||||
|
||||
const ADB = detectAdb()
|
||||
const NO_LAUNCH = process.argv.includes('--no-launch')
|
||||
|
||||
// 监听范围与扩展名
|
||||
// 注意:不要监听 simpleDemo/src/main/assets(构建注入产物)、res(prepare 会覆盖图标/启动图)、build 目录,否则构建自触发死循环
|
||||
const WATCH_ROOTS = [
|
||||
{ dir: path.join(ROOT, 'src'), recursive: true },
|
||||
{
|
||||
dir: path.join(ROOT, 'android-offline', 'HBuilder-Integrate-AS', 'simpleDemo', 'src', 'main', 'java'),
|
||||
recursive: true,
|
||||
},
|
||||
{
|
||||
// 只监听直接文件(AndroidManifest.xml),不递归:assets 是 prepare 注入产物
|
||||
dir: path.join(ROOT, 'android-offline', 'HBuilder-Integrate-AS', 'simpleDemo', 'src', 'main'),
|
||||
recursive: false,
|
||||
},
|
||||
]
|
||||
const WATCH_EXTS = new Set([
|
||||
'.vue', '.js', '.ts', '.json', '.scss', '.css', '.cjs', '.ps1', '.xml', '.java', '.png', '.jpg', '.jpeg', '.md',
|
||||
])
|
||||
|
||||
const log = (msg) => console.log(`[dev-adb] ${msg}`)
|
||||
const run = (cmd, args, opts = {}) => {
|
||||
// Windows 下通过 shell 执行,自动解析 npm.cmd / 全路径 exe
|
||||
const res = spawnSync(cmd, args, {
|
||||
cwd: opts.cwd || ROOT,
|
||||
stdio: 'inherit',
|
||||
env: { ...process.env, ...(opts.env || {}) },
|
||||
shell: process.platform === 'win32',
|
||||
})
|
||||
if (res.error) {
|
||||
console.error(`[dev-adb] spawn 失败 ${cmd}: ${res.error.message}`)
|
||||
return false
|
||||
}
|
||||
return res.status === 0
|
||||
}
|
||||
|
||||
// ---------- 1. 列出并解析设备 ----------
|
||||
function listDevices() {
|
||||
const res = spawnSync(ADB, ['devices', '-l'], { encoding: 'utf-8' })
|
||||
const out = res.stdout || ''
|
||||
log(`adb devices 输出:\n${out.trim()}`)
|
||||
const lines = out.split(/\r?\n/)
|
||||
const devices = []
|
||||
for (const line of lines) {
|
||||
const m = line.trim().match(/^(\S+)\s+device\b(.*)$/)
|
||||
if (m) {
|
||||
devices.push({ serial: m[1], desc: m[2].trim() })
|
||||
}
|
||||
}
|
||||
return devices
|
||||
}
|
||||
|
||||
function ask(question) {
|
||||
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
|
||||
return new Promise((resolve) => {
|
||||
rl.question(question, (answer) => {
|
||||
rl.close()
|
||||
resolve(String(answer || '').trim())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function pickDevice(devices) {
|
||||
if (devices.length === 0) {
|
||||
console.error('[dev-adb] 未检测到任何已连接设备,请检查 USB 连接/ADB 授权后重试')
|
||||
process.exit(1)
|
||||
}
|
||||
if (devices.length === 1) {
|
||||
log(`唯一设备,自动选中: ${devices[0].serial} (${devices[0].desc})`)
|
||||
return devices[0]
|
||||
}
|
||||
devices.forEach((d, i) => console.log(` [${i + 1}] ${d.serial} ${d.desc}`))
|
||||
const answer = await ask(`请选择设备序号 [1-${devices.length}],默认 1: `)
|
||||
const idx = answer ? Number(answer) - 1 : 0
|
||||
if (!Number.isInteger(idx) || idx < 0 || idx >= devices.length) {
|
||||
console.error(`[dev-adb] 无效序号: ${answer}`)
|
||||
process.exit(1)
|
||||
}
|
||||
return devices[idx]
|
||||
}
|
||||
|
||||
// ---------- 2. 构建 → 打包 → 安装 → 启动 ----------
|
||||
let logcatProc = null
|
||||
|
||||
// 真机 console 实时打印:logcat 只跟随 UniConsole(逻辑层) 与 UniViewConsole(视图层 renderjs)
|
||||
function startLogcat(serial) {
|
||||
if (logcatProc) {
|
||||
return
|
||||
}
|
||||
spawnSync(ADB, ['-s', serial, 'logcat', '-c'], { stdio: 'ignore' })
|
||||
logcatProc = spawn(ADB, ['-s', serial, 'logcat', '-v', 'time', 'UniConsole:V', 'UniViewConsole:V', '*:S'], {
|
||||
stdio: ['ignore', 'pipe', 'inherit'],
|
||||
})
|
||||
let buf = ''
|
||||
logcatProc.stdout.setEncoding('utf-8')
|
||||
logcatProc.stdout.on('data', (chunk) => {
|
||||
buf += chunk
|
||||
let idx
|
||||
while ((idx = buf.indexOf('\n')) >= 0) {
|
||||
const line = buf.slice(0, idx)
|
||||
buf = buf.slice(idx + 1)
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed) {
|
||||
continue
|
||||
}
|
||||
const isErr = trimmed.includes(' W/') || trimmed.includes(' E/')
|
||||
console.log(isErr ? `\x1b[31m[真机] ${trimmed}\x1b[0m` : `\x1b[36m[真机] ${trimmed}\x1b[0m`)
|
||||
}
|
||||
})
|
||||
logcatProc.on('exit', () => {
|
||||
logcatProc = null
|
||||
// adb 重连/设备重启后自动恢复跟随
|
||||
setTimeout(() => startLogcat(serial), 3000)
|
||||
})
|
||||
log('真机 console 实时打印已开启(UniConsole/UniViewConsole)')
|
||||
}
|
||||
|
||||
function clearLogcat(serial) {
|
||||
spawnSync(ADB, ['-s', serial, 'logcat', '-c'], { stdio: 'ignore' })
|
||||
}
|
||||
|
||||
function findApk() {
|
||||
// 优先按 package.json version 精确匹配
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf-8'))
|
||||
const exact = path.join(ROOT, 'release', 'android', `wms-worker-station_v${pkg.version}_release.apk`)
|
||||
if (fs.existsSync(exact)) {
|
||||
return exact
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略
|
||||
}
|
||||
// 兜底:目录里最新的 apk
|
||||
const dir = path.join(ROOT, 'release', 'android')
|
||||
if (!fs.existsSync(dir)) {
|
||||
return null
|
||||
}
|
||||
const apks = fs.readdirSync(dir).filter((f) => f.endsWith('.apk')).map((f) => ({
|
||||
name: f,
|
||||
mtime: fs.statSync(path.join(dir, f)).mtimeMs,
|
||||
}))
|
||||
if (apks.length === 0) {
|
||||
return null
|
||||
}
|
||||
apks.sort((a, b) => b.mtime - a.mtime)
|
||||
return path.join(dir, apks[0].name)
|
||||
}
|
||||
|
||||
let building = false
|
||||
let pending = false
|
||||
let lastChangeAt = 0
|
||||
let buildFinishedAt = 0
|
||||
|
||||
async function buildAndInstall(serial, trigger) {
|
||||
const t0 = Date.now()
|
||||
log(`开始构建(触发: ${trigger})`)
|
||||
// 1. uni-app 编译 App 资源
|
||||
if (!run('npm', ['run', 'build:app-plus'])) {
|
||||
log('✗ build:app-plus 失败,跳过安装')
|
||||
return false
|
||||
}
|
||||
// 2. 离线打包(prepare + gradle 增量 + 复制 APK),跳过发布上传
|
||||
if (!run('npm', ['run', 'android:pack', '--', '-NoUpload'])) {
|
||||
log('✗ android:pack 失败,跳过安装')
|
||||
return false
|
||||
}
|
||||
// 3. 定位 APK
|
||||
const apk = findApk()
|
||||
if (!apk) {
|
||||
log('✗ 未找到 APK 产物')
|
||||
return false
|
||||
}
|
||||
log(`APK: ${path.relative(ROOT, apk)}`)
|
||||
// 4. 安装(失败重试 2 次,设备忙时常见)
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const res = spawnSync(ADB, ['-s', serial, 'install', '-r', apk], { stdio: 'inherit' })
|
||||
if (res.status === 0) {
|
||||
break
|
||||
}
|
||||
if (i === 2) {
|
||||
log('✗ adb install 失败(已重试 3 次)')
|
||||
return false
|
||||
}
|
||||
log(`安装失败,2 秒后重试 (${i + 1}/2)`)
|
||||
await new Promise((r) => setTimeout(r, 2000))
|
||||
}
|
||||
// 5. 启动应用(Android 7 用 monkey 拉起 launcher 入口最稳)
|
||||
if (!NO_LAUNCH) {
|
||||
clearLogcat(serial)
|
||||
spawnSync(ADB, ['-s', serial, 'shell', 'am', 'force-stop', 'com.gztbyc.sandan'], { stdio: 'ignore' })
|
||||
spawnSync(ADB, ['-s', serial, 'shell', 'monkey', '-p', 'com.gztbyc.sandan', '-c', 'android.intent.category.LAUNCHER', '1'], { stdio: 'ignore' })
|
||||
log('已启动应用')
|
||||
}
|
||||
log(`✓ 完成,耗时 ${((Date.now() - t0) / 1000).toFixed(1)}s`)
|
||||
return true
|
||||
}
|
||||
|
||||
async function triggerBuild(serial, trigger) {
|
||||
if (building) {
|
||||
pending = true
|
||||
return
|
||||
}
|
||||
building = true
|
||||
try {
|
||||
await buildAndInstall(serial, trigger)
|
||||
} finally {
|
||||
building = false
|
||||
buildFinishedAt = Date.now()
|
||||
if (pending) {
|
||||
pending = false
|
||||
log('构建期间有新变更,继续构建...')
|
||||
triggerBuild(serial, 'pending')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 3. 目录监听(Windows 兼容:watch 每个子目录) ----------
|
||||
function collectWatchDirs() {
|
||||
const dirs = new Set()
|
||||
for (const root of WATCH_ROOTS) {
|
||||
if (!fs.existsSync(root.dir)) {
|
||||
log(`警告: 监听目录不存在: ${root.dir}`)
|
||||
continue
|
||||
}
|
||||
dirs.add(root.dir)
|
||||
if (!root.recursive) {
|
||||
continue
|
||||
}
|
||||
const walk = (dir) => {
|
||||
let entries = []
|
||||
try {
|
||||
entries = fs.readdirSync(dir, { withFileTypes: true })
|
||||
} catch (e) {
|
||||
return
|
||||
}
|
||||
for (const e of entries) {
|
||||
if (e.isDirectory()) {
|
||||
const full = path.join(dir, e.name)
|
||||
if (e.name === 'node_modules' || e.name === '.git' || e.name === 'build' || e.name === '.gradle') {
|
||||
continue
|
||||
}
|
||||
dirs.add(full)
|
||||
walk(full)
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(root.dir)
|
||||
}
|
||||
return [...dirs]
|
||||
}
|
||||
|
||||
function watchDirs(serial) {
|
||||
const watched = new Set()
|
||||
const attach = (dir) => {
|
||||
if (watched.has(dir)) {
|
||||
return
|
||||
}
|
||||
watched.add(dir)
|
||||
try {
|
||||
const watcher = fs.watch(dir, (eventType, filename) => {
|
||||
if (!filename) {
|
||||
return
|
||||
}
|
||||
// 构建期间自身写入产物(图标/启动图覆盖等)的变更直接忽略,防止自触发循环
|
||||
if (building || Date.now() - buildFinishedAt < 3000) {
|
||||
return
|
||||
}
|
||||
const ext = path.extname(filename).toLowerCase()
|
||||
if (!WATCH_EXTS.has(ext)) {
|
||||
return
|
||||
}
|
||||
const now = Date.now()
|
||||
if (now - lastChangeAt < 150) {
|
||||
// 一次保存可能触发多次事件,靠防抖合并
|
||||
}
|
||||
lastChangeAt = now
|
||||
clearTimeout(watchDirs._debounce)
|
||||
watchDirs._debounce = setTimeout(() => {
|
||||
triggerBuild(serial, `${dir}/${filename}`.slice(ROOT.length + 1))
|
||||
}, 800)
|
||||
})
|
||||
watcher.on('error', () => {
|
||||
// 目录可能被删除重建,稍后重新收集
|
||||
})
|
||||
} catch (e) {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
for (const dir of collectWatchDirs()) {
|
||||
attach(dir)
|
||||
}
|
||||
// 目录结构变化(新增/删除目录)时重新收集
|
||||
setInterval(() => {
|
||||
for (const dir of collectWatchDirs()) {
|
||||
attach(dir)
|
||||
}
|
||||
}, 10000)
|
||||
log(`正在监听 ${watched.size} 个目录,保存文件后自动构建重装...`)
|
||||
}
|
||||
|
||||
// ---------- 主流程 ----------
|
||||
async function main() {
|
||||
log(`ADB: ${ADB}`)
|
||||
const devices = listDevices()
|
||||
const target = await pickDevice(devices)
|
||||
log(`目标设备: ${target.serial}`)
|
||||
startLogcat(target.serial)
|
||||
watchDirs(target.serial)
|
||||
log('首次启动构建...')
|
||||
triggerBuild(target.serial, 'initial')
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('[dev-adb] 异常:', err)
|
||||
process.exit(1)
|
||||
})
|
||||
30
src/App.vue
30
src/App.vue
@ -9,6 +9,33 @@ const BASE_FONT_SIZE = 100
|
||||
// 真机 APP-PLUS 的 rem 由下方全局纯 CSS 承担(0.675 系数,修复真机退出登录后白屏),JS 仅 H5 参与计算
|
||||
const REM_SCALE = 0.28
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
// 打开应用后将系统音量调至最大(仓库环境语音播报需要;setStreamVolume 无需额外权限)
|
||||
function setSystemVolumeMax () {
|
||||
try {
|
||||
const main = plus.android.runtimeMainActivity()
|
||||
const Context = plus.android.importClass('android.content.Context')
|
||||
// Context.AUDIO_SERVICE 常量值为 "audio",访问失败时兜底用字符串
|
||||
const serviceName = Context.AUDIO_SERVICE || 'audio'
|
||||
const audioManager = main.getSystemService(serviceName)
|
||||
const streams = {
|
||||
music: 3, // STREAM_MUSIC 媒体音量(语音播报 innerAudioContext 走此通道)
|
||||
system: 1, // STREAM_SYSTEM 系统音量
|
||||
notification: 5, // STREAM_NOTIFICATION 通知音量
|
||||
alarm: 4, // STREAM_ALARM 闹钟音量
|
||||
ring: 2 // STREAM_RING 铃声音量
|
||||
}
|
||||
for (const name in streams) {
|
||||
// Native.js 桥接对象在 service 层不支持点方法调用,必须用 plus.android.invoke
|
||||
const max = plus.android.invoke(audioManager, 'getStreamMaxVolume', streams[name])
|
||||
plus.android.invoke(audioManager, 'setStreamVolume', streams[name], max, 0)
|
||||
}
|
||||
} catch (e) {
|
||||
// 音量设置失败不阻断启动
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
|
||||
function logScreenInfo () {
|
||||
try {
|
||||
const info = uni.getSystemInfoSync()
|
||||
@ -65,6 +92,9 @@ export default {
|
||||
onLaunch: function () {
|
||||
console.log('App Launch')
|
||||
setRemBase()
|
||||
// #ifdef APP-PLUS
|
||||
setSystemVolumeMax()
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
window.addEventListener('resize', setRemBase)
|
||||
// #endif
|
||||
|
||||
@ -47,6 +47,20 @@ export function getWorkbenchInfo(token: string) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前工作台班次打包统计(免登录、免鉴权)
|
||||
* - 统计窗口:本地时间当日 08:00 至次日 08:00(早于 08:00 为昨日 08:00 起)
|
||||
* - personal:group_wave_count/single_order_count/group_single_ratio/avg_piece_count
|
||||
* - group:group_wave_count/group_order_count/single_order_count
|
||||
*/
|
||||
export function getWorkbenchCount(token: string) {
|
||||
return request<ApiBody>(
|
||||
'workbench.getWorkbenchCount',
|
||||
{ token },
|
||||
{ skipAuth: true }
|
||||
)
|
||||
}
|
||||
|
||||
/** 工牌 / 条码码登录 */
|
||||
export function loginByCode(code: string) {
|
||||
return request<ApiBody>('user.loginByCode', { code }, { skipAuth: true })
|
||||
|
||||
41
src/main.js
41
src/main.js
@ -6,6 +6,47 @@ import appEnv from './config/env'
|
||||
import { installNavGuard } from './core/nav-guard'
|
||||
import { getVoice } from './core/voice'
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
// 真机调试:把逻辑层 console 转发到 logcat(tag: UniConsole),由 dev-adb 脚本实时打印到终端
|
||||
// (release 包 console 不会自动输出到 logcat,这里统一接管)
|
||||
try {
|
||||
const Log = plus.android.importClass('android.util.Log')
|
||||
const levelMap = { log: 'i', info: 'i', warn: 'w', error: 'e', debug: 'd' }
|
||||
const formatArgs = (args) => args.map((a) => {
|
||||
if (typeof a === 'string') return a
|
||||
if (a instanceof Error) return (a && a.stack) || String(a)
|
||||
try { return JSON.stringify(a) } catch (e) { return String(a) }
|
||||
}).join(' ')
|
||||
const emit = (level, ...args) => {
|
||||
try {
|
||||
// 注意:importClass 类的静态方法在 service 层不支持 plus.android.invoke,用点方法调用(已实测)
|
||||
Log[levelMap[level] || 'i']('UniConsole', formatArgs(args))
|
||||
} catch (e) {
|
||||
// 转发失败不阻断
|
||||
}
|
||||
}
|
||||
// 1) uni-app 编译后的 console.log 会走 uni.__log__(level, pos, ...args),需一并接管
|
||||
const origUniLog = typeof uni !== 'undefined' ? uni.__log__ : null
|
||||
if (typeof uni !== 'undefined') {
|
||||
uni.__log__ = function (level, pos, ...args) {
|
||||
emit(level, `${pos || ''} ${formatArgs(args)}`.trim())
|
||||
if (origUniLog) return origUniLog.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
// 2) 直接 console.* 调用也转发
|
||||
Object.keys(levelMap).forEach((level) => {
|
||||
const orig = typeof console[level] === 'function' ? console[level].bind(console) : null
|
||||
console[level] = function (...args) {
|
||||
emit(level, ...args)
|
||||
if (orig) orig(...args)
|
||||
}
|
||||
})
|
||||
Log.i('UniConsole', 'console 转发已安装')
|
||||
} catch (e) {
|
||||
// plus 不可用时保持原 console
|
||||
}
|
||||
// #endif
|
||||
|
||||
// 全局提示语音:所有 uni.showToast 同时语音播报(仓库作业场景,语音提示来自散单项目方案)
|
||||
const originalShowToast = uni.showToast
|
||||
uni.showToast = function (options) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "WMS工作台",
|
||||
"appid" : "__UNI__F18BF9C",
|
||||
"appid" : "__UNI__900BDC1",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.1",
|
||||
"versionCode" : "101",
|
||||
|
||||
@ -538,18 +538,12 @@ export default {
|
||||
}
|
||||
this.restoreWorkbenchMembers()
|
||||
this.restoreScanRecords()
|
||||
// 真机进入页面即锁横屏(远程提交特性);成员恢复沿用本地多成员模型 restoreWorkbenchMembers(已兼容旧单成员缓存)
|
||||
this.lockLandscape()
|
||||
this.loadTodayPackStat()
|
||||
this.loadWorkbenchInfo()
|
||||
},
|
||||
onShow() {
|
||||
try {
|
||||
this.pageActive = true
|
||||
this.lockLandscape()
|
||||
setTimeout(() => {
|
||||
this.lockLandscape()
|
||||
}, 300)
|
||||
this.attachPlusKeyboardListener()
|
||||
this.attachGlobalKeyboardListener()
|
||||
this.startScanWatchdog()
|
||||
@ -568,29 +562,6 @@ export default {
|
||||
this.clearIdleAutoLogoutTimer()
|
||||
},
|
||||
methods: {
|
||||
// 强制锁定横屏 + 全屏重排:真机 reLaunch 后新 WebView 可能以竖屏尺寸创建,需 setStyle 强制全屏
|
||||
lockLandscape() {
|
||||
// #ifdef APP-PLUS
|
||||
try {
|
||||
const screen = plus && plus.screen
|
||||
if (screen && typeof screen.lockOrientation === 'function') {
|
||||
screen.lockOrientation('landscape')
|
||||
console.log('[packaging] lockOrientation=landscape done')
|
||||
}
|
||||
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')
|
||||
}
|
||||
}
|
||||
return true
|
||||
} catch (e) {
|
||||
console.error('[packaging] lockOrientation 异常:', e)
|
||||
}
|
||||
// #endif
|
||||
return false
|
||||
},
|
||||
handlePackSearch() {
|
||||
const kw = this.dedupeRepeatedScan(String(this.keyword || '').trim())
|
||||
if (!kw) {
|
||||
@ -2877,9 +2848,19 @@ export default {
|
||||
</script>
|
||||
|
||||
<script module="remInject" lang="renderjs">
|
||||
import { installZeroViewportFix, installConsoleForward } from '../../render-common/viewport-fix.js'
|
||||
|
||||
export default {
|
||||
mounted() {
|
||||
// #ifdef APP-PLUS
|
||||
// 视图层 console 转发到 logcat(tag: UniViewConsole),dev-adb 终端实时可见
|
||||
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,新页面照此接入即可。
|
||||
// 已对照验证:移除自愈白屏复现,本修复必需保留。
|
||||
installZeroViewportFix()
|
||||
// 真机 rem 由 App.vue 全局纯 CSS(html { font-size: min(3.515625vw, 5.2734375vh) },0.675 系数)承担,
|
||||
// renderjs 不再覆盖,避免与 CSS 方案互相覆盖导致白屏/抖动
|
||||
return
|
||||
|
||||
95
src/render-common/viewport-fix.js
Normal file
95
src/render-common/viewport-fix.js
Normal file
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* 真机 WebView 0×0 视口自愈(供各页面 renderjs 模块 import)
|
||||
*
|
||||
* 背景:RK3288/Android7 真机上 reLaunch 创建的新页面 WebView 视口可能为 0×0,
|
||||
* CSS 的 vw/vh 随之计算为 0 → html fontSize=0 → 所有 rem 尺寸归零 → 白屏;
|
||||
* 切后台回前台能恢复(Activity resume 触发原生重排)。
|
||||
* 方案:检测到 0×0 视口时强制原生 decorView 重排自愈。
|
||||
* 详见根目录 README「真机坑:登录页 reLaunch 到打包模式白屏」章节。
|
||||
*
|
||||
* 注意:本文件会被打进 view 层(renderjs 环境),
|
||||
* - 可以使用 window / document / plus;
|
||||
* - 不能使用 uni.* API、不能依赖 Vue 实例。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 把视图层(renderjs)的 console 转发到 logcat(tag: UniViewConsole),
|
||||
* 供 dev-adb 脚本实时打印到终端(renderjs 的 console 默认不进 logcat)。
|
||||
* 与 src/main.js 的逻辑层转发(UniConsole)配套使用。
|
||||
*/
|
||||
export function installConsoleForward() {
|
||||
if (typeof plus === 'undefined' || !plus.android) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const Log = plus.android.importClass('android.util.Log')
|
||||
const levelMap = { log: 'i', info: 'i', warn: 'w', error: 'e', debug: 'd' }
|
||||
const formatArgs = (args) =>
|
||||
args
|
||||
.map((a) => {
|
||||
if (typeof a === 'string') {
|
||||
return a
|
||||
}
|
||||
if (a instanceof Error) {
|
||||
return (a && a.stack) || String(a)
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(a)
|
||||
} catch (e) {
|
||||
return String(a)
|
||||
}
|
||||
})
|
||||
.join(' ')
|
||||
Object.keys(levelMap).forEach((level) => {
|
||||
const orig = typeof console[level] === 'function' ? console[level].bind(console) : null
|
||||
console[level] = function (...args) {
|
||||
try {
|
||||
// 注意:importClass 类的静态方法用点方法调用(plus.android.invoke 静态方法在渲染层同样不可靠)
|
||||
Log[levelMap[level]]('UniViewConsole', formatArgs(args))
|
||||
} catch (e) {
|
||||
// 转发失败不阻断
|
||||
}
|
||||
if (orig) {
|
||||
orig(...args)
|
||||
}
|
||||
}
|
||||
})
|
||||
Log.i('UniViewConsole', '视图层 console 转发已安装')
|
||||
} catch (e) {
|
||||
// plus 不可用时保持原 console
|
||||
}
|
||||
}
|
||||
|
||||
export function installZeroViewportFix(options = {}) {
|
||||
// H5/非 APP 环境直接跳过(无 plus)
|
||||
if (typeof window === 'undefined' || typeof plus === 'undefined' || !plus.android) {
|
||||
return
|
||||
}
|
||||
const maxAttempts = options.maxAttempts || 8
|
||||
const interval = options.interval || 400
|
||||
const startDelay = options.startDelay || 300
|
||||
let attempts = 0
|
||||
|
||||
const fix = () => {
|
||||
// 视口已恢复则停止
|
||||
if (window.innerWidth > 0 && window.innerHeight > 0) {
|
||||
return
|
||||
}
|
||||
attempts++
|
||||
if (attempts > maxAttempts) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const main = plus.android.runtimeMainActivity()
|
||||
const win = plus.android.invoke(main, 'getWindow')
|
||||
const decor = plus.android.invoke(win, 'getDecorView')
|
||||
plus.android.invoke(decor, 'requestLayout')
|
||||
plus.android.invoke(decor, 'invalidate')
|
||||
} catch (e) {
|
||||
// 重排失败不阻断,等待系统侧恢复(切后台回前台仍可恢复)
|
||||
}
|
||||
setTimeout(fix, interval)
|
||||
}
|
||||
|
||||
setTimeout(fix, startDelay)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user