diff --git a/.roadhogrc.mock.js b/.roadhogrc.mock.js index 30d0a03859190e4a6796ea84dc8b51abd38af40c..89c3134bf0b0ad8a6f8816085310fd48c228dd9a 100644 --- a/.roadhogrc.mock.js +++ b/.roadhogrc.mock.js @@ -69,11 +69,11 @@ const proxy = { 'GET /api/profile/basic': getProfileBasicData, 'GET /api/profile/advanced': getProfileAdvancedData, 'POST /api/login/account': (req, res) => { - const { password, userName } = req.body; - res.send({ status: password === '888888' && userName === 'admin' ? 'ok' : 'error', type: 'account' }); - }, - 'POST /api/login/mobile': (req, res) => { - res.send({ status: 'ok', type: 'mobile' }); + const { password, userName, type } = req.body; + res.send({ + status: password === '888888' && userName === 'admin' ? 'ok' : 'error', + type, + }); }, 'POST /api/register': (req, res) => { res.send({ status: 'ok' }); diff --git a/src/models/login.js b/src/models/login.js index 5b130336dd0109b90aa2deee4bd2ee93501fbe0a..55eda43e0869e3df6377206b1725c5d58f8b5822 100644 --- a/src/models/login.js +++ b/src/models/login.js @@ -1,5 +1,5 @@ import { routerRedux } from 'dva/router'; -import { fakeAccountLogin, fakeMobileLogin } from '../services/api'; +import { fakeAccountLogin } from '../services/api'; export default { namespace: 'login', @@ -9,7 +9,7 @@ export default { }, effects: { - *accountSubmit({ payload }, { call, put }) { + *login({ payload }, { call, put }) { yield put({ type: 'changeSubmitting', payload: true, @@ -19,25 +19,10 @@ export default { type: 'changeLoginStatus', payload: response, }); - yield put({ - type: 'changeSubmitting', - payload: false, - }); - }, - *mobileSubmit(_, { call, put }) { - yield put({ - type: 'changeSubmitting', - payload: true, - }); - const response = yield call(fakeMobileLogin); - yield put({ - type: 'changeLoginStatus', - payload: response, - }); - yield put({ - type: 'changeSubmitting', - payload: false, - }); + // Login successfully + if (response.status === 'ok') { + yield put(routerRedux.push('/')); + } }, *logout(_, { put }) { yield put({ @@ -56,6 +41,7 @@ export default { ...state, status: payload.status, type: payload.type, + submitting: false, }; }, changeSubmitting(state, { payload }) { diff --git a/src/routes/User/Login.js b/src/routes/User/Login.js index ad9fc8a6ddbd8f94fd844a599ac5a8b2095d7e17..1433118fd86c722b2106977d0b1ae82ddd48c7de 100644 --- a/src/routes/User/Login.js +++ b/src/routes/User/Login.js @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import { connect } from 'dva'; -import { routerRedux, Link } from 'dva/router'; +import { Link } from 'dva/router'; import { Form, Input, Tabs, Button, Icon, Checkbox, Row, Col, Alert } from 'antd'; import styles from './Login.less'; @@ -17,20 +17,12 @@ export default class Login extends Component { type: 'account', } - componentWillReceiveProps(nextProps) { - if (nextProps.login.status === 'ok') { - this.props.dispatch(routerRedux.push('/')); - } - } - componentWillUnmount() { clearInterval(this.interval); } - onSwitch = (key) => { - this.setState({ - type: key, - }); + onSwitch = (type) => { + this.setState({ type }); } onGetCaptcha = () => { @@ -47,13 +39,15 @@ export default class Login extends Component { handleSubmit = (e) => { e.preventDefault(); - const { type } = this.state; this.props.form.validateFields({ force: true }, (err, values) => { if (!err) { this.props.dispatch({ - type: `login/${type}Submit`, - payload: values, + type: 'login/login', + payload: { + ...values, + type: this.state.type, + }, }); } } diff --git a/src/services/api.js b/src/services/api.js index b6f485f9ea414e1aeb00630d4ec3dfe66d33aca4..2f3e21a5ec5b8eede761f20f3e5f01870ec382bc 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -67,13 +67,6 @@ export async function fakeAccountLogin(params) { }); } -export async function fakeMobileLogin(params) { - return request('/api/login/mobile', { - method: 'POST', - body: params, - }); -} - export async function fakeRegister(params) { return request('/api/register', { method: 'POST',