From d21b73593f8fe2757aa784af8f067ce820c911cf Mon Sep 17 00:00:00 2001 From: ShenQiLun <97694732@qq.com> Date: Fri, 26 Jun 2026 09:51:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=85=88=E6=98=BE=E7=A4=BA=E5=8E=9F?= =?UTF-8?q?=E5=9B=BE=E7=A1=AE=E4=BF=9D=E6=8C=89=E9=92=AE=E5=87=BA=E7=8E=B0?= =?UTF-8?q?,=E5=BC=82=E6=AD=A5plus.zip=E8=A3=81=E5=89=AA1080=C3=971080?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/camera_capture.nvue | 71 +++++++++++++++++--------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/pages/upload/camera_capture.nvue b/pages/upload/camera_capture.nvue index 87cf61b..c989fd5 100644 --- a/pages/upload/camera_capture.nvue +++ b/pages/upload/camera_capture.nvue @@ -6,6 +6,8 @@ :style="'width:' + camSize + 'px;height:' + camSize + 'px;margin-top:' + frameTop + 'px;margin-left:' + frameLeft + 'px;'" flash="off" facing="back" + :widthRatio="1" + :heightRatio="1" @onPictureTaken="onPictureTaken" @onCameraOpened="onCameraOpened" > @@ -67,8 +69,6 @@ - - @@ -135,43 +135,46 @@ this.resizeTo1080(path) } }, - // 居中裁剪为 1080×1080 + // 先添加原图确保UI响应,再异步替换为1080×1080 resizeTo1080(srcPath) { var that = this - uni.getImageInfo({ - src: srcPath, - success: function(info) { - var w = info.width - var h = info.height - var size = Math.min(w, h) - var sx = Math.floor((w - size) / 2) - var sy = Math.floor((h - size) / 2) - // 用canvas裁剪 + 缩放 - var ctx = uni.createCanvasContext('resizeCanvas', that) - ctx.drawImage(srcPath, sx, sy, size, size, 0, 0, 1080, 1080) - ctx.draw(false, function() { - setTimeout(function() { - uni.canvasToTempFilePath({ - canvasId: 'resizeCanvas', - x: 0, y: 0, - width: 1080, height: 1080, - destWidth: 1080, destHeight: 1080, - fileType: 'jpg', - quality: 1, - success: function(res) { - that.capturedList.push(res.tempFilePath) - }, - fail: function() { - that.capturedList.push(srcPath) + // 先占位,让完成按钮立即出现 + var idx = this.capturedList.length + this.capturedList.push(srcPath) + // 异步尝试压缩 + try { + if (typeof plus !== 'undefined' && plus.zip) { + uni.getImageInfo({ + src: srcPath, + success: function(info) { + var w = info.width + var h = info.height + var size = Math.min(w, h) + var cx = Math.floor((w - size) / 2) + var cy = Math.floor((h - size) / 2) + plus.zip.compressImage({ + src: srcPath, + dst: '_doc/sq_' + Date.now() + '.jpg', + width: '1080', + height: '1080', + quality: 95, + overwrite: true, + clip: { + x: cx, y: cy, + width: size, height: size } - }, that) - }, 300) + }, + function(res) { + that.capturedList[idx] = res.target + }, + function() { + // 保持原图 + }) + }, + fail: function() {} }) - }, - fail: function() { - that.capturedList.push(srcPath) } - }) + } catch(e) {} }, flipCamera() { this.facing = this.facing === 'back' ? 'front' : 'back'