From e5c0f833798d700ce763390644d92fe61eeccae9 Mon Sep 17 00:00:00 2001
From: guanpengchn <875499765@qq.com>
Date: Sun, 11 Aug 2019 19:05:54 +0800
Subject: [PATCH] =?UTF-8?q?feat(=E6=94=AF=E6=8C=81=E5=9B=BE=E7=89=87?=
=?UTF-8?q?=E4=B8=8A=E4=BC=A0)=20=E6=96=B0=E5=A2=9ESM.MS=E5=9B=BE=E5=BA=8A?=
=?UTF-8?q?,=E6=94=AF=E6=8C=81=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 1 +
src/App.js | 3 +-
src/components/Button/Picture.js | 68 ++++++++++++++++++++++++--------
src/utils/constant.js | 3 ++
yarn.lock | 17 +++++++-
5 files changed, 73 insertions(+), 19 deletions(-)
diff --git a/package.json b/package.json
index eaf12dd..6e9fd66 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
"@material-ui/core": "^3.9.2",
"@material-ui/icons": "^3.0.2",
"@svgr/webpack": "4.1.0",
+ "axios": "^0.19.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0",
"babel-jest": "23.6.0",
diff --git a/src/App.js b/src/App.js
index 60af774..6e56572 100755
--- a/src/App.js
+++ b/src/App.js
@@ -92,7 +92,8 @@ const styles = theme => ({
width: contentWidth + "mm",
height: contentHeight + "mm",
background: "white",
- overflow: "auto"
+ overflow: "auto",
+ wordBreak: "break-all"
},
navbar: {
width: "100%",
diff --git a/src/components/Button/Picture.js b/src/components/Button/Picture.js
index d750c09..74735fe 100644
--- a/src/components/Button/Picture.js
+++ b/src/components/Button/Picture.js
@@ -4,30 +4,61 @@ import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import Tooltip from "@material-ui/core/Tooltip";
import Button from "@material-ui/core/Button";
+import axios from "axios";
import picture from "../../icons/picture.svg";
-import { ENTER_DELAY, LEAVE_DELAY, DATA_MARKDOWN } from "../../utils/constant";
+import {
+ ENTER_DELAY,
+ LEAVE_DELAY,
+ DATA_MARKDOWN,
+ DATA_ORIGIN,
+ SM_MS_PROXY
+} from "../../utils/constant";
import { observer, inject } from "mobx-react";
@inject("navbar")
@inject("resume")
+@inject("hint")
@observer
class Picture extends Component {
/**
- * 更新markdown样式
+ * 上传图片
*/
- updateStyle = flag => event => {
- event.stopPropagation();
- const id = this.props.resume.choosenKey;
- const element = document.getElementById(id);
- let content = element.getAttribute(DATA_MARKDOWN);
- content = "- " + content;
+ uploadPicture = async ({ target }) => {
+ const file = document.getElementById("uploadImage");
+ const formData = new FormData();
+ formData.append("smfile", file.files[0]);
- // 更新markdown内容
- element.childNodes[0].innerText = content;
- element.setAttribute(DATA_MARKDOWN, content);
+ const result = await axios.post(SM_MS_PROXY, formData);
+ if (result.data.message === "Image upload repeated limit.") {
+ this.props.hint.setError({
+ isOpen: true,
+ message: "同一张图片无法上传多次"
+ });
+ } else {
+ const id = this.props.resume.choosenKey;
+ console.log(id);
+ const element = document.getElementById(id);
+
+ const { isMarkdownMode } = this.props.navbar;
+ let content;
+ if (isMarkdownMode) {
+ content = ``;
+ element.childNodes[0].innerText = content;
+ element.setAttribute(DATA_MARKDOWN, content);
+ } else {
+ content = `
\n`
+ element.childNodes[0].innerHTML = content;
+ element.setAttribute(DATA_ORIGIN, content);
+ }
+
+ }
+ };
+
+ stopPropagation = event => {
+ event.stopPropagation();
};
render() {
@@ -44,6 +75,7 @@ class Picture extends Component {
-