1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<template>
<div class="app-carouse">
<Carousel :autoplay="swipeConfig.isAuto" :autoplay-speed="swipeConfig.timeSpan" radius-dot>
<CarouselItem v-for="(item, index) in swipeData" :key="index">
<div class="carousel-img-item">
<a v-if="item.linkPath" :href="item.linkPath">
<img class="app-carouse-img" v-if="item.imgPath" :src="item.imgPath" @error="imgError" />
<i v-else :class="item.iconClass"></i>
</a>
<img class="app-carouse-img" v-else-if="item.imgPath" :src="item.imgPath" @error="imgError" />
<i v-else :class="item.iconClass.cssClass" :style="handleIconCss(item.iconClass)"></i>
</div>
</CarouselItem>
</Carousel>
</div>
</template>
<script lang='ts'>
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
@Component({})
export default class AppCarousel extends Vue {
/**
* @description 轮播图数据
* @param {*}
* @memberof AppCarousel
*/
@Prop() public data: any;
/**
* @description 轮播图图片所有项数据
* @memberof AppCarousel
*/
public swipeData: any[] = [];
/**
* @description 轮播图配置
* @memberof AppCarousel
*/
public swipeConfig: any = {};
/**
* data值变化
*
* @param {*} newVal
* @param {*} oldVal
* @memberof AppCarousel
*/
@Watch('data', { immediate: true })
public onDataChange(newVal: any, oldVal: any) {
if (!Object.is(newVal, oldVal)) {
this.swipeData = newVal.swipeData;
this.swipeConfig = newVal.swipeConfig;
}
}
/**
* @description 构建之前
* @memberof AppCarousel
*/
created() {
this.swipeData = this.data.swipeData;
this.swipeConfig = this.data.swipeConfig;
}
/**
* 处理图标大小
* @memberof AppMobCarousel
*/
public handleIconCss(data: any) {
return {
width: data.width || 6 + 'px',
height: data.height || 6 + 'px',
};
}
/**
* img src错误
*
* @param {*} $event
* @memberof AppCarousel
*/
imgError($event: any) {
let img = $event.srcElement;
if (img && !img.imgSign) {
if (img && !img.imgSign) {
img.src = 'assets/img/404.png';
img.imgSign = true;
img.imgSign = true;
}
img.onerror = null;
}
}
}
</script>
<style lang='less'>
@import './app-carousel.less';
</style>