Commit 0ad15bc8 by zhanghaozhe

更换滑块验证

parent ca9d3562
import React, { Component } from 'react';
import './index.scss'
import { initCaptchaNC } from "@/utils"
const appkey = 'FFFF0N000000000090FC'
const scene = 'nc_login_h5'
class CaptchaAli extends Component {
nc = null
state = {
isLoaded: false
}
componentDidMount() {
const _this = this
const el = document.querySelector('#nc')
el && initCaptchaNC(() => {
const nc_token = [appkey, (new Date()).getTime(), Math.random()].join(':');
this.nc = NoCaptcha.init({
renderTo: '#nc',
appkey,
scene,
token: nc_token,
elementID: ['tel'],
bannerHidden: false,
callback(data) {
_this.props.onVerify({
app_key: appkey,
scene,
token: nc_token,
session_id: data.csessionid,
sig: data.sig
})
},
error(s) {
console.log(s)
}
})
NoCaptcha.setEnabled(true);
this.nc.reset()
this.props.getInstance(this.nc)
})
}
render() {
const {mb = 30} = this.props
return (
<div id={'captcha'} style={{marginBottom: `${mb}px`}}>
<div id="nc"></div>
</div>
);
}
}
export default CaptchaAli;
\ No newline at end of file
#captcha {
._nc {
.stage {
padding: 0;
}
.stage1 {
height: 48px;
.label {
height: 46px;
}
.button {
width: 48px;
height: 48px;
}
.slider {
height: 48px;
width: 100%;
left: 0;
}
}
}
}
\ No newline at end of file
...@@ -5,6 +5,7 @@ export { default as OrderItem } from './OrderList' ...@@ -5,6 +5,7 @@ export { default as OrderItem } from './OrderList'
export { default as HeaderBar } from './HeaderBar' export { default as HeaderBar } from './HeaderBar'
export { default as CallApp } from './CallApp' export { default as CallApp } from './CallApp'
export { default as Captcha } from './Captcha' export { default as Captcha } from './Captcha'
export { default as CaptchaAli } from './Captcha-ali'
export { default as ClearableInput } from "./ClearableInput" export { default as ClearableInput } from "./ClearableInput"
export { default as Loading } from './Loading' export { default as Loading } from './Loading'
export { default as RenderTabBar } from './renderTabBar' export { default as RenderTabBar } from './renderTabBar'
......
...@@ -323,6 +323,34 @@ ...@@ -323,6 +323,34 @@
border-radius: 10px; border-radius: 10px;
box-sizing: border-box; box-sizing: border-box;
background-color: #fff; background-color: #fff;
#nc{
$height: 36px;
height: $height;
._nc{
.stage1{
height: $height;
.icon{
left: 5px;
}
.button{
width: $height;
height: $height;
}
}
.slider{
height: $height;
.label{
height: 100%;
line-height: $height;
}
.bg-green{
height: $height;
line-height: $height;
}
}
}
}
} }
.popup-form__title { .popup-form__title {
......
...@@ -5,11 +5,7 @@ import { http, getParam } from "@/utils" ...@@ -5,11 +5,7 @@ import { http, getParam } from "@/utils"
import { compose } from "redux" import { compose } from "redux"
import { connect } from "react-redux" import { connect } from "react-redux"
import { setCurrentUser } from "@/store/userAction" import { setCurrentUser } from "@/store/userAction"
import Captcha from '@/common/Captcha' import { HeaderBar, CaptchaAli } from '@/common'
import { HeaderBar } from '@/common'
// import ClearableInput from '@common/ClearableInput'
import ClearableInput from '../common/clearableInputWithCountryCodes' import ClearableInput from '../common/clearableInputWithCountryCodes'
import Button from '../common/Button' import Button from '../common/Button'
import VeriCodeInput from '../common/veriCodeInput' import VeriCodeInput from '../common/veriCodeInput'
...@@ -21,7 +17,8 @@ class BindingTel extends Component { ...@@ -21,7 +17,8 @@ class BindingTel extends Component {
state = { state = {
validate: null, validate: null,
captchaInstance: null captchaInstance: null,
validationData: null
} }
getCaptchaInstance = instance => { getCaptchaInstance = instance => {
...@@ -29,14 +26,11 @@ class BindingTel extends Component { ...@@ -29,14 +26,11 @@ class BindingTel extends Component {
captchaInstance: instance captchaInstance: instance
}) })
} }
onVerify = (err, data) => { onVerify = (data) => {
if (err) { this.setState({
console.log(err) validate: true,
} else { validationData: data
this.setState({ })
validate: data.validate
})
}
} }
render() { render() {
...@@ -79,16 +73,16 @@ class BindingTel extends Component { ...@@ -79,16 +73,16 @@ class BindingTel extends Component {
placeholder={'验证码'} placeholder={'验证码'}
account={values.tel} account={values.tel}
tel={values.tel} tel={values.tel}
challenge={this.state.validate}
instance={this.state.captchaInstance} instance={this.state.captchaInstance}
action={'auth'} action={'auth'}
country={country} country={country}
validationData={this.state.validationData}
/> />
) )
}} }}
/> />
<Captcha onVerify={this.onVerify} getInstance={this.getCaptchaInstance}/> <CaptchaAli onVerify={this.onVerify} getInstance={this.getCaptchaInstance} mb={0}/>
<Button className={'complete-btn'} <Button className={'complete-btn'}
active={values.tel && values.veriCode && isEmpty(errors)}>完成</Button> active={values.tel && values.veriCode && isEmpty(errors)}>完成</Button>
</Form> </Form>
......
...@@ -2,7 +2,7 @@ import React, { Component } from 'react'; ...@@ -2,7 +2,7 @@ import React, { Component } from 'react';
import './veri-code-input.scss' import './veri-code-input.scss'
import { http, validateEmail } from '@/utils'; import { http, validateEmail } from '@/utils';
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import { has } from 'lodash' import { has, isEmpty } from 'lodash'
import classnames from 'classnames' import classnames from 'classnames'
...@@ -10,152 +10,151 @@ import classnames from 'classnames' ...@@ -10,152 +10,151 @@ import classnames from 'classnames'
import Input from '../Input' import Input from '../Input'
class VeriCodeInput extends Component { class VeriCodeInput extends Component {
count = 60 count = 60
state = { state = {
counting: false, counting: false,
count: this.count, count: this.count,
isFirst: true
}
timer = null
countDown = () => {
let {count} = this.state
if (!this.state.isFirst) {
Toast.info('请重新进行滑块验证', 2, null, false)
this.props.instance.reset()
this.setState({
isFirst: true isFirst: true
} })
timer = null return
countDown = () => {
let {count} = this.state
if (!this.state.isFirst) {
Toast.info('请重新进行滑块验证', 2, null, false)
this.props.instance.refresh()
this.setState({
isFirst: true
})
return
}
if (!this.state.counting) {
if (!this.sendCode()) {
return
}
this.setState({count: count--, counting: true})
this.timer = setInterval(() => {
if (count <= 0) {
clearInterval(this.timer)
this.setState({counting: false, count: this.count})
return
}
this.setState({count: count--})
}, 1000)
}
} }
getType = () => { if (!this.state.counting) {
const {email} = this.props if (!this.sendCode()) {
if (validateEmail(email)) { return
return 'email' }
this.setState({count: count--, counting: true})
this.timer = setInterval(() => {
if (count <= 0) {
clearInterval(this.timer)
this.setState({counting: false, count: this.count})
return
} }
this.setState({count: count--})
}, 1000)
} }
}
getType = () => {
sendCode = () => { const {email} = this.props
if (!this.validate()) return if (validateEmail(email)) {
this.getType() === 'email' ? this.sendEmail() : this.sendSMS(); return 'email'
return true;
} }
}
sendEmail = () => {
const {email, challenge} = this.props
http.post(`${API['passport-api']}/send_email_code`, { sendCode = () => {
email, if (!this.validate()) return
challenge this.getType() === 'email' ? this.sendEmail() : this.sendSMS();
}).then(res => { return true;
if (res.data.errno === 0) { }
Toast.info('验证码发送成功', 2, null, false)
} else { sendEmail = () => {
Toast.info(res.data.msg, 2, null, false) const {email, validationData} = this.props
} http.post(`${API['passport-api']}/send_email_code`, {
this.setState({ email,
isFirst: false ...validationData
}) }).then(res => {
}) if (res.data.errno === 0) {
Toast.info('验证码发送成功', 2, null, false)
} else {
Toast.info(res.data.msg, 2, null, false)
}
this.setState({
isFirst: false
})
})
}
sendSMS = () => {
const {action, tel, account, validationData, checking, country} = this.props
if (!tel) {
Toast.info('请输入手机号')
return
} }
http.post(`${API['passport-api']}/quick_sms`, {
sendSMS = () => { phone_num: tel || account,
const {action, tel, account, challenge, checking, country} = this.props action: action || 'login',
if (!tel) { area_code: '00' + country.num,
Toast.info('请输入手机号') checking,
return ...validationData
} }).then(res => {
http.post(`${API['passport-api']}/quick_sms`, { if (res.data.errno === 0) {
phone_num: tel || account, Toast.info('验证码发送成功', 2, null, false)
action: action || 'login', } else {
area_code: '00'+country.num, Toast.info(res.data.msg, 2, null, false)
challenge, }
checking this.setState({
}).then(res => { isFirst: false
if (res.data.errno === 0) { })
Toast.info('验证码发送成功', 2, null, false) })
} else { }
Toast.info(res.data.msg, 2, null, false)
}
this.setState({ validate = () => {
isFirst: false const {tel, validationData, email} = this.props
}) let hasTel = has(this.props, 'tel')
}) let content
if (hasTel) {
if (!tel) {
content = '手机号码不能为空'
}
if (!/\d/.test(tel)) {
content = '请输入正确格式的手机号码'
}
} else {
if (!email) {
content = '电子邮件不能为空'
}
if (!validateEmail(email)) {
content = '请输入正确格式的电子邮件'
}
} }
if (content) {
validate = () => { Toast.info(content, 2, null, false)
const {tel, challenge, email} = this.props return false
let hasTel = has(this.props, 'tel')
let content
if (hasTel) {
if (!tel) {
content = '手机号码不能为空'
}
if (!/\d/.test(tel)) {
content = '请输入正确格式的手机号码'
}
} else {
if (!email) {
content = '电子邮件不能为空'
}
if (!validateEmail(email)) {
content = '请输入正确格式的电子邮件'
}
}
if (content) {
Toast.info(content, 2, null, false)
return false
}
if (!challenge) {
Toast.info('请进行滑块验证', 2, null, false)
return false
}
return true
} }
render() { if (isEmpty(validationData)) {
let {className, ...rest} = this.props Toast.info('请进行滑块验证', 2, null, false)
return ( return false
<Input
type={'number'}
wrapperClass={className}
{...rest}
>
<button type='button' className={classnames('verify', {active: !this.state.counting})}
onClick={this.countDown}>
{
this.state.counting ?
(`重新发送${this.state.count}s`)
: '发送验证码'
}
</button>
</Input>
);
} }
return true
}
render() {
let {className, validationData, ...rest} = this.props
return (
<Input
type={'number'}
wrapperClass={className}
{...rest}
>
<button type='button' className={classnames('verify', {active: !this.state.counting})}
onClick={this.countDown}>
{
this.state.counting ?
(`重新发送${this.state.count}s`)
: '发送验证码'
}
</button>
</Input>
);
}
} }
export default VeriCodeInput; export default VeriCodeInput;
\ No newline at end of file
...@@ -6,7 +6,7 @@ import { withFormik, Form, Field } from 'formik'; ...@@ -6,7 +6,7 @@ import { withFormik, Form, Field } from 'formik';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { compose } from 'redux'; import { compose } from 'redux';
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import { HeaderBar, Captcha } from "@/common"; import { HeaderBar, CaptchaAli } from "@/common";
import ClearableInput from '../common/clearableInputWithCountryCodes' import ClearableInput from '../common/clearableInputWithCountryCodes'
import { http } from "@/utils"; import { http } from "@/utils";
import { quickLogin } from '@/store/userAction'; import { quickLogin } from '@/store/userAction';
...@@ -16,129 +16,128 @@ import { Link } from "react-router-dom"; ...@@ -16,129 +16,128 @@ import { Link } from "react-router-dom";
class ForgotPassword extends Component { class ForgotPassword extends Component {
state = { state = {
validate: null, validate: null,
captchaInstance: null captchaInstance: null,
} validationData: null
}
getCaptchaInstance = instance => { getCaptchaInstance = instance => {
this.setState({ this.setState({
captchaInstance: instance captchaInstance: instance
}) })
} }
onVerify = (err, data) => { onVerify = (data) => {
if (err) { this.setState({
console.log(err) validationData: data,
} else { validate: true
this.setState({ })
validate: data.validate }
}) onSubmissionError = () => {
} const errors = Object.values(this.props.errors);
} errors.length && Toast.info(errors[0], 2, null, false)
onSubmissionError = () => { }
const errors = Object.values(this.props.errors);
errors.length && Toast.info(errors[0], 2, null, false)
}
render() { render() {
const { const {
values, values,
isValid, isValid,
country country
} = this.props } = this.props
return ( return (
<div className={'forgot-password'}> <div className={'forgot-password'}>
<HeaderBar title='忘记密码' arrow={true}/> <HeaderBar title='忘记密码' arrow={true}/>
<div className="content"> <div className="content">
<Form className='forgot-password-form'> <Form className='forgot-password-form'>
<Field <Field
name={'tel'} name={'tel'}
render={({field, form}) => { render={({field, form}) => {
return ( return (
<ClearableInput <ClearableInput
{...field} {...field}
type={'tel'} type={'tel'}
placeholder={'请输入注册时的手机号'} placeholder={'请输入注册时的手机号'}
wrapperClass={'tel-input'} wrapperClass={'tel-input'}
setFieldValue={form.setFieldValue} setFieldValue={form.setFieldValue}
country={country} country={country}
/>) />)
}} }}
/> />
{ {
this.state.validate && this.state.validate &&
<Field <Field
name='veriCode' name='veriCode'
render={({field}) => { render={({field}) => {
return ( return (
<VeriCodeInput <VeriCodeInput
{...field} {...field}
className={'verify-code'} className={'verify-code'}
icon={<i className={'iconfont iconduanxin'} icon={<i className={'iconfont iconduanxin'}
style={{fontSize: '20px', left: '12px'}} style={{fontSize: '20px', left: '12px'}}
/>} />}
tel={values.tel} tel={values.tel}
challenge={this.state.validate} challenge={this.state.validate}
instance={this.state.captchaInstance} instance={this.state.captchaInstance}
action={'auth'} action={'auth'}
checking={1} checking={1}
country={country} country={country}
/> validationData={this.state.validationData}
) />
}} )
/> }}
} />
<OnSubmissionError callback={this.onSubmissionError}/> }
<Captcha getInstance={this.getCaptchaInstance} onVerify={this.onVerify}/> <OnSubmissionError callback={this.onSubmissionError}/>
<Button className={'next_step'} active={isValid}>下一步</Button> <CaptchaAli getInstance={this.getCaptchaInstance} onVerify={this.onVerify}/>
<Link className={'to-email'} to={`/passport/forgot-password-email`} replace>邮箱找回</Link> <Button className={'next_step'} active={isValid}>下一步</Button>
</Form> <Link className={'to-email'} to={`/passport/forgot-password-email`} replace>邮箱找回</Link>
</div> </Form>
</div> </div>
); </div>
} );
}
} }
const formikConfig = { const formikConfig = {
mapPropsToValues: () => ({ mapPropsToValues: () => ({
tel: '', tel: '',
veriCode: '' veriCode: ''
}), }),
validateOnChange: true, validateOnChange: true,
validateOnBlur: true, validateOnBlur: true,
validate: values => { validate: values => {
let errors = {} let errors = {}
if (!/\d/.test(values.tel)) { if (!/\d/.test(values.tel)) {
errors.tel = '请输入正确的手机号' errors.tel = '请输入正确的手机号'
} }
values.veriCode.toString().length !== 6 && (errors.veriCode = '验证码格式不正确') values.veriCode.toString().length !== 6 && (errors.veriCode = '验证码格式不正确')
return errors return errors
}, },
handleSubmit(values, {props}) { handleSubmit(values, {props}) {
sessionStorage.setItem('r_type', 'phone') sessionStorage.setItem('r_type', 'phone')
sessionStorage.setItem('tel', values.tel) sessionStorage.setItem('tel', values.tel)
http.post(`${API['passport-api']}/check_phone_code`, { http.post(`${API['passport-api']}/check_phone_code`, {
phone: values.tel, phone: values.tel,
code: values.veriCode, code: values.veriCode,
area_code: '00'+props.country.num area_code: '00' + props.country.num
}).then(res => { }).then(res => {
if (res.data.errno == 0) { if (res.data.errno == 0) {
props.history.push('/passport/set-password', {from: props.location}) props.history.push('/passport/set-password', {from: props.location})
} else { } else {
Toast.info(res.data.msg, 2, null, false) Toast.info(res.data.msg, 2, null, false)
} }
}) })
}, },
} }
export default compose( export default compose(
connect( connect(
state => ({country: state.country}), state => ({country: state.country}),
{quickLogin} {quickLogin}
), ),
withFormik(formikConfig) withFormik(formikConfig)
)(ForgotPassword) )(ForgotPassword)
\ No newline at end of file
...@@ -6,8 +6,8 @@ import { withFormik, Form, Field } from 'formik'; ...@@ -6,8 +6,8 @@ import { withFormik, Form, Field } from 'formik';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { compose } from 'redux'; import { compose } from 'redux';
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import { HeaderBar, Captcha, ClearableInput } from "@/common"; import { HeaderBar, ClearableInput, CaptchaAli } from "@/common";
import { validateEmail, http, api } from "@/utils"; import { validateEmail, http } from "@/utils";
import { quickLogin } from '@/store/userAction'; import { quickLogin } from '@/store/userAction';
import OnSubmissionError from '../common/OnSubmissionError' import OnSubmissionError from '../common/OnSubmissionError'
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
...@@ -15,125 +15,125 @@ import { Link } from "react-router-dom"; ...@@ -15,125 +15,125 @@ import { Link } from "react-router-dom";
class ForgotPassword extends Component { class ForgotPassword extends Component {
state = { state = {
validate: null, validate: null,
captchaInstance: null captchaInstance: null,
} validationData: null
}
getCaptchaInstance = instance => { getCaptchaInstance = instance => {
this.setState({ this.setState({
captchaInstance: instance captchaInstance: instance
}) })
} }
onVerify = (err, data) => { onVerify = (data) => {
if (err) { this.setState({
console.log(err) validationData: data,
} else { validate: true
this.setState({ })
validate: data.validate }
}) onSubmissionError = () => {
} const errors = Object.values(this.props.errors);
} errors.length && Toast.info(errors[0], 2, null, false)
onSubmissionError = () => { }
const errors = Object.values(this.props.errors);
errors.length && Toast.info(errors[0], 2, null, false)
}
render() { render() {
const { const {
values, values,
isValid isValid
} = this.props } = this.props
return ( return (
<div className={'forgot-password-email'}> <div className={'forgot-password-email'}>
<HeaderBar title='忘记密码' arrow={true}/> <HeaderBar title='忘记密码' arrow={true}/>
<div className="content"> <div className="content">
<Form className='forgot-password-form'> <Form className='forgot-password-form'>
<Field <Field
name={'email'} name={'email'}
render={({field, form}) => { render={({field, form}) => {
return ( return (
<ClearableInput <ClearableInput
{...field} {...field}
type={'email'} type={'email'}
placeholder={'请输入注册时的邮箱账号'} placeholder={'请输入注册时的邮箱账号'}
wrapperClass={'email-input'} wrapperClass={'email-input'}
setFieldValue={form.setFieldValue} setFieldValue={form.setFieldValue}
/>) />)
}} }}
/> />
{ {
this.state.validate && this.state.validate &&
<Field <Field
name='veriCode' name='veriCode'
render={({field}) => { render={({field}) => {
return ( return (
<VeriCodeInput <VeriCodeInput
{...field} {...field}
className={'verify-code'} className={'verify-code'}
icon={<i className={'iconfont iconduanxin'} icon={<i className={'iconfont iconduanxin'}
style={{fontSize: '20px', left: '12px'}} style={{fontSize: '20px', left: '12px'}}
/>} />}
email={values.email} email={values.email}
challenge={this.state.validate} challenge={this.state.validate}
instance={this.state.captchaInstance} instance={this.state.captchaInstance}
action={'auth'} validationData={this.state.validationData}
checking={1} action={'auth'}
/> checking={1}
) />
}} )
/> }}
} />
<OnSubmissionError callback={this.onSubmissionError}/> }
<Captcha getInstance={this.getCaptchaInstance} onVerify={this.onVerify}/> <OnSubmissionError callback={this.onSubmissionError}/>
<Button className={'next_step'} active={isValid}>下一步</Button> {/*<Captcha getInstance={this.getCaptchaInstance} onVerify={this.onVerify}/>*/}
<Link className={'to-phone'} to={'/passport/forgot-password'} replace>手机号找回</Link> <CaptchaAli getInstance={this.getCaptchaInstance} onVerify={this.onVerify}/>
</Form> <Button className={'next_step'} active={isValid}>下一步</Button>
</div> <Link className={'to-phone'} to={'/passport/forgot-password'} replace>手机号找回</Link>
</div> </Form>
); </div>
} </div>
);
}
} }
const formikConfig = { const formikConfig = {
mapPropsToValues: () => ({ mapPropsToValues: () => ({
email: '', email: '',
veriCode: '' veriCode: ''
}), }),
validateOnChange: true, validateOnChange: true,
validateOnBlur: true, validateOnBlur: true,
validate: values => { validate: values => {
let errors = {} let errors = {}
if (!validateEmail(values.email)) { if (!validateEmail(values.email)) {
errors.email = '请输入正确的邮箱地址' errors.email = '请输入正确的邮箱地址'
} }
values.veriCode.toString().length !== 6 && (errors.veriCode = '验证码格式不正确') values.veriCode.toString().length !== 6 && (errors.veriCode = '验证码格式不正确')
return errors return errors
}, },
handleSubmit(values, {props}) { handleSubmit(values, {props}) {
sessionStorage.setItem('r_type', 'email') sessionStorage.setItem('r_type', 'email')
sessionStorage.setItem('email', values.email) sessionStorage.setItem('email', values.email)
http.post(`${API['passport-api']}/check_email_code`, { http.post(`${API['passport-api']}/check_email_code`, {
email: values.email, email: values.email,
code: values.veriCode code: values.veriCode
}).then(res => { }).then(res => {
if (res.data.errno == 0) { if (res.data.errno == 0) {
props.history.push('/passport/set-password', {from: props.location}) props.history.push('/passport/set-password', {from: props.location})
} else { } else {
Toast.info(res.data.msg, 2, null, false) Toast.info(res.data.msg, 2, null, false)
} }
}) })
}, },
} }
export default compose( export default compose(
connect( connect(
null, null,
{quickLogin} {quickLogin}
), ),
withFormik(formikConfig) withFormik(formikConfig)
)(ForgotPassword) )(ForgotPassword)
\ No newline at end of file
...@@ -5,8 +5,7 @@ import { studentLogin } from '@/store/userAction'; ...@@ -5,8 +5,7 @@ import { studentLogin } from '@/store/userAction';
import { http } from '@/utils'; import { http } from '@/utils';
import { Formik, Form, Field } from 'formik'; import { Formik, Form, Field } from 'formik';
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import { HeaderBar } from "@/common"; import { HeaderBar, CaptchaAli } from "@/common";
import Captcha from '@/common/Captcha'
import Header from '../common/Header'; import Header from '../common/Header';
import Input from '../common/inputWithCountryCodes'; import Input from '../common/inputWithCountryCodes';
import VeriCodeInput from '../common/veriCodeInput'; import VeriCodeInput from '../common/veriCodeInput';
...@@ -33,6 +32,7 @@ class StudentRoot extends PureComponent { ...@@ -33,6 +32,7 @@ class StudentRoot extends PureComponent {
list: [], list: [],
schoolList: [], schoolList: [],
schoolName: '', schoolName: '',
validationData: null,
}; };
} }
...@@ -73,7 +73,7 @@ class StudentRoot extends PureComponent { ...@@ -73,7 +73,7 @@ class StudentRoot extends PureComponent {
redirect: from && window.location.origin + from.pathname + from.search + from.hash, redirect: from && window.location.origin + from.pathname + from.search + from.hash,
}).then(res => { }).then(res => {
if (res.hasError) { if (res.hasError) {
captchaInstance.refresh(); captchaInstance.reset();
Toast.info(res.msg, 2, null, false); Toast.info(res.msg, 2, null, false);
} }
}); });
...@@ -84,13 +84,12 @@ class StudentRoot extends PureComponent { ...@@ -84,13 +84,12 @@ class StudentRoot extends PureComponent {
captchaInstance: instance captchaInstance: instance
}); });
} }
onVerify = (err, data) => { onVerify = (data) => {
if (!err) { this.setState({
this.setState({ validationData: data,
validate: data.validate validate: true
}); })
}
} }
selectSwitch = (key, value) => { selectSwitch = (key, value) => {
...@@ -123,7 +122,7 @@ class StudentRoot extends PureComponent { ...@@ -123,7 +122,7 @@ class StudentRoot extends PureComponent {
<HeaderBar title={'助学计划'} arrow={true}/> <HeaderBar title={'助学计划'} arrow={true}/>
<Header/> <Header/>
<Formik <Formik
initialValues={{ initialValues={{
tel: '', tel: '',
password: '', password: '',
code: '', code: '',
...@@ -185,20 +184,16 @@ class StudentRoot extends PureComponent { ...@@ -185,20 +184,16 @@ class StudentRoot extends PureComponent {
)} )}
/> />
<div className="student-form__item"> <div className="student-form__item">
<Field <Field
className="student-form__input" className="student-form__input"
type="password" type="password"
name="password" name="password"
minLength="6" minLength="6"
maxLength="16" maxLength="16"
placeholder="密码需要包含6-16位字母和数字" placeholder="密码需要包含6-16位字母和数字"
/> />
</div> </div>
<Captcha <CaptchaAli getInstance={this.getCaptchaInstance} onVerify={this.onVerify} mb={15}/>
mrBtm={'15px'}
getInstance={this.getCaptchaInstance}
onVerify={this.onVerify}
/>
{ {
validate && validate &&
<Field <Field
...@@ -210,7 +205,7 @@ class StudentRoot extends PureComponent { ...@@ -210,7 +205,7 @@ class StudentRoot extends PureComponent {
className={'student-form__code'} className={'student-form__code'}
icon={<i className={'iconfont iconduanxin'} style={{fontSize: '20px', left: '12px'}}/>} icon={<i className={'iconfont iconduanxin'} style={{fontSize: '20px', left: '12px'}}/>}
tel={props.values.tel} tel={props.values.tel}
challenge={validate} validationData={this.state.validationData}
errors={props.errors} errors={props.errors}
placeholder={'请输入验证码'} placeholder={'请输入验证码'}
instance={captchaInstance} instance={captchaInstance}
...@@ -221,7 +216,7 @@ class StudentRoot extends PureComponent { ...@@ -221,7 +216,7 @@ class StudentRoot extends PureComponent {
} }
<div className="student-form__item"> <div className="student-form__item">
<label className="student-form__label">学校</label> <label className="student-form__label">学校</label>
<StudentSelect <StudentSelect
name="school" name="school"
value={props.values.school} value={props.values.school}
schoolName={schoolName} schoolName={schoolName}
...@@ -236,12 +231,12 @@ class StudentRoot extends PureComponent { ...@@ -236,12 +231,12 @@ class StudentRoot extends PureComponent {
props.setFieldValue('college', '') props.setFieldValue('college', '')
}} }}
selectSwitch={this.selectSwitch} selectSwitch={this.selectSwitch}
changeToCollege={this.changeToCollege} changeToCollege={this.changeToCollege}
/> />
</div> </div>
<div className="student-form__item"> <div className="student-form__item">
<label className="student-form__label">学院</label> <label className="student-form__label">学院</label>
<StudentSelect <StudentSelect
name="college" name="college"
value={props.values.college} value={props.values.college}
data={{ data={{
...@@ -252,7 +247,7 @@ class StudentRoot extends PureComponent { ...@@ -252,7 +247,7 @@ class StudentRoot extends PureComponent {
options={collegeList} options={collegeList}
placeholder="请先选择学校" placeholder="请先选择学校"
onChange={props.setFieldValue} onChange={props.setFieldValue}
selectSwitch={this.selectSwitch} selectSwitch={this.selectSwitch}
/> />
</div> </div>
<div className="student-form__item"> <div className="student-form__item">
...@@ -280,8 +275,8 @@ class StudentRoot extends PureComponent { ...@@ -280,8 +275,8 @@ class StudentRoot extends PureComponent {
} }
const StudentSelect = (props) => { const StudentSelect = (props) => {
const { const {
options = [], options = [],
data: { key = '' , val = false }, data: { key = '' , val = false },
schoolName, schoolName,
isClick = true, isClick = true,
...@@ -295,23 +290,23 @@ const StudentSelect = (props) => { ...@@ -295,23 +290,23 @@ const StudentSelect = (props) => {
} = props; } = props;
return ( return (
<div className="student-select"> <div className="student-select">
<input <input
className={classnames({'active': val})} className={classnames({'active': val})}
value={value} value={value}
type="text" type="text"
placeholder={placeholder} placeholder={placeholder}
readOnly readOnly
onClick={() => { onClick={() => {
isClick && selectSwitch(key, true); isClick && selectSwitch(key, true);
}} }}
/> />
{ {
val && val &&
<ul className="student-select__list"> <ul className="student-select__list">
{ {
options.length > 0 && options.map((item, index) => ( options.length > 0 && options.map((item, index) => (
<li <li
className="student-select__option" className="student-select__option"
key={index} key={index}
onClick={() => { onClick={() => {
selectSwitch(key, false); selectSwitch(key, false);
......
...@@ -16,7 +16,6 @@ const accountLogin = user => dispatch => { ...@@ -16,7 +16,6 @@ const accountLogin = user => dispatch => {
const studentLogin = params => dispatch => { const studentLogin = params => dispatch => {
return http.post(`${API['passport-api']}/phone_reg`, { return http.post(`${API['passport-api']}/phone_reg`, {
challenge: params.validate,
phone: params.tel, phone: params.tel,
password: params.password, password: params.password,
code: params.code, code: params.code,
......
...@@ -67,6 +67,15 @@ function initCaptcha(cb) { ...@@ -67,6 +67,15 @@ function initCaptcha(cb) {
} }
function initCaptchaNC(cb) {
if (window.NoCaptcha && typeof window.NoCaptcha.init === 'function') {
cb()
} else {
const url = '//g.alicdn.com/sd/nch5/index.js' + '?t=' + getTimestamp(1 * 60 * 1000)
loadScript(url, cb)
}
}
export const is_weixin = () => { export const is_weixin = () => {
var ua = window.navigator.userAgent.toLowerCase(); var ua = window.navigator.userAgent.toLowerCase();
...@@ -126,11 +135,12 @@ export { ...@@ -126,11 +135,12 @@ export {
export { export {
html, html,
initCaptcha, initCaptcha,
initCaptchaNC,
validateTel, validateTel,
validateEmail, validateEmail,
browser, browser,
isLogin, isLogin,
dateCountDown dateCountDown,
} }
export { export {
default as SendMessageToApp default as SendMessageToApp
......
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