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
...@@ -52,3 +53,8 @@ export const NOMORE_COURSE = 'NOMORE_COURSES' ...@@ -52,3 +53,8 @@ export const NOMORE_COURSE = 'NOMORE_COURSES'
export const nomoreCourse = () => ({ export const nomoreCourse = () => ({
type: NOMORE_COURSE type: NOMORE_COURSE
}) })
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,8 +100,11 @@ class MyCourses extends PureComponent { ...@@ -95,8 +100,11 @@ 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}>
{
list && list.length !== 0
?
<> <>
<div className="my-course-uid"> <div className="my-course-uid">
{`加群请备注您的学号:${this.props.user.data.uid}`} {`加群请备注您的学号:${this.props.user.data.uid}`}
...@@ -156,9 +164,7 @@ class MyCourses extends PureComponent { ...@@ -156,9 +164,7 @@ class MyCourses extends PureComponent {
: null : null
} }
</> </>
) :
} else {
return (
<div className="empty"> <div className="empty">
<p><i className='iconfont iconfish'/></p> <p><i className='iconfont iconfish'/></p>
<p className='empty-prompt'>还是咸鱼一条,快去翻身~</p> <p className='empty-prompt'>还是咸鱼一条,快去翻身~</p>
...@@ -166,8 +172,8 @@ class MyCourses extends PureComponent { ...@@ -166,8 +172,8 @@ class MyCourses extends PureComponent {
<Link className='select-course' to='/classify'>去选课</Link> <Link className='select-course' to='/classify'>去选课</Link>
</p> </p>
</div> </div>
)
} }
</Loading>
} }
} }
...@@ -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