💄 UI: httputil中展示错误提醒
This commit is contained in:
parent
78567a5d9a
commit
beb2794537
@ -1,7 +1,7 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import { Button, Input, message, Checkbox } from "antd";
|
import { Button, Input, Checkbox } from "antd";
|
||||||
import IconFont from "../../../components/IconFont";
|
import IconFont from "../../../components/IconFont";
|
||||||
import styles from "./index.module.less";
|
import styles from "./index.module.less";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
@ -70,23 +70,18 @@ class Login extends Component {
|
|||||||
if (!(this.checkStr(str) && this.checkPassword(password))) {
|
if (!(this.checkStr(str) && this.checkPassword(password))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
axios
|
axios.post("/user/login", this.state).then(res => {
|
||||||
.post("/user/login", this.state)
|
const token = res.token;
|
||||||
.then(res => {
|
delete res.token;
|
||||||
const token = res.token;
|
localStorage.setItem("token", token);
|
||||||
delete res.token;
|
window.token = token;
|
||||||
localStorage.setItem("token", token);
|
this.props.updateToken(token);
|
||||||
window.token = token;
|
if (this.query.redirect) {
|
||||||
this.props.updateToken(token);
|
this.props.history.replace(decodeURIComponent(this.query.redirect));
|
||||||
if (this.query.redirect) {
|
} else {
|
||||||
this.props.history.replace(decodeURIComponent(this.query.redirect));
|
this.props.history.replace("/");
|
||||||
} else {
|
}
|
||||||
this.props.history.replace("/");
|
});
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
message.error(error);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -122,23 +122,17 @@ export default class Register extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (current === REGISTER_TYPE) {
|
if (current === REGISTER_TYPE) {
|
||||||
axios
|
axios.put("/user", form).then(() => {
|
||||||
.put("/user", form)
|
message.success("注册成功");
|
||||||
.then(() => {
|
setTimeout(() => this.props.history.replace("/public/login"), 500);
|
||||||
message.success("注册成功");
|
});
|
||||||
setTimeout(() => this.props.history.replace("/public/login"), 500);
|
|
||||||
})
|
|
||||||
.catch(error => message.error(error));
|
|
||||||
} else {
|
} else {
|
||||||
delete form.username;
|
delete form.username;
|
||||||
axios
|
axios.post("/user/resetPassword", form).then(() => {
|
||||||
.post("/user/resetPassword", form)
|
message.success("操作成功");
|
||||||
.then(() => {
|
console.log(this.location);
|
||||||
message.success("操作成功");
|
setTimeout(() => this.props.history.replace("/public/login"), 500);
|
||||||
console.log(this.location);
|
});
|
||||||
setTimeout(() => this.props.history.replace("/public/login"), 500);
|
|
||||||
})
|
|
||||||
.catch(error => message.error(error));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { notification } from "antd";
|
import { notification, message } from "antd";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
//定义http实例
|
//定义http实例
|
||||||
@ -25,6 +25,7 @@ instance.interceptors.response.use(
|
|||||||
if (data.code === 1) {
|
if (data.code === 1) {
|
||||||
return data.data;
|
return data.data;
|
||||||
} else if (data.code === -2) {
|
} else if (data.code === -2) {
|
||||||
|
message.error(data.message);
|
||||||
return Promise.reject(data.message);
|
return Promise.reject(data.message);
|
||||||
} else {
|
} else {
|
||||||
showError(data);
|
showError(data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user