Commit 07aed763 by 杨明

图片适应

1 parent 94dba41e
<template> <template>
<view <view class="popup-box" v-if="popupShow">
class="popup-box"
v-if="popupShow"
>
<view class="nav-bar"> <view class="nav-bar">
<view <view class="back" @click="back">
class="back" <uni-icons type="left" :size="20" color="#fff"></uni-icons>
@click="back"
>
<uni-icons
type="left"
:size="20"
color="#fff"
></uni-icons>
</view> </view>
<view class="title">{{ title }}</view> <view class="title">{{ title }}</view>
</view> </view>
<view class="popup-body"> <view class="popup-body">
<video <video ref="videoPlayer" :src="detailUrl" controls v-if="sourceType == 2"></video>
ref="videoPlayer" <view class="img-detail" v-else>
:src="detailUrl" <image @click="back" :src="detailUrl" mode="heightFix" />
controls
v-if="sourceType == 2"
></video>
<view
class="img-detail"
v-else
>
<image
@click="back"
:src="detailUrl"
:style="{ width: width + 'px' }"
/>
</view> </view>
</view> </view>
</view> </view>
...@@ -46,7 +24,6 @@ export default { ...@@ -46,7 +24,6 @@ export default {
}, },
data () { data () {
return { return {
width: 0,
title: '', title: '',
sourceType: '', sourceType: '',
detailUrl: '' detailUrl: ''
...@@ -80,19 +57,6 @@ export default { ...@@ -80,19 +57,6 @@ export default {
this.title = tabName this.title = tabName
this.sourceType = sourceType this.sourceType = sourceType
this.detailUrl = detailUrl this.detailUrl = detailUrl
const _this = this
uni.getImageInfo({
src: detailUrl, // 替换为你的图片路径
success (img) {
uni.createSelectorQuery().select('.img-detail').boundingClientRect(function (rect) {
_this.width = rect.height * img.height / img.width
}).exec();
},
fail: function (error) {
console.error('获取图片信息失败:', error);
}
});
}, },
back () { back () {
if (this.isComponents) this.$emit('previewBack') if (this.isComponents) this.$emit('previewBack')
...@@ -143,7 +107,7 @@ export default { ...@@ -143,7 +107,7 @@ export default {
height: 100%; height: 100%;
text-align: center; text-align: center;
image { image {
height: 100%; height: calc(100vh - #{toRpx(200)});
width: auto; width: auto;
} }
} }
......
<template> <template>
<view <view class="popup-box" v-if="popupShow">
class="popup-box"
v-if="popupShow"
>
<view class="nav-bar"> <view class="nav-bar">
<view <view class="back" @click="back">
class="back" <uni-icons type="left" :size="20" color="#fff"></uni-icons>
@click="back"
>
<uni-icons
type="left"
:size="20"
color="#fff"
></uni-icons>
</view> </view>
<view class="title">{{ title }}</view> <view class="title">{{ title }}</view>
</view> </view>
<view class="popup-body"> <view class="popup-body">
<video <video ref="videoPlayer" :src="detailUrl" controls v-if="sourceType == 2"></video>
ref="videoPlayer" <view class="img-detail" v-else>
:src="detailUrl" <image @click="back" :src="detailUrl" mode="heightFix" />
controls
v-if="sourceType == 2"
></video>
<view
class="img-detail"
v-else
>
<image
@click="back"
:src="detailUrl"
:style="{ width: width + 'px' }"
/>
</view> </view>
</view> </view>
</view> </view>
...@@ -81,19 +59,19 @@ export default { ...@@ -81,19 +59,19 @@ export default {
this.title = tabName this.title = tabName
this.sourceType = sourceType this.sourceType = sourceType
this.detailUrl = detailUrl this.detailUrl = detailUrl
const _this = this // const _this = this
uni.getImageInfo({ // uni.getImageInfo({
src: detailUrl, // 替换为你的图片路径 // src: detailUrl, // 替换为你的图片路径
success (img) { // success (img) {
uni.createSelectorQuery().select('.img-detail').boundingClientRect(function (rect) { // uni.createSelectorQuery().select('.img-detail').boundingClientRect(function (rect) {
_this.width = rect.height * img.height / img.width // _this.width = rect.height * img.height / img.width
}).exec(); // }).exec();
}, // },
fail: function (error) { // fail: function (error) {
console.error('获取图片信息失败:', error); // console.error('获取图片信息失败:', error);
} // }
}); // });
}, },
back () { back () {
if (this.isComponents) this.$emit('previewBack') if (this.isComponents) this.$emit('previewBack')
...@@ -144,7 +122,7 @@ export default { ...@@ -144,7 +122,7 @@ export default {
height: 100%; height: 100%;
text-align: center; text-align: center;
image { image {
height: 100%; height: calc(100% - #{toRpx(200)});
width: auto; width: auto;
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!