图片显示、预览组件优化

This commit is contained in:
zhujingzhou
2025-07-20 12:46:08 +07:00
parent fa06b597e5
commit 5dd5e96efd
2 changed files with 32 additions and 72 deletions
+2 -5
View File
@@ -9,7 +9,7 @@
<el-dialog class="img_dialog" append-to-body :title="title" align="center" :visible.sync="dialogVisible" width="40%" :before-close="handleClose" :close-on-click-modal="false" :modal-append-to-body='false'> <el-dialog class="img_dialog" append-to-body :title="title" align="center" :visible.sync="dialogVisible" width="40%" :before-close="handleClose" :close-on-click-modal="false" :modal-append-to-body='false'>
<el-carousel v-if="isArry" indicator-position="outside"> <el-carousel v-if="isArry" indicator-position="outside">
<el-carousel-item v-for="item in mediaUrl" :key="item"> <el-carousel-item v-for="item in mediaUrl" :key="item">
<div class="media-box" id="img-box" > <img :src="changeImg(item)" /></div> <div class="media-box" id="img-box" > <img :src="item" /></div>
</el-carousel-item> </el-carousel-item>
</el-carousel> </el-carousel>
<div v-else class="media-box" id="img-box" > <img :src="mediaUrl" /></div> <div v-else class="media-box" id="img-box" > <img :src="mediaUrl" /></div>
@@ -17,7 +17,7 @@
</template> </template>
<script> <script>
import { handleVerAutoImg } from '@/utils/index.js'
export default { export default {
data() { data() {
return { return {
@@ -38,9 +38,6 @@ export default {
mounted() { mounted() {
}, },
methods: { methods: {
async changeImg(url) {
return await handleVerAutoImg(this.domain + url)
},
handleClose() { handleClose() {
if (this.player) { if (this.player) {
this.player.dispose() this.player.dispose()
+30 -67
View File
@@ -8,18 +8,16 @@
<template> <template>
<div class="img-wrap"> <div class="img-wrap">
<div v-if='showChangeBtn' class="changeLeft" @click="changeLeft"> <div v-if="showChangeBtn" class="changeLeft" @click="changeLeft">
<i class="el-icon-arrow-left"></i> <i class="el-icon-arrow-left"></i>
</div> </div>
<div class="showImg"> <div class="showImg">
<div v-if="showNoImg">暂无</div> <div v-if="showNoImg">暂无</div>
<el-image v-else :src="src" @click="checkMedia()" lazy > <el-image v-else :src="currentSrc" :preview-src-list="imgsUrl" lazy>
<div slot="placeholder" class="image-slot" :style="{width: width, height: height, lineHeight: height}"> <div slot="placeholder" class="image-slot" :style="{ width: width, height: height, lineHeight: height }"><i class="el-icon-loading"></i>加载中</div>
<i class="el-icon-loading"></i>加载中
</div>
</el-image> </el-image>
</div> </div>
<div v-if='showChangeBtn' class="changeRight" @click="changeRight"> <div v-if="showChangeBtn" class="changeRight" @click="changeRight">
<i class="el-icon-arrow-right"></i> <i class="el-icon-arrow-right"></i>
</div> </div>
<!--封面图视频弹窗组件--> <!--封面图视频弹窗组件-->
@@ -39,63 +37,34 @@ export default {
imgsUrl: [] imgsUrl: []
} }
}, },
computed: {
currentSrc() {
const src = this.src || this.imgsUrl[0]
return src
}
},
components: { components: {
Dialog Dialog
}, },
props: ['width', 'height', 'urls'], props: ['width', 'height', 'urls'],
watch: { watch: {
async urls(newval, oldval) { urls: {
this.urls = newval async handler() {
this.imgsUrl = [] this.imgsUrl = []
if (this.urls) { // 判断是否存在 const urls = []
if (typeof (this.urls) === 'string') { // 判断是单张图片还是数组 if (typeof this.urls === 'string') {
this.src = await handleVerAutoImg(this.domain + this.urls) urls.push(this.urls)
this.showNoImg = false } else if (Array.isArray(this.urls)) {
} else { urls.push(...this.urls)
if (this.urls.length) { // 判断是否为空数组
if (this.urls.length === 1) { // 判断数组中是否只有一张图片
this.showChangeBtn = false
} else {
this.showChangeBtn = true
}
this.urls.forEach(async item => {
this.imgsUrl.push(await handleVerAutoImg(this.domain + this.urls))
})
this.src = this.imgsUrl[0]
this.showNoImg = false
} else {
this.showNoImg = true
}
} }
} else { this.showChangeBtn = urls.length > 1
this.showChangeBtn = false this.showNoImg = urls.length < 1
this.showNoImg = true urls.forEach(async(item, i) => {
} this.imgsUrl.push(await handleVerAutoImg(this.domain + item))
} if (i < 1) this.src = this.imgsUrl[0]
}, })
async mounted() { },
this.imgsUrl = [] immediate: true
if (this.urls) { // 判断是否存在
if (typeof (this.urls) === 'string') { // 判断是单张图片还是数组
this.src = await handleVerAutoImg(this.domain + this.urls)
} else {
if (this.urls.length) { // 判断是否为空数组
if (this.urls.length === 1) { // 判断数组中是否只有一张图片
this.showChangeBtn = false
} else {
this.showChangeBtn = true
}
this.urls.forEach(async item => {
this.imgsUrl.push(await handleVerAutoImg(this.domain + item))
})
this.src = this.imgsUrl[0]
} else {
this.showNoImg = true
}
}
} else {
this.showChangeBtn = false
this.showNoImg = true
} }
}, },
methods: { methods: {
@@ -116,14 +85,8 @@ export default {
} }
}, },
// 查看媒体 // 查看媒体
async checkMedia() { async checkMedia() {
if (this.urls) { // 判断是否存在 this.$refs.dialog.open(this.imgsUrl, 'img')
if (typeof (this.urls) === 'string') { // 判断是单张图片还是数组
this.$refs.dialog.open(await handleVerAutoImg(this.domain + this.urls), 'img')
} else {
this.$refs.dialog.open(this.imgsUrl, 'img')
}
}
} }
} }
} }
@@ -145,7 +108,7 @@ export default {
} }
.showImg { .showImg {
width: 100%; width: 100%;
height:100%; height: 100%;
.image-slot { .image-slot {
background: #f5f7fa; background: #f5f7fa;
font-size: 12px; font-size: 12px;
@@ -154,7 +117,7 @@ export default {
.el-image__error { .el-image__error {
font-size: 12px; font-size: 12px;
} }
.el-image{ .el-image {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }