Skip to content

Commit

Permalink
feat: ✨ Swiper 轮播项type字段的处理逻辑限制在可选值范围内 (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moonofweisheng authored Dec 15, 2024
1 parent b1f42af commit 1fd0a27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/pages/swiper/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ const current6 = ref<number>(0)
const current7 = ref<number>(0)
const current8 = ref<number>(0)
const current9 = ref<number>(0)
const current10 = ref<number>(0)
const isLoop = ref(false)
Expand Down
25 changes: 14 additions & 11 deletions src/uni_modules/wot-design-uni/components/wd-swiper/wd-swiper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,8 @@
@animationfinish="handleAnimationfinish"
>
<swiper-item v-for="(item, index) in list" :key="index" class="wd-swiper__item">
<image
v-if="isImage(item)"
:src="isObj(item) ? item[valueKey] : item"
:class="`wd-swiper__image ${customImageClass} ${customItemClass} ${getCustomItemClass(currentValue, index, list)}`"
:style="{ height: addUnit(height) }"
:mode="imageMode"
@click="handleClick(index, item)"
/>
<video
v-else-if="isVideo(item)"
v-if="isVideo(item)"
:id="`video-${index}-${uid}`"
:style="{ height: addUnit(height) }"
:src="isObj(item) ? item[valueKey] : item"
Expand All @@ -44,6 +36,15 @@
objectFit="cover"
@click="handleClick(index, item)"
/>
<image
v-else
:src="isObj(item) ? item[valueKey] : item"
:class="`wd-swiper__image ${customImageClass} ${customItemClass} ${getCustomItemClass(currentValue, index, list)}`"
:style="{ height: addUnit(height) }"
:mode="imageMode"
@click="handleClick(index, item)"
/>

<text v-if="isObj(item) && item[textKey]" :class="`wd-swiper__text ${customTextClass}`" :style="customTextStyle">{{ item[textKey] }}</text>
</swiper-item>
</swiper>
Expand Down Expand Up @@ -137,10 +138,12 @@ const swiperIndicator = computed(() => {
})
const getMediaType = (item: string | SwiperList, type: 'video' | 'image') => {
const checkType = (url: string) => (type === 'video' ? isVideoUrl(url) : isImageUrl(url))
if (isObj(item)) {
return item.type ? item.type === type : type === 'video' ? isVideoUrl(item[props.valueKey]) : isImageUrl(item[props.valueKey])
return item.type && ['video', 'image'].includes(item.type) ? item.type === type : checkType(item[props.valueKey])
} else {
return type === 'video' ? isVideoUrl(item) : isImageUrl(item)
return checkType(item)
}
}
Expand Down

0 comments on commit 1fd0a27

Please sign in to comment.