|
@@ -21,7 +21,7 @@ export default class Login extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.validNumber = 0;
|
|
|
- this.state = { type: LOGIN_WX, data: { area: MobileArea[0].value } };
|
|
|
+ this.state = { type: LOGIN_WX, error: {}, data: { area: MobileArea[0].value } };
|
|
|
window.addEventListener(
|
|
|
'message',
|
|
|
event => {
|
|
@@ -41,14 +41,12 @@ export default class Login extends Component {
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
if (nextProps.user.needLogin && !this.init) {
|
|
|
this.init = true;
|
|
|
- Main.getContract('register')
|
|
|
- .then(result => {
|
|
|
- this.setState({ registerContract: result });
|
|
|
- });
|
|
|
- Main.getContract('privacy')
|
|
|
- .then(result => {
|
|
|
- this.setState({ privacyContract: result });
|
|
|
- });
|
|
|
+ Main.getContract('register').then(result => {
|
|
|
+ this.setState({ registerContract: result });
|
|
|
+ });
|
|
|
+ Main.getContract('privacy').then(result => {
|
|
|
+ this.setState({ privacyContract: result });
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -57,11 +55,16 @@ export default class Login extends Component {
|
|
|
}
|
|
|
|
|
|
login() {
|
|
|
- const { data, needEmail, mobileError, validError } = this.state;
|
|
|
+ const { data, needEmail, mobileError, validError, error } = this.state;
|
|
|
const { area, mobile, mobileVerifyCode, email } = data;
|
|
|
if (mobileError || validError) return;
|
|
|
- if (!area || !mobile || !mobileVerifyCode) return;
|
|
|
- if (needEmail && !email) return;
|
|
|
+ if (!area || !mobile || !mobileVerifyCode || (needEmail && !email)) {
|
|
|
+ error[LOGIN_PHONE] = { mobile: !mobile, mobileVerifyCode: !mobileVerifyCode, email: !email };
|
|
|
+ this.setState({ error });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ error[LOGIN_PHONE] = {};
|
|
|
+ this.setState({ error });
|
|
|
User.login(area, mobile, mobileVerifyCode, email, null, false)
|
|
|
.then(result => {
|
|
|
if (result.bindWechat) {
|
|
@@ -80,11 +83,16 @@ export default class Login extends Component {
|
|
|
}
|
|
|
|
|
|
bind() {
|
|
|
- const { data, needEmail, mobileError, validError } = this.state;
|
|
|
+ const { data, needEmail, mobileError, validError, error } = this.state;
|
|
|
const { area, mobile, mobileVerifyCode, email } = data;
|
|
|
if (mobileError || validError) return;
|
|
|
- if (!area || !mobile || !mobileVerifyCode) return;
|
|
|
- if (needEmail && !email) return;
|
|
|
+ if (!area || !mobile || !mobileVerifyCode || (needEmail && !email)) {
|
|
|
+ error[BIND_PHONE] = { mobile: !mobile, mobileVerifyCode: !mobileVerifyCode, email: !email };
|
|
|
+ this.setState({ error });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ error[BIND_PHONE] = {};
|
|
|
+ this.setState({ error });
|
|
|
User.bind(area, mobile, mobileVerifyCode, email)
|
|
|
.then(() => {
|
|
|
this.close();
|
|
@@ -99,13 +107,14 @@ export default class Login extends Component {
|
|
|
}
|
|
|
|
|
|
scanLogin(code) {
|
|
|
- User.loginWechat(code, false).then(result => {
|
|
|
- if (result.bindMobile) {
|
|
|
- this.close();
|
|
|
- } else {
|
|
|
- this.setState({ type: BIND_PHONE });
|
|
|
- }
|
|
|
- })
|
|
|
+ User.loginWechat(code, false)
|
|
|
+ .then(result => {
|
|
|
+ if (result.bindMobile) {
|
|
|
+ this.close();
|
|
|
+ } else {
|
|
|
+ this.setState({ type: BIND_PHONE });
|
|
|
+ }
|
|
|
+ })
|
|
|
.catch(err => {
|
|
|
this.setState({ type: BIND_WX_ERROR, wechatError: err.message });
|
|
|
});
|
|
@@ -212,7 +221,8 @@ export default class Login extends Component {
|
|
|
}
|
|
|
|
|
|
renderLoginPhone() {
|
|
|
- const { needEmail, registerContract = {}, privacyContract } = this.state;
|
|
|
+ const { needEmail, registerContract = {}, privacyContract, error = {} } = this.state;
|
|
|
+ const emptyError = error[LOGIN_PHONE] || {};
|
|
|
return (
|
|
|
<div className="body">
|
|
|
<div className="title">手机号登录</div>
|
|
@@ -226,6 +236,7 @@ export default class Login extends Component {
|
|
|
select={MobileArea}
|
|
|
value={this.state.data.mobile}
|
|
|
error={this.state.mobileError}
|
|
|
+ empty={emptyError.mobile}
|
|
|
onSelect={value => {
|
|
|
this.changeData('area', value);
|
|
|
this.validMobile(true);
|
|
@@ -239,6 +250,7 @@ export default class Login extends Component {
|
|
|
placeholder="请输入验证码"
|
|
|
value={this.state.data.mobileVerifyCode}
|
|
|
error={this.state.validError}
|
|
|
+ empty={emptyError.mobileVerifyCode}
|
|
|
onSend={() => {
|
|
|
return this.sendValid();
|
|
|
}}
|
|
@@ -250,15 +262,26 @@ export default class Login extends Component {
|
|
|
<Input
|
|
|
placeholder="请输入邮箱"
|
|
|
value={this.state.data.email}
|
|
|
+ empty={emptyError.email}
|
|
|
onChange={e => {
|
|
|
this.changeData('email', e.target.value);
|
|
|
}}
|
|
|
/>
|
|
|
)}
|
|
|
- {needEmail && (<div>
|
|
|
- <RadioItem checked theme="white" className="m-r-5" />
|
|
|
- 我已经阅读并同意 <a href={`/contract/${registerContract.key}`} target="_blank">{registerContract.title}</a> 与 <a href={`/contract/${privacyContract.key}`} target="_blank">{privacyContract.title}</a>.
|
|
|
- </div>)}
|
|
|
+ {needEmail && (
|
|
|
+ <div>
|
|
|
+ <RadioItem checked theme="white" className="m-r-5" />
|
|
|
+ 我已经阅读并同意{' '}
|
|
|
+ <a href={`/contract/${registerContract.key}`} target="_blank">
|
|
|
+ {registerContract.title}
|
|
|
+ </a>{' '}
|
|
|
+ 与{' '}
|
|
|
+ <a href={`/contract/${privacyContract.key}`} target="_blank">
|
|
|
+ {privacyContract.title}
|
|
|
+ </a>
|
|
|
+ .
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
<Button
|
|
|
type="primary"
|
|
|
size="large"
|
|
@@ -311,7 +334,8 @@ export default class Login extends Component {
|
|
|
}
|
|
|
|
|
|
renderBindPhone() {
|
|
|
- const { needEmail, contract = {} } = this.state;
|
|
|
+ const { needEmail = true, contract = {}, error = {} } = this.state;
|
|
|
+ const emptyError = error[BIND_PHONE] || {};
|
|
|
return (
|
|
|
<div className="body">
|
|
|
<div className="title">绑定手机号</div>
|
|
@@ -325,6 +349,7 @@ export default class Login extends Component {
|
|
|
select={MobileArea}
|
|
|
value={this.state.data.mobile}
|
|
|
error={this.state.mobileError}
|
|
|
+ empty={emptyError.mobile}
|
|
|
onSelect={value => {
|
|
|
this.changeData('area', value);
|
|
|
this.validMobile(false);
|
|
@@ -338,6 +363,7 @@ export default class Login extends Component {
|
|
|
placeholder="请输入验证码"
|
|
|
value={this.state.data.mobileVerifyCode}
|
|
|
error={this.state.validError}
|
|
|
+ empty={emptyError.mobileVerifyCode}
|
|
|
onSend={() => {
|
|
|
return this.sendValid();
|
|
|
}}
|
|
@@ -349,15 +375,26 @@ export default class Login extends Component {
|
|
|
<Input
|
|
|
placeholder="请输入邮箱"
|
|
|
value={this.state.data.email}
|
|
|
+ empty={emptyError.email}
|
|
|
onChange={e => {
|
|
|
this.changeData('email', e.target.value);
|
|
|
}}
|
|
|
/>
|
|
|
)}
|
|
|
- {needEmail && (<div>
|
|
|
- <RadioItem checked theme="white" className="m-r-5" />
|
|
|
- 我已经阅读并同意 <a href={`/contract/${contract.key}`} target="_blank">{contract.title}</a> 与 <a href={`/contract/${contract.key}`} target="_blank">隐私政策</a>.
|
|
|
- </div>)}
|
|
|
+ {needEmail && (
|
|
|
+ <div className="m-b-2">
|
|
|
+ <RadioItem checked theme="white" className="m-r-5" />
|
|
|
+ 我已经阅读并同意{' '}
|
|
|
+ <a href={`/contract/${contract.key}`} target="_blank">
|
|
|
+ {contract.title}
|
|
|
+ </a>{' '}
|
|
|
+ 与{' '}
|
|
|
+ <a href={`/contract/${contract.key}`} target="_blank">
|
|
|
+ 隐私政策
|
|
|
+ </a>
|
|
|
+ .
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
<Button
|
|
|
type="primary"
|
|
|
size="large"
|
|
@@ -424,13 +461,13 @@ export default class Login extends Component {
|
|
|
|
|
|
export class Input extends Component {
|
|
|
render() {
|
|
|
- const { className = '', onChange, placeholder, value, error, left, right } = this.props;
|
|
|
+ const { className = '', onChange, placeholder, value, error, left, right, empty } = this.props;
|
|
|
return (
|
|
|
<div className={`g-input-container ${className}`}>
|
|
|
<div className={`g-input-wrapper ${error ? 'error' : ''}`}>
|
|
|
{left && <div className="g-input-left">{left}</div>}
|
|
|
<input
|
|
|
- className="g-input"
|
|
|
+ className={`g-input ${empty ? 'empty' : ''}`}
|
|
|
placeholder={placeholder}
|
|
|
value={value}
|
|
|
onChange={data => onChange && onChange(data)}
|
|
@@ -453,7 +490,7 @@ export class SelectInput extends Component {
|
|
|
|
|
|
render() {
|
|
|
const { showSelect } = this.state;
|
|
|
- const { className = '', onChange, placeholder, value, error, selectValue, select, onSelect } = this.props;
|
|
|
+ const { className = '', onChange, placeholder, value, error, empty, selectValue, select, onSelect } = this.props;
|
|
|
return (
|
|
|
<Input
|
|
|
className={className}
|
|
@@ -483,6 +520,7 @@ export class SelectInput extends Component {
|
|
|
placeholder={placeholder}
|
|
|
onChange={data => onChange && onChange(data)}
|
|
|
error={error}
|
|
|
+ empty={empty}
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
@@ -518,7 +556,7 @@ export class VerificationInput extends Component {
|
|
|
|
|
|
render() {
|
|
|
const { loading } = this.state;
|
|
|
- const { className = '', onChange, placeholder, value, error } = this.props;
|
|
|
+ const { className = '', onChange, placeholder, value, error, empty } = this.props;
|
|
|
return (
|
|
|
<Input
|
|
|
className={className}
|
|
@@ -527,10 +565,13 @@ export class VerificationInput extends Component {
|
|
|
<span className="g-input-right-verification" onClick={() => this.onSend()}>
|
|
|
获取验证码
|
|
|
</span>
|
|
|
- ) : (<span className="g-input-right-verification-loading">等待{loading}秒</span>)
|
|
|
+ ) : (
|
|
|
+ <span className="g-input-right-verification-loading">等待{loading}秒</span>
|
|
|
+ )
|
|
|
}
|
|
|
value={value}
|
|
|
error={error}
|
|
|
+ empty={empty}
|
|
|
placeholder={placeholder}
|
|
|
onChange={data => onChange && onChange(data)}
|
|
|
/>
|