resource-focus-image.vue
4.12 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<template>
<resource class="focus-image">
<awesome-swiper name="mySwiper" :reg-success="swiperSuccess" :options="swiperOption" class="swipe">
<div class="swiper-wrapper" @click="activeLink">
<div class="swiper-slide"
v-for="focus in value.data"
:key="focus.src"
:style="{backgroundColor: focus.bgColor}">
<img-format :src="focus.src" :w="750" :h="480"></img-format>
</div>
</div>
<div class="swiper-pagination"></div>
</awesome-swiper>
<a-link ref="linkA" :href="activeHref" :yas="value" :yas-f="index" :yas-i="imageIndex"></a-link>
</resource>
</template>
<script>
import Resource from './resource';
export default {
name: 'ResourceFocusImage',
props: {
value: Object,
index: Number
},
data() {
return {
activeHref: '',
swiperOption: {
loop: true,
autoplay: true,
pagination: {
el: '.swiper-pagination'
},
on:{
slideChange: this._slideChange,
}
},
itemVisibleStatus: {}
};
},
computed: {
imageIndex() {
return this.mySwiper ? this.mySwiper.realIndex : 0;
}
},
methods: {
swiperSuccess(swiper) {
this.mySwiper = swiper;
// 注册成功后上报首个slide
let param = {
I_INDEX: this.mySwiper.realIndex + 1,
P_NAME: this.$route.name,
F_NAME: this.value.template_name,
F_ID: this.value.template_id,
F_INDEX: this.index + 1,
ACTION_URL: this.value.data[this.mySwiper.realIndex].url
};
this.dataRecord(param);
},
activeLink() {
const img = this.value.data[this.mySwiper.realIndex];
if (img) {
this.activeHref = img.url;
this.$nextTick(() => {
this.$refs.linkA.click();
});
}
},
_slideChange() {
if (this.mySwiper) {
// fixed: slideChange回调执行时,realIndex为0会前后触发两次
if (this.mySwiper.previousIndex === this.value.data.length + 1) {
return;
}
let param = {
I_INDEX: this.mySwiper.realIndex + 1,
P_NAME: this.$route.name,
F_NAME: this.value.template_name,
F_ID: this.value.template_id,
F_INDEX: this.index + 1,
ACTION_URL: this.value.data[this.mySwiper.realIndex].url
};
this.dataRecord(param);
}
},
dataRecord(param) {
// index 用户父组件判断当前组件是否可见
this.$parent.focusComponentDataRecord(this.index, param)
}
},
components: {Resource}
};
</script>
<style lang="scss">
.focus-image {
padding: 0 !important;
height: 480px;
overflow: hidden;
.swipe {
position: relative;
height: 100%;
}
.swiper-slide {
a {
display: block;
}
img {
width: 100%;
height: 100%;
}
}
.swiper-pagination-bullet {
width: 10px;
height: 10px;
background: #e0e0e0;
opacity: 1;
border-radius: 0;
&.swiper-pagination-bullet-active {
width: 20px;
background: #fff;
}
}
}
</style>