ocr识别相机修改
This commit is contained in:
parent
236d4e237c
commit
6a02be057f
|
|
@ -164,11 +164,15 @@ export default {
|
||||||
showFocusIndicator: false,
|
showFocusIndicator: false,
|
||||||
focusIndicatorStyle: {},
|
focusIndicatorStyle: {},
|
||||||
autoFocusEnabled: true,
|
autoFocusEnabled: true,
|
||||||
focusTimeout: null
|
focusTimeout: null,
|
||||||
|
// 设备信息
|
||||||
|
systemInfo: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.initializeCordova();
|
this.initializeCordova();
|
||||||
|
// 获取设备信息用于相机配置
|
||||||
|
this.getDeviceInfo();
|
||||||
},
|
},
|
||||||
onHide() {
|
onHide() {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
|
|
@ -177,6 +181,36 @@ export default {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
},
|
},
|
||||||
methods: {
|
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 - 改进版本
|
// 初始化Cordova - 改进版本
|
||||||
initializeCordova() {
|
initializeCordova() {
|
||||||
console.log('开始初始化Cordova...');
|
console.log('开始初始化Cordova...');
|
||||||
|
|
@ -289,6 +323,9 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
// 在Android上尝试全屏模式
|
||||||
|
this.setFullscreenMode(true);
|
||||||
|
|
||||||
// 显示相机界面
|
// 显示相机界面
|
||||||
this.showCamera = true;
|
this.showCamera = true;
|
||||||
// 等待UI更新
|
// 等待UI更新
|
||||||
|
|
@ -298,6 +335,7 @@ export default {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('打开相机失败:', error);
|
console.error('打开相机失败:', error);
|
||||||
this.showCamera = false;
|
this.showCamera = false;
|
||||||
|
this.setFullscreenMode(false);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: error.message || '打开相机失败',
|
title: error.message || '打开相机失败',
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
|
|
@ -316,18 +354,50 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取屏幕尺寸
|
// 获取屏幕尺寸和状态栏高度
|
||||||
const screenWidth = uni.getSystemInfoSync().screenWidth;
|
const systemInfo = this.systemInfo || uni.getSystemInfoSync();
|
||||||
const screenHeight = uni.getSystemInfoSync().screenHeight;
|
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 = {
|
const options = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: cameraY,
|
||||||
width: window.innerWidth || 375,
|
width: screenWidth,
|
||||||
height: window.innerHeight || 667,
|
height: cameraHeight,
|
||||||
camera: CameraPreview.CAMERA_DIRECTION?.BACK || 'back',
|
camera: CameraPreview.CAMERA_DIRECTION?.BACK || 'back',
|
||||||
tapPhoto: false,
|
tapPhoto: false,
|
||||||
previewDrag: false,
|
previewDrag: false,
|
||||||
toBack: true, // 设置为 true,让相机显示在背景
|
toBack: toBack, // 根据平台动态设置
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
tapFocus: true, // 启用点击聚焦
|
tapFocus: true, // 启用点击聚焦
|
||||||
disableExifHeaderStripping: false
|
disableExifHeaderStripping: false
|
||||||
|
|
@ -513,6 +583,8 @@ export default {
|
||||||
this.showCamera = false;
|
this.showCamera = false;
|
||||||
this.cameraStarted = false;
|
this.cameraStarted = false;
|
||||||
this.resetFocusState();
|
this.resetFocusState();
|
||||||
|
// 恢复全屏模式
|
||||||
|
this.setFullscreenMode(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -894,6 +966,8 @@ export default {
|
||||||
}
|
}
|
||||||
// 重置聚焦状态
|
// 重置聚焦状态
|
||||||
this.resetFocusState();
|
this.resetFocusState();
|
||||||
|
// 恢复全屏模式
|
||||||
|
this.setFullscreenMode(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -946,13 +1020,13 @@ export default {
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
background-color: transparent;
|
background-color: #000000;
|
||||||
z-index: 99999;
|
z-index: 99999;
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-tip {
|
.top-tip {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 80rpx;
|
top: 120rpx;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
|
@ -972,7 +1046,7 @@ export default {
|
||||||
/* 聚焦状态提示 */
|
/* 聚焦状态提示 */
|
||||||
.focus-tip {
|
.focus-tip {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 160rpx;
|
top: 200rpx;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue