Commit 2a04d736 by zhanghaozhe

Merge branch 'master' into study

parents 6fccff3b c3c32002
......@@ -61,6 +61,7 @@
"react-mobile-swiper": "^1.1.4",
"react-redux": "^7.0.2",
"react-router-dom": "^5.0.1",
"react-spinners": "^0.5.4",
"redux": "^4.0.1",
"redux-immutable": "^4.0.0",
"redux-logger": "^3.0.6",
......
import React, { Component } from 'react'
import Routes from './router'
import cookie from 'js-cookie'
import { http, api } from '@/utils';
import { connect } from 'react-redux';
import { setCurrentUser } from '@/store/userAction';
import { connect } from "react-redux";
import { setCurrentUser, startFetchUser } from "@/store/userAction";
import { withRouter } from 'react-router-dom'
import { compose } from 'redux'
import { api, getParam, http } from "@/utils";
import { Toast } from "antd-mobile";
import jsCookie from 'js-cookie'
import { addDays } from 'date-fns'
//拦截ajax请求,返回mock数据
......@@ -24,12 +29,45 @@ class App extends Component {
//平台信息
cookie.set('plat', '5')
this.props.startFetchUser()
http.get(`${api.home}/m/user_info`).then(res => {
this.props.setCurrentUser(this.storeUser(res))
this.props.setCurrentUser(this.transformUser(res))
})
let code = getParam('code')
if (code) {
http.get(`${api['home']}/m/wx_loginInfo/code/${code}`)
.then(res => {
let data = res.data
console.log(res)
if (data.errno == 200) {
if (data.data['is_bind_mobile']) {
window.location.assign(data.data.url)
} else {
let user = this.transformWxUser(res)
let {role, uid, token} = data.data
let expires = {expires: addDays(new Date(), 90)}
jsCookie.set('role', role, expires)
jsCookie.set('uid', uid, expires)
jsCookie.set('token', token, expires)
this.props.receiveUser(user)
}
} else {
Toast.info(data.msg)
}
})
}
}
storeUser = res => {
transformUser = res => {
let payload
if (res.data.code === 200) {
const {
......@@ -64,13 +102,41 @@ class App extends Component {
return payload
}
transformWxUser = res => {
let data = res.data
if (data.errno == 200) {
let {uid, token, avatar_file: avatar, uname: username,} = data.data
return {
hasError: false,
data: {
uid,
token,
avatar,
username
},
msg: data.msg
}
} else {
let {code, msg} = data.data
return {
code,
msg,
hasError: true,
data: {}
}
}
}
render() {
return <Routes/>
}
}
export default connect(
null,
{setCurrentUser}
export default compose(
connect(
null,
{setCurrentUser, startFetchUser}
),
withRouter
)(App)
\ No newline at end of file
......@@ -40,6 +40,7 @@ $font_12: 12px;
*/
$bg_active: #09f;
$bg_0078FF: #0078FF;
$bg_0080FF: #0080FF;
$bg_fff: #fff;
$bg_000: #000;
$bg_f4f4f4: #f4f4f4;
......
import React, { Component } from 'react'
import { ActivityIndicator } from 'antd-mobile'
import React, { Component } from 'react';
import ReactDOM from 'react-dom'
import { HashLoader } from "react-spinners";
import './loading.scss'
export default class componentName extends Component {
const container = document.body
class Loading extends Component {
static defaultProps = {
text: '加载中',
fake: 0
}
state = {
isLoading: true
}
componentDidUpdate(prevProps) {
let {isLoading, fake} = this.props
if (!isLoading) {
if(fake){
setTimeout(() => {
this.setState({
isLoading
})
}, fake)
}else {
if(prevProps.isLoading != isLoading){
this.setState({
isLoading
})
}
}
}
}
render() {
return (
const innerLoading =
<div className="loading">
<ActivityIndicator></ActivityIndicator>
<span>加载中</span>
<div className="loading-wrapper">
<HashLoader
css={{
display: 'block',
marginTop: '-100px'
}}
size={50}
color={'#09f'}
/>
<p>{this.props.text}</p>
</div>
</div>
)
return (
this.state.isLoading ? ReactDOM.createPortal(innerLoading, container) : this.props.children
);
}
}
export default Loading;
\ No newline at end of file
.loading{
display: flex;
width:100%;
height:44px;
line-height: 44px;
justify-content: center;
align-items: center;
span{
margin-left:5px;
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
.loading-wrapper {
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
p {
font-size: 14px;
margin-top: 12px;
color: $active;
}
}
}
\ No newline at end of file
......@@ -153,7 +153,8 @@ class Index extends Component {
{/* 直播间预约 */}
{
this.state.islive &&
<LiveRoom isShow={this.state.isShow} colseBox={this.colseBox} roomMess={this.state.roomMess}></LiveRoom>
<LiveRoom isShow={this.state.isShow} colseBox={this.colseBox}
roomMess={this.state.roomMess}></LiveRoom>
}
</div>
......@@ -258,10 +259,13 @@ function ScrollBox(props) {
<div className="item-content">
<h2 className="item-title">{item.live_title}</h2>
<p className="item-teacher">讲师:{item.live_teacher_name}</p>
<p className="item-time">时间:{item.live_start_time}</p>
{
item.live_status === 1 &&
<span>已预约</span>
item.is_prepare &&
<p className="item-time">时间:{item.live_start_time}</p>
}
{
!item.is_prepare &&
<p className='item-btn'>预约</p>
}
</div>
</div>
......
......@@ -185,10 +185,12 @@
text-align: center;
border-radius: 0 20px 20px 0;
}
.no-start{
.no-start {
background-color: $red;
}
.start{
.start {
background-color: $bg_active;
}
......@@ -205,6 +207,18 @@
white-space: nowrap
}
.item-btn {
width: 49px;
height: 20px;
text-align: center;
line-height: 20px;
background: linear-gradient(60deg, $bg_active 0%, $bg_0080FF 100%);
border-radius: 10px;
font-size: 14px;
color: $white;
margin-top: 10px;
}
.item-title {
font-size: 16px;
color: $color_333;
......
......@@ -39,10 +39,13 @@ function OrderList(props) {
onClick={() => { }}
>
<Link to={{
pathname: `/coupons?id=${course_id}`,
pathname: `/coupons`,
search: `?id=${course_id}`,
state: {
from: '/order',
a: 'sldfasldjfsl'
}}}>
{/* <Link to='coupons' query={{id: course_id}} state={{from: '/order'}}> */}
<Flex justify='between'>
<span style={{ color: '#333', fontSize: '15px' }}>优惠券</span>
<span style={{ fontSize: '14px', color: '#999999' }}>{!coupon_desc ? (coupon_num === 0 ? '无' : `${coupon_num}张可用`) : (coupon_desc)}</span>
......@@ -90,10 +93,11 @@ class Order extends Component {
if(res.data.code !== 200) {
return;
}
this.props.history.replace(`/payorder?oid=${res.data.data.oid}`);
sessionStorage.removeItem('orderUseCacheObj');
this.props.history.replace(`/payorder?oid=${res.data.data.order_id}`);
});
}
// 使用余额
// 勾选取消勾选 是否使用余额
useBalance = () => {
let useBalanceFlag = this.state.useBalance;
this.setState({
......@@ -103,22 +107,29 @@ class Order extends Component {
this.cacheObj = {
...this.state
}
sessionStorage.setItem('orderUseCacheObj', JSON.stringify(this.state));
}else{
sessionStorage.removeItem('orderUseCacheObj');
}
// console.log(useBalance);
this.computedMoney(useBalanceFlag);
}
// 勾选取消勾选时:计算金额、优惠金额、优惠券等
computedMoney = (useBalanceFlag) => {
let totalSale = parseFloat(this.cacheObj.total),
userAccount = parseFloat(this.cacheObj.user_account);
const { discount } = this.state;
if (!useBalanceFlag) {
if (totalSale > userAccount) {
this.setState({
offset: userAccount.toFixed(2),
total: (totalSale - userAccount).toFixed(2),
discount: userAccount.toFixed(2),
discount: (userAccount + parseFloat(discount)).toFixed(2),
});
} else {
this.setState({
offset: totalSale.toFixed(2),
total: 0,
discount: totalSale.toFixed(2),
discount: (totalSale + parseFloat(discount)).toFixed(2),
});
}
} else {
......@@ -128,11 +139,25 @@ class Order extends Component {
discount: this.cacheObj.discount,
});
}
this.computedMoney();
}
// 计算金额、优惠金额、优惠券等
computedMoney = () => {
};
// 选择优惠券返回时根据是否勾选计算
computedMoneyByCache = () => {
let totalSale = parseFloat(this.cacheObj.total),
userAccount = parseFloat(this.cacheObj.user_account),
discount = parseFloat(this.cacheObj.discount);
if(totalSale > userAccount) {
this.setState({
offset: userAccount.toFixed(2),
total: (totalSale - userAccount).toFixed(2),
discount: (discount + userAccount).toFixed(2),
});
}else{
this.setState({
offset: totalSale.toFixed(2),
total: 0,
discount: totalSale.toFixed(2),
});
}
};
// 展示余额抵扣规则
showInfo = () => {
......@@ -146,7 +171,13 @@ class Order extends Component {
return;
}
const { course, total, user_account, user_info, discount } = res.data.data;
this.dataCache = JSON.parse(JSON.stringify(res.data.data));
this.cacheObj = {
perfect: user_info,
orderList: course,
user_account,
total,
discount,
}
this.setState({
perfect: user_info,
orderList: course,
......@@ -154,12 +185,19 @@ class Order extends Component {
total,
discount,
});
if(this.props.history.action === 'PUSH') {
sessionStorage.removeItem('orderUseCacheObj');
}
else{
const cacheObj = sessionStorage.getItem('orderUseCacheObj');
if(cacheObj !== null) {
this.setState({
useBalance: true
});
this.computedMoneyByCache();
}
}
})
// // 获取报名信息 获取课程列表 获取用户账户余额
// Promise.race([http.get(), http.get(), http.get()]).then(res=>{
// });
};
render() {
const {
......@@ -224,17 +262,21 @@ class Order extends Component {
<Flex align='center'>
<span>余额抵扣</span>
<span className="order-balanceprice"> (余额: <i className="order-money">{`${user_account}元`}</i>)</span>
<i className="iconfont iconiconfront-22" onClick={this.showInfo}></i>
<i className="iconfont iconiconfront-22 question-mark" onClick={this.showInfo}></i>
</Flex>
<div>
<Flex>
{
useBalance ? (
<span style={{ color: '#FF2121', fontSize: '15px', marginRight: "6px" }}>{`-${offset}`}</span>
) : null
<>
<span style={{ color: '#FF2121', fontSize: '15px', marginRight: "6px" }}>{`-${offset}`}</span>
<i className={`iconfont icondanseshixintubiao-5 balance-used`} onClick={throttle(this.useBalance, 600)}></i>
</>
) : (
<i className='circle-icon' onClick={throttle(this.useBalance, 600)}></i>
)
}
<i className={`iconfont ${useBalance ? 'icondanseshixintubiao-5' : 'iconiconfront-3'} `} onClick={throttle(this.useBalance, 600)}></i>
</div>
</Flex>
</Flex>
</Item>
</List>
......
......@@ -40,6 +40,7 @@
.user-icon {
font-size: 28px;
flex-basis: 40px;
}
.order-cell {
......@@ -47,6 +48,7 @@
font-size: 13px;
color: $color_333;
line-height: 20px;
flex: 1 1 auto;
.name {
margin-bottom: 10px;
......@@ -212,17 +214,33 @@
}
}
.order-balanceprice {
color: $color_666;
font-size: $font_12;
.order-money {
color: #ff2121;
font-size: $font_12 !important;
font-weight: normal;
font-style: inherit;
vertical-align: middle;
margin: 0;
.order-balance{
.order-balanceprice {
color: $color_666;
font-size: $font_12;
.order-money {
color: #ff2121;
font-size: $font_12 !important;
font-weight: normal;
font-style: inherit;
vertical-align: middle;
margin: 0;
}
}
.am-list-content .iconiconfront-22.question-mark {
font-size: 24px;
}
.balance-used {
font-size: 24px;
color: #0099FF;
}
.circle-icon {
width: 20px;
height: 20px;
border: 1px solid #BFBFBF;
border-radius: 50%;
margin-right: 2px;
}
}
......@@ -232,7 +250,6 @@
.order-list {
.am-list-item {
padding-left: 0 !important;
}
}
......
......@@ -6,6 +6,7 @@ import { compose } from 'redux';
import { accountLogin } from '@/store/userAction';
import { connect } from "react-redux";
import { isEmpty } from 'lodash'
import { HeaderBar } from "@/common";
import Header from "../common/Header";
......@@ -16,11 +17,6 @@ import { Toast } from "antd-mobile";
class AccountLogin extends PureComponent {
componentDidMount() {
console.log(this.props.values);
}
render() {
const {
errors,
......@@ -28,6 +24,7 @@ class AccountLogin extends PureComponent {
} = this.props
return (
<div className={'account-login'}>
<HeaderBar arrow={true} title={'登录'}/>
<Header/>
<Form className="login-info">
<FastField
......@@ -75,10 +72,9 @@ const formikConfig = {
props.accountLogin({
username, password
}).then(res => {
console.log(res);
if (!res.hasError) {
let {from} = props.location.state || {from: {pathname: '/'}}
history.push(from.pathname)
history.replace(from.pathname)
} else {
Toast.info(res.msg, 2, null, false)
}
......
......@@ -11,13 +11,6 @@
margin-bottom: 21px;
}
.place {
width: 100%;
height: 39px;
margin-bottom: 33px;
background: #56abff;
}
.verification {
margin-bottom: 21px;
}
......
import React, { Component } from 'react';
import './binding-tel.scss'
import { withFormik, Field, Form } from "formik";
import { validateTel, http, api, getParam } from "@/utils";
import { compose } from "redux";
import { connect } from "react-redux";
import { setCurrentUser } from "@/store/userAction";
import Captcha from '@/common/Captcha'
import ClearableInput from '@common/ClearableInput'
import Button from '../common/Button'
import VeriCodeInput from '../common/veriCodeInput'
import { Toast } from "antd-mobile";
import { isEmpty } from "lodash";
class BindingTel extends Component {
constructor(props) {
super(props);
this.state = {
veriCode: ''
};
state = {
validate: null,
captchaInstance: null
}
handleChange = (val) => {
this.setState({veriCode: val});
getCaptchaInstance = instance => {
this.setState({
captchaInstance: instance
})
}
onVerify = (err, data) => {
if (err) {
console.log(err)
} else {
this.setState({
validate: data.validate
})
}
}
render() {
const {
values,
errors
} = this.props
return (
<div className={'binding-tel'}>
<p className={'title'}>为提高您的账号安全,请绑定手机号</p>
<ClearableInput
type={'number'}
placeholder={'请输入需要绑定的手机号'}
wrapperClass={'tel'}
icon={<i className={'iconfont iconshouji'}
style={{fontSize: '22px', left: '11px'}}
/>}
/>
<VeriCodeInput
type={'number'}
className={'verification'}
onChange={this.handleChange}
icon={<i className={'iconfont iconduanxin'}
style={{fontSize: '20px', left: '12px'}}
/>}
/>
<div className="place"/>
<Button className={'complete-btn'}>完成</Button>
<Form>
<Field
name='tel'
render={({field, form}) => {
return (
<ClearableInput
{...field}
setFieldValue={form.setFieldValue}
placeholder={'请输入需要绑定的手机号'}
wrapperClass={'tel'}
icon={<i className={'iconfont iconshouji'}
style={{fontSize: '22px', left: '11px'}}
/>}
/>
)
}}
/>
<Field
name='veriCode'
render={({field}) => {
return (
<VeriCodeInput
{...field}
className={'verification'}
icon={<i className={'iconfont iconduanxin'}
style={{fontSize: '20px', left: '12px'}}
/>}
account={values.tel}
tel={values.tel}
challenge={this.state.validate}
instance={this.state.captchaInstance}
action={'auth'}
/>
)
}}
/>
<Captcha onVerify={this.onVerify} getInstance={this.getCaptchaInstance}/>
<Button className={'complete-btn'} active={values.tel && values.veriCode && isEmpty(errors)}>完成</Button>
</Form>
</div>
);
}
}
export default BindingTel;
\ No newline at end of file
const formikConfig = {
mapPropsToValues() {
return {
tel: '',
veriCode: ''
}
},
validateOnChange: true,
validate(values) {
let errors = {}
if (!validateTel(values.tel)) {
errors.tel = '请输入正确的手机号'
}
if (!values.veriCode) {
errors.veriCode = '请填写验证码'
}
return errors
},
handleSubmit(values, {props}) {
http.post(`${api['passport-api']}/bind_mobile`, {
phone_num: values.tel,
phone_code: values.veriCode,
mkey: getParam('mkey'),
plat: 5
}).then(res => {
const data = res.data
if (data.errno == 200) {
if (data.data['is_set_pwd']) {
props.setCurrentUser({
hasError: false,
data: {
uid: data.data.uid
},
msg: data.data.msg
})
props.history.replace(`/passport/set-password`)
}else {
location.assign(data.data['jump_url'])
}
} else {
Toast.info(data.msg, 2, null, false)
}
/*props.setCurrentUser({
hasError,
data
})*/
})
}
}
export default compose(
connect(
null,
{setCurrentUser}
),
withFormik(formikConfig),
)(BindingTel);
\ No newline at end of file
import React, { PureComponent } from 'react';
import { browser } from "@/utils";
import './loginWays.scss'
class LoginWays extends PureComponent {
handleClick = (index) => {
this.props.onClick(index)
state = {
ways: this.props.loginWays
}
componentDidMount() {
if (!browser.isWeixin) {
this.setState({
ways: this.state.ways.filter(item => item.text !== '微信')
})
}
}
handleClick = text => {
this.props.onClick(text)
}
render() {
......@@ -14,9 +28,9 @@ class LoginWays extends PureComponent {
<div className="bottom-title">其他登录方式</div>
<ul className='login-ways-container'>
{
this.props.loginWays.map((item, index) => {
this.state.ways.map((item, index) => {
return (
<li key={index} onClick={this.handleClick.bind(this, index)}>
<li key={index} onClick={this.handleClick.bind(this, item.text)}>
<img src={item.logo} alt=""/>
<p>{item.text}</p>
</li>
......
......@@ -36,6 +36,10 @@
li {
text-align: center;
a{
display: block;
}
img {
width: 34px;
}
......
......@@ -110,7 +110,7 @@ class VeriCodeInput extends Component {
if (!tel) {
content = '手机号码不能为空'
}
if (validateTel(tel)) {
if (!validateTel(tel)) {
content = '请输入正确格式的手机号码'
}
} else {
......
......@@ -128,7 +128,7 @@ const formikConfig = {
code: values.veriCode
}).then(res => {
if (res.data.errno == 0) {
props.history.push('/passport/set-password')
props.history.push('/passport/set-password', {from: props.location})
} else {
Toast.info(res.data.msg)
}
......
......@@ -8,6 +8,8 @@ import AccountLogin from './accountLogin'
import ForgotPassword from './forgotPassword'
import SetPassword from './setPassword'
import BindingTel from './bindingTel'
import {connect} from "react-redux";
import {compose} from "redux";
import account from './account.png'
import qq from './qq.png'
......@@ -17,6 +19,8 @@ import wechat from './wechat.png'
class Passport extends Component {
redirect_url = location.protocol + '//' + location.hostname
constructor(props) {
super(props);
......@@ -28,15 +32,18 @@ class Passport extends Component {
},
{
logo: wechat,
text: '微信'
text: '微信',
url: 'https://www.baidu.com'
},
{
logo: qq,
text: 'QQ'
text: 'QQ',
url: 'https://www.baidu.com'
},
{
logo: sina,
text: '新浪'
text: '新浪',
url: `http://passport-test.julyedu.com/mob/sinalogin?redirect_url=${this.redirect_url}`
},
]
}
......@@ -52,7 +59,9 @@ class Passport extends Component {
to={{...location, ...{pathname: '/passport/login'}}}
/>
<Route path={match.url + '/login'}
render={props => <Login {...props} loginWays={this.state.loginWays}/>}/>
render={props => {
return <Login {...props} loginWays={this.state.loginWays}/>
}}/>
<Route path={match.url + '/account-login'} component={AccountLogin}/>
<Route path={match.url + '/forgot-password'} component={ForgotPassword}/>
<Route path={match.url + '/set-password'} component={SetPassword}/>
......@@ -64,4 +73,10 @@ class Passport extends Component {
}
export default WithFullSize(Passport)
\ No newline at end of file
export default compose(
connect(
state => ({user: state.user}),
null
),
WithFullSize
)(Passport)
\ No newline at end of file
......@@ -12,21 +12,36 @@ import { connect } from 'react-redux';
import { compose } from 'redux';
import { isEmpty } from 'lodash'
import { Toast } from 'antd-mobile';
import {validateTel} from "@/utils";
import { validateTel } from "@/utils";
class WechatLogin extends Component {
class Login extends Component {
state = {
validate: null,
captchaInstance: null
}
loginWaysClick = index => {
switch (index) {
case 0:
this.props.history.push('/passport/account-login')
loginWaysClick = method => {
const {history, loginWays, location} = this.props
const item = loginWays.find(item => item.text === method)
switch (method) {
case '账号登录':
history.push('/passport/account-login', location.state)
break;
case '微信':
let {from} = location.state || {from: {pathname: '/'}}
const redirectURI = window.location.protocol + '//' + window.location.hostname + from.pathname
// alert(redirectURI)
window.location.assign(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=${encodeURIComponent(redirectURI)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`)
break;
default:
window.location.assign(item.url)
}
}
getCaptchaInstance = instance => {
......@@ -140,4 +155,4 @@ export default compose(
{quickLogin}
),
withFormik(FormikConfig),
)(WechatLogin)
\ No newline at end of file
)(Login)
\ No newline at end of file
......@@ -10,11 +10,15 @@ import { http, api } from "@/utils";
import { Toast } from "antd-mobile";
import { encrypt } from "@/components/passport/encryption";
import { Link } from "react-router-dom";
import { isEmpty } from "lodash";
import { connect } from "react-redux";
class SetPassword extends Component {
render() {
let {values, errors, location} = this.props
let {from} = location.state || {from: {pathname: '/'}}
return (
<>
<HeaderBar arrow={true} title={'设置密码'}/>
......@@ -34,7 +38,8 @@ class SetPassword extends Component {
)
}}
/>
<Button className={'btn-active'}>完成</Button>
<Button className={'btn-active'}
active={values.password && values.agreement && isEmpty(errors)}>完成</Button>
<label htmlFor="agreement" className='user-agreement'>
<Field type='checkbox'
name='agreement'
......@@ -46,7 +51,8 @@ class SetPassword extends Component {
同意<span>《七月在线用户使用协议》</span>
</label>
</Form>
<div className="skip">
<div className="skip"
style={{display: from && from.pathname.includes('forgot-password') ? 'none' : 'block'}}>
<Link replace to='/passport/account-login'>跳过</Link>
</div>
</div>
......@@ -64,28 +70,16 @@ const formikConfig = {
},
handleSubmit: (values, {props}) => {
let key = sessionStorage.getItem('r_type') === 'email' ? 'email' : 'tel'
let encrypted = encrypt(values.password)
http.post(`${api['passport-api']}/up_pass${key === 'tel' && '_by_phone' || ''}`, {
[key]: sessionStorage.getItem(key),
pass: encrypted,
re_pass: encrypted
})
.then(res => {
if (res.data.errno == 0) {
Toast.info('密码设置成功')
setTimeout(function () {
props.history.replace('/passport')
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
})
let {from} = props.location.state || {from: {pathname: '/'}}
if (from.pathname.includes('forgot-password')) {
forgotPasswordReset(values, props);
} else {
bindMobileSetPassword(values, props)
}
},
validateOnChange: false,
validate: (values) => {
validate: values => {
let errors = {}
const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
if (!re.test(values.password)) {
......@@ -100,6 +94,49 @@ const formikConfig = {
}
}
function forgotPasswordReset(values, props) {
let key = sessionStorage.getItem('r_type') === 'email' ? 'email' : 'tel'
http.post(`${api['passport-api']}/account/up_pass_by_${key === 'email' ? 'email' : 'phone'}`, {
[key]: sessionStorage.getItem(key),
password: encrypt(values.password)
})
.then(res => {
if (res.data.errno == 200) {
Toast.info('密码设置成功')
setTimeout(function () {
props.history.replace('/passport/account-login')
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
})
}
function bindMobileSetPassword(values, props) {
http.post(`${api['passport-api']}/bind_mobile/set_pwd_new`, {
uid: props.user.data.uid,
password: encrypt(values.password)
})
.then(res => {
if (res.data.errno == 200) {
Toast.info('密码设置成功')
let {from} = location.state || {from: {pathname: '/'}}
setTimeout(function () {
props.history.replace(from.pathname)
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
})
}
export default compose(
connect(
state => ({user: state.user}),
null
),
withFormik(formikConfig)
)(SetPassword);
\ No newline at end of file
......@@ -4,6 +4,7 @@ import Tag from '@common/Tag/index.js'
import { http, api } from '@/utils'
import './index.scss';
import { Link } from 'react-router-dom'
import Loading from '@/common/Loading'
class Search extends PureComponent {
......@@ -12,14 +13,16 @@ class Search extends PureComponent {
searchHistory: JSON.parse(localStorage.getItem('searchHistory')) || [],
hot_words: [],
searchList: [],
value: ''
value: '',
isLoading: true
}
async componentDidMount() {
const res = await http.get(`${api['search-api']}/search_hot_word`)
if (res.data.errno === 0) {
this.setState({
hot_words: res.data.data.info.hot_words
hot_words: res.data.data.info.hot_words,
isLoading: false
})
}
}
......@@ -54,51 +57,53 @@ class Search extends PureComponent {
handleChange={this.handleChange}
handleSearch={this.handleSearch}
/>
<div className="search-main">
<div className="search-land">
<div className='search-history'>
<span>最近搜索</span>
<i className="iconfont iconiconfront-56" onClick={this.clearHistory}/>
<Loading isLoading={this.state.isLoading}>
<div className="search-main">
<div className="search-land">
<div className='search-history'>
<span>最近搜索</span>
<i className="iconfont iconiconfront-56" onClick={this.clearHistory}/>
</div>
<div className="search-tag">
{
searchHistory.length > 0 ?
searchHistory.map((v, i) => {
return (
<Link
key={i}
to={`/search-result?word=${encodeURIComponent(v)}`}
>
<Tag>{v}</Tag>
</Link>
)
})
: <div style={{textAlign: 'center', padding: '20px'}}>暂无历史</div>
}
</div>
</div>
<div className="search-tag">
{
searchHistory.length > 0 ?
searchHistory.map((v, i) => {
return (
<Link
key={i}
to={`/search-result?word=${encodeURIComponent(v)}`}
>
<Tag>{v}</Tag>
</Link>
)
})
: <div style={{textAlign: 'center', padding: '20px'}}>暂无历史</div>
}
<div className="search-land search-hot">
<label>
<span>热门搜索</span>
</label>
<div className="search-tag">
{
this.state['hot_words'].length > 0 ?
this.state['hot_words'].map((v, i) => {
return (
<Link key={i}
to={`/search-result?word=${encodeURIComponent(v)}`}
onClick={this.storeHistory.bind(this, v)}
>
<Tag>{v}</Tag>
</Link>
)
})
: <div style={{textAlign: 'center', padding: '20px'}}>暂无热门</div>
}
</div>
</div>
</div>
<div className="search-land search-hot">
<label>
<span>热门搜索</span>
</label>
<div className="search-tag">
{
this.state['hot_words'].length > 0 ?
this.state['hot_words'].map((v, i) => {
return (
<Link key={i}
to={`/search-result?word=${encodeURIComponent(v)}`}
onClick={this.storeHistory.bind(this, v)}
>
<Tag>{v}</Tag>
</Link>
)
})
: <div style={{textAlign: 'center', padding: '20px'}}>暂无热门</div>
}
</div>
</div>
</div>
</Loading>
</div>
)
......
......@@ -2,6 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware, compose } from 'redux'
import { Provider } from 'react-redux'
import { BrowserRouter as Router } from 'react-router-dom'
import thunk from 'redux-thunk'
import logger from 'redux-logger'
import rootReducers from './store'
......@@ -20,6 +21,8 @@ const store = createStore(
ReactDOM.render(
<Provider store={store}>
<App/>
<Router>
<App/>
</Router>
</Provider>,
document.getElementById('root'));
\ No newline at end of file
import React from 'react'
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'
import { Switch, Route } from 'react-router-dom'
import RouterConfig from './router-config'
import PrivateRoute from './privateRoute'
export default function () {
return (
<Router>
<Switch>
{RouterConfig.map((item, index) => {
let {isPrivate, ...rest} = item
if (isPrivate) {
return <PrivateRoute {...rest} key={index}/>
} else {
return (
<Route {...rest} key={index}/>
)
}
})}
</Switch>
</Router>
<Switch>
{RouterConfig.map((item, index) => {
let {isPrivate, ...rest} = item
if (isPrivate) {
return <PrivateRoute {...rest} key={index}/>
} else {
return (
<Route {...rest} key={index}/>
)
}
})}
</Switch>
)
}
\ No newline at end of file
import React from 'react';
import { connect } from 'react-redux';
import React, { useEffect } from 'react';
import { withRouter } from "react-router-dom";
import { compose } from "redux";
import { connect } from "react-redux";
const Loading = ({user, history, state}) => {
if (Object.values(user.data).filter(item => !!item).length !== 0) {
history.replace(location.pathname)
} else {
history.replace('/passport', {...state})
}
function Loading(props) {
useEffect(() => {
let {user, location, history} = props
if (!user.isFetching) {
if (user.hasError) {
history.push('/passport', {from: location})
} else {
if (Object.values(user.data).every(item => !!item).length !== 0) {
history.push(location.pathname)
}
}
}
})
return (
<div className={'loading'}>
loading...
</div>
);
};
}
export default compose(
connect(
......@@ -23,4 +32,4 @@ export default compose(
null
),
withRouter
)(Loading);
\ No newline at end of file
)(Loading)
\ No newline at end of file
import React from 'react';
import { Route, Redirect } from "react-router-dom";
import { Route } from "react-router-dom";
import { connect } from "react-redux";
import jsCookie from 'js-cookie'
import Loading from './loading'
const PrivateRoute = ({component: Component, path, user, ...rest}) => {
let authenticated = jsCookie.get('token') && jsCookie.get('uid')
return (
<Route {...rest} render={props => {
return authenticated
......
......@@ -16,9 +16,10 @@ import Examination from '@/components/examination'
import ShopCart from '@/components/shopCart';
import BargainMiddlePage from '@/components/bargainMiddlePage';
import Passport from '@/components/passport';
import {Scholarship} from '@/components/scholarship/index';
import { Scholarship } from '@/components/scholarship/index';
import DrawDocument from '@/components/scholarship/DrawDocument/DrawDocument';
import PayOrder from '@/components/order/payOrder/PayOrder'
import Loading from '@/common/Loading'
const Coupons = loadable(() => import(/* webpackChunkName: 'coupons'*/ '@/components/coupons'))
const Study = loadable(() => import(/* webpackChunkName: 'study'*/'@/components/study'))
......@@ -137,5 +138,9 @@ export default [
component: ToGroup,
isPrivate: true
},
{
path: '/loading',
component: Loading,
},
]
\ No newline at end of file
......@@ -12,7 +12,7 @@ module.exports = function (app) {
pathRewrite: {
[`^${config[item]['development']}`]: ''
},
cookieDomainRewrite: 'localhost',
// cookieDomainRewrite: 'localhost',
...config[item]['proxy']
}
))
......
......@@ -45,7 +45,7 @@ const storeUser = (res, dispatch) => {
const SET_CURRENT_USER = 'SET_CURRENT_USER'
const setCurrentUser = payload => ({
type: SET_CURRENT_USER,
payload
payload: {...payload, isFetching: false}
})
......@@ -63,6 +63,12 @@ const updateUser = payload => ({
payload
})
const START_FETCH_USER = 'START_FETCH_USER'
const startFetchUser = () => ({
type: START_FETCH_USER
})
export {
accountLogin,
SET_CURRENT_USER,
......@@ -70,5 +76,7 @@ export {
quickLogin,
logout,
UPDATE_USER,
updateUser
updateUser,
START_FETCH_USER,
startFetchUser,
}
\ No newline at end of file
import { SET_CURRENT_USER, UPDATE_USER } from '@/store/userAction';
import { SET_CURRENT_USER, UPDATE_USER, START_FETCH_USER } from '@/store/userAction';
import { merge } from 'lodash'
......@@ -12,7 +12,8 @@ const initialState = {
token: '',
email: '',
uid: ''
}
},
isFetching: true
}
......@@ -22,6 +23,8 @@ export default function (state = initialState, action) {
return action.payload
case UPDATE_USER:
return merge({}, state, action.payload)
case START_FETCH_USER:
return {...state, isFetching: true}
default:
return state
}
......
export { default as http } from './http'
export { default as api } from './api'
export { html, initCaptcha, validateTel, validateEmail,browser }
import jsCookie from "js-cookie";
export const getParam = (key, str) => {
......@@ -87,4 +85,13 @@ const browser = (function () {
isIOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(ua),
isIPad: /iPad/i.test(ua)
}
})()
\ No newline at end of file
})()
const isLogin = (function () {
return jsCookie.get('uid') && jsCookie.get('token')
})()
export { default as http } from './http'
export { default as api } from './api'
export { html, initCaptcha, validateTel, validateEmail, browser, isLogin }
const config = {
const config = {
home: {
development: '/api',
test: 'http://fast-test.julyedu.com',
......@@ -25,11 +25,19 @@ const config = {
production: 'http://passport.julyedu.com',
proxy: {}
},
'pay-api':{
'pay-api': {
development: '/pay-api',
test: 'http://api-test.julyedu.com',
production: 'https://api.julyedu.com',
proxy: {}
},
'base-api': {
development: '/base-api',
test: 'http://api-test.julyedu.com',
production: 'https://api.julyedu.com',
proxy: {
secure: false
}
}
}
......
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