Skip to content

Commit 1fd0a27

Browse files
feat: ✨ Swiper 轮播项type字段的处理逻辑限制在可选值范围内 (#785)
1 parent b1f42af commit 1fd0a27

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/pages/swiper/Index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ const current6 = ref<number>(0)
212212
const current7 = ref<number>(0)
213213
const current8 = ref<number>(0)
214214
const current9 = ref<number>(0)
215-
const current10 = ref<number>(0)
216215
217216
const isLoop = ref(false)
218217

src/uni_modules/wot-design-uni/components/wd-swiper/wd-swiper.vue

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,8 @@
2020
@animationfinish="handleAnimationfinish"
2121
>
2222
<swiper-item v-for="(item, index) in list" :key="index" class="wd-swiper__item">
23-
<image
24-
v-if="isImage(item)"
25-
:src="isObj(item) ? item[valueKey] : item"
26-
:class="`wd-swiper__image ${customImageClass} ${customItemClass} ${getCustomItemClass(currentValue, index, list)}`"
27-
:style="{ height: addUnit(height) }"
28-
:mode="imageMode"
29-
@click="handleClick(index, item)"
30-
/>
3123
<video
32-
v-else-if="isVideo(item)"
24+
v-if="isVideo(item)"
3325
:id="`video-${index}-${uid}`"
3426
:style="{ height: addUnit(height) }"
3527
:src="isObj(item) ? item[valueKey] : item"
@@ -44,6 +36,15 @@
4436
objectFit="cover"
4537
@click="handleClick(index, item)"
4638
/>
39+
<image
40+
v-else
41+
:src="isObj(item) ? item[valueKey] : item"
42+
:class="`wd-swiper__image ${customImageClass} ${customItemClass} ${getCustomItemClass(currentValue, index, list)}`"
43+
:style="{ height: addUnit(height) }"
44+
:mode="imageMode"
45+
@click="handleClick(index, item)"
46+
/>
47+
4748
<text v-if="isObj(item) && item[textKey]" :class="`wd-swiper__text ${customTextClass}`" :style="customTextStyle">{{ item[textKey] }}</text>
4849
</swiper-item>
4950
</swiper>
@@ -137,10 +138,12 @@ const swiperIndicator = computed(() => {
137138
})
138139
139140
const getMediaType = (item: string | SwiperList, type: 'video' | 'image') => {
141+
const checkType = (url: string) => (type === 'video' ? isVideoUrl(url) : isImageUrl(url))
142+
140143
if (isObj(item)) {
141-
return item.type ? item.type === type : type === 'video' ? isVideoUrl(item[props.valueKey]) : isImageUrl(item[props.valueKey])
144+
return item.type && ['video', 'image'].includes(item.type) ? item.type === type : checkType(item[props.valueKey])
142145
} else {
143-
return type === 'video' ? isVideoUrl(item) : isImageUrl(item)
146+
return checkType(item)
144147
}
145148
}
146149

0 commit comments

Comments
 (0)