mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-06 17:18:40 +08:00
parent
314c2e8c9d
commit
1e039cb707
@ -346,7 +346,13 @@ const isLoop = ref(false)
|
|||||||
|
|
||||||
### SwiperList
|
### SwiperList
|
||||||
|
|
||||||
轮播图项的列表配置,包括 图片或视频地址`value`、视频封面`poster` 等属性,支持扩展属性。
|
轮播图项的列表配置,包括 图片或视频地址`value`、视频封面`poster` 、文件资源的类型`type`等属性,支持扩展属性。指定`type`后组件将不在内部判断文件类型,以`type`为准。
|
||||||
|
| name | 说明 | 最低版本 |
|
||||||
|
| --------- | ------------ | -------- |
|
||||||
|
| value | 图片或视频地址 |- |
|
||||||
|
| poster | 视频封面 |- |
|
||||||
|
| type | 用于指定文件资源的类型,可选值`image`、`video` | $LOWEST_VERSION$ |
|
||||||
|
|
||||||
|
|
||||||
### SwiperIndicatorProps
|
### SwiperIndicatorProps
|
||||||
|
|
||||||
|
|||||||
@ -26,12 +26,17 @@ export type IndicatorPositionType = 'left' | 'top-left' | 'top' | 'top-right' |
|
|||||||
*/
|
*/
|
||||||
export type AdjustHeightType = 'first' | 'current' | 'highest' | 'none'
|
export type AdjustHeightType = 'first' | 'current' | 'highest' | 'none'
|
||||||
|
|
||||||
|
// 资源类型
|
||||||
|
export type SwiperItemType = 'image' | 'video'
|
||||||
|
|
||||||
export interface SwiperList {
|
export interface SwiperList {
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
// 图片、视频等资源地址
|
// 图片、视频等资源地址
|
||||||
value?: string
|
value?: string
|
||||||
// 视频资源的封面
|
// 视频资源的封面
|
||||||
poster?: string
|
poster?: string
|
||||||
|
// 资源文件类型,可选值:'image' | 'video'
|
||||||
|
type?: SwiperItemType
|
||||||
}
|
}
|
||||||
|
|
||||||
export const swiperProps = {
|
export const swiperProps = {
|
||||||
|
|||||||
@ -21,14 +21,14 @@
|
|||||||
>
|
>
|
||||||
<swiper-item v-for="(item, index) in list" :key="index" class="wd-swiper__item" @click="handleClick(index, item)">
|
<swiper-item v-for="(item, index) in list" :key="index" class="wd-swiper__item" @click="handleClick(index, item)">
|
||||||
<image
|
<image
|
||||||
v-if="isImageUrl(isObj(item) ? item[valueKey] : item)"
|
v-if="isImage(item)"
|
||||||
:src="isObj(item) ? item[valueKey] : item"
|
:src="isObj(item) ? item[valueKey] : item"
|
||||||
:class="`wd-swiper__image ${customImageClass} ${customItemClass} ${getCustomItemClass(navCurrent, index, list)}`"
|
:class="`wd-swiper__image ${customImageClass} ${customItemClass} ${getCustomItemClass(navCurrent, index, list)}`"
|
||||||
:style="{ height: addUnit(height) }"
|
:style="{ height: addUnit(height) }"
|
||||||
:mode="imageMode"
|
:mode="imageMode"
|
||||||
/>
|
/>
|
||||||
<video
|
<video
|
||||||
v-else
|
v-else-if="isVideo(item)"
|
||||||
:id="`video-${index}-${uid}`"
|
:id="`video-${index}-${uid}`"
|
||||||
:style="{ height: addUnit(height) }"
|
:style="{ height: addUnit(height) }"
|
||||||
:src="isObj(item) ? item[valueKey] : item"
|
:src="isObj(item) ? item[valueKey] : item"
|
||||||
@ -77,7 +77,7 @@ export default {
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import wdSwiperNav from '../wd-swiper-nav/wd-swiper-nav.vue'
|
import wdSwiperNav from '../wd-swiper-nav/wd-swiper-nav.vue'
|
||||||
import { computed, watch, ref, getCurrentInstance } from 'vue'
|
import { computed, watch, ref, getCurrentInstance } from 'vue'
|
||||||
import { addUnit, isObj, isImageUrl, isVideoUrl, uuid } from '../common/util'
|
import { addUnit, isObj, isImageUrl, isVideoUrl, uuid, isDef } from '../common/util'
|
||||||
import { swiperProps, type SwiperList } from './types'
|
import { swiperProps, type SwiperList } from './types'
|
||||||
import type { SwiperNavProps } from '../wd-swiper-nav/types'
|
import type { SwiperNavProps } from '../wd-swiper-nav/types'
|
||||||
|
|
||||||
@ -122,6 +122,22 @@ const swiperIndicator = computed(() => {
|
|||||||
return swiperIndicator
|
return swiperIndicator
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const getMediaType = (item: string | SwiperList, type: 'video' | 'image') => {
|
||||||
|
if (isObj(item)) {
|
||||||
|
return item.type ? item.type === type : type === 'video' ? isVideoUrl(item[props.valueKey]) : isImageUrl(item[props.valueKey])
|
||||||
|
} else {
|
||||||
|
return type === 'video' ? isVideoUrl(item) : isImageUrl(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isVideo = (item: string | SwiperList) => {
|
||||||
|
return getMediaType(item, 'video')
|
||||||
|
}
|
||||||
|
|
||||||
|
const isImage = (item: string | SwiperList) => {
|
||||||
|
return getMediaType(item, 'image')
|
||||||
|
}
|
||||||
|
|
||||||
function go(index: number) {
|
function go(index: number) {
|
||||||
navCurrent.value = index
|
navCurrent.value = index
|
||||||
}
|
}
|
||||||
@ -205,15 +221,12 @@ function handleVideoChange(previous: number, current: number) {
|
|||||||
function handleStartVideoPaly(index: number) {
|
function handleStartVideoPaly(index: number) {
|
||||||
if (props.autoplayVideo) {
|
if (props.autoplayVideo) {
|
||||||
const currentItem = props.list[index]
|
const currentItem = props.list[index]
|
||||||
if (currentItem) {
|
if (isDef(currentItem) && isVideo(currentItem)) {
|
||||||
const url = isObj(currentItem) ? currentItem.url : currentItem
|
|
||||||
if (isVideoUrl(url)) {
|
|
||||||
const video = uni.createVideoContext(`video-${index}-${uid.value}`, proxy)
|
const video = uni.createVideoContext(`video-${index}-${uid.value}`, proxy)
|
||||||
video.play()
|
video.play()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止播放指定视频
|
* 停止播放指定视频
|
||||||
@ -222,13 +235,10 @@ function handleStartVideoPaly(index: number) {
|
|||||||
function handleStopVideoPaly(index: number) {
|
function handleStopVideoPaly(index: number) {
|
||||||
if (props.stopPreviousVideo) {
|
if (props.stopPreviousVideo) {
|
||||||
const previousItem = props.list[index]
|
const previousItem = props.list[index]
|
||||||
if (previousItem) {
|
if (isDef(previousItem) && isVideo(previousItem)) {
|
||||||
const url = isObj(previousItem) ? previousItem.url : previousItem
|
|
||||||
if (isVideoUrl(url)) {
|
|
||||||
const video = uni.createVideoContext(`video-${index}-${uid.value}`, proxy)
|
const video = uni.createVideoContext(`video-${index}-${uid.value}`, proxy)
|
||||||
video.pause()
|
video.pause()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (props.stopAutoplayWhenVideoPlay) {
|
} else if (props.stopAutoplayWhenVideoPlay) {
|
||||||
handleVideoPause()
|
handleVideoPause()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user