Commit 437fc544 by zhanghaozhe

study redux

parent 96638577
src/
\ No newline at end of file
...@@ -4046,6 +4046,11 @@ ...@@ -4046,6 +4046,11 @@
} }
} }
}, },
"date-fns": {
"version": "1.30.1",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz",
"integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw=="
},
"date-now": { "date-now": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz",
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"bfj": "6.1.1", "bfj": "6.1.1",
"case-sensitive-paths-webpack-plugin": "2.2.0", "case-sensitive-paths-webpack-plugin": "2.2.0",
"css-loader": "1.0.0", "css-loader": "1.0.0",
"date-fns": "^1.30.1",
"dotenv": "6.0.0", "dotenv": "6.0.0",
"dotenv-expand": "4.2.0", "dotenv-expand": "4.2.0",
"eslint": "5.12.0", "eslint": "5.12.0",
......
...@@ -7,7 +7,7 @@ const VList = (props) => { ...@@ -7,7 +7,7 @@ const VList = (props) => {
<div className="content"> <div className="content">
<div className="cover" onClick={props.handleClick}> <div className="cover" onClick={props.handleClick}>
{props.status} {props.status}
<img src='https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/4c5ccac604.jpg' alt=""/> <img src={props.img} alt=""/>
</div> </div>
{props.info} {props.info}
</div> </div>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
border-bottom: 1px solid $sp_e7eaf1; border-bottom: 1px solid $sp_e7eaf1;
.cover { .cover {
flex: 1 0 auto; flex: 0 0 auto;
margin-right: 16px; margin-right: 16px;
position: relative; position: relative;
img { img {
......
...@@ -16,10 +16,12 @@ class FreeCourse extends PureComponent { ...@@ -16,10 +16,12 @@ class FreeCourse extends PureComponent {
state = { state = {
courses: [], courses: [],
live: [], live: [],
page: 1,
num: 10
} }
async componentDidMount() { componentDidMount() {
api.get('/m/free_course/1/10') this.getFreeCourses()
.then(res => { .then(res => {
if (res.data.code == 200) { if (res.data.code == 200) {
this.setState({ this.setState({
...@@ -29,9 +31,9 @@ class FreeCourse extends PureComponent { ...@@ -29,9 +31,9 @@ class FreeCourse extends PureComponent {
console.log(res.data.msg) console.log(res.data.msg)
} }
}) })
api.get('/m/live/free_list') this.getFreeLive()
.then(res => { .then(res => {
if(res.data.code == 200){ if (res.data.code == 200) {
this.setState({ this.setState({
live: res.data.data live: res.data.data
}) })
...@@ -39,6 +41,14 @@ class FreeCourse extends PureComponent { ...@@ -39,6 +41,14 @@ class FreeCourse extends PureComponent {
}) })
} }
getFreeCourses = () => {
return api.get(`/m/free_course/${this.state.page}/${this.state.num}`)
}
getFreeLive = () => {
return api.get(`/m/live/free_list`)
}
render() { render() {
return ( return (
<ul className='free-courses'> <ul className='free-courses'>
...@@ -49,9 +59,6 @@ class FreeCourse extends PureComponent { ...@@ -49,9 +59,6 @@ class FreeCourse extends PureComponent {
src: item.logo, src: item.logo,
title: item.video_course_name title: item.video_course_name
}} }}
top={
<Tag className={'tag-starting top'}>即将开始</Tag>
}
bottom={ bottom={
<Bottom audience={item.lessons} className={'tag-category'} text={item.category}/> <Bottom audience={item.lessons} className={'tag-category'} text={item.category}/>
} }
...@@ -60,12 +67,12 @@ class FreeCourse extends PureComponent { ...@@ -60,12 +67,12 @@ class FreeCourse extends PureComponent {
</Course> </Course>
)) ))
} }
{ {/*{
/*this.state.live.map((item,index) => ( this.state.live.map((item,index) => (
<Course <Course
data={{ data={{
src: item.logo, src: item.live_img,
title: item.video_course_name title: item.live_title
}} }}
top={ top={
<Tag className={'tag-starting top'}>即将开始</Tag> <Tag className={'tag-starting top'}>即将开始</Tag>
...@@ -73,13 +80,14 @@ class FreeCourse extends PureComponent { ...@@ -73,13 +80,14 @@ class FreeCourse extends PureComponent {
bottom={ bottom={
<Bottom audience={item.lessons} className={'tag-category'} text={item.category}/> <Bottom audience={item.lessons} className={'tag-category'} text={item.category}/>
} }
key={index} key={item.live_id}
/> />
))*/ ))
} }*/}
</ul> </ul>
) )
} }
} }
export default FreeCourse export default FreeCourse
\ No newline at end of file
import { api } from '@/utils'
export const RECEIVE_MY_COURSES = 'RECEIVE_MY_COURSES'
export const receiveMyCourses = payload => ({
type: RECEIVE_MY_COURSES,
payload
})
export const getMyCourses = payload => dispatch => {
return api.get(`/m/my_course/${payload.page}/${payload.num}`)
.then(res => {
dispatch(receiveMyCourses(res.data))
})
}
const fetchCoursesListIfNeeded = payload => {
}
...@@ -2,6 +2,10 @@ import React, { PureComponent } from "react" ...@@ -2,6 +2,10 @@ import React, { PureComponent } from "react"
import { VList } from '../../../common' import { VList } from '../../../common'
import './my-courses.scss' import './my-courses.scss'
import { api } from '@/utils' import { api } from '@/utils'
import { isToday, format } from "date-fns"
import { connect } from "react-redux"
import { getMyCourses } from "./actions"
const mockData = [ const mockData = [
{ {
...@@ -42,6 +46,15 @@ const mockData = [ ...@@ -42,6 +46,15 @@ const mockData = [
] ]
function getStudyTime(seconds) {
return {
hour: Math.floor(seconds / (60 * 60)),
min: Math.floor(seconds / 60) % 60,
sec: seconds % 60
}
}
function AddCourse(props) { function AddCourse(props) {
return ( return (
<div className='add-course'> <div className='add-course'>
...@@ -50,7 +63,39 @@ function AddCourse(props) { ...@@ -50,7 +63,39 @@ function AddCourse(props) {
) )
} }
export default class MyCourses extends PureComponent { function Record({record: {seconds, lesson_name}}) {
let re = /第[\s\S]+?课/,
result = ''
if (lesson_name) {
let matchResult = re.exec(lesson_name)
result += (matchResult && matchResult[0]) ? matchResult[0] : ''
}
if (seconds) {
let studyTime = getStudyTime(seconds)
let hour = studyTime.hour ? String(studyTime.hour).padStart(2, '0') + ':' : '',
min = studyTime.min ? String(studyTime.min).padStart(2, '0') + ':' : '',
sec = studyTime.sec ? String(studyTime.sec).padStart(2, '0') : ''
result += hour + min + sec
}
return (
<span className={'record'}>
{
result.length ? `学习到${result}` : null
}
</span>
)
}
class MyCourses extends PureComponent {
state = {
courseList: this.props.courseList.data
}
handleClick = () => { handleClick = () => {
console.log(1); console.log(1);
} }
...@@ -58,26 +103,49 @@ export default class MyCourses extends PureComponent { ...@@ -58,26 +103,49 @@ export default class MyCourses extends PureComponent {
console.log(2); console.log(2);
} }
render() { componentDidMount() {
console.log(this.props.courseList)
/*api.get('/m/my_course/1/10')
.then(res => {
if (res.data.code == 200) {
this.setState({
courseList: res.data.data
});
} else {
console.log(res.data.msg)
}
})*/
this.props.getMyCourses({page: 1, num: 10});
}
if (mockData.length !== 0) { render() {
let { data } = this.props.courseList
console.log(data)
if (data && data.length !== 0) {
return ( return (
<> <>
<ul> <ul>
{ {
mockData.map((item, index) => { data.map((item, index) => {
let date = new Date(item.ago * 1000)
let time = isToday(date) ? format(date, 'HH时mm分') : format(date, 'MM月DD日')
const Info = ( const Info = (
<div className="info"> <div className="info">
<p className='title'>{item.title}</p> <p className='title'>{item.course_title}</p>
<p className='contact'>{item.contact}</p> <p className='contact'>QQ群:{item.course_qq || 449141326}</p>
<p className='des'> <p className='des'>
<span className='time'>{item.time}</span> <span className='time'>{time}</span>
<span className='record'>{item.record}</span> <Record record={item}/>
</p> </p>
</div> </div>
) )
return ( return (
<VList handleClick={this.handleClick} {...item} key={index} info={Info}></VList> <VList img={item.image_name}
handleClick={this.handleClick}
{...item} key={index}
info={Info}/>
) )
}) })
} }
...@@ -98,4 +166,12 @@ export default class MyCourses extends PureComponent { ...@@ -98,4 +166,12 @@ export default class MyCourses extends PureComponent {
} }
} }
} }
\ No newline at end of file
const mapStateToProps = state => ({
courseList: state.myCourses.courseList
})
const mapDispatchToProps = {getMyCourses}
export default connect(mapStateToProps,mapDispatchToProps)(MyCourses)
\ No newline at end of file
.info { .info {
display: flex; display: flex;
//flex-flow: column wrap;
//justify-content: space-between;
flex-wrap: wrap; flex-wrap: wrap;
width: 55%;
.title { .title {
font-size: 15px; font-size: 15px;
font-weight: 400; font-weight: 400;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
} }
.contact { .contact {
...@@ -13,9 +20,10 @@ ...@@ -13,9 +20,10 @@
} }
.des { .des {
align-self: center;
color: $color_999; color: $color_999;
font-size: 11px; font-size: 11px;
align-self: flex-end;
line-height: 1;
.time { .time {
margin-right: 10px; margin-right: 10px;
......
import {RECEIVE_MY_COURSES} from './actions'
const initialState = {
isValid: false,
courseList: []
}
export default function myCourses(state = initialState, action) {
switch (action.type) {
case RECEIVE_MY_COURSES:
return Object.assign({}, state, {courseList: action.payload})
default:
return state
}
}
\ No newline at end of file
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import searchReducer from '@/components/search/store/reducer'; import searchReducer from '@/components/search/store/reducer';
import myCourses from '@/components/study/myCourses/reducers'
const reducer = combineReducers({ const reducer = combineReducers({
searchReducer searchReducer,
myCourses
}); });
export default reducer; export default reducer;
\ No newline at end of file
...@@ -6,10 +6,7 @@ export const BASE_URL = process.env.NODE_ENV === 'development' ? '/api': 'https: ...@@ -6,10 +6,7 @@ export const BASE_URL = process.env.NODE_ENV === 'development' ? '/api': 'https:
const instance = axios.create({ const instance = axios.create({
baseURL: BASE_URL, baseURL: BASE_URL,
transformRequest: [ transformRequest: [
(data) => { (data) => qs.stringify(data)
return qs.stringify(data)
}
] ]
}) })
......
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