Commit 06952d0d by zhanghaozhe

首页banner跳转

parent 925bc0f7
import React, {Component} from 'react' import React, { Component } from 'react'
import {Course, CallApp} from '../../common' import { Course, CallApp } from '../../common'
import './index.scss' import './index.scss'
import {WithTab} from '@/HOCs' import { WithTab } from '@/HOCs'
import Swiper from 'react-mobile-swiper' import Swiper from 'react-mobile-swiper'
import createStyle from './createStyle' import createStyle from './createStyle'
import LazyLoad from 'react-lazy-load' import LazyLoad from 'react-lazy-load'
import {http} from '@/utils' import { http } from '@/utils'
import LiveRoom from './liveRoom' 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'; import { getCourses } from './../detail/actions';
const animateTypes = Swiper.animateTypes const animateTypes = Swiper.animateTypes
...@@ -66,11 +66,11 @@ class Index extends Component { ...@@ -66,11 +66,11 @@ class Index extends Component {
getIndexData = () => { getIndexData = () => {
http.get(`${API.home}/m/home`).then((res) => { http.get(`${API.home}/m/home`).then((res) => {
if (res.data.code === 200) { if (res.data.code === 200) {
const { data } = res.data || {} const {data} = res.data || {}
this.setState({ this.setState({
banner: data.banner, banner: data.banner,
lives: data.lives, lives: data.lives,
modules: typeof data.modules === 'object' && data.modules.length > 0? data.modules : [] modules: typeof data.modules === 'object' && data.modules.length > 0 ? data.modules : []
}) })
} else { } else {
Toast.info(res.data.msg, 2) Toast.info(res.data.msg, 2)
...@@ -109,7 +109,7 @@ class Index extends Component { ...@@ -109,7 +109,7 @@ class Index extends Component {
} }
toCourseDetail = (id) => { toCourseDetail = (id) => {
const { dispatch, history } = this.props; const {dispatch, history} = this.props;
dispatch(getCourses(id, () => { dispatch(getCourses(id, () => {
history.push(`/detail?id=${id}`); history.push(`/detail?id=${id}`);
return false; return false;
...@@ -200,11 +200,15 @@ function TopSwiper({bannerList}) { ...@@ -200,11 +200,15 @@ function TopSwiper({bannerList}) {
<Swiper type={animateTypes.CARD} loop={true} height={168} autoPlay={true} typePro createStyle={createStyle}> <Swiper type={animateTypes.CARD} loop={true} height={168} autoPlay={true} typePro createStyle={createStyle}>
{bannerList && bannerList.length > 0 && bannerList.map((item, index) => { {bannerList && bannerList.length > 0 && bannerList.map((item, index) => {
return ( return (
Number.isNaN(parseInt(item.jump_url)) ?
<a href={item.jump_url} key={index}> <a href={item.jump_url} key={index}>
{/* <Link to={item.jump_url} key={index}> */} {/* <Link to={item.jump_url} key={index}> */}
<img className="item" src={item.name} alt=""/> <img className="item" src={item.name} alt=""/>
{/* </Link> */} {/* </Link> */}
</a> </a> :
<Link to={{pathname: '/detail', search: `?id=${item.jump_url}`}}>
<img className="item" src={item.name} alt=""/>
</Link>
) )
}) })
} }
...@@ -219,7 +223,7 @@ function CourseList({modules, toDetail}) { ...@@ -219,7 +223,7 @@ function CourseList({modules, toDetail}) {
// 数量为奇数时,第一个课程显示大图(如后台未上传,前台显示小图),课程数量为偶数时,均显示小图 // 数量为奇数时,第一个课程显示大图(如后台未上传,前台显示小图),课程数量为偶数时,均显示小图
let filterList = '' let filterList = ''
if(isOdd){ if (isOdd) {
filterList = modules.list filterList = modules.list
} else { } else {
filterList = modules.list[0].course_img === modules.list[0].course_img_small ? modules.list : modules.list.slice(1) filterList = modules.list[0].course_img === modules.list[0].course_img_small ? modules.list : modules.list.slice(1)
...@@ -238,7 +242,7 @@ function CourseList({modules, toDetail}) { ...@@ -238,7 +242,7 @@ function CourseList({modules, toDetail}) {
<LazyLoad offset={50}> <LazyLoad offset={50}>
<ul className='index-course-detail'> <ul className='index-course-detail'>
{ {
!isOdd && modules.list[0].course_img!== modules.list[0].course_img_small && !isOdd && modules.list[0].course_img !== modules.list[0].course_img_small &&
<div className="category-vip" onClick={() => toDetail(modules.list[0].course_id)}> <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} alt=""/> <img src={modules.list[0].course_img} alt=""/>
......
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