Commit 07aed763 by 杨明

图片适应

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