fileUploaded

dev_forum
hjm 5 years ago
parent 45082a61d2
commit d1a8ebad1d

@ -39,11 +39,27 @@ class ChangeHeaderPicModal extends Component{
URL.revokeObjectURL(uploadedImageURL);
}
const image = document.getElementById( imageId );
image.src = uploadedImageURL = URL.createObjectURL(file);
// 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 = () => {
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");

Loading…
Cancel
Save