This commit is contained in:
hongchao 2025-08-04 16:00:55 +08:00
commit 4e65fff14b
5 changed files with 343 additions and 1433 deletions

View File

@ -87,11 +87,18 @@
<div v-for="(img, index) in imgList" :key="index" class="upload-item">
<image :src="img.url" style="width: 160rpx; height: 160rpx" mode="aspectFill"></image>
<view class="delete-btn" @click.stop="deleteImage(index)">×</view>
<PreviewImg :imgUrl="img.url" />
</div>
<div class="upload" @click="uploadImg" v-if="imgList.length < 3">+</div>
</div>
</uni-col>
</uni-row>
<uni-row style="display: flex; align-items: center">
<uni-col :span="4">备注</uni-col>
<uni-col :span="20">
<uni-easyinput placeholder="请输入备注" v-model="remark" :clearable="false" />
</uni-col>
</uni-row>
</div>
<div class="btn">
<!-- <button class="btn-cont" @click="reject">取消</button> -->
@ -108,6 +115,7 @@ import ScanQrCode from '@/pages/devicesSearch/ScanQrCode.vue'
import { baseURL } from '@/utils/http'
import { useMemberStore } from '@/stores'
import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm'
import PreviewImg from '@/components/PreviewImg/index.vue'
const memberStore = useMemberStore()
const backPerson = ref('')
const phone = ref('')
@ -118,6 +126,7 @@ const bmFileInfos = ref([])
const qrCode = ref('') //
const maInfo = ref({}) //
const scanQrCodeRef = ref(null)
const remark = ref('')
//
@ -237,6 +246,7 @@ const submitCode = () => {
badNum: apDetection.value == '不合格' ? 1 : 0,
bmFileInfos: bmFileInfos.value,
preNum: 1,
remark: remark.value,
},
]
let param = {

View File

@ -79,14 +79,14 @@ export default {
return;
}
document.addEventListener('deviceready', () => {
if (cordova.plugins && cordova.plugins.camerapreview) {
window.CameraPreview = cordova.plugins.camerapreview;
// document.addEventListener('deviceready', () => {
// if (cordova.plugins && cordova.plugins.camerapreview) {
// window.CameraPreview = cordova.plugins.camerapreview;
this.startCamera();
} else {
console.error('CameraPreview插件未加载');
}
}, false);
// } else {
// console.error('CameraPreview');
// }
// }, false);
},
//

View File

@ -21,7 +21,7 @@ export default {
methods: {
//
openCamera() {
this.$cordova.plugins.cameraPreview.startCamera({
window.CameraPreview.startCamera({
x: 0,
y: 0,
width: window.screen.width,

File diff suppressed because it is too large Load Diff

View File

@ -76,10 +76,16 @@
</view>
</view>
<!-- 相机预览页面 - 修改为固定全屏 -->
<!-- 相机预览页面 -->
<view v-if="showCamera" class="camera-container">
<!-- 底部控制区 -->
<view class="bottom-controls">
<view v-if="showCamera" class="camera-wrapper">
<!-- 相机预览容器 - 单独放置 -->
<view class="camera-preview-container"></view>
<!-- UI控制层 - 独立于相机预览 -->
<view class="camera-ui-layer">
<!-- 底部控制区 -->
<view class="bottom-controls">
<view class="control-btn" @click="closeCamera">
<text class="control-icon"></text>
</view>
@ -99,12 +105,7 @@
</view>
</view>
</view>
<!-- 隐藏的canvas用于图片处理 -->
<canvas
canvas-id="imageCanvas"
style="position: fixed; top: -9999px; left: -9999px; width: 1px; height: 1px;"
></canvas>
</view>
</view>
</template>
@ -163,25 +164,6 @@ export default {
}
},
// 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...');
@ -259,10 +241,7 @@ export default {
getCameraPlugin() {
//
const possiblePaths = [
() => window.CameraPreview, //
() => window.cordova?.plugins?.CameraPreview,
() => window.plugins?.CameraPreview,
() => cordova?.plugins?.CameraPreview
() => window.CameraPreview //
];
for (let getPlugin of possiblePaths) {
try {
@ -311,59 +290,45 @@ export default {
}
},
// -
// -
// -
async initCamera() {
return new Promise((resolve, reject) => {
console.log('初始化相机预览...');
const CameraPreview = this.getCameraPlugin();
if (!CameraPreview) {
reject(new Error('相机插件不可用'));
return;
}
//
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 = true; // UI
console.log('屏幕信息:', {
platform: systemInfo.platform,
screenWidth,
screenHeight,
statusBarHeight,
cameraY,
cameraHeight,
toBack
});
//
const cameraWrapper = document.querySelector('.camera-wrapper');
if (!cameraWrapper) {
reject(new Error('找不到相机容器'));
return;
}
const rect = cameraWrapper.getBoundingClientRect();
const options = {
x: 0,
y: cameraY,
width: screenWidth,
height: cameraHeight,
x: rect.left,
y: rect.top,
width: rect.width,
height: rect.height,
camera: CameraPreview.CAMERA_DIRECTION?.BACK || 'back',
tapPhoto: false,
previewDrag: false,
toBack: toBack, //
toBack: false, // WebView
alpha: 1,
tapFocus: true, //
tapFocus: true,
disableExifHeaderStripping: false
};
console.log('相机配置:', options);
CameraPreview.startCamera(
options,
(result) => {
console.log('相机启动成功:', result);
this.cameraStarted = true;
//
this.performAutoFocus();
resolve();
},
(error) => {
@ -375,153 +340,27 @@ export default {
});
},
//
async performAutoFocus() {
if (!this.cameraStarted || !this.autoFocusEnabled) {
return;
}
//
handleOverlayClick(event) {
//
const rect = event.currentTarget.getBoundingClientRect();
const x = event.touches[0].clientX - rect.left;
const y = event.touches[0].clientY - rect.top;
const CameraPreview = this.getCameraPlugin();
if (!CameraPreview || typeof CameraPreview.setFocus !== 'function') {
console.log('相机插件不支持聚焦功能');
return;
}
try {
this.isFocusing = true;
this.focusSuccess = false;
//
if (this.focusTimeout) {
clearTimeout(this.focusTimeout);
}
console.log('开始自动聚焦...');
await new Promise((resolve, reject)=> {
//
this.focusTimeout = setTimeout(() => {
console.log('聚焦超时');
this.isFocusing = false;
resolve();
}, 3000);
CameraPreview.setFocus(
(result) => {
console.log('自动聚焦成功:', result);
if (this.focusTimeout) {
clearTimeout(this.focusTimeout);
this.focusTimeout = null;
}
this.isFocusing = false;
this.focusSuccess = true;
//
setTimeout(() => {
this.focusSuccess = false;
}, 1000);
resolve();
},
(error) => {
console.error('自动聚焦失败:', error);
if (this.focusTimeout) {
clearTimeout(this.focusTimeout);
this.focusTimeout = null;
}
this.isFocusing = false;
resolve(); // 使
}
);
});
} catch (error) {
console.error('聚焦过程出错:', error);
this.isFocusing = false;
}
//
this.tapToFocus(x, y);
},
//
async handleTapToFocus(event) {
if (!this.cameraStarted || this.isFocusing) {
return;
}
//
tapToFocus(x, y) {
const CameraPreview = this.getCameraPlugin();
if (!CameraPreview || typeof CameraPreview.tapToFocus !== 'function') {
console.log('相机插件不支持点击聚焦功能');
return;
}
try {
//
const rect = event.currentTarget.getBoundingClientRect();
const x = event.detail.x - rect.left;
const y = event.detail.y - rect.top;
// (0-1)
const relativeX = x / rect.width;
const relativeY = y / rect.height;
console.log('点击聚焦位置:', { x: relativeX, y: relativeY });
//
this.showFocusIndicator = true;
this.focusIndicatorStyle = {
left: `${x - 30}rpx`,
top: `${y - 30}rpx`
};
this.isFocusing = true;
this.focusSuccess = false;
//
if (this.focusTimeout) {
clearTimeout(this.focusTimeout);
}
await new Promise((resolve, reject)=> {
//
this.focusTimeout = setTimeout(() => {
console.log('点击聚焦超时');
this.isFocusing = false;
this.showFocusIndicator = false;
resolve();
}, 3000);
CameraPreview.tapToFocus(
relativeX,
relativeY,
(result) => {
console.log('点击聚焦成功:', result);
if (this.focusTimeout) {
clearTimeout(this.focusTimeout);
this.focusTimeout = null;
}
this.isFocusing = false;
this.focusSuccess = true;
//
setTimeout(() => {
this.focusSuccess = false;
this.showFocusIndicator = false;
}, 1000);
resolve();
},
(error) => {
console.error('点击聚焦失败:', error);
if (this.focusTimeout) {
clearTimeout(this.focusTimeout);
this.focusTimeout = null;
}
this.isFocusing = false;
this.showFocusIndicator = false;
resolve(); // 使
}
);
}
)
;
} catch (error) {
console.error('点击聚焦过程出错:', error);
this.isFocusing = false;
this.showFocusIndicator = false;
if (CameraPreview && this.cameraStarted) {
CameraPreview.tapToFocus(
x,
y,
() => console.log('聚焦成功'),
(error) => console.error('聚焦失败', error)
);
}
},
@ -900,6 +739,15 @@ export default {
//
cleanup() {
console.log('清理资源...');
if (this.cameraStarted) {
const CameraPreview = this.getCameraPlugin();
if (CameraPreview) {
CameraPreview.setOnView(null); //
CameraPreview.stopCamera();
}
this.cameraStarted = false;
}
//
if (this.deviceReadyTimeout) {
clearTimeout(this.deviceReadyTimeout);
@ -923,6 +771,37 @@ export default {
</script>
<style>
/* 新增相机包装器样式 */
.camera-wrapper {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10000; /* 基础层级 */
}
/* 相机预览容器 - 无内容,仅用于定位 */
.camera-preview-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1; /* 较低层级 */
}
/* UI控制层 - 显示在相机之上 */
.camera-ui-layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2; /* 高于相机预览 */
pointer-events: none; /* 允许点击穿透到相机 */
}
.page-container {
display: flex;
height: auto;
@ -964,27 +843,43 @@ export default {
/* 相机预览样式 */
.camera-container {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: #000000;
z-index: 100000; /* 增加相机预览层级 */
position: relative;
width: 100%;
height: 70vh; /* 增加高度 */
background-color: #000;
overflow: hidden;
z-index: 1000; /* 确保在H5层级中 */
}
/* 控制区 */
.bottom-controls {
.camera-preview {
position: absolute;
bottom: 100rpx;
top: 0;
left: 0;
right: 0;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 0 100rpx;
z-index: 100001; /* 底部控制按钮层级 */
width: 100%;
height: 100%;
z-index: 1; /* 相机预览在底层 */
}
/* 透明覆盖层 - 关键 */
.camera-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2; /* 覆盖层在上层 */
pointer-events: auto; /* 捕获点击事件 */
}
/* 控制按钮区域 - 需要单独设置可点击 */
.bottom-controls {
/* 原有样式保持不变 */
position: absolute;
bottom: 0;
left: 0;
width: 100%;
z-index: 3; /* 控制按钮在最高层 */
pointer-events: auto; /* 启用点击事件 */
}
.control-btn {
@ -1042,17 +937,15 @@ export default {
background-color: #ccc;
}
/* 加载层 */
.loading-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
justify-content: center;
align-items: center;
z-index: 10003; /* 加载层级最高 */
z-index: 100; /* 加载层在最高层 */
pointer-events: auto; /* 阻止底层交互 */
}
.loading-content {