+
+ {this.state.status >= 2
+ ?

: null
- }
-
-
-
-
-
+ }
+ {this.state.status >= 0
+ ? (
+
+
+ {this.state.status === 3
+ ? (
+
+ ) : null
+ }
+ {this.state.status <= 1
+ ? (
+
+
+
+ {this.state.status === 0 ? '加载中' : '压缩中'}
+
+
+ ) : null
+ }
+ {this.state.status === 4
+ ? (
+
上传成功
+ ) : null}
+
+
+ {this.state.status === 2
+ ? (
+
+ ) : null
+ }
+ {this.state.status === 2 || this.state.status === 4
+ ? (
+
+ ) : null
+ }
+
+
+
+ ) : null
+ }
);
diff --git a/src/components/UploadUnit/upload.css b/src/components/UploadUnit/upload.css
index e69de29..3a81628 100644
--- a/src/components/UploadUnit/upload.css
+++ b/src/components/UploadUnit/upload.css
@@ -0,0 +1,78 @@
+.upload-wrap {
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
+.upload-unit {
+ width: calc(100%);
+ height: 200px;
+ min-width: 150px;
+ border: 2px dashed blue;
+ border-radius: 8px;
+ box-sizing: border-box;
+ transition: width .3s ease-out, height .3s ease-out, border .3s ease-out;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ overflow: hidden;
+}
+.upload-unit.open {
+ width: 200px;
+ border-width: 0;
+}
+.upload-unit > img {
+ margin-bottom: -200px;
+ height: 200px;
+ animation: fade-in .3s ease-out;
+ border-radius: 8px;
+}
+
+.upload-unit-mask {
+ width: 100%;
+ height: 100%;
+ background: rgba(0, 0, 0, 0.5);
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ transition: filter .3s ease-out;
+}
+.upload-unit-mask.hide {
+ filter: opacity(0);
+}
+
+.upload-unit-progress {
+ width: 50px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
+.progress-detail {
+ color: white;
+ font-size: 16px;
+ margin-top: 10px;
+}
+.progress-circle {
+ width: 50px;
+ height: 50px;
+}
+
+.upload-btns {
+ display: flex;
+ justify-content: center;
+ margin-top: -60px;
+ z-index: 1;
+}
+.upload-btns > button {
+ margin: 0 5px;
+}
+
+@keyframes fade-in {
+ from {
+ filter: opacity(0);
+ }
+ to {
+ filter: opacity(1);
+ }
+}
\ No newline at end of file
diff --git a/src/env.example.json b/src/env.example.json
new file mode 100644
index 0000000..4576918
--- /dev/null
+++ b/src/env.example.json
@@ -0,0 +1,3 @@
+{
+ "backEndBaseURL": "localhost:9444"
+}
\ No newline at end of file
diff --git a/src/helper/apis.js b/src/helper/apis.js
new file mode 100644
index 0000000..1370c5f
--- /dev/null
+++ b/src/helper/apis.js
@@ -0,0 +1,13 @@
+import { backEndBaseURL } from '../env.json';
+export const apis = {
+ uploadImage: "https://image.kieng.cn/upload.html?type=jd",
+
+ login: backEndBaseURL + "/user/login",
+ getProfile: backEndBaseURL + "/user/me",
+
+ submitMessage: backEndBaseURL + "/post/submit",
+ listEssence: backEndBaseURL + "/post/listPublished",
+
+ listAll: backEndBaseURL + "/admin/list",
+ setStatus: backEndBaseURL + "/admin/setStatus"
+};
\ No newline at end of file
diff --git a/src/helper/axios.js b/src/helper/axios.js
new file mode 100644
index 0000000..883fdb8
--- /dev/null
+++ b/src/helper/axios.js
@@ -0,0 +1,18 @@
+import axios from 'axios';
+
+export function get(url) {
+ return axios.get(url, {
+ headers: {
+ Authorization: 'Bearer ' + localStorage.getItem('jwt'),
+ "Allow-Control-Allow-Origin": "*"
+ }
+ });
+}
+export function post(url, data) {
+ return axios.post(url, data, {
+ headers: {
+ Authorization: 'Bearer ' + localStorage.getItem('jwt'),
+ "Allow-Control-Allow-Origin": "*"
+ }
+ });
+}
\ No newline at end of file
diff --git a/src/resources.json b/src/resources.json
index 3f7e743..ac4e087 100644
--- a/src/resources.json
+++ b/src/resources.json
@@ -1,5 +1,5 @@
{
"apis": {
- "uploadImage": "https://image.kieng.cn/upload.html?type=jd"
+
}
}
\ No newline at end of file
diff --git a/src/upload/upload.css b/src/upload/upload.css
index 08a151c..99e557c 100644
--- a/src/upload/upload.css
+++ b/src/upload/upload.css
@@ -28,23 +28,40 @@
.message-box {
width: 100%;
height: 200px;
+ margin-top: 40px;
}
.message-box-textarea {
width: 100%;
resize: none;
height: 100%;
box-sizing: border-box;
+ border-radius: 8px;
+ font-size: 16px;
+ padding: 10px;
+}
+.message-box-textarea:focus {
+ outline: none;
+ border-color: #008cff;
}
.upload-box {
width: 100%;
height: 200px;
+ margin-top: 15px;
}
.upload-area {
width: 100%;
height: 100%;
border: 2px dashed blue;
border-radius: 8px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ box-sizing: border-box;
+ cursor: pointer;
+}
+.upload-area-text {
+ font-size: 16px;
}
.btn-upload {
diff --git a/src/upload/upload.js b/src/upload/upload.js
index 82bba48..b6dafd4 100644
--- a/src/upload/upload.js
+++ b/src/upload/upload.js
@@ -1,19 +1,48 @@
import { Component } from 'react';
import Dropzone from 'react-dropzone';
+import Spinner from '../components/Spinner/Spinner';
+import UploadUnit from '../components/UploadUnit/UploadUnit';
+import { post } from 'axios';
+import { apis } from '../helper/apis';
+
import './upload.css';
export class UploadContainer extends Component {
constructor(props) {
super(props);
this.state = {
- files: [],
- msg: ""
+ file: null,
+ msg: "",
+ url: "",
+ submitting: false
};
+ this.handleChange = this.handleChange.bind(this);
+ this.handleUploadError = this.handleUploadError.bind(this);
+ this.handleSubmit = this.handleSubmit.bind(this);
}
- handleChange = files => {
- console.log(files);
- this.setState({ files });
+ handleChange(files) {
+ if (files.length > 0)
+ this.setState({ file: files[0] });
+ }
+
+ handleUploadError(msg) {
+ this.setState({ submitting: false });
+ }
+
+ handleSubmit() {
+ if ((this.state.msg === "" && this.file === null) || this.state.submitting) return;
+ this.setState({ submitting: true });
+ }
+
+ componentDidUpdate() {
+ 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: "" });
+ });
+ }
}
render() {
@@ -36,26 +65,38 @@ export class UploadContainer extends Component {
placeholder="留下您的寄语"
value={this.state.msg}
onChange={e => this.setState({ msg: e.target.value })}
+ disabled={this.state.submitting}
/>
+ onClick={this.handleSubmit}
+ disabled={(this.state.msg === "" && this.state.file === null) || this.state.submitting}
+ >{this.state.submitting ? (