改成自己的router,基本完成网络通信

This commit is contained in:
2021-07-26 23:51:30 +08:00
parent d8c40cfe59
commit 41f5239ae6
9 changed files with 294 additions and 23 deletions

View File

@@ -4,6 +4,7 @@ import Spinner from '../components/Spinner/Spinner';
import UploadUnit from '../components/UploadUnit/UploadUnit';
import { post } from '../helper/axios';
import { apis } from '../helper/apis';
import { alert } from '../helper/alert';
import './upload.css';
@@ -39,8 +40,13 @@ export class UploadContainer extends Component {
if (this.state.submitting && (!this.state.file || this.state.url !== "")) {
// upload using axios
post(apis.submitMessage, { content: this.state.msg, image: this.state.url })
.then(res => {
this.setState({ submitting: false, msg: "", url: "" });
.then(({ data, status, networkStatus }) => {
if (networkStatus !== 200) return;
if (!status) return alert('提交内容失败:' + data);
this.setState({ submitting: false, msg: "", url: "", file: null });
alert('内容提交成功啦').then(({ isConfirmed }) => {
if (isConfirmed) window.close();
});
});
}
}