Commit 25943c4d by zhanghaozhe

temp

parent c61460e4
...@@ -17,6 +17,15 @@ class Loading extends Component { ...@@ -17,6 +17,15 @@ class Loading extends Component {
isLoading: true isLoading: true
} }
componentDidMount() {
if(!this.props.isLoading){
this.setState({
isLoading: false
})
}
}
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
let {isLoading, fake} = this.props let {isLoading, fake} = this.props
if (!isLoading) { if (!isLoading) {
......
...@@ -62,7 +62,7 @@ class UseCoupon extends PureComponent { ...@@ -62,7 +62,7 @@ class UseCoupon extends PureComponent {
if (this.state.showUseButton) { if (this.state.showUseButton) {
this.setState({ this.setState({
couponList: [...state.couponList, coupon], couponList: [...this.state.couponList, coupon],
redeemCode: '' redeemCode: ''
}) })
} else { } else {
......
...@@ -22,6 +22,7 @@ export const fetchCoursesListIfNeeded = () => (dispatch, getState) => { ...@@ -22,6 +22,7 @@ export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
} }
export const getMyCourses = payload => dispatch => { export const getMyCourses = payload => dispatch => {
dispatch(startFetchingCourses)
return http.get(`${api.home}/m/my_course/${payload.page}/${payload.num}`) return http.get(`${api.home}/m/my_course/${payload.page}/${payload.num}`)
.then(res => { .then(res => {
const {data, code, msg} = res.data const {data, code, msg} = res.data
...@@ -51,4 +52,9 @@ export const switchTab = payload => ({ ...@@ -51,4 +52,9 @@ export const switchTab = payload => ({
export const NOMORE_COURSE = 'NOMORE_COURSES' export const NOMORE_COURSE = 'NOMORE_COURSES'
export const nomoreCourse = () => ({ export const nomoreCourse = () => ({
type: NOMORE_COURSE type: NOMORE_COURSE
}) })
\ No newline at end of file
export const START_FETCHING_COURSES = 'START_FETCHING_COURSES'
export const startFetchingCourses = () => {
return {type: START_FETCHING_COURSES, payload: {isLoading: true}}
}
\ No newline at end of file
...@@ -7,6 +7,7 @@ import { fetchCoursesListIfNeeded, switchTab } from "./actions" ...@@ -7,6 +7,7 @@ import { fetchCoursesListIfNeeded, switchTab } from "./actions"
import InfiniteScroll from 'react-infinite-scroller' import InfiniteScroll from 'react-infinite-scroller'
import { debounce } from 'lodash' import { debounce } from 'lodash'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { Loading } from "@/common";
function getStudyTime(seconds) { function getStudyTime(seconds) {
...@@ -69,7 +70,11 @@ const Bottom = React.memo(({item}) => { ...@@ -69,7 +70,11 @@ const Bottom = React.memo(({item}) => {
class MyCourses extends PureComponent { class MyCourses extends PureComponent {
list; list
state = {
isLoading: true
}
handleClick = id => { handleClick = id => {
this.props.history.push(`/play/video?id=${id}`) this.props.history.push(`/play/video?id=${id}`)
...@@ -95,79 +100,80 @@ class MyCourses extends PureComponent { ...@@ -95,79 +100,80 @@ class MyCourses extends PureComponent {
render() { render() {
let list = this.props.courseList let list = this.props.courseList
if (list && list.length !== 0) {
return ( return <Loading isLoading={this.props.isLoading}>
<> {
<div className="my-course-uid"> list && list.length !== 0
{`加群请备注您的学号:${this.props.user.data.uid}`} ?
</div> <>
<InfiniteScroll <div className="my-course-uid">
pageStart={0} {`加群请备注您的学号:${this.props.user.data.uid}`}
hasMore={true} </div>
loadMore={this.loadFunc} <InfiniteScroll
useWindow={false} pageStart={0}
> hasMore={true}
<ul ref={el => this.list = el}> loadMore={this.loadFunc}
{ useWindow={false}
list.map((item, index) => { >
<ul ref={el => this.list = el}>
const Info = ( {
<div className="info"> list.map((item, index) => {
<div className='title'>{item.course_title}</div>
{ const Info = (
item.is_aist <div className="info">
? <div className='contact'>助教微信:{item.assist_weixin}</div> <div className='title'>{item.course_title}</div>
: <div className='contact'>QQ群:{item.course_qq}</div> {
} item.is_aist
{ ? <div className='contact'>助教微信:{item.assist_weixin}</div>
item.is_aist && item.aist_schedule && : <div className='contact'>QQ群:{item.course_qq}</div>
<div className="process-status"> }
<div className="process-wrapper"> {
<div className="process-bar" item.is_aist && item.aist_schedule &&
style={{width: `${parseFloat(item.aist_schedule)}%`}}/> <div className="process-status">
<div className="process-wrapper">
<div className="process-bar"
style={{width: `${parseFloat(item.aist_schedule)}%`}}/>
</div>
<div className="process-text">{item.aist_schedule}</div>
</div> </div>
<div className="process-text">{item.aist_schedule}</div> }
</div> <Bottom item={item}/>
} </div>
<Bottom item={item}/> )
</div>
) const status = (
item.is_aist && <span className='status'>返现</span>
const status = ( )
item.is_aist && <span className='status'>返现</span> return (
) <VList img={item.image_name}
return ( handleClick={this.handleClick}
<VList img={item.image_name} {...item}
handleClick={this.handleClick} key={index}
{...item} info={Info}
key={index} status={status}
info={Info} id={item['course_id']}
status={status} />
id={item['course_id']} )
/> })
) }
}) </ul>
} </InfiniteScroll>
</ul> {
</InfiniteScroll> list.length % 10 !== 0 ?
{ <AddCourse addCourseClick={this.addCourseClick}/>
list.length % 10 !== 0 ? : null
<AddCourse addCourseClick={this.addCourseClick}/> }
: null </>
} :
</> <div className="empty">
) <p><i className='iconfont iconfish'/></p>
} else { <p className='empty-prompt'>还是咸鱼一条,快去翻身~</p>
return ( <p>
<div className="empty"> <Link className='select-course' to='/classify'>去选课</Link>
<p><i className='iconfont iconfish'/></p> </p>
<p className='empty-prompt'>还是咸鱼一条,快去翻身~</p> </div>
<p> }
<Link className='select-course' to='/classify'>去选课</Link> </Loading>
</p>
</div>
)
}
} }
} }
...@@ -175,7 +181,8 @@ class MyCourses extends PureComponent { ...@@ -175,7 +181,8 @@ class MyCourses extends PureComponent {
export default connect( export default connect(
state => ({ state => ({
courseList: state.myCourses.courseList, courseList: state.myCourses.courseList,
user: state.user user: state.user,
isLoading: state.myCourses.isLoading
}), }),
{ {
fetchCoursesListIfNeeded, fetchCoursesListIfNeeded,
......
import { import {
RECEIVE_MY_COURSES, RECEIVE_MY_COURSES,
SWITCH_TAB, SWITCH_TAB,
NOMORE_COURSE NOMORE_COURSE,
START_FETCHING_COURSES
} from './actions' } from './actions'
const initialState = { const initialState = {
...@@ -11,6 +12,7 @@ const initialState = { ...@@ -11,6 +12,7 @@ const initialState = {
statusCode: 0, statusCode: 0,
msg: '', msg: '',
noMore: false, noMore: false,
isLoading: true
} }
...@@ -20,8 +22,11 @@ export default function myCourses(state = initialState, action) { ...@@ -20,8 +22,11 @@ export default function myCourses(state = initialState, action) {
let {courseList, ...rest} = action.payload let {courseList, ...rest} = action.payload
return { return {
...state, ...rest, ...state, ...rest,
courseList: Object.keys(courseList).length === 0 ? state.courseList : state.courseList.concat(courseList) courseList: Object.keys(courseList).length === 0 ? state.courseList : state.courseList.concat(courseList),
isLoading: false
} }
case START_FETCHING_COURSES:
return {...state, ...action.payload}
case SWITCH_TAB: case SWITCH_TAB:
return {...state, switchTab: action.payload} return {...state, switchTab: action.payload}
case NOMORE_COURSE: case NOMORE_COURSE:
......
...@@ -101,7 +101,7 @@ class Video extends Component { ...@@ -101,7 +101,7 @@ class Video extends Component {
this.ws = new WebSocket('ws://process-test.julyedu.com:9502'); this.ws = new WebSocket('ws://process-test.julyedu.com:9502');
this.ws.addEventListener('error', () => { this.ws.addEventListener('error', () => {
this.ws = null this.ws = null
this.setupWS(); // this.setupWS();
}) })
this.ws.addEventListener('open', () => { this.ws.addEventListener('open', () => {
console.log('open'); console.log('open');
...@@ -109,7 +109,7 @@ class Video extends Component { ...@@ -109,7 +109,7 @@ class Video extends Component {
this.ws.addEventListener('close', () => { this.ws.addEventListener('close', () => {
if(this.reconnect){ if(this.reconnect){
this.ws = null this.ws = null
this.setupWS() // this.setupWS()
} }
clearInterval(this.timer) clearInterval(this.timer)
}) })
...@@ -332,7 +332,7 @@ class Video extends Component { ...@@ -332,7 +332,7 @@ class Video extends Component {
} }
} }
hasAuth = (index) => { hasAuth = () => {
const {course, videoList, activeIndex} = this.state const {course, videoList, activeIndex} = this.state
let lesson = videoList[activeIndex] let lesson = videoList[activeIndex]
if (!lesson['is_free']) { if (!lesson['is_free']) {
......
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