Commit 6bb59db8 by zhanghaozhe

Merge branch 'bug' into pre

parents ce46660f 5e29c1a8
......@@ -10,7 +10,6 @@ import LiveRoom from './liveRoom'
import { Link } from "react-router-dom"
import { Toast } from 'antd-mobile'
import { connect } from "react-redux";
import { getCourses } from './../detail/actions';
const animateTypes = Swiper.animateTypes
......@@ -148,10 +147,10 @@ class Index extends Component {
this.state.tabdata.map((item, index) => {
return (
<li key={index}>
<a href={item.href}>
<Link to={item.href}>
<img src={item.src} alt="" />
<span>{item.name}</span>
</a>
</Link>
</li>
)
})
......
......@@ -5,6 +5,8 @@ import { http } from '@/utils'
import { Toast } from "antd-mobile";
import classnames from 'classnames'
import { isEmpty } from 'lodash'
import InfiniteScroll from "react-infinite-scroller";
import {HashLoader} from 'react-spinners'
import './free-courses.scss'
......@@ -17,11 +19,14 @@ const Bottom = (props) => (
)
class FreeCourse extends PureComponent {
page = 1
num = 10
state = {
courses: [],
live: [],
page: 1,
num: 10
hasMore: false
}
componentDidMount() {
......@@ -31,6 +36,7 @@ class FreeCourse extends PureComponent {
if (data.code == 200) {
this.setState({
courses: data.data,
hasMore: true
})
} else {
Toast.info(data.msg)
......@@ -54,7 +60,7 @@ class FreeCourse extends PureComponent {
}
getFreeCourses = () => {
return http.get(`${API.home}/m/free_course/${this.state.page}/${this.state.num}`)
return http.get(`${API.home}/m/free_course/${this.page++}/${this.num}`)
}
getFreeLive = () => {
......@@ -70,9 +76,38 @@ class FreeCourse extends PureComponent {
}
}
loadFunc = () => {
if (this.state.hasMore) {
this.setState({
hasMore: this.state.courses.length % 10 === 0
}, () => {
this.getFreeCourses()
.then(res => {
let data = res.data
if (data.code == 200) {
Array.isArray(data.data) && this.setState({
courses: this.state.courses.concat(data.data),
hasMore: data.data.length % 10 === 0
})
} else {
Toast.info(data.msg)
}
})
})
}
}
render() {
return (
<ul className='free-courses'>
<InfiniteScroll
pageStart={0}
loadMore={this.loadFunc}
useWindow={false}
className={'free-courses'}
element={'ul'}
hasMore={this.state.hasMore}
threshold={250}
>
{
this.state.live.map((item, index) => {
const Bottom = (
......@@ -119,7 +154,7 @@ class FreeCourse extends PureComponent {
/>
))
}
</ul>
</InfiniteScroll>
)
}
}
......
......@@ -12,7 +12,6 @@ const PAGE_INTERVAL = 1
export const NUM_INTERVAL = 10
export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
const myCourses = getState().myCourses
console.log(myCourses);
const {switchTab, page, noMore} = myCourses
if (!switchTab && !noMore) {
dispatch(getMyCourses({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment