图片显示、预览组件优化

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
+30 -67
View File
@@ -8,18 +8,16 @@
<template>
<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>
</div>
<div class="showImg">
<div v-if="showNoImg">暂无</div>
<el-image v-else :src="src" @click="checkMedia()" lazy >
<div slot="placeholder" class="image-slot" :style="{width: width, height: height, lineHeight: height}">
<i class="el-icon-loading"></i>加载中
</div>
<el-image v-else :src="currentSrc" :preview-src-list="imgsUrl" lazy>
<div slot="placeholder" class="image-slot" :style="{ width: width, height: height, lineHeight: height }"><i class="el-icon-loading"></i>加载中</div>
</el-image>
</div>
<div v-if='showChangeBtn' class="changeRight" @click="changeRight">
<div v-if="showChangeBtn" class="changeRight" @click="changeRight">
<i class="el-icon-arrow-right"></i>
</div>
<!--封面图视频弹窗组件-->
@@ -39,63 +37,34 @@ export default {
imgsUrl: []
}
},
computed: {
currentSrc() {
const src = this.src || this.imgsUrl[0]
return src
}
},
components: {
Dialog
},
props: ['width', 'height', 'urls'],
watch: {
async urls(newval, oldval) {
this.urls = newval
this.imgsUrl = []
if (this.urls) { // 判断是否存在
if (typeof (this.urls) === 'string') { // 判断是单张图片还是数组
this.src = await handleVerAutoImg(this.domain + this.urls)
this.showNoImg = false
} 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 + this.urls))
})
this.src = this.imgsUrl[0]
this.showNoImg = false
} else {
this.showNoImg = true
}
urls: {
async handler() {
this.imgsUrl = []
const urls = []
if (typeof this.urls === 'string') {
urls.push(this.urls)
} else if (Array.isArray(this.urls)) {
urls.push(...this.urls)
}
} else {
this.showChangeBtn = false
this.showNoImg = true
}
}
},
async mounted() {
this.imgsUrl = []
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
this.showChangeBtn = urls.length > 1
this.showNoImg = urls.length < 1
urls.forEach(async(item, i) => {
this.imgsUrl.push(await handleVerAutoImg(this.domain + item))
if (i < 1) this.src = this.imgsUrl[0]
})
},
immediate: true
}
},
methods: {
@@ -116,14 +85,8 @@ export default {
}
},
// 查看媒体
async checkMedia() {
if (this.urls) { // 判断是否存在
if (typeof (this.urls) === 'string') { // 判断是单张图片还是数组
this.$refs.dialog.open(await handleVerAutoImg(this.domain + this.urls), 'img')
} else {
this.$refs.dialog.open(this.imgsUrl, 'img')
}
}
async checkMedia() {
this.$refs.dialog.open(this.imgsUrl, 'img')
}
}
}
@@ -145,7 +108,7 @@ export default {
}
.showImg {
width: 100%;
height:100%;
height: 100%;
.image-slot {
background: #f5f7fa;
font-size: 12px;
@@ -154,7 +117,7 @@ export default {
.el-image__error {
font-size: 12px;
}
.el-image{
.el-image {
width: 100%;
height: 100%;
}