Commit 965f1b83 authored by spc's avatar spc

fixed

parent 081fdb63
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<!-- 图片区域 --> <!-- 图片区域 -->
<view class="poster-image-wrapper"> <view class="poster-image-wrapper">
<image class="poster-image-bg" :src="`${$baseUrl}homepage/Q3Res/xingmaLabPosterImgBg.png`" <image class="poster-image-bg" :src="`${$baseUrl}homepage/Q3Res/xingmaLabPosterImgBg2.png`"
mode="aspectFit"></image> mode="aspectFit"></image>
<image v-if="imageUrl" class="poster-image" :src="imageUrl" mode="aspectFit"></image> <image v-if="imageUrl" class="poster-image" :src="imageUrl" mode="aspectFit"></image>
<!-- 文字内容 --> <!-- 文字内容 -->
...@@ -525,25 +525,28 @@ const getImageInfo = (src) => { ...@@ -525,25 +525,28 @@ const getImageInfo = (src) => {
}) })
} }
// 计算自适应尺寸(保持宽高比,类似 aspectFit // 计算自适应尺寸(保持宽高比,根据超出比例决定适配方向
const calculateFitSize = (imageWidth, imageHeight, containerWidth, containerHeight) => { const calculateFitSize = (imageWidth, imageHeight, containerWidth, containerHeight) => {
const imageRatio = imageWidth / imageHeight const imageRatio = imageWidth / imageHeight
const containerRatio = containerWidth / containerHeight
// 计算超出比例
const widthOverflowRatio = (imageWidth - containerWidth) / containerWidth
const heightOverflowRatio = (imageHeight - containerHeight) / containerHeight
let drawWidth, drawHeight, drawX, drawY let drawWidth, drawHeight, drawX, drawY
if (imageRatio > containerRatio) { // 如果高度超出的比例大,则高度适配(固定高度,宽度自适应)
// 图片更宽,以宽度为准 if (heightOverflowRatio > widthOverflowRatio) {
drawHeight = containerHeight
drawWidth = containerHeight * imageRatio
drawX = (containerWidth - drawWidth) / 2
drawY = 0
} else {
// 如果宽度超出的比例大,则宽度适配(固定宽度,高度自适应)
drawWidth = containerWidth drawWidth = containerWidth
drawHeight = containerWidth / imageRatio drawHeight = containerWidth / imageRatio
drawX = 0 drawX = 0
drawY = (containerHeight - drawHeight) / 2 drawY = (containerHeight - drawHeight) / 2
} else {
// 图片更高,以高度为准
drawWidth = containerHeight * imageRatio
drawHeight = containerHeight
drawX = (containerWidth - drawWidth) / 2
drawY = 0
} }
return { drawWidth, drawHeight, drawX, drawY } return { drawWidth, drawHeight, drawX, drawY }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment