From dc15addab7fd43f07cc1f7f0466e52b2607a9467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=93=E6=99=A8?= <2777689609@qq.com> Date: Thu, 25 Jan 2024 22:50:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(image.viewer.ts):=20=E4=BF=AE=E5=A4=8DImage?= =?UTF-8?q?Viewer=E5=85=AC=E5=85=B1=E7=BB=84=E4=BB=B6=E5=AF=B9=E7=BA=B5?= =?UTF-8?q?=E5=9B=BE=E5=A4=84=E7=90=86=E4=B8=8D=E5=BD=93=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=A2=AB=E8=A3=81=E5=89=AA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#2575)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用者提出issue,反馈ImageViewer 图片预览没有设置宽高限制的情况下,图片被截断了,特此修复了公共组件中对纵图处理不当导致图片被裁剪的问题 --- src/image-viewer/image-viewer.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/image-viewer/image-viewer.ts b/src/image-viewer/image-viewer.ts index 07d8a1db8..c48f02ef8 100644 --- a/src/image-viewer/image-viewer.ts +++ b/src/image-viewer/image-viewer.ts @@ -105,12 +105,24 @@ export default class ImageViewer extends SuperComponent { }, }; } + + // 图片的高大于宽(纵向图),设定高度为100vh,宽度自适应,且确保宽度不超过屏幕宽度 + const scaledHeight = ratio * windowHeight * 2; + if (scaledHeight < windowWidth) { + return { + styleObj: { + width: `${scaledHeight}rpx`, + height: '100vh', + left: '50%', + transform: 'translate(-50%, -50%)', + }, + }; + } + // 当通过高度计算的图片宽度超过屏幕宽度时, 以屏幕宽度为基准, 重新计算高度 return { styleObj: { - width: `${ratio * windowHeight * 2}rpx`, - height: '100vh', - left: '50%', - transform: 'translate(-50%, -50%)', + width: '100vw', + height: `${(windowWidth / imageWidth) * imageHeight * 2}rpx`, }, }; },