Commit acf4003d by xuzhenghua

登录

parent 10311673
......@@ -6,6 +6,7 @@ import {connect} from "react-redux"
import {addDays} from "date-fns"
import cookie from "js-cookie"
import {setCurrentUser, startFetchUser} from "@/store/userAction"
import {Toast} from "antd-mobile"
@connect(state => ({
......@@ -32,6 +33,88 @@ class ML extends Component {
window['loginInfo'] = result => {
_this.loginInfo(result)
}
if (browser.isWeixin) {
this.isweixinPay()
}
if (getParam('weixinpay')) {
this.payCallback()
}
}
// 微信内部支付回调
isweixinPay = () => {
let _this = this;
let weixin_code = getParam('code');
if (weixin_code) {
if (getParam('oid') === undefined) {
return
} else {
http.get(`${API['base-api']}/pay/wxpay/pub_charge/oid/${getParam('oid')}/code/${weixin_code}`).then((res) => {
if (res.data.errno === 0) {
let data = res.data.data;
function onBridgeReady() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
appId: data.appId, //公众号名称,由商户传入
timeStamp: data.timeStamp, //时间戳,自1970年以来的秒数
nonceStr: data.nonceStr, //随机串
package: data.package,
signType: data.signType, //微信签名方式:
paySign: data.paySign //微信签名
},
function (res) {
if (res.err_msg == "get_brand_wcpsys/order_status/ay_request:ok") {
Toast.info('支付成功', 2);
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
} else {
Toast.info('支付失败', 2);
}
}
)
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
}
} else {
onBridgeReady();
}
} else {
Toast.info(res.data.msg, 2)
}
})
}
}
}
// 支付完成之后获取状态
payCallback = () => {
const _this = this;
// 支付回调
// 定时器轮训获取订单状态
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
}
// 获取app登录数据
......@@ -133,9 +216,9 @@ class ML extends Component {
<div>
{
isPay === 0 && (
<PythonDes
<PythonDes
backwardVersion={backwardVersion}
history={this.props.history}
history={this.props.history}
isAppUpdate={isAppUpdate}
isPay={isPay}
/>
......
import React, { Component } from 'react'
import React, {Component} from 'react'
import './index.scss'
import Description from './Description/index.js'
import Study from './Study/index.js'
......@@ -9,389 +9,326 @@ import Selection from './Selection'
import Mask from './../poup/index.js'
import InAction from "./InAction"
import ShareRank from "@components/detail/shareRank"
import { http, getParam, SendMessageToApp, browser} from '@/utils'
import { connect } from 'react-redux'
import { Toast } from "antd-mobile"
import { CallApp } from "@common/index"
import {http, getParam, SendMessageToApp, browser} from '@/utils'
import {connect} from 'react-redux'
import {Toast} from "antd-mobile"
import {CallApp} from "@common/index"
@connect(state => ({
user: state.user
user: state.user
}))
class PythonDes extends Component {
constructor(props) {
super(props)
this.state = {
syllabus: [], // 阶梯学习
allSyllabus: [], // 阶梯学习
allSyllabusShow: false,
allPractice: [], // 课后实操
toApp: false,
payMoney: 0,
isOnline: true, //课程是否上架
courseInfo: {},
isShowChannel: window.sessionStorage.getItem('isShowSiteWindowByChannel'),
orderId:''
constructor(props) {
super(props)
this.state = {
syllabus: [], // 阶梯学习
allSyllabus: [], // 阶梯学习
allSyllabusShow: false,
allPractice: [], // 课后实操
toApp: false,
payMoney: 0,
isOnline: true, //课程是否上架
courseInfo: {},
isShowChannel: window.sessionStorage.getItem('isShowSiteWindowByChannel'),
orderId: ''
}
}
}
// 立即报名
// signUp = () => {
// this.statistics(3)
// // 已登录
// if (!this.props.user.hasError) {
// this.toDetail()
// } else {// 未登录
// this.toLogin()
// }
// }
// 立即报名
// signUp = () => {
// this.statistics(3)
// // 已登录
// if (!this.props.user.hasError) {
// this.toDetail()
// } else {// 未登录
// this.toLogin()
// }
// }
// 立即体验、免费试学
tryLearn = type => {
this.statistics(type)
// 已登录
if (!this.props.user.hasError) {
this.creatOid()
} else {// 未登录
this.toLogin()
// 立即体验、免费试学
tryLearn = type => {
this.statistics(type)
// 已登录
if (!this.props.user.hasError) {
this.creatOid()
} else {// 未登录
this.toLogin()
}
}
}
creatOid=()=>{
http.post(`${API['base-api']}/sys/trial_create`, {course_id: getParam('id')}).then(res => {
const {errno, data, msg} = res.data
if (errno === 200) {
this.setState({
orderId: data.oid
creatOid = () => {
http.post(`${API['base-api']}/sys/trial_create`, {course_id: getParam('id')}).then(res => {
const {errno, data, msg} = res.data
if (errno === 200) {
this.setState({
orderId: data.oid
})
this.weixinPay(data.oid)
} else {
Toast.info(msg, 2)
}
})
this.weixinPay(data.oid)
} else {
Toast.info(msg, 2)
}
})
}
// 微信支付
weixinPay = (orderId) => {
// 微信内部-支付
if (browser.isWeixin) {
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=" + encodeURIComponent(window.location.href + "&aa=bb&oid=" + orderId).toLowerCase() + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
} else {
// 微信外部-支付
http.get(`${API['base-api']}/pay/wxpay/wap_charge/oid/${orderId}`).then((res) => {
if (res.data.errno === 0) {
window.location.href = res.data.data.url + "&redirect_url=" + encodeURIComponent(window.location.href + "&weixinpay=1&oid=" + orderId).toLowerCase();
}
// 微信支付
weixinPay = (orderId) => {
// 微信内部-支付
if (browser.isWeixin) {
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=" + encodeURIComponent(window.location.href + "&aa=bb&oid=" + orderId).toLowerCase() + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
} else {
Toast.info(res.data.msg, 2)
// 微信外部-支付
http.get(`${API['base-api']}/pay/wxpay/wap_charge/oid/${orderId}`).then((res) => {
if (res.data.errno === 0) {
window.location.href = res.data.data.url + "&redirect_url=" + encodeURIComponent(window.location.href + "&weixinpay=1&oid=" + orderId).toLowerCase()
} else {
Toast.info(res.data.msg, 2)
}
})
}
})
}
}
// 微信支付
isweixinPay = () => {
let _this = this;
let weixin_code = getParam('code');
if (weixin_code) {
if (getParam('oid') === undefined) {
return
} else {
http.get(`${API['base-api']}/pay/wxpay/pub_charge/oid/${getParam('oid')}/code/${weixin_code}`).then((res) => {
if (res.data.errno === 0) {
let data = res.data.data;
function onBridgeReady() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
appId: data.appId, //公众号名称,由商户传入
timeStamp: data.timeStamp, //时间戳,自1970年以来的秒数
nonceStr: data.nonceStr, //随机串
package: data.package,
signType: data.signType, //微信签名方式:
paySign: data.paySign //微信签名
},
function (res) {
if (res.err_msg == "get_brand_wcpsys/order_status/ay_request:ok") {
Toast.info('支付成功', 2);
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
toLearn = () => {
const {backwardVersion} = this.props
http.post(`${API['home']}/m/it/user/trialCourse`, {course_id: getParam('id')}).then((res) => {
const {code, msg} = res.data
if (code == 200) {
if (!getParam('version')) { // H5
this.setState({
toApp: true
})
} else { // APP
if (backwardVersion) {
Toast.info('当前版本不支持该课程模式,请升级到最新版本或前往PC端体验', 2)
} else {
Toast.info('支付失败', 2);
SendMessageToApp("toLearn", getParam('id'))
}
}
)
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
}
}
} else {
onBridgeReady();
Toast.info(msg, 2)
}
} else {
Toast.info(res.data.msg, 2)
}
})
}
}
}
// 支付完成之后获取状态
payCallback = () => {
const _this = this;
// 支付回调
// 定时器轮训获取订单状态
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
}
toLearn = () => {
const {backwardVersion} = this.props;
http.post(`${API['home']}/m/it/user/trialCourse`, {course_id: getParam('id')}).then((res) => {
const {code, msg} = res.data
if (code == 200) {
closePop = () => {
this.setState({
toApp: false
})
}
toDetail = () => {
const {backwardVersion} = this.props
const id = getParam('id')
if (!getParam('version')) { // H5
this.setState({
toApp: true
})
http.get(`${API['base-api']}/m/cart/addtopreorder/[${id}]`).then((res) => {
if (res.data.errno === 0) {
this.props.history.push(`/order?id=${id}`, {simple: 1})
} else {
Toast.info(res.data.msg, 2)
}
})
} else { // APP
if (backwardVersion) {
Toast.info('当前版本不支持该课程模式,请升级到最新版本或前往PC端体验', 2)
} else {
SendMessageToApp("toLearn", getParam('id'))
}
if (backwardVersion) {
Toast.info('当前版本不支持该课程模式,请升级到最新版本或前往PC端购买', 2)
let onlyoneUse = setTimeout(() => {
clearTimeout(onlyoneUse)
onlyoneUse = null
SendMessageToApp('toPay', id)
}, 2000)
} else {
SendMessageToApp('toPay', id)
}
}
} else {
Toast.info(msg, 2)
}
})
}
closePop = () => {
this.setState({
toApp: false
})
}
}
toDetail = () => {
const {backwardVersion} = this.props;
const id = getParam('id')
if (!getParam('version')) { // H5
http.get(`${API['base-api']}/m/cart/addtopreorder/[${id}]`).then((res) => {
if (res.data.errno === 0) {
this.props.history.push(`/order?id=${id}`, {simple: 1})
} else {
Toast.info(res.data.msg, 2)
toLogin = () => {
if (!getParam('version')) { // H5
this.changeLoginType()
} else { // APP
SendMessageToApp("toLogin")
}
})
} else { // APP
if (backwardVersion) {
Toast.info('当前版本不支持该课程模式,请升级到最新版本或前往PC端购买', 2);
let onlyoneUse = setTimeout(() => {
clearTimeout(onlyoneUse);
onlyoneUse = null;
SendMessageToApp('toPay', id)
}, 2000);
} else {
SendMessageToApp('toPay', id)
}
}
}
toLogin = () => {
if (!getParam('version')) { // H5
this.props.history.push('/passport')
} else { // APP
SendMessageToApp("toLogin")
// 点击登录 提示微信登录还是账号登录,微信授权登录不需要绑定手机号
changeLoginType = () => {
// 微信登录
if (browser.isWeixin) {
// tool.setCookie('redirect_url', window.location.href);
let url = window.location.href
if (url.includes('code=') && url.includes('state=STATE')) {
let index = url.lastIndexOf('code=')
url = url.substr(0, index - 1)
}
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=" + encodeURIComponent(url).toLowerCase() + "&aa=bb&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
} else {
// 账号登录
this.props.history.push('/passport')
}
}
}
showAll = (key) => {
if (key === 1) {
this.setState({
syllabus: this.state.allSyllabus,
allSyllabusShow: true,
})
}
if (key === 2) {
this.setState({
practice: this.state.allPractice,
allPracticeShow: true,
})
}
}
hideSome = (key) => {
if (key === 1) {
this.setState({
syllabus: this.state.allSyllabus.slice(0, 2),
allSyllabusShow: false,
})
showAll = (key) => {
if (key === 1) {
this.setState({
syllabus: this.state.allSyllabus,
allSyllabusShow: true,
})
}
if (key === 2) {
this.setState({
practice: this.state.allPractice,
allPracticeShow: true,
})
}
}
if (key === 2) {
this.setState({
practice: this.state.allPractice.slice(0, 2),
allPracticeShow: false,
})
hideSome = (key) => {
if (key === 1) {
this.setState({
syllabus: this.state.allSyllabus.slice(0, 2),
allSyllabusShow: false,
})
}
if (key === 2) {
this.setState({
practice: this.state.allPractice.slice(0, 2),
allPracticeShow: false,
})
}
}
}
getStatus = () => {
http.get(`${API['home']}/web/it_detail?course_id=${getParam('id')}`).then(res => {
const {code, data, msg} = res.data
if (code == 200) {
this.setState({
syllabus: data.syllabus.slice(0, 2),
allSyllabus: data.syllabus,
allPractice: data.practice,
payMoney: data.course_info.price1,
courseInfo: data.course_info
getStatus = () => {
http.get(`${API['home']}/web/it_detail?course_id=${getParam('id')}`).then(res => {
const {code, data, msg} = res.data
if (code == 200) {
this.setState({
syllabus: data.syllabus.slice(0, 2),
allSyllabus: data.syllabus,
allPractice: data.practice,
payMoney: data.course_info.price1,
courseInfo: data.course_info
})
} else {
Toast.info(msg)
}
})
} else {
Toast.info(msg)
}
})
}
}
componentDidMount() {
this.getStatus()
componentDidMount() {
this.getStatus()
const {backwardVersion, isPay} = this.props;
if (backwardVersion && isPay === 1) {
Toast.info('当前版本不支持该课程模式,请升级到最新版本或前往PC端学习', 2);
const {backwardVersion, isPay} = this.props
if (backwardVersion && isPay === 1) {
Toast.info('当前版本不支持该课程模式,请升级到最新版本或前往PC端学习', 2)
}
}
if (browser.isWeixin) {
this.isweixinPay()
}
if (getParam('weixinpay')) {
this.payCallback()
// 统计
statistics = type => {
http.post(`${API.home}/web/it_click_num/${getParam('id')}`, {type})
}
}
// 统计
statistics = type => {
http.post(`${API.home}/web/it_click_num/${getParam('id')}`, {type})
}
shouldComponentUpdate(nextProps, nextState, nextContext) {
if (this.props.isAppUpdate !== nextProps.isAppUpdate) {
this.getStatus()
return false
shouldComponentUpdate(nextProps, nextState, nextContext) {
if (this.props.isAppUpdate !== nextProps.isAppUpdate) {
this.getStatus()
return false
}
return true
}
return true
}
render() {
const {
syllabus,
allSyllabusShow,
toApp,
payMoney,
isOnline,
courseInfo
} = this.state
return (
<div className={'python__des'}>
<div className={'des__start'}></div>
{
!!courseInfo.is_dist && <ShareRank courseInfo={courseInfo}/>
}
<div className={'course__introduce'}></div>
{
isOnline
? (
<div className={'bottom__btn_group'}>
<div className={'course__price'}>
<div className={'money'}>{payMoney}<span style={{fontSize: '18px'}}></span></div>
<div className={'discount'}>
限时特惠
<div className={'triangle'}></div>
</div>
</div>
render() {
const {
syllabus,
allSyllabusShow,
toApp,
payMoney,
isOnline,
courseInfo
} = this.state
return (
<div className={'python__des'}>
<div className={'des__start'}></div>
{
!!courseInfo.is_dist && <ShareRank courseInfo={courseInfo}/>
}
<div className={'course__introduce'}></div>
{
isOnline
? (
<div className={'bottom__btn_group'}>
<div className={'course__price'}>
<div className={'money'}>{payMoney}<span style={{fontSize: '18px'}}></span></div>
<div className={'discount'}>
限时特惠
<div className={'triangle'}></div>
</div>
</div>
<div className={'btn__group'}>
<div className={'try__study'} onClick={() => {
this.tryLearn(3)
}}>立即报名</div>
<div className={'sign__now'} onClick={() => {
this.tryLearn(2)
}}>9.9特价试学
</div>
</div>
</div>
)
: (
<div className="bottom__btn_group">
<p className="online__label">Python人工智能</p>
<button className="online__button">即将上架 敬请期待</button>
</div>
)
}
<div className={'btn__group'}>
<div className={'try__study'} onClick={() => {
this.tryLearn(3)
}}>立即报名
</div>
<div className={'sign__now'} onClick={() => {
this.tryLearn(2)
}}>9.9特价试学
</div>
</div>
</div>
)
: (
<div className="bottom__btn_group">
<p className="online__label">Python人工智能</p>
<button className="online__button">即将上架 敬请期待</button>
</div>
)
}
{
this.state.isShowChannel == 1 &&
<CallApp className='toapp'/>
}
{/* 课程介绍 */}
<Description/>
{
this.state.isShowChannel == 1 &&
<CallApp className='toapp'/>
}
{/* 课程介绍 */}
<Description/>
<Study syllabus={syllabus} allSyllabusShow={allSyllabusShow} show={this.showAll}
hide={this.hideSome}></Study>
<Study syllabus={syllabus} allSyllabusShow={allSyllabusShow} show={this.showAll}
hide={this.hideSome}></Study>
{/*精选习题*/}
<Selection/>
{/*精选习题*/}
<Selection/>
{/*项目实战*/}
<InAction/>
{/*项目实战*/}
<InAction/>
<Team/>
<Team/>
{/* 试学体验 */}
<Experience tryLearn={this.tryLearn} isOnline={isOnline}/>
<img
style={{
display: 'block',
width: '100%',
height: '8px'
}}
src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/mlCourse/m/di.png"
alt=""
/>
{/* 试学体验 */}
<Experience tryLearn={this.tryLearn} isOnline={isOnline}/>
<img
style={{
display: 'block',
width: '100%',
height: '8px'
}}
src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/mlCourse/m/di.png"
alt=""
/>
{/* 常见问题 */}
<Progream/>
{
toApp && (<Mask type={1} closePop={this.closePop}/>)
}
</div>
)
}
{/* 常见问题 */}
<Progream/>
{
toApp && (<Mask type={1} closePop={this.closePop}/>)
}
</div>
)
}
}
function DefineItem(props) {
const {item, item: {desInfo}} = props
return (
<div className={'number_one'}>
<img className={'trophy'} src={item.titleUrl}></img>
<p className={'item__title'}>{item.title}</p>
<p className={'item__subtitle'} style={{width: item.subWidth}}>{item.subTitle}</p>
<img style={{width: desInfo.width, height: desInfo.height}} src={item.bottomUrl}></img>
</div>
)
const {item, item: {desInfo}} = props
return (
<div className={'number_one'}>
<img className={'trophy'} src={item.titleUrl}></img>
<p className={'item__title'}>{item.title}</p>
<p className={'item__subtitle'} style={{width: item.subWidth}}>{item.subTitle}</p>
<img style={{width: desInfo.width, height: desInfo.height}} src={item.bottomUrl}></img>
</div>
)
}
export default PythonDes
......@@ -23,13 +23,6 @@ class PythonStudy extends Component {
componentDidMount() {
this.fetchCourseDetail()
if (browser.isWeixin) {
this.isweixinPay()
}
if (getParam('weixinpay')) {
this.payCallback()
}
}
fetchCourseDetail = () => {
......@@ -119,79 +112,7 @@ class PythonStudy extends Component {
})
}
}
// 微信支付
isweixinPay = () => {
let _this = this;
let weixin_code = getParam('code');
if (weixin_code) {
if (getParam('oid') === undefined) {
return
} else {
http.get(`${API['base-api']}/pay/wxpay/pub_charge/oid/${getParam('oid')}/code/${weixin_code}`).then((res) => {
if (res.data.errno === 0) {
let data = res.data.data;
function onBridgeReady() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
appId: data.appId, //公众号名称,由商户传入
timeStamp: data.timeStamp, //时间戳,自1970年以来的秒数
nonceStr: data.nonceStr, //随机串
package: data.package,
signType: data.signType, //微信签名方式:
paySign: data.paySign //微信签名
},
function (res) {
if (res.err_msg == "get_brand_wcpsys/order_status/ay_request:ok") {
Toast.info('支付成功', 2);
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
} else {
Toast.info('支付失败', 2);
}
}
)
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
}
} else {
onBridgeReady();
}
} else {
Toast.info(res.data.msg, 2)
}
})
}
}
}
// 支付完成之后获取状态
payCallback = () => {
const _this = this;
// 支付回调
// 定时器轮训获取订单状态
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
}
render() {
const {user} = this.props
......
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