From d1a8ebad1d878800286e846c363bf77ec6ddde36 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Thu, 11 Jul 2019 18:03:50 +0800 Subject: [PATCH] fileUploaded --- .../user/account/ChangeHeaderPicModal.js | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/public/react/src/modules/user/account/ChangeHeaderPicModal.js b/public/react/src/modules/user/account/ChangeHeaderPicModal.js index 08b4e9d18..997d99357 100644 --- a/public/react/src/modules/user/account/ChangeHeaderPicModal.js +++ b/public/react/src/modules/user/account/ChangeHeaderPicModal.js @@ -39,11 +39,27 @@ class ChangeHeaderPicModal extends Component{ URL.revokeObjectURL(uploadedImageURL); } const image = document.getElementById( imageId ); - image.src = uploadedImageURL = URL.createObjectURL(file); - that.refs['cropper'].renew(image) - // cropper.destroy(); - // cropper = new Cropper(image, options); - inputImage.value = null; + + // base64 + var reader = new FileReader(); + reader.readAsBinaryString(file); + + reader.onload = () => { + let base64_content = btoa(reader.result); + console.log(); + + image.src = `data:${file.type};base64,${base64_content}` // uploadedImageURL = URL.createObjectURL(file); + that.fileUploaded = true; + that.refs['cropper'].renew(image) + // cropper.destroy(); + // cropper = new Cropper(image, options); + inputImage.value = null; + }; + reader.onerror = function() { + console.log('there are some problems'); + }; + + } else { this.props.showNotification && this.props.showNotification("请选择一个图片格式的文件") // window.alert('Please choose an image file.'); @@ -57,6 +73,8 @@ class ChangeHeaderPicModal extends Component{ this.refs['modalWrapper'].setVisible(visible) if (visible) { + this.fileUploaded = false; + setTimeout(() => { this.init() }, 500) @@ -69,7 +87,12 @@ class ChangeHeaderPicModal extends Component{ } onOk = () => { - var img_lg = document.getElementById(previewId); + if (this.fileUploaded != true) { + this.props.showNotification("请先上传图片") + return; + } + var img_lg = document.getElementById(previewId); + // https://github.com/niklasvh/html2canvas/issues/1908 // 截图小的显示框内的内容 window.html2canvas(img_lg).then((canvas) => { var dataUrl = canvas.toDataURL("image/jpeg");