图片显示、预览组件优化

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()
+23 -60
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.showChangeBtn = urls.length > 1
this.imgsUrl.push(await handleVerAutoImg(this.domain + this.urls)) this.showNoImg = urls.length < 1
}) urls.forEach(async(item, i) => {
this.src = this.imgsUrl[0]
this.showNoImg = false
} else {
this.showNoImg = true
}
}
} 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.imgsUrl.push(await handleVerAutoImg(this.domain + item))
if (i < 1) this.src = this.imgsUrl[0]
}) })
this.src = this.imgsUrl[0] },
} else { immediate: true
this.showNoImg = true
}
}
} else {
this.showChangeBtn = false
this.showNoImg = true
} }
}, },
methods: { methods: {
@@ -117,16 +86,10 @@ export default {
}, },
// 查看媒体 // 查看媒体
async checkMedia() { 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') this.$refs.dialog.open(this.imgsUrl, 'img')
} }
} }
} }
}
}
</script> </script>
<style lang="scss"> <style lang="scss">