Commit 6f816124 by xuzhenghua

登陆

parent 968a968f
import React, { Component } from 'react' import React, {Component} from 'react'
import {http, getParam} from '@/utils' import {http, getParam, SendMessageToApp} from '@/utils'
import PythonDes from './pythomDes' import PythonDes from './pythomDes'
import PythonStudy from './pythonStudy' import PythonStudy from './pythonStudy'
import {Toast} from 'antd-mobile' import {connect} from "react-redux"
import {addDays} from "date-fns"
import cookie from "js-cookie"
import {setCurrentUser, startFetchUser} from "@/store/userAction"
@connect(state => ({
user: state.user
}),
{setCurrentUser, startFetchUser}
)
class Python extends Component { class Python extends Component {
constructor(props) { constructor(props) {
super(props); super(props)
this.state = { this.state = {
isPay: '', isPay: '',
userInfoList: [],
isAppUpdate: false
} }
} }
componentDidMount() { componentDidMount() {
this.fetchCourseInfo(); const _this = this
this.fetchCourseInfo()
// 获取App登录信息
window['loginInfo'] = result => {
_this.loginInfo(result)
}
}
// 获取app登录数据
loginInfo = (result) => {
this.setState({
userInfoList: result
}, () => {
if (this.state.userInfoList.length) {
this.props.startFetchUser()
this.appLogin()
}
})
} }
// 保存cookie
appLogin = () => {
let expires = addDays(new Date(), 90)
this.state.userInfoList.map((item, index) => {
cookie.set("token", item.token, {expires, path: '/', domain: '.julyedu.com'})
cookie.set("plat", item.plat, {expires, path: '/', domain: '.julyedu.com'})
cookie.set("uid", item.uid, {expires, path: '/', domain: '.julyedu.com'})
cookie.set("uname", item.uname, {expires, path: '/', domain: '.julyedu.com'})
cookie.set("avatar_file", item.avatar_file, {expires, path: '/', domain: '.julyedu.com'})
})
if (cookie.get("token") && cookie.get("uid")) {
this.setState({
isAppUpdate: true
})
}
this.props.setCurrentUser(this.transformUser(this.state.userInfoList))
}
transformUser = res => {
let payload
res.map((item, index) => {
payload = {
hasError: false,
data: {
username: item.uname,
avatar: item.avatar_file,
token: item.token,
uid: item.uid
},
isFetching: false
}
})
return payload
}
fetchCourseInfo = () => { fetchCourseInfo = () => {
const id = getParam('id'); const id = getParam('id')
http.get(`${API.home}/m/course/detail/${id}`).then((res) => { http.get(`${API.home}/m/course/detail/${id}`).then((res) => {
const { data, code } = res.data; const {data, code} = res.data
if (code === 200) { if (code === 200) {
this.setState({ this.setState({
isPay: data.course_info.is_pay isPay: data.course_info.is_pay
}) })
} }
}); })
} }
render() { render() {
const { isPay } = this.state; const {isPay, isAppUpdate} = this.state
return ( return (
<div> <div>
{ {
isPay === 0 && <PythonDes history={this.props.history}></PythonDes> isPay === 0 && <PythonDes history={this.props.history} isAppUpdate={isAppUpdate}></PythonDes>
} }
{ {
(isPay === 1 && !getParam('version')) && <PythonStudy /> (isPay === 1 && !getParam('version')) && <PythonStudy isAppUpdate={isAppUpdate}/>
} }
</div> </div>
) )
......
import React, { Component } from 'react' import React, {Component} from 'react'
import './index.scss' import './index.scss'
import Description from './Description/index.js'; import Description from './Description/index.js'
import NoWorry from './NoWorry/index.js'; import NoWorry from './NoWorry/index.js'
import Study from './Study/index.js'; import Study from './Study/index.js'
import Test from './Test/index.js'; import Test from './Test/index.js'
import Team from './Team/index.js'; import Team from './Team/index.js'
import Experience from './Experience/index.js' import Experience from './Experience/index.js'
import Progream from './Progream/index.js' import Progream from './Progream/index.js'
import Mask from './../poup/index.js' import Mask from './../poup/index.js'
import {http, getParam, SendMessageToApp, } from '@/utils' import {http, getParam, SendMessageToApp,} from '@/utils'
import { connect } from 'react-redux'; import {connect} from 'react-redux'
import { Toast } from "antd-mobile"; import {Toast} from "antd-mobile"
@connect(state => ({ @connect(state => ({
user: state.user user: state.user
})) }))
class PythonDes extends Component { class PythonDes extends Component {
constructor(props) { constructor(props) {
super(props); super(props)
this.state = { this.state = {
syllabus: [], // 阶梯学习 syllabus: [], // 阶梯学习
allSyllabus: [], // 阶梯学习 allSyllabus: [], // 阶梯学习
...@@ -61,14 +62,38 @@ class PythonDes extends Component { ...@@ -61,14 +62,38 @@ class PythonDes extends Component {
} }
], ],
desList: [ desList: [
{url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/xingshi.png', title: '全新课程形式', subTitle: '对话式交互教学,轻松、生动、不无聊'}, {
{url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/huanjing.png', title: '在线编程环境', subTitle: '无需安装任何编程软件'}, url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/xingshi.png',
{url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/rumen.png', title: '20天零基础入门', subTitle: '降低学习门槛,20天入门人工智能'}, title: '全新课程形式',
subTitle: '对话式交互教学,轻松、生动、不无聊'
},
{
url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/huanjing.png',
title: '在线编程环境',
subTitle: '无需安装任何编程软件'
},
{
url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/rumen.png',
title: '20天零基础入门',
subTitle: '降低学习门槛,20天入门人工智能'
},
], ],
worryList: [ worryList: [
{url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/jiechu.png', title: '初次接触,担心学不会', subTitle: '本课程专门为零基础的你打造,全篇通过最白话沟通交流的方式进行讲解,无论你有无编程经验都可以轻松理解并且掌握。'}, {
{url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/xuexi.png', title: '想学习,没有坚持下来', subTitle: '以故事性的方式编写学习内容, 把生硬的知识点有趣化。精美的图片+幽默的文字+代码编写让你越学越向学。'}, url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/jiechu.png',
{url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/zhishidian.png', title: '知识点掌握了,不知如何运用', subTitle: '每节课的知识点都设有代码编写部分,每节课课后都有课后实操。有多次代码编写练习的机会,助你真正学以致用。'}, title: '初次接触,担心学不会',
subTitle: '本课程专门为零基础的你打造,全篇通过最白话沟通交流的方式进行讲解,无论你有无编程经验都可以轻松理解并且掌握。'
},
{
url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/xuexi.png',
title: '想学习,没有坚持下来',
subTitle: '以故事性的方式编写学习内容, 把生硬的知识点有趣化。精美的图片+幽默的文字+代码编写让你越学越向学。'
},
{
url: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/zhishidian.png',
title: '知识点掌握了,不知如何运用',
subTitle: '每节课的知识点都设有代码编写部分,每节课课后都有课后实操。有多次代码编写练习的机会,助你真正学以致用。'
},
], ],
} }
} }
...@@ -76,31 +101,30 @@ class PythonDes extends Component { ...@@ -76,31 +101,30 @@ class PythonDes extends Component {
// 立即报名 // 立即报名
signUp = () => { signUp = () => {
// 已登录 // 已登录
if(!this.props.user.hasError) { if (!this.props.user.hasError) {
this.toDetail(); this.toDetail()
}else{// 未登录 } else {// 未登录
this.toLogin(); this.toLogin()
} }
} }
// 立即体验、免费试学 // 立即体验、免费试学
tryLearn = () => { tryLearn = () => {
// 已登录 // 已登录
if(!this.props.user.hasError) { if (!this.props.user.hasError) {
this.toLearn(); this.toLearn()
}else{// 未登录 } else {// 未登录
this.toLogin(); this.toLogin()
} }
} }
toLearn = () => { toLearn = () => {
const id = getParam('id');
if (!getParam('version')) { // H5 if (!getParam('version')) { // H5
this.setState({ this.setState({
toApp: true toApp: true
}) })
} else { // APP } else { // APP
SendMessageToApp("toLearn", id); // TODO 待定 需要APP确认 SendMessageToApp("toLearn")
} }
} }
...@@ -111,36 +135,36 @@ class PythonDes extends Component { ...@@ -111,36 +135,36 @@ class PythonDes extends Component {
} }
toDetail = () => { toDetail = () => {
const id = getParam('id'); const id = getParam('id')
if (!getParam('version')) { // H5 if (!getParam('version')) { // H5
http.get(`${API['base-api']}/m/cart/addtopreorder/[${id}]`).then((res) => { http.get(`${API['base-api']}/m/cart/addtopreorder/[${id}]`).then((res) => {
if (res.data.errno === 0) { if (res.data.errno === 0) {
this.props.history.push(`/order?id=${id}`, {simple: 1}) this.props.history.push(`/order?id=${id}`, {simple: 1})
} else { } else {
Toast.info(res.data.msg, 2); Toast.info(res.data.msg, 2)
} }
}) })
} else { // APP } else { // APP
SendMessageToApp('toPay', id); SendMessageToApp('toPay', id)
} }
} }
toLogin = () => { toLogin = () => {
if (!getParam('version')) { // H5 if (!getParam('version')) { // H5
this.props.history.push('/passport'); this.props.history.push('/passport')
} else { // APP } else { // APP
SendMessageToApp("toLogin"); SendMessageToApp("toLogin")
} }
} }
showAll = (key) => { showAll = (key) => {
if(key === 1) { if (key === 1) {
this.setState({ this.setState({
syllabus: this.state.allSyllabus, syllabus: this.state.allSyllabus,
allSyllabusShow: true, allSyllabusShow: true,
}) })
} }
if(key === 2) { if (key === 2) {
this.setState({ this.setState({
practice: this.state.allPractice, practice: this.state.allPractice,
allPracticeShow: true, allPracticeShow: true,
...@@ -148,13 +172,13 @@ class PythonDes extends Component { ...@@ -148,13 +172,13 @@ class PythonDes extends Component {
} }
} }
hideSome = (key) => { hideSome = (key) => {
if(key === 1) { if (key === 1) {
this.setState({ this.setState({
syllabus: this.state.allSyllabus.slice(0, 2), syllabus: this.state.allSyllabus.slice(0, 2),
allSyllabusShow: false, allSyllabusShow: false,
}) })
} }
if(key === 2) { if (key === 2) {
this.setState({ this.setState({
practice: this.state.allPractice.slice(0, 2), practice: this.state.allPractice.slice(0, 2),
allPracticeShow: false, allPracticeShow: false,
...@@ -162,9 +186,9 @@ class PythonDes extends Component { ...@@ -162,9 +186,9 @@ class PythonDes extends Component {
} }
} }
componentDidMount() { getStatus = () => {
http.get(`${API['home']}/web/it_detail?course_id=180`).then(res => { http.get(`${API['home']}/web/it_detail?course_id=${getParam('id')}`).then(res => {
const { code, data, msg } = res.data const {code, data, msg} = res.data
if (code == 200) { if (code == 200) {
this.setState({ this.setState({
syllabus: data.syllabus.slice(0, 2), syllabus: data.syllabus.slice(0, 2),
...@@ -173,22 +197,37 @@ class PythonDes extends Component { ...@@ -173,22 +197,37 @@ class PythonDes extends Component {
allPractice: data.practice, allPractice: data.practice,
}) })
} else { } else {
Message.warning(msg); Toast.info(msg)
}
})
}
componentDidMount() {
this.getStatus()
}
shouldComponentUpdate(nextProps, nextState, nextContext) {
if (this.props.isAppUpdate !== nextProps.isAppUpdate) {
this.getStatus()
return false
} }
}); return true
} }
render() { render() {
const {defineList, desList, worryList, syllabus, practice, allSyllabusShow, allPracticeShow, toApp} = this.state; const {defineList, desList, worryList, syllabus, practice, allSyllabusShow, allPracticeShow, toApp} = this.state
return ( return (
<div className={'python__des'}> <div className={'python__des'}>
<div className={'des__start'}></div> <div className={'des__start'}></div>
<div className={'python__define'}> <div className={'python__define'}>
<img className={'left__decorate'} src={'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/left__decorate.png'}></img> <img className={'left__decorate'}
<img className={'right__decorate'} src={'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/right__decorate.png'}></img> src={'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/left__decorate.png'}></img>
<img className={'right__decorate'}
src={'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/right__decorate.png'}></img>
<p className={'define__title'}> / / / Python</p> <p className={'define__title'}> / / / Python</p>
{ {
defineList.map((item,index) => { defineList.map((item, index) => {
return <DefineItem item={item} key={index}></DefineItem> return <DefineItem item={item} key={index}></DefineItem>
}) })
} }
...@@ -210,14 +249,17 @@ class PythonDes extends Component { ...@@ -210,14 +249,17 @@ class PythonDes extends Component {
</div> </div>
<Description list={desList}></Description> <Description list={desList}></Description>
<NoWorry list={worryList}></NoWorry> <NoWorry list={worryList}></NoWorry>
<Study syllabus={syllabus} allSyllabusShow={allSyllabusShow} show={this.showAll} hide={this.hideSome}></Study> <Study syllabus={syllabus} allSyllabusShow={allSyllabusShow} show={this.showAll}
<Test practice={practice} allPracticeShow={allPracticeShow} show={this.showAll} hide={this.hideSome}></Test> hide={this.hideSome}></Study>
<Team /> <Test practice={practice} allPracticeShow={allPracticeShow} show={this.showAll}
<Experience tryLearn={this.tryLearn} /> hide={this.hideSome}></Test>
<img style={{display: 'block', width: '100%', height: '8px'}} src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/changjian.png" alt=""/> <Team/>
<Progream /> <Experience tryLearn={this.tryLearn}/>
<img style={{display: 'block', width: '100%', height: '8px'}}
src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/h5_python_class/changjian.png" alt=""/>
<Progream/>
{ {
toApp && (<Mask type={1} closePop={this.closePop} />) toApp && (<Mask type={1} closePop={this.closePop}/>)
} }
</div> </div>
) )
...@@ -225,7 +267,7 @@ class PythonDes extends Component { ...@@ -225,7 +267,7 @@ class PythonDes extends Component {
} }
function DefineItem(props) { function DefineItem(props) {
const {item, item: {desInfo}} = props; const {item, item: {desInfo}} = props
return ( return (
<div className={'number_one'}> <div className={'number_one'}>
<img className={'trophy'} src={item.titleUrl}></img> <img className={'trophy'} src={item.titleUrl}></img>
......
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