2023-01-14 02:09:13 -05:00
|
|
|
import React from 'react'
|
2023-01-14 02:43:31 -05:00
|
|
|
import { Swiper, Grid } from 'antd-mobile'
|
2023-01-14 02:09:13 -05:00
|
|
|
import axios from 'axios';
|
2023-01-14 02:43:31 -05:00
|
|
|
import WidthUseNavigate from '../WidthUseNavigate';
|
2023-01-14 02:09:13 -05:00
|
|
|
import './index.css'
|
|
|
|
import ImgZZ from './../../assets/images/nav-1.png'
|
|
|
|
import ImgHZ from './../../assets/images/nav-2.png'
|
|
|
|
import ImgDTZF from './../../assets/images/nav-3.png'
|
|
|
|
import ImgQCZ from './../../assets/images/nav-4.png'
|
2023-01-14 02:43:31 -05:00
|
|
|
|
2023-01-14 02:09:13 -05:00
|
|
|
const localCatalog = [
|
2023-01-14 03:39:41 -05:00
|
|
|
{ "imgSrc": ImgZZ, "title": "整租", "path": "/todo" },
|
|
|
|
{ "imgSrc": ImgHZ, "title": "合租", "path": "/todo" },
|
|
|
|
{ "imgSrc": ImgDTZF, "title": "地图找房", "path": "/message" },
|
|
|
|
{ "imgSrc": ImgQCZ, "title": "去出租", "path": "/me" }
|
2023-01-14 02:09:13 -05:00
|
|
|
]
|
2023-01-14 02:43:31 -05:00
|
|
|
class HomeInner extends React.Component {
|
2023-01-14 02:09:13 -05:00
|
|
|
state = {
|
2023-01-14 03:39:41 -05:00
|
|
|
swipers: [],
|
|
|
|
isSwiperLoaded: false
|
2023-01-14 02:09:13 -05:00
|
|
|
}
|
|
|
|
async getSwitpers() {
|
|
|
|
const res = await axios.get('http://localhost:8080/home/swiper')
|
|
|
|
this.setState(
|
2023-01-14 03:39:41 -05:00
|
|
|
{
|
|
|
|
swipers: res.data.body,
|
|
|
|
isSwiperLoaded: true
|
|
|
|
},
|
|
|
|
|
2023-01-14 02:09:13 -05:00
|
|
|
// ()=>{
|
|
|
|
// return{swipers:res.data.body}
|
|
|
|
// }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
componentDidMount() {
|
|
|
|
this.getSwitpers()
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSwipers() {
|
|
|
|
return this.state.swipers.map(item => (<Swiper.Item key={item.id}>
|
2023-01-14 03:39:41 -05:00
|
|
|
<img height='212'
|
2023-01-14 02:09:13 -05:00
|
|
|
src={'http://localhost:8080' + item.imgSrc}
|
|
|
|
style={{ width: '100%', verticalAlign: 'top' }}
|
|
|
|
/>
|
|
|
|
</Swiper.Item>))
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <div className='context'>
|
2023-01-14 03:39:41 -05:00
|
|
|
<div className='context-swapper'>
|
|
|
|
{
|
|
|
|
this.state.isSwiperLoaded ? <Swiper autoplay loop autoplayInterval='1500'>{this.renderSwipers()}</Swiper> : ""
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
2023-01-14 02:09:13 -05:00
|
|
|
<Grid columns={4}>
|
|
|
|
{
|
2023-01-14 03:39:41 -05:00
|
|
|
localCatalog.map((item, index) => (
|
|
|
|
<Grid.Item key={index} onClick={() => {
|
2023-01-14 02:09:13 -05:00
|
|
|
console.log("点击跳转")
|
2023-01-14 03:39:41 -05:00
|
|
|
this.props.to(item.path)
|
|
|
|
}}>
|
2023-01-14 02:09:13 -05:00
|
|
|
<div ><img src={item.imgSrc} /><h2>{item.title}</h2></div>
|
|
|
|
</Grid.Item>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</Grid>
|
|
|
|
</div>
|
|
|
|
};
|
2023-01-14 02:43:31 -05:00
|
|
|
}
|
|
|
|
// 使用高阶组件包裹当前类组件
|
|
|
|
const Home = WidthUseNavigate(HomeInner);
|
|
|
|
// 导出包裹后的类组件
|
|
|
|
export default Home;
|