Commit 5e29c1a8 by zhanghaozhe

公开课

parent 6b68cf90
...@@ -10,7 +10,6 @@ import LiveRoom from './liveRoom' ...@@ -10,7 +10,6 @@ import LiveRoom from './liveRoom'
import { Link } from "react-router-dom" import { Link } from "react-router-dom"
import { Toast } from 'antd-mobile' import { Toast } from 'antd-mobile'
import { connect } from "react-redux"; import { connect } from "react-redux";
import { getCourses } from './../detail/actions';
const animateTypes = Swiper.animateTypes const animateTypes = Swiper.animateTypes
...@@ -148,10 +147,10 @@ class Index extends Component { ...@@ -148,10 +147,10 @@ class Index extends Component {
this.state.tabdata.map((item, index) => { this.state.tabdata.map((item, index) => {
return ( return (
<li key={index}> <li key={index}>
<a href={item.href}> <Link to={item.href}>
<img src={item.src} alt="" /> <img src={item.src} alt="" />
<span>{item.name}</span> <span>{item.name}</span>
</a> </Link>
</li> </li>
) )
}) })
......
...@@ -5,6 +5,8 @@ import { http } from '@/utils' ...@@ -5,6 +5,8 @@ import { http } from '@/utils'
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import classnames from 'classnames' import classnames from 'classnames'
import { isEmpty } from 'lodash' import { isEmpty } from 'lodash'
import InfiniteScroll from "react-infinite-scroller";
import {HashLoader} from 'react-spinners'
import './free-courses.scss' import './free-courses.scss'
...@@ -17,11 +19,14 @@ const Bottom = (props) => ( ...@@ -17,11 +19,14 @@ const Bottom = (props) => (
) )
class FreeCourse extends PureComponent { class FreeCourse extends PureComponent {
page = 1
num = 10
state = { state = {
courses: [], courses: [],
live: [], live: [],
page: 1, page: 1,
num: 10 hasMore: false
} }
componentDidMount() { componentDidMount() {
...@@ -31,6 +36,7 @@ class FreeCourse extends PureComponent { ...@@ -31,6 +36,7 @@ class FreeCourse extends PureComponent {
if (data.code == 200) { if (data.code == 200) {
this.setState({ this.setState({
courses: data.data, courses: data.data,
hasMore: true
}) })
} else { } else {
Toast.info(data.msg) Toast.info(data.msg)
...@@ -54,7 +60,7 @@ class FreeCourse extends PureComponent { ...@@ -54,7 +60,7 @@ class FreeCourse extends PureComponent {
} }
getFreeCourses = () => { 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 = () => { getFreeLive = () => {
...@@ -70,9 +76,38 @@ class FreeCourse extends PureComponent { ...@@ -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() { render() {
return ( 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) => { this.state.live.map((item, index) => {
const Bottom = ( const Bottom = (
...@@ -119,7 +154,7 @@ class FreeCourse extends PureComponent { ...@@ -119,7 +154,7 @@ class FreeCourse extends PureComponent {
/> />
)) ))
} }
</ul> </InfiniteScroll>
) )
} }
} }
......
...@@ -12,7 +12,6 @@ const PAGE_INTERVAL = 1 ...@@ -12,7 +12,6 @@ const PAGE_INTERVAL = 1
export const NUM_INTERVAL = 10 export const NUM_INTERVAL = 10
export const fetchCoursesListIfNeeded = () => (dispatch, getState) => { export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
const myCourses = getState().myCourses const myCourses = getState().myCourses
console.log(myCourses);
const {switchTab, page, noMore} = myCourses const {switchTab, page, noMore} = myCourses
if (!switchTab && !noMore) { if (!switchTab && !noMore) {
dispatch(getMyCourses({ 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