From b09e2e7aee79e517b9958f219bf5c2074b3d6cf8 Mon Sep 17 00:00:00 2001 From: ShenQiLun <97694732@qq.com> Date: Fri, 26 Jun 2026 09:28:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=BF=9E=E6=8B=8D=E6=94=B9=E7=94=A8takePho?= =?UTF-8?q?to=E5=85=A8=E5=88=86=E8=BE=A8=E7=8E=87+=E8=A3=81=E5=89=AA1080?= =?UTF-8?q?=C3=971080=E8=A7=A3=E5=86=B3=E6=A8=A1=E7=B3=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/camera_capture.nvue | 41 ++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/pages/upload/camera_capture.nvue b/pages/upload/camera_capture.nvue index ef4acf2..a08ae31 100644 --- a/pages/upload/camera_capture.nvue +++ b/pages/upload/camera_capture.nvue @@ -123,7 +123,7 @@ uni.showToast({ title: '相机未就绪', icon: 'none' }) return } - this.$refs.cameraRef.takePhotoSnapshot() + this.$refs.cameraRef.takePhoto() }, onPictureTaken(e) { var path = '' @@ -131,9 +131,46 @@ path = e.detail.path || '' } if (path) { - this.capturedList.push(path) + this.resizeTo1080(path) } }, + // 居中裁剪为 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 clipX = Math.floor((w - size) / 2) + var clipY = 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: clipX, + y: clipY, + width: size, + height: size + } + }, + function(res) { + that.capturedList.push(res.target) + }, + function() { + that.capturedList.push(srcPath) + }) + }, + fail: function() { + that.capturedList.push(srcPath) + } + }) + }, flipCamera() { this.facing = this.facing === 'back' ? 'front' : 'back' this.$refs.cameraRef.changeFacing(this.facing)