import React , { useEffect , useState , useCallback } from 'react' ; import { View , RichText } from '@tarojs/components' ; import { AtCard , AtDivider } from 'taro-ui' ; import { fetchAllRecruitList , RecruitItemType } from '@shared/model/trpg' ; import Taro , { usePullDownRefresh } from '@tarojs/taro' ; import { showToasts } from '@shared/manager/ui' ; import { PageView } from '../../components/PageView' ; import './index.less' ; const Index = ( ) => { const [ recruitList , setRecruitList ] = useState < RecruitItemType [ ] > ( [ ] ) ; const fetchList = useCallback ( async ( ) => { try { const list = await fetchAllRecruitList ( ) ; setRecruitList ( list ) ; showToasts ( '加载成功' , 'success' ) ; } catch ( err ) { console . error ( err ) ; showToasts ( '加载招募列表失败: ' + String ( err ) , 'error' ) ; setRecruitList ( [ ] ) ; } } , [ ] ) ; usePullDownRefresh ( ( ) => { fetchList ( ) . then ( ( ) => { Taro . stopPullDownRefresh ( ) ; } ) ; } ) ; useEffect ( ( ) => { fetchList ( ) ; } , [ ] ) ; const handleClick = useCallback ( ( recruitUUID ) => { Taro . navigateTo ( { url : `/pages/recruitDetail/index?recruitUUID=${ recruitUUID }` , } ) ; } , [ ] ) ; return ( < PageView className = "root" > { recruitList . map ( ( recruit ) => { return ( < View key = { recruit . uuid } style = { { marginBottom : 10 , } } onClick = { ( ) => handleClick ( recruit . uuid ) } > < AtCard note = { recruit . author } extra = { recruit . platform } title = { recruit . title } icon = { { value : 'calendar' , color : '#999' , } } > < RichText nodes = { recruit . content } /> < /AtCard> < /View>); } ) } { recruitList . length > 3 && < AtDivider content = "没有更多了" / > } < /PageView>); } ; export default Index ;