parent
28db708b15
commit
fe4c7108d8
@ -0,0 +1,4 @@ |
||||
export default definePageConfig({ |
||||
navigationBarTitleText: '健康知识', |
||||
onReachBottomDistance: 30 |
||||
}) |
@ -0,0 +1,34 @@ |
||||
.container { |
||||
width: 100%; |
||||
padding: 0 20rpx; |
||||
box-sizing: border-box; |
||||
columns: 2; |
||||
column-gap: 20rpx; |
||||
} |
||||
|
||||
.health { |
||||
break-inside: avoid; |
||||
background: #fff; |
||||
border-radius: 10px; |
||||
overflow: hidden; |
||||
margin-bottom: 20rpx; |
||||
position: relative; |
||||
|
||||
image, |
||||
Image { |
||||
background: #eee; |
||||
width: 100%; |
||||
min-height: 345rpx; |
||||
} |
||||
} |
||||
|
||||
.play { |
||||
position: absolute; |
||||
min-height: 70rpx !important; |
||||
z-index: 9999; |
||||
width: 40rpx !important; |
||||
height: 40rpx !important; |
||||
top: 20rpx; |
||||
right: 20rpx; |
||||
background: transparent !important; |
||||
} |
@ -0,0 +1,42 @@ |
||||
import {FC, useEffect, useState} from "react"; |
||||
import {Image, ScrollView, View} from "@tarojs/components"; |
||||
import {HomeApi} from "@/api"; |
||||
import {useReachBottom} from "@tarojs/taro"; |
||||
import styles from './health.module.scss' |
||||
import play from '@/static/img/play.png' |
||||
|
||||
const Health: FC = () => { |
||||
const [page, setPage] = useState(1) |
||||
const [data, setData] = useState<Health[]>([]) |
||||
const [total, setTotal] = useState(0) |
||||
|
||||
async function getData(page: number) { |
||||
const res = await HomeApi.health(page, 10) |
||||
setData(res.data) |
||||
setTotal(res.total) |
||||
} |
||||
|
||||
useReachBottom(() => { |
||||
data.length < total && setPage(page + 1) |
||||
}) |
||||
|
||||
useEffect(() => { |
||||
getData(page) |
||||
}, [page]) |
||||
|
||||
return ( |
||||
<ScrollView> |
||||
<View className={styles.container}> |
||||
{ |
||||
data.map(d => <View key={d.id} className={styles.health}> |
||||
<Image src={d.url_path} mode='widthFix' lazyLoad fadeIn/> |
||||
<Image src={play} className={styles.play} mode='aspectFit'/> |
||||
<View className='text-ellipsis-2 p-2'>{d.title}</View> |
||||
</View>) |
||||
} |
||||
</View> |
||||
</ScrollView> |
||||
) |
||||
} |
||||
|
||||
export default Health |
@ -0,0 +1,6 @@ |
||||
interface Health { |
||||
id: number |
||||
title: string |
||||
introduction: string |
||||
url_path: string |
||||
} |
Loading…
Reference in new issue