|
@@ -1,40 +1,27 @@
|
1
|
1
|
<template>
|
2
|
2
|
<div class="swiper">
|
3
|
3
|
<van-swipe :autoplay="3000" @change="onChange" ref="swipe">
|
4
|
|
- <van-swipe-item v-for="(image, index) in images" :key="index">
|
5
|
|
- <van-image height="300" :src="image.image" @click="onPerView(index)" />
|
|
4
|
+ <van-swipe-item v-for="(item, index) in imageList" :key="index">
|
|
5
|
+ <van-image height="300" :src="item.image" @click="onPerView(index)" />
|
6
|
6
|
</van-swipe-item>
|
|
7
|
+ <template #indicator>
|
|
8
|
+ <div class="swiper-indicator" ref="indicator">
|
|
9
|
+ <span
|
|
10
|
+ v-for="(item, index) in imageList"
|
|
11
|
+ :key="index"
|
|
12
|
+ :class="{ active: current === index }"
|
|
13
|
+ >
|
|
14
|
+ {{ item.text }}
|
|
15
|
+ </span>
|
|
16
|
+ </div>
|
|
17
|
+ </template>
|
7
|
18
|
</van-swipe>
|
8
|
|
- <div class="swiper-tabs">
|
9
|
|
- <van-tabs
|
10
|
|
- v-model:active="current"
|
11
|
|
- background="rgba(0, 0, 0, 0.69)"
|
12
|
|
- line-width="0"
|
13
|
|
- color="#fff"
|
14
|
|
- title-active-color="#d75e3a"
|
15
|
|
- @click="onClickTab"
|
16
|
|
- >
|
17
|
|
- <van-tab
|
18
|
|
- v-for="(image, index) in images"
|
19
|
|
- :key="index"
|
20
|
|
- :title="image?.text"
|
21
|
|
- >
|
22
|
|
- </van-tab>
|
23
|
|
- </van-tabs>
|
24
|
|
- </div>
|
25
|
19
|
</div>
|
26
|
20
|
</template>
|
27
|
21
|
|
28
|
22
|
<script>
|
29
|
|
-import { ref } from 'vue'
|
30
|
|
-import {
|
31
|
|
- Swipe,
|
32
|
|
- SwipeItem,
|
33
|
|
- Image as VanImage,
|
34
|
|
- ImagePreview,
|
35
|
|
- Tabs,
|
36
|
|
- Tab,
|
37
|
|
-} from 'vant'
|
|
23
|
+import { computed, ref } from 'vue'
|
|
24
|
+import { Swipe, SwipeItem, Image as VanImage, ImagePreview } from 'vant'
|
38
|
25
|
|
39
|
26
|
export default {
|
40
|
27
|
name: 'swiper',
|
|
@@ -42,27 +29,34 @@ export default {
|
42
|
29
|
[Swipe.name]: Swipe,
|
43
|
30
|
[SwipeItem.name]: SwipeItem,
|
44
|
31
|
[VanImage.name]: VanImage,
|
45
|
|
- [Tabs.name]: Tabs,
|
46
|
|
- [Tab.name]: Tab,
|
47
|
32
|
},
|
48
|
33
|
props: {
|
49
|
34
|
images: {
|
50
|
35
|
type: Array,
|
51
|
|
- default: () => [
|
52
|
|
- {
|
53
|
|
- image: '',
|
54
|
|
- text: '暂无',
|
55
|
|
- },
|
56
|
|
- ],
|
|
36
|
+ default: () => [],
|
57
|
37
|
},
|
58
|
38
|
},
|
59
|
39
|
|
60
|
40
|
setup(props) {
|
61
|
41
|
const current = ref(0)
|
62
|
42
|
const swipe = ref()
|
|
43
|
+ const indicator = ref()
|
|
44
|
+
|
|
45
|
+ const imageList = computed(() => {
|
|
46
|
+ const list = (props.image || []).filter(Boolean)
|
|
47
|
+ return list.length
|
|
48
|
+ ? list
|
|
49
|
+ : [
|
|
50
|
+ {
|
|
51
|
+ image: 'https://img01.yzcdn.cn/vant/custom-empty-image.png',
|
|
52
|
+ text: '暂无图片',
|
|
53
|
+ },
|
|
54
|
+ ]
|
|
55
|
+ })
|
63
|
56
|
|
64
|
57
|
const onChange = (index) => {
|
65
|
58
|
current.value = index
|
|
59
|
+ // indicator.value.scrollTo({ left: 1000 })
|
66
|
60
|
}
|
67
|
61
|
const onPerView = (index) => {
|
68
|
62
|
ImagePreview({
|
|
@@ -79,10 +73,12 @@ export default {
|
79
|
73
|
}
|
80
|
74
|
|
81
|
75
|
// refs.checkbox.toggle();
|
82
|
|
- onPerView
|
|
76
|
+
|
83
|
77
|
return {
|
84
|
78
|
swipe,
|
85
|
79
|
current,
|
|
80
|
+ indicator,
|
|
81
|
+ imageList,
|
86
|
82
|
onChange,
|
87
|
83
|
onPerView,
|
88
|
84
|
onClickTab,
|
|
@@ -106,11 +102,26 @@ export default {
|
106
|
102
|
width: 100%;
|
107
|
103
|
}
|
108
|
104
|
}
|
109
|
|
-.swiper .van-swipe-item {
|
110
|
|
- /* color: #fff;
|
111
|
|
- font-size: 20px;
|
112
|
|
- line-height: 150px;
|
113
|
|
- text-align: center;
|
114
|
|
- background-color: #39a9ed; */
|
|
105
|
+
|
|
106
|
+.swiper-indicator {
|
|
107
|
+ position: absolute;
|
|
108
|
+ bottom: 0;
|
|
109
|
+ left: 0;
|
|
110
|
+ background: rgba(0, 0, 0, 0.69);
|
|
111
|
+ color: #aaa;
|
|
112
|
+ display: flex;
|
|
113
|
+ flex-wrap: nowrap;
|
|
114
|
+ font-size: 0.85em;
|
|
115
|
+ min-width: 100vw;
|
|
116
|
+
|
|
117
|
+ span {
|
|
118
|
+ display: inline-block;
|
|
119
|
+ padding: 0.8em;
|
|
120
|
+ flex: none;
|
|
121
|
+
|
|
122
|
+ &.active {
|
|
123
|
+ color: #d75e3a;
|
|
124
|
+ }
|
|
125
|
+ }
|
115
|
126
|
}
|
116
|
127
|
</style>
|