diff --git a/src/pages/devicesSearch/ocrSearch.nvue b/src/pages/devicesSearch/ocrSearch.nvue index 29c8a71..2034e4a 100644 --- a/src/pages/devicesSearch/ocrSearch.nvue +++ b/src/pages/devicesSearch/ocrSearch.nvue @@ -164,11 +164,15 @@ export default { showFocusIndicator: false, focusIndicatorStyle: {}, autoFocusEnabled: true, - focusTimeout: null + focusTimeout: null, + // 设备信息 + systemInfo: null } }, onShow() { this.initializeCordova(); + // 获取设备信息用于相机配置 + this.getDeviceInfo(); }, onHide() { this.cleanup(); @@ -177,6 +181,36 @@ export default { this.cleanup(); }, methods: { + // 获取设备信息 + getDeviceInfo() { + try { + const systemInfo = uni.getSystemInfoSync(); + console.log('设备信息:', systemInfo); + this.systemInfo = systemInfo; + } catch (error) { + console.error('获取设备信息失败:', error); + } + }, + + // 设置全屏模式(仅Android) + setFullscreenMode(enable) { + try { + // #ifdef APP-PLUS + if (this.systemInfo && this.systemInfo.platform === 'android') { + if (enable) { + // 隐藏状态栏和导航栏 + plus.navigator.setFullscreen(true); + } else { + // 恢复状态栏和导航栏 + plus.navigator.setFullscreen(false); + } + } + // #endif + } catch (error) { + console.error('设置全屏模式失败:', error); + } + }, + // 初始化Cordova - 改进版本 initializeCordova() { console.log('开始初始化Cordova...'); @@ -289,6 +323,9 @@ export default { } } try { + // 在Android上尝试全屏模式 + this.setFullscreenMode(true); + // 显示相机界面 this.showCamera = true; // 等待UI更新 @@ -298,6 +335,7 @@ export default { } catch (error) { console.error('打开相机失败:', error); this.showCamera = false; + this.setFullscreenMode(false); uni.showToast({ title: error.message || '打开相机失败', icon: 'none', @@ -316,18 +354,50 @@ export default { return; } - // 获取屏幕尺寸 - const screenWidth = uni.getSystemInfoSync().screenWidth; - const screenHeight = uni.getSystemInfoSync().screenHeight; + // 获取屏幕尺寸和状态栏高度 + const systemInfo = this.systemInfo || uni.getSystemInfoSync(); + const screenWidth = systemInfo.screenWidth; + const screenHeight = systemInfo.screenHeight; + const statusBarHeight = systemInfo.statusBarHeight || 0; + + // 判断平台和设备,动态调整配置 + let cameraY = 0; + let cameraHeight = screenHeight; + let toBack = false; + + // Android设备处理导航栏遮挡问题 + if (systemInfo.platform === 'android') { + // 对于Android,尝试避开导航栏 + const navigationBarHeight = 44; + cameraY = statusBarHeight + navigationBarHeight; + cameraHeight = screenHeight - cameraY; + toBack = false; + } else { + // iOS或其他平台,使用全屏预览 + cameraY = 0; + cameraHeight = screenHeight; + toBack = true; + } + + console.log('屏幕信息:', { + platform: systemInfo.platform, + screenWidth, + screenHeight, + statusBarHeight, + cameraY, + cameraHeight, + toBack + }); + const options = { x: 0, - y: 0, - width: window.innerWidth || 375, - height: window.innerHeight || 667, + y: cameraY, + width: screenWidth, + height: cameraHeight, camera: CameraPreview.CAMERA_DIRECTION?.BACK || 'back', tapPhoto: false, previewDrag: false, - toBack: true, // 设置为 true,让相机显示在背景 + toBack: toBack, // 根据平台动态设置 alpha: 1, tapFocus: true, // 启用点击聚焦 disableExifHeaderStripping: false @@ -513,6 +583,8 @@ export default { this.showCamera = false; this.cameraStarted = false; this.resetFocusState(); + // 恢复全屏模式 + this.setFullscreenMode(false); } }, @@ -894,6 +966,8 @@ export default { } // 重置聚焦状态 this.resetFocusState(); + // 恢复全屏模式 + this.setFullscreenMode(false); } } } @@ -946,13 +1020,13 @@ export default { left: 0; width: 100vw; height: 100vh; - background-color: transparent; + background-color: #000000; z-index: 99999; } .top-tip { position: absolute; - top: 80rpx; + top: 120rpx; left: 50%; transform: translateX(-50%); z-index: 10; @@ -972,7 +1046,7 @@ export default { /* 聚焦状态提示 */ .focus-tip { position: absolute; - top: 160rpx; + top: 200rpx; left: 50%; transform: translateX(-50%); z-index: 10;