Commit 2c845752 by FE

modify home, because modify question to course detail

parent c7d02352
...@@ -10,10 +10,14 @@ import LiveRoom from './liveRoom' ...@@ -10,10 +10,14 @@ 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
@connect(state => ({
user: state.user
}))
class Index extends Component { class Index extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
...@@ -104,6 +108,14 @@ class Index extends Component { ...@@ -104,6 +108,14 @@ class Index extends Component {
this.props.history.push('/search') this.props.history.push('/search')
} }
toCourseDetail = (id) => {
const { dispatch, history } = this.props;
dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`);
return false;
}));
}
render() { render() {
return ( return (
<div className='index-box'> <div className='index-box'>
...@@ -154,7 +166,7 @@ class Index extends Component { ...@@ -154,7 +166,7 @@ class Index extends Component {
(this.state.modules && this.state.modules.length > 0) ? this.state.modules.map((item, index) => { (this.state.modules && this.state.modules.length > 0) ? this.state.modules.map((item, index) => {
return ( return (
<div key={index}> <div key={index}>
<CourseList modules={item}/> <CourseList modules={item} toDetail={this.toCourseDetail}/>
<p className="borderTop"></p> <p className="borderTop"></p>
</div> </div>
) )
...@@ -199,7 +211,7 @@ function TopSwiper({bannerList}) { ...@@ -199,7 +211,7 @@ function TopSwiper({bannerList}) {
// 课程模块儿公共组件 // 课程模块儿公共组件
// 课程数量是奇数第一个课程需要横着展示沾满一行,课程数量是偶数一行显示两个 // 课程数量是奇数第一个课程需要横着展示沾满一行,课程数量是偶数一行显示两个
function CourseList({modules}) { function CourseList({modules, toDetail}) {
let isOdd = modules.list.length % 2 === 0 let isOdd = modules.list.length % 2 === 0
// 数量为奇数时,第一个课程显示大图(如后台未上传,前台显示小图),课程数量为偶数时,均显示小图 // 数量为奇数时,第一个课程显示大图(如后台未上传,前台显示小图),课程数量为偶数时,均显示小图
let filterList = '' let filterList = ''
...@@ -223,10 +235,10 @@ function CourseList({modules}) { ...@@ -223,10 +235,10 @@ function CourseList({modules}) {
<ul className='index-course-detail'> <ul className='index-course-detail'>
{ {
!isOdd && modules.list[0].course_img!=='' && !isOdd && modules.list[0].course_img!=='' &&
<div className="category-vip"> <div className="category-vip" onClick={() => toDetail(modules.list[0].course_id)}>
<Link to={`/detail?id=${modules.list[0].course_id}`}> {/* <Link to={`/detail?id=${modules.list[0].course_id}`}> */}
<img src={modules.list[0].course_img_small} alt=""/> <img src={modules.list[0].course_img_small} alt=""/>
</Link> {/* </Link> */}
</div> </div>
} }
{ {
...@@ -255,9 +267,17 @@ function CourseList({modules}) { ...@@ -255,9 +267,17 @@ function CourseList({modules}) {
</div> </div>
) )
return ( return (
<Course key={index} top={top} data={item} bottom={bottom} img={item.course_img_small} <Course
title={item.course_title} id={item.course_id} key={index}
className='text-overflow-2'></Course> top={top}
data={item}
bottom={bottom}
img={item.course_img_small}
title={item.course_title}
id={item.course_id}
toDetail={toDetail}
className='text-overflow-2'
/>
) )
}) })
} }
...@@ -314,7 +334,4 @@ function ScrollBox(props) { ...@@ -314,7 +334,4 @@ function ScrollBox(props) {
} }
export default connect( export default WithTab(Index);
state => ({user: state.user}),
null
)(WithTab(Index))
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