diff --git a/front/src/pages/public/Login/index.jsx b/front/src/pages/public/Login/index.jsx index 8a7b244..0805af2 100644 --- a/front/src/pages/public/Login/index.jsx +++ b/front/src/pages/public/Login/index.jsx @@ -1,7 +1,7 @@ import React, { Component } from "react"; import { Link } from "react-router-dom"; import queryString from "query-string"; -import { Button, Input, message, Checkbox } from "antd"; +import { Button, Input, Checkbox } from "antd"; import IconFont from "../../../components/IconFont"; import styles from "./index.module.less"; import { connect } from "react-redux"; @@ -70,23 +70,18 @@ class Login extends Component { if (!(this.checkStr(str) && this.checkPassword(password))) { return; } - axios - .post("/user/login", this.state) - .then(res => { - const token = res.token; - delete res.token; - localStorage.setItem("token", token); - window.token = token; - this.props.updateToken(token); - if (this.query.redirect) { - this.props.history.replace(decodeURIComponent(this.query.redirect)); - } else { - this.props.history.replace("/"); - } - }) - .catch(error => { - message.error(error); - }); + axios.post("/user/login", this.state).then(res => { + const token = res.token; + delete res.token; + localStorage.setItem("token", token); + window.token = token; + this.props.updateToken(token); + if (this.query.redirect) { + this.props.history.replace(decodeURIComponent(this.query.redirect)); + } else { + this.props.history.replace("/"); + } + }); }; render() { diff --git a/front/src/pages/public/RegisterOrReset/index.jsx b/front/src/pages/public/RegisterOrReset/index.jsx index 8474b70..3e6f5b2 100644 --- a/front/src/pages/public/RegisterOrReset/index.jsx +++ b/front/src/pages/public/RegisterOrReset/index.jsx @@ -122,23 +122,17 @@ export default class Register extends React.Component { return; } if (current === REGISTER_TYPE) { - axios - .put("/user", form) - .then(() => { - message.success("注册成功"); - setTimeout(() => this.props.history.replace("/public/login"), 500); - }) - .catch(error => message.error(error)); + axios.put("/user", form).then(() => { + message.success("注册成功"); + setTimeout(() => this.props.history.replace("/public/login"), 500); + }); } else { delete form.username; - axios - .post("/user/resetPassword", form) - .then(() => { - message.success("操作成功"); - console.log(this.location); - setTimeout(() => this.props.history.replace("/public/login"), 500); - }) - .catch(error => message.error(error)); + axios.post("/user/resetPassword", form).then(() => { + message.success("操作成功"); + console.log(this.location); + setTimeout(() => this.props.history.replace("/public/login"), 500); + }); } }; diff --git a/front/src/util/httpUtil.js b/front/src/util/httpUtil.js index 7532c9c..a2c563f 100644 --- a/front/src/util/httpUtil.js +++ b/front/src/util/httpUtil.js @@ -1,4 +1,4 @@ -import { notification } from "antd"; +import { notification, message } from "antd"; import axios from "axios"; //定义http实例 @@ -25,6 +25,7 @@ instance.interceptors.response.use( if (data.code === 1) { return data.data; } else if (data.code === -2) { + message.error(data.message); return Promise.reject(data.message); } else { showError(data);