图片显示、预览组件优化
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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,15 +86,9 @@ 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>
|
||||||
|
|
||||||
@@ -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%;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user