Skip to content

Commit

Permalink
fix(image.viewer.ts): 修复ImageViewer公共组件对纵图处理不当导致图片被裁剪的问题 (#2575)
Browse files Browse the repository at this point in the history
使用者提出issue,反馈ImageViewer 图片预览没有设置宽高限制的情况下,图片被截断了,特此修复了公共组件中对纵图处理不当导致图片被裁剪的问题
  • Loading branch information
azx1573 authored Jan 25, 2024
1 parent 299a69c commit dc15add
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/image-viewer/image-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
};
},
Expand Down

0 comments on commit dc15add

Please sign in to comment.