|
@@ -1,26 +1,32 @@
|
|
|
<template>
|
|
|
- <el-carousel
|
|
|
- class="carousel-list"
|
|
|
- :autoplay="autoplay"
|
|
|
- :interval="interval"
|
|
|
- :indicator-position="indicatorPosition"
|
|
|
- :arrow="arrow"
|
|
|
- :height="height"
|
|
|
- >
|
|
|
- <el-carousel-item v-for="(item, index) in list" :key="index">
|
|
|
- <a
|
|
|
- class="link-wrapper"
|
|
|
- :class="{ unlink: !item.link }"
|
|
|
- target="_blank"
|
|
|
- @click="openNewTab(item)"
|
|
|
- :id="[code, index].join('-')"
|
|
|
- :data-exposure="exposurePrefix + item.name"
|
|
|
- data-exposure-loop
|
|
|
- >
|
|
|
- <img :src="item.pic" :alt="item.name" />
|
|
|
- </a>
|
|
|
- </el-carousel-item>
|
|
|
- </el-carousel>
|
|
|
+ <el-carousel
|
|
|
+ class="carousel-list"
|
|
|
+ :autoplay="autoplay"
|
|
|
+ :interval="interval"
|
|
|
+ :indicator-position="indicatorPosition"
|
|
|
+ :arrow="arrow"
|
|
|
+ :height="calcStyleHeight"
|
|
|
+ @change="doChangeHeight"
|
|
|
+ >
|
|
|
+ <el-carousel-item v-for="(item, index) in list" :key="index">
|
|
|
+ <a
|
|
|
+ class="link-wrapper"
|
|
|
+ :class="{ unlink: !item.link }"
|
|
|
+ target="_blank"
|
|
|
+ @click="openNewTab(item)"
|
|
|
+ :id="[code, index].join('-')"
|
|
|
+ :data-exposure="exposurePrefix + item.name"
|
|
|
+ data-exposure-loop
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ ref="cImg"
|
|
|
+ :src="item.pic"
|
|
|
+ :alt="item.name"
|
|
|
+ @load="calcHeight(index)"
|
|
|
+ />
|
|
|
+ </a>
|
|
|
+ </el-carousel-item>
|
|
|
+ </el-carousel>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
@@ -41,6 +47,10 @@ export default {
|
|
|
required: true,
|
|
|
default: ''
|
|
|
},
|
|
|
+ autoHeight: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
height: {
|
|
|
type: String,
|
|
|
default: ''
|
|
@@ -82,8 +92,24 @@ export default {
|
|
|
} else {
|
|
|
return ''
|
|
|
}
|
|
|
+ },
|
|
|
+ calcStyleHeight() {
|
|
|
+ if (this.autoHeight) {
|
|
|
+ return this.imgHeights[this.activeIndex] + 'px'
|
|
|
+ } else {
|
|
|
+ return this.height
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ imgHeights: [],
|
|
|
+ activeIndex: 0,
|
|
|
}
|
|
|
},
|
|
|
+ mounted () {
|
|
|
+ this.calcHeight(0)
|
|
|
+ },
|
|
|
methods: {
|
|
|
resolveLink(link) {
|
|
|
const { href } = this.$router.resolve(link)
|
|
@@ -95,12 +121,17 @@ export default {
|
|
|
window.open(link)
|
|
|
}
|
|
|
},
|
|
|
- calcStyle(extend) {
|
|
|
- if (!extend) return ''
|
|
|
- return {
|
|
|
- width: extend.width || '',
|
|
|
- height: extend.height || ''
|
|
|
- }
|
|
|
+ calcHeight (index) {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.$refs.cImg) {
|
|
|
+ const cHeight = this.list.length > 1 ? this.$refs.cImg[index]?.clientHeight : this.$refs.cImg[0]?.clientHeight
|
|
|
+ this.$set(this.imgHeights, index, cHeight)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ doChangeHeight (index) {
|
|
|
+ this.calcHeight(index)
|
|
|
+ this.activeIndex = index
|
|
|
}
|
|
|
}
|
|
|
}
|