37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { formatImgUrl } from "@/common/fotmat"
|
|
import { Image, Swiper, SwiperItem, View } from "@tarojs/components"
|
|
import { useMemo, useRef, useState } from "react"
|
|
import styles from './index.module.scss'
|
|
|
|
type item = {title:string, img:string, url:string, id:number}
|
|
type params = {
|
|
list?: item[]
|
|
}
|
|
|
|
export default ({list = []}: params) => {
|
|
const [pageIndex, setPageIndex] = useState(1)
|
|
const pageRef = useRef<any>(null)
|
|
|
|
const pageCount = useMemo(() => {
|
|
return list.length
|
|
},[list])
|
|
|
|
const swiperChange = (e) => {
|
|
setPageIndex(e.detail.current + 1)
|
|
}
|
|
|
|
return (
|
|
<View className={styles.swiper}>
|
|
<Swiper className={styles.swiper_item} circular={true} onAnimationFinish={(e) => swiperChange(e)}>
|
|
{list?.map((item) => {
|
|
return <SwiperItem key={item.id}>
|
|
<View className={styles.image_item} >
|
|
<Image mode="aspectFill" src={formatImgUrl(item)}></Image>
|
|
</View>
|
|
</SwiperItem>
|
|
})}
|
|
</Swiper>
|
|
{(list.length > 0)&&<View className={styles.page} ref={pageRef}>{pageIndex+'/'+pageCount}</View>}
|
|
</View>
|
|
)
|
|
} |