From 56c79aaf3a6e800017a567b49e735eb8fe31ff51 Mon Sep 17 00:00:00 2001 From: "97694732@qq.com" Date: Sat, 6 Jun 2026 17:10:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=91=84=E5=83=8F=E5=A4=B4=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0initdone=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC+=E9=87=8D?= =?UTF-8?q?=E8=AF=95=E6=9C=BA=E5=88=B6+id=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/camera_capture.vue | 56 +++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/pages/upload/camera_capture.vue b/pages/upload/camera_capture.vue index 571ee2f..f2b1f50 100644 --- a/pages/upload/camera_capture.vue +++ b/pages/upload/camera_capture.vue @@ -2,7 +2,10 @@ - + + + 摄像头初始化中... + @@ -21,7 +24,7 @@ - + @@ -36,13 +39,34 @@ data() { return { capturedList: [], - ctx: null + ctx: null, + ctxReady: false } }, onReady() { - this.ctx = uni.createCameraContext() + this.initCamera() }, methods: { + initCamera() { + try { + this.ctx = uni.createCameraContext() + if (this.ctx) { + this.ctxReady = true + console.log('摄像头已就绪') + } else { + // 延时重试 + setTimeout(() => this.initCamera(), 500) + } + } catch (e) { + console.error('摄像头初始化失败:', e) + // 延时重试 + setTimeout(() => this.initCamera(), 500) + } + }, + onCameraInit() { + console.log('摄像头initdone') + this.initCamera() + }, onCameraError(e) { console.error('摄像头错误:', e) uni.showToast({ title: '摄像头启动失败', icon: 'none', duration: 3000 }) @@ -52,7 +76,7 @@ uni.showToast({ title: '最多拍9张', icon: 'none' }) return } - if (!this.ctx) { + if (!this.ctx || !this.ctxReady) { uni.showToast({ title: '摄像头未就绪', icon: 'none' }) return } @@ -78,7 +102,6 @@ uni.showToast({ title: '请先拍照', icon: 'none' }) return } - // 获取上一页实例,设置数据并返回 var pages = getCurrentPages() var prevPage = pages[pages.length - 2] if (prevPage) { @@ -96,16 +119,33 @@ flex-direction: column; height: 100vh; background: #000; + overflow: hidden; } .cc-camera-wrap { flex: 1; position: relative; overflow: hidden; + background: #111; } .cc-camera { width: 100%; height: 100%; } + .cc-camera-hint { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + display: flex; + align-items: center; + justify-content: center; + background: #111; + } + .cc-hint-text { + color: #999; + font-size: 28rpx; + } .cc-thumb-bar { background: #1a1a1a; padding: 16rpx 20rpx; @@ -165,6 +205,10 @@ display: flex; align-items: center; justify-content: center; + transition: opacity 0.3s; + } + .cc-capture-btn.disabled { + opacity: 0.4; } .cc-capture-inner { width: 64rpx;