1
|
<template>
|
1
|
<template>
|
2
|
- <div class="image-swipe" v-if="allLoaded">
|
2
|
+ <div class="image-swipe" v-if="showSwiper">
|
3
|
<div class="swipe-wrap" @click.prevent="showcase()">
|
3
|
<div class="swipe-wrap" @click.prevent="showcase()">
|
4
|
<swiper :options="swiperOption" ref="swiper">
|
4
|
<swiper :options="swiperOption" ref="swiper">
|
5
|
<swiper-slide v-for="item in goodsList" :key="item.title">
|
5
|
<swiper-slide v-for="item in goodsList" :key="item.title">
|
|
@@ -41,7 +41,7 @@ |
|
@@ -41,7 +41,7 @@ |
41
|
vm.setActiveSlide(swiper.realIndex)
|
41
|
vm.setActiveSlide(swiper.realIndex)
|
42
|
}
|
42
|
}
|
43
|
},
|
43
|
},
|
44
|
- allLoaded: false
|
44
|
+ showSwiper: false
|
45
|
};
|
45
|
};
|
46
|
},
|
46
|
},
|
47
|
components: {
|
47
|
components: {
|
|
@@ -59,49 +59,12 @@ |
|
@@ -59,49 +59,12 @@ |
59
|
let temp = val.slice();
|
59
|
let temp = val.slice();
|
60
|
const len = temp.length;
|
60
|
const len = temp.length;
|
61
|
|
61
|
|
62
|
- if (len > 1 && len < 4) {
|
62
|
+ if (len > 1) {
|
63
|
temp.unshift(temp.splice(len - 1)[0]);
|
63
|
temp.unshift(temp.splice(len - 1)[0]);
|
64
|
}
|
64
|
}
|
65
|
|
65
|
|
66
|
- if (len >= 4) {
|
|
|
67
|
- const sp = temp.splice(0, 2);
|
|
|
68
|
-
|
|
|
69
|
- temp.push(sp[0]);
|
|
|
70
|
- temp.push(sp[1]);
|
|
|
71
|
- }
|
|
|
72
|
this.goodsList = temp;
|
66
|
this.goodsList = temp;
|
73
|
this.slideCount = this.goodsList.length;
|
67
|
this.slideCount = this.goodsList.length;
|
74
|
- },
|
|
|
75
|
- goodsList(goods) {
|
|
|
76
|
- const preloadImg = (list, loaded) => {
|
|
|
77
|
- loaded = loaded || [];
|
|
|
78
|
-
|
|
|
79
|
- // 加载完成
|
|
|
80
|
- if(list.length === 0) {
|
|
|
81
|
- let $ssr = document.getElementById('ssr');
|
|
|
82
|
- $ssr && $ssr.remove();
|
|
|
83
|
- this.allLoaded = true;
|
|
|
84
|
- return;
|
|
|
85
|
- }
|
|
|
86
|
-
|
|
|
87
|
- let img = new Image();
|
|
|
88
|
- img.src = util.getImgUrl(list[0].image_url, '580', '770');
|
|
|
89
|
-
|
|
|
90
|
- if(img.complete) {
|
|
|
91
|
- loaded.push(img);
|
|
|
92
|
- list.shift();
|
|
|
93
|
- preloadImg(list, loaded);
|
|
|
94
|
- }
|
|
|
95
|
- else {
|
|
|
96
|
- img.onload = function() {
|
|
|
97
|
- loaded.push(img);
|
|
|
98
|
- list.shift();
|
|
|
99
|
- preloadImg(list, loaded);
|
|
|
100
|
- };
|
|
|
101
|
- }
|
|
|
102
|
- };
|
|
|
103
|
-
|
|
|
104
|
- preloadImg(goods[0].images_list);
|
|
|
105
|
}
|
68
|
}
|
106
|
},
|
69
|
},
|
107
|
methods: {
|
70
|
methods: {
|
|
@@ -122,25 +85,10 @@ |
|
@@ -122,25 +85,10 @@ |
122
|
this.activeIndex = this.calcIndex(idx);
|
85
|
this.activeIndex = this.calcIndex(idx);
|
123
|
},
|
86
|
},
|
124
|
calcIndex(realIdx){
|
87
|
calcIndex(realIdx){
|
125
|
- const len = this.goods.length;
|
|
|
126
|
-
|
|
|
127
|
- if (len >= 4) {
|
|
|
128
|
- if (realIdx === len -1) {
|
|
|
129
|
- realIdx = 0;
|
|
|
130
|
- } else {
|
|
|
131
|
- realIdx += 1;
|
|
|
132
|
- }
|
|
|
133
|
-
|
|
|
134
|
- if (realIdx < len -2) {
|
|
|
135
|
- realIdx += 2;
|
|
|
136
|
- } else if (realIdx === len -2) {
|
|
|
137
|
- realIdx = 0;
|
|
|
138
|
- } else {
|
|
|
139
|
- realIdx = 1;
|
|
|
140
|
- }
|
|
|
141
|
- }
|
|
|
142
|
-
|
|
|
143
|
return realIdx;
|
88
|
return realIdx;
|
|
|
89
|
+ },
|
|
|
90
|
+ show() {
|
|
|
91
|
+ this.showSwiper = true;
|
144
|
}
|
92
|
}
|
145
|
}
|
93
|
}
|
146
|
};
|
94
|
};
|