💄 UI: httputil中展示错误提醒
This commit is contained in:
parent
78567a5d9a
commit
beb2794537
@ -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() {
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user