From 962d7157fc860836154cbeaa178fda1f6b27e445 Mon Sep 17 00:00:00 2001
From: zm2000 <18386612143@163.com>
Date: Tue, 31 Mar 2026 20:07:53 +0800
Subject: [PATCH] feat: add login update flow and debug logging
---
.eslintignore | 6 +
.eslintrc.cjs | 20 ++
core/store/modules/deviceInfo.js | 9 +
core/store/modules/user.js | 10 +-
manifest.json | 9 +-
pages/login/index.vue | 529 ++++++++++++++++++++++++++++++-
6 files changed, 575 insertions(+), 8 deletions(-)
create mode 100644 .eslintignore
create mode 100644 .eslintrc.cjs
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000..dc67e33
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,6 @@
+node_modules/
+dist/
+unpackage/
+uni_modules/
+.hbuilderx/
+*.min.js
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
new file mode 100644
index 0000000..90d4ac4
--- /dev/null
+++ b/.eslintrc.cjs
@@ -0,0 +1,20 @@
+module.exports = {
+ root: true,
+ env: {
+ browser: true,
+ node: true,
+ es2021: true
+ },
+ parserOptions: {
+ ecmaVersion: 'latest',
+ sourceType: 'module'
+ },
+ ignorePatterns: [
+ 'node_modules/',
+ 'dist/',
+ 'unpackage/',
+ 'uni_modules/',
+ '.hbuilderx/'
+ ],
+ rules: {}
+};
diff --git a/core/store/modules/deviceInfo.js b/core/store/modules/deviceInfo.js
index 4407bce..f919bce 100644
--- a/core/store/modules/deviceInfo.js
+++ b/core/store/modules/deviceInfo.js
@@ -85,6 +85,15 @@ const actions = {
collectedAt: new Date().toISOString()
};
+ // 输出 PDA 的屏幕宽高与窗口宽高,以及像素比,供调试使用
+ console.log('[deviceInfo] screen size:', {
+ screenWidth: baseDeviceInfo.screenWidth,
+ screenHeight: baseDeviceInfo.screenHeight,
+ windowWidth: baseDeviceInfo.windowWidth,
+ windowHeight: baseDeviceInfo.windowHeight,
+ pixelRatio: baseDeviceInfo.pixelRatio
+ });
+
if (save) {
dispatch('setDeviceInfo', baseDeviceInfo);
}
diff --git a/core/store/modules/user.js b/core/store/modules/user.js
index 1a5acc7..64bce8b 100644
--- a/core/store/modules/user.js
+++ b/core/store/modules/user.js
@@ -218,16 +218,18 @@ const actions = {
state,
dispatch
}, payload) {
- const code = String(payload?.code || payload?.uuid || '').trim();
+ const code = String(payload?.code || '').trim();
+ const uuid = String(payload?.uuid || '').trim();
+ const loginCode = code || uuid;
return new Promise((resolve, reject) => {
- if (!code) {
- reject({ msg: '缺少工牌标识' });
+ if (!loginCode) {
+ reject({ msg: '缺少或无效的登录码code' });
return;
}
http('user.loginByCode', {
- code,
+ code: loginCode,
device: state.app.device,
project: state.app.project
}).then(async response => {
diff --git a/manifest.json b/manifest.json
index f6e519e..98fad78 100644
--- a/manifest.json
+++ b/manifest.json
@@ -2,8 +2,8 @@
"name" : "WMS_PDA",
"appid" : "__UNI__0B3DAD3",
"description" : "多平台快速开发的UI框架",
- "versionName" : "2.0.37",
- "versionCode" : 1,
+ "versionName" : "1.0.8",
+ "versionCode" : 8,
"transformPx" : false,
"app-plus" : {
"optimization" : {
@@ -24,7 +24,10 @@
"nvueCompiler" : "uni-app",
"compilerVersion" : 3,
"modules" : {
- "Webview-x5" : {}
+ "Webview-x5" : {},
+ "Barcode" : {},
+ "Bluetooth" : {},
+ "Camera" : {}
},
"distribute" : {
"android" : {
diff --git a/pages/login/index.vue b/pages/login/index.vue
index 4423a10..934d1c9 100644
--- a/pages/login/index.vue
+++ b/pages/login/index.vue
@@ -55,6 +55,58 @@
+
+
+
+
+
+
+ 安装包
+ {{ updateInfo.file || '未提供文件名' }}
+
+
+ 发布时间
+ {{ formatUpdateTime(updateInfo.publishedAtUtc) }}
+
+
+ 检测到新版本,确认后将开始下载安装包。
+ 下载完成后会自动打开文件。
+
+
+
+
+ 正在下载更新
+ {{ updateDownloadProgress }}%
+
+
+
+
+
+
+ {{ updateErrorMessage }}
+
+
+
+
+
+
+
+
+
@@ -71,6 +123,22 @@ export default {
data() {
return {
bgStyle: '',
+ updateLogSeq: 0,
+ currentAppVersion: '',
+ showUpdateDialog: false,
+ isCheckingUpdate: false,
+ isDownloadingUpdate: false,
+ updateDownloadProgress: 0,
+ updateErrorMessage: '',
+ hasCheckedUpdate: false,
+ updateTask: null,
+ updateInfo: {
+ version: '',
+ file: '',
+ url: '',
+ sha256: '',
+ publishedAtUtc: ''
+ },
showLoginConfirm: false,
showPassword: false,
scanning: false,
@@ -94,12 +162,19 @@ export default {
const storageBg = uni.getStorageSync("bg");
const bgUrl = storageBg || "/static/loginbg.jpg";
this.bgStyle = `--bg-url: url(${bgUrl})`;
+ this.logNonBuildInfo('登录页启动调试信息', {
+ nodeEnv: process.env.NODE_ENV,
+ platform: process.env.VUE_APP_PLATFORM || 'unknown'
+ });
this.scanning = true;
uni.hideTabBar();
this.$store.dispatch('broadcast/setCallbacks', {
onResult: this.handleBroadcastResult
});
this.$store.dispatch('broadcast/start');
+ this.updateLogSeq = 0;
+ this.logUpdateStep('onLoad -> 准备执行 checkForAppUpdate');
+ this.checkForAppUpdate();
},
onShow() {
this.scanning = true;
@@ -112,6 +187,325 @@ export default {
this.$store.dispatch('broadcast/stop');
},
methods: {
+ logNonBuildInfo(message, payload) {
+ if (process.env.NODE_ENV === 'production') {
+ return;
+ }
+ if (typeof payload === 'undefined') {
+ console.log(`[non-build] ${message}`);
+ return;
+ }
+ console.log(`[non-build] ${message}`, payload);
+ },
+ logUpdateStep(step, payload) {
+ this.updateLogSeq += 1;
+ const seq = String(this.updateLogSeq).padStart(2, '0');
+ if (typeof payload === 'undefined') {
+ console.log(`[update][${seq}] ${step}`);
+ return;
+ }
+ console.log(`[update][${seq}] ${step}`, payload);
+ },
+ async checkForAppUpdate() {
+ this.logUpdateStep('checkForAppUpdate -> 开始执行');
+ if (this.hasCheckedUpdate || this.isCheckingUpdate) {
+ this.logUpdateStep('checkForAppUpdate -> 已检查过或正在检查,直接返回', {
+ hasCheckedUpdate: this.hasCheckedUpdate,
+ isCheckingUpdate: this.isCheckingUpdate
+ });
+ return;
+ }
+
+ if (typeof plus === 'undefined' || !plus.runtime) {
+ this.logUpdateStep('checkForAppUpdate -> 非 APP-PLUS 环境,跳过更新检查');
+ return;
+ }
+
+ this.hasCheckedUpdate = true;
+ this.isCheckingUpdate = true;
+ this.updateErrorMessage = '';
+ this.logUpdateStep('checkForAppUpdate -> 状态已置为检查中');
+
+ try {
+ this.logUpdateStep('checkForAppUpdate -> 并行获取当前版本和远端配置');
+ const [currentVersion, latestInfoRaw] = await Promise.all([
+ this.getCurrentAppVersion(),
+ this.fetchLatestVersionInfo()
+ ]);
+ const latestInfo = this.normalizeLatestInfo(latestInfoRaw);
+
+ this.currentAppVersion = currentVersion;
+ this.logUpdateStep('checkForAppUpdate -> 已拿到版本信息', {
+ currentVersion,
+ latestVersion: latestInfo && latestInfo.version ? latestInfo.version : ''
+ });
+ this.logUpdateStep('checkForAppUpdate -> 标准化后的远端配置', latestInfo || {});
+
+ if (!latestInfo || !latestInfo.version || !latestInfo.url) {
+ this.logUpdateStep('checkForAppUpdate -> 远端配置缺少必要字段,结束', latestInfo || {});
+ return;
+ }
+
+ const isNewer = this.isVersionNewer(latestInfo.version, currentVersion);
+ this.logUpdateStep('checkForAppUpdate -> 版本比较完成', {
+ latestVersion: latestInfo.version,
+ currentVersion,
+ isNewer
+ });
+
+ if (!isNewer) {
+ this.logUpdateStep('checkForAppUpdate -> 远端版本不高于当前版本,不弹窗');
+ return;
+ }
+
+ this.updateInfo = {
+ version: String(latestInfo.version || '').trim(),
+ file: String(latestInfo.file || '').trim(),
+ url: String(latestInfo.url || '').trim(),
+ sha256: String(latestInfo.sha256 || '').trim(),
+ publishedAtUtc: String(latestInfo.publishedAtUtc || '').trim()
+ };
+ this.showUpdateDialog = true;
+ this.logUpdateStep('checkForAppUpdate -> 发现新版本,显示更新弹窗', this.updateInfo);
+ } catch (error) {
+ this.logUpdateStep('checkForAppUpdate -> 检查异常', error);
+ console.warn('[update] check failed:', error);
+ } finally {
+ this.isCheckingUpdate = false;
+ this.logUpdateStep('checkForAppUpdate -> 结束,isCheckingUpdate=false');
+ }
+ },
+ fetchLatestVersionInfo() {
+ this.logUpdateStep('fetchLatestVersionInfo -> 发起请求', {
+ url: 'http://dl.wms.gztbyc.com/pda/latest.json'
+ });
+ return new Promise((resolve, reject) => {
+ uni.request({
+ url: 'http://dl.wms.gztbyc.com/pda/latest.json',
+ method: 'GET',
+ timeout: 10000,
+ success: (res) => {
+ this.logUpdateStep('fetchLatestVersionInfo -> 请求成功', {
+ statusCode: res.statusCode
+ });
+ if (res.statusCode !== 200) {
+ this.logUpdateStep('fetchLatestVersionInfo -> 状态码异常,reject', {
+ statusCode: res.statusCode
+ });
+ reject(new Error(`更新配置获取失败: ${res.statusCode}`));
+ return;
+ }
+
+ try {
+ const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
+ this.logUpdateStep('fetchLatestVersionInfo -> 配置解析成功', data || {});
+ resolve(data || {});
+ } catch (parseError) {
+ this.logUpdateStep('fetchLatestVersionInfo -> 配置解析失败', parseError);
+ reject(parseError);
+ }
+ },
+ fail: (error) => {
+ this.logUpdateStep('fetchLatestVersionInfo -> 请求失败', error);
+ reject(error || new Error('更新配置获取失败'));
+ }
+ });
+ });
+ },
+ normalizeLatestInfo(raw) {
+ const source = raw && typeof raw === 'object' ? raw : {};
+ const version = String(source.version || source.versionName || source.appVersion || '').trim();
+ const url = String(
+ source.url ||
+ source.downloadUrl ||
+ source.apkUrl ||
+ source.download_url ||
+ ''
+ ).trim();
+ const file = String(source.file || source.fileName || source.apkName || source.name || '').trim();
+
+ return {
+ ...source,
+ version,
+ url,
+ file,
+ sha256: String(source.sha256 || source.md5 || '').trim(),
+ publishedAtUtc: String(source.publishedAtUtc || source.publishedAt || source.releaseTime || '').trim()
+ };
+ },
+ getCurrentAppVersion() {
+ this.logUpdateStep('getCurrentAppVersion -> 开始读取当前版本');
+ return new Promise((resolve) => {
+ if (typeof plus === 'undefined' || !plus.runtime) {
+ this.logUpdateStep('getCurrentAppVersion -> 非 APP-PLUS,返回空版本');
+ resolve('');
+ return;
+ }
+
+ try {
+ plus.runtime.getProperty(plus.runtime.appid, (info) => {
+ const version = String(info?.version || plus.runtime.version || '').trim();
+ this.logUpdateStep('getCurrentAppVersion -> 读取成功', {
+ version,
+ appid: plus.runtime.appid
+ });
+ resolve(version);
+ });
+ } catch (error) {
+ const fallbackVersion = String((typeof plus !== 'undefined' && plus.runtime && plus.runtime.version) || '').trim();
+ this.logUpdateStep('getCurrentAppVersion -> 读取异常,走兜底版本', {
+ fallbackVersion,
+ error
+ });
+ resolve(fallbackVersion);
+ }
+ });
+ },
+ isVersionNewer(latestVersion, currentVersion) {
+ const normalize = (version) => String(version || '')
+ .split('.')
+ .map(item => parseInt(item, 10) || 0);
+
+ const latest = normalize(latestVersion);
+ const current = normalize(currentVersion);
+
+ const maxLength = Math.max(latest.length, current.length);
+ for (let i = 0; i < maxLength; i++) {
+ const latestPart = latest[i] || 0;
+ const currentPart = current[i] || 0;
+
+ if (latestPart > currentPart) {
+ return true;
+ }
+ if (latestPart < currentPart) {
+ return false;
+ }
+ }
+
+ return false;
+ },
+ formatUpdateTime(value) {
+ if (!value) {
+ return '';
+ }
+
+ const date = new Date(value);
+ if (Number.isNaN(date.getTime())) {
+ return value;
+ }
+
+ const pad = (num) => String(num).padStart(2, '0');
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
+ },
+ closeUpdateDialog() {
+ if (this.isDownloadingUpdate) {
+ this.logUpdateStep('closeUpdateDialog -> 下载中,禁止关闭弹窗');
+ return;
+ }
+
+ this.showUpdateDialog = false;
+ this.updateErrorMessage = '';
+ this.logUpdateStep('closeUpdateDialog -> 用户取消更新,弹窗关闭');
+ },
+ confirmUpdateDownload() {
+ if (this.isDownloadingUpdate) {
+ this.logUpdateStep('confirmUpdateDownload -> 已在下载中,忽略重复点击');
+ return;
+ }
+
+ this.logUpdateStep('confirmUpdateDownload -> 用户确认更新,准备下载');
+ this.startUpdateDownload();
+ },
+ startUpdateDownload() {
+ this.logUpdateStep('startUpdateDownload -> 开始下载流程', {
+ url: this.updateInfo.url,
+ file: this.updateInfo.file
+ });
+ if (!this.updateInfo.url) {
+ this.updateErrorMessage = '未获取到下载地址';
+ this.logUpdateStep('startUpdateDownload -> 缺少下载地址,终止');
+ return;
+ }
+
+ this.isDownloadingUpdate = true;
+ this.updateDownloadProgress = 0;
+ this.updateErrorMessage = '';
+
+ const downloadTask = uni.downloadFile({
+ url: this.updateInfo.url,
+ success: (res) => {
+ this.updateTask = null;
+ this.logUpdateStep('startUpdateDownload -> 下载完成回调', {
+ statusCode: res.statusCode,
+ tempFilePath: res.tempFilePath
+ });
+ if (res.statusCode !== 200 || !res.tempFilePath) {
+ this.isDownloadingUpdate = false;
+ this.updateErrorMessage = '安装包下载失败';
+ this.logUpdateStep('startUpdateDownload -> 下载结果无效,终止');
+ return;
+ }
+
+ this.updateDownloadProgress = 100;
+ this.logUpdateStep('startUpdateDownload -> 下载成功,准备打开文件');
+ this.openDownloadedFile(res.tempFilePath);
+ },
+ fail: (error) => {
+ this.updateTask = null;
+ this.isDownloadingUpdate = false;
+ this.updateErrorMessage = error?.errMsg || '安装包下载失败';
+ this.logUpdateStep('startUpdateDownload -> 下载失败', error);
+ }
+ });
+
+ this.updateTask = downloadTask;
+ this.logUpdateStep('startUpdateDownload -> downloadTask 已创建');
+
+ if (downloadTask && typeof downloadTask.onProgressUpdate === 'function') {
+ downloadTask.onProgressUpdate((progressEvent) => {
+ this.updateDownloadProgress = Number(progressEvent.progress || 0);
+ this.logUpdateStep('startUpdateDownload -> 下载进度', {
+ progress: this.updateDownloadProgress,
+ totalBytesWritten: progressEvent.totalBytesWritten,
+ totalBytesExpectedToWrite: progressEvent.totalBytesExpectedToWrite
+ });
+ });
+ } else {
+ this.logUpdateStep('startUpdateDownload -> 当前环境不支持进度回调');
+ }
+ },
+ openDownloadedFile(filePath) {
+ this.logUpdateStep('openDownloadedFile -> 尝试打开下载文件', {
+ filePath
+ });
+ if (typeof plus === 'undefined' || !plus.runtime || typeof plus.runtime.openFile !== 'function') {
+ this.updateTask = null;
+ this.isDownloadingUpdate = false;
+ this.updateErrorMessage = '当前环境不支持打开安装包';
+ this.logUpdateStep('openDownloadedFile -> 环境不支持 plus.runtime.openFile');
+ return;
+ }
+
+ try {
+ plus.runtime.openFile(filePath, {}, () => {
+ this.updateTask = null;
+ this.isDownloadingUpdate = false;
+ this.updateErrorMessage = '';
+ this.showUpdateDialog = false;
+ this.logUpdateStep('openDownloadedFile -> 文件打开成功,更新流程完成');
+ }, (error) => {
+ this.updateTask = null;
+ this.isDownloadingUpdate = false;
+ this.updateErrorMessage = error?.message || '文件已下载,但打开失败';
+ this.logUpdateStep('openDownloadedFile -> 文件打开失败', error);
+ });
+ } catch (error) {
+ this.updateTask = null;
+ this.isDownloadingUpdate = false;
+ this.updateErrorMessage = error?.message || '文件已下载,但打开失败';
+ this.logUpdateStep('openDownloadedFile -> 调用异常', error);
+ }
+ },
togglePasswordVisibility() {
this.showPassword = !this.showPassword;
},
@@ -243,13 +637,16 @@ export default {
async confirmLogin() {
try {
const code = String(this.deviceCode || '').trim()
- if (!code) {
+ const uuid = String(this.scanUuid || this.parseScanUuid(code) || '').trim()
+ if (!code || !uuid) {
throw new Error('请先扫描有效工牌')
}
await this.$store.dispatch('loginByCode', { code })
uni.switchTab({ url: '/pages/index/index' })
} catch (error) {
this.scanning = true;
+ this.deviceCode = '';
+ this.scanUuid = '';
this.currentDevice = null;
this.$store.dispatch('broadcast/resume');
uni.showToast({
@@ -318,6 +715,136 @@ export default {
box-sizing: border-box;
}
+.update-mask {
+ position: fixed;
+ left: 0;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ background: rgba(0, 0, 0, 0.48);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ z-index: 9999;
+ padding: 32rpx;
+ box-sizing: border-box;
+}
+
+.update-dialog {
+ width: 100%;
+ max-width: 680rpx;
+ background: #fff;
+ border-radius: 24rpx;
+ padding: 36rpx;
+ box-sizing: border-box;
+ box-shadow: 0 24rpx 80rpx rgba(0, 0, 0, 0.18);
+}
+
+.update-header {
+ display: flex;
+ flex-direction: column;
+ gap: 10rpx;
+ margin-bottom: 28rpx;
+}
+
+.update-title {
+ font-size: 36rpx;
+ font-weight: 600;
+ color: #222;
+}
+
+.update-version {
+ font-size: 24rpx;
+ color: #5c6b77;
+}
+
+.update-body {
+ display: flex;
+ flex-direction: column;
+ gap: 20rpx;
+}
+
+.update-row {
+ display: flex;
+ justify-content: space-between;
+ align-items: flex-start;
+ gap: 20rpx;
+}
+
+.update-label {
+ font-size: 26rpx;
+ color: #86909c;
+ flex-shrink: 0;
+}
+
+.update-value {
+ font-size: 26rpx;
+ color: #333;
+ text-align: right;
+ word-break: break-all;
+}
+
+.update-tip-box {
+ background: #f6f9ff;
+ border-radius: 16rpx;
+ padding: 24rpx;
+ display: flex;
+ flex-direction: column;
+ gap: 12rpx;
+}
+
+.update-tip {
+ font-size: 26rpx;
+ line-height: 1.6;
+ color: #4e5969;
+}
+
+.update-progress-section {
+ margin-top: 8rpx;
+}
+
+.update-progress-head {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 14rpx;
+}
+
+.update-progress-text {
+ font-size: 26rpx;
+ color: #333;
+}
+
+.update-progress-bar {
+ height: 18rpx;
+ background: #eef1f5;
+ border-radius: 999rpx;
+ overflow: hidden;
+}
+
+.update-progress-inner {
+ height: 100%;
+ background: linear-gradient(90deg, #2979ff, #19be6b);
+ border-radius: 999rpx;
+ transition: width 0.2s ease;
+}
+
+.update-error {
+ font-size: 24rpx;
+ color: #fa3534;
+ line-height: 1.6;
+}
+
+.update-actions {
+ display: flex;
+ gap: 20rpx;
+ margin-top: 32rpx;
+}
+
+.update-actions :deep(.u-button) {
+ flex: 1;
+}
+
.header-section {
text-align: left;
margin-bottom: 60rpx;