对接api

This commit is contained in:
2022-05-09 10:03:33 +08:00
parent e7a130533d
commit 4c46c6e22d
16 changed files with 243 additions and 184 deletions
+18
View File
@@ -0,0 +1,18 @@
.swiper_con{
padding:0 20px;
height: 178px;
.xswiper {
height: 100% !important;
border-radius: 20px;
.image_item{
width: 100%;
height: 100%;
image{
width: 100%;
height: 100%;
border-radius: 20px;
}
}
}
}
+51
View File
@@ -0,0 +1,51 @@
import { Image, Swiper, SwiperItem, View } from "@tarojs/components"
import { goLink } from "@/common/common"
import {GetBannerList} from "@/api/banner"
import styles from './index.module.scss'
import { useEffect, useState } from "react"
type item = {title:string, img:string, url:string, id:number}
type params = {
list?: item[]
swiperOnClick?: (val: item) => void,
style?: Object
}
export default (props:params) => {
let {swiperOnClick, style = {}} = props
const [list, setList] = useState<any[]>([])
const {fetchData, state} = GetBannerList()
useEffect(() => {
getData()
}, [])
const getData = async () => {
const res = await fetchData()
setList(res.data.list)
}
return (
<View className={styles.swiper_con} style={style}>
<Swiper
className={styles.xswiper}
indicatorColor='#ccc'
indicatorActiveColor='#fff'
circular
indicatorDots
autoplay>
{
list.map(item => {
return <SwiperItem key={item.id}>
<View className={styles.image_item} onClick={() => goLink(item.link)}>
<Image mode="aspectFill" src={item.prev_view_url}></Image>
</View>
</SwiperItem>
})
}
</Swiper>
</View>
)
}