import React, { Component } from 'react'; import { getUrl2 } from 'educoder' const $ = window.$ let _url_origin = getUrl2() // let _url_origin = `http://47.96.87.25:48080`; if (!window.Cropper) { $('head').append($('') .attr('href', `${_url_origin}/react/public/js/cropper/cropper.min.css`)); $.getScript( `${_url_origin}/react/public/js/cropper/cropper.js`, (data, textStatus, jqxhr) => { }); $.getScript( `${_url_origin}/react/public/js/cropper/html2canvas.min.js`, (data, textStatus, jqxhr) => { }); } function save_avatar(){ // if($(img_lg).html().trim() == ""){ // $("#avatar-name").html("请先选择图片上传").css("color", 'red'); // } else { // $("#avatar-name").html("").css("color", '#333'); const previewId = this.props.previewId var img_lg = document.getElementById(previewId || 'img-preview'); // 截图小的显示框内的内容 html2canvas(img_lg).then(function(canvas) { // for test // document.getElementById('canvasWrap').appendChild(canvas); var dataUrl = canvas.toDataURL("image/jpeg"); console.log(dataUrl) // TODO upload base64 image data to server }); return // 老版接口: // html2canvas(img_lg, { // allowTaint: true, // taintTest: false, // onrendered: function(canvas) { // canvas.id = "mycanvas"; // //生成base64图片数据 // var dataUrl = canvas.toDataURL("image/jpeg"); // console.log(dataUrl) // var newImg = document.getElementById("showImg"); // newImg.src = dataUrl; // return; // imagesAjax(dataUrl); // $(".avatar-save").attr("disabled","true"); // } // }); // } } class Cropper extends Component { state = { }; handleChange = (info) => { } componentDidMount() { setTimeout(() => { const image = document.getElementById('image'); const cropper = new window.Cropper(image, { aspectRatio: 1, crop(event) { // console.log(event.detail.x); // console.log(event.detail.y); // console.log(event.detail.width); // console.log(event.detail.height); // console.log(event.detail.rotate); // console.log(event.detail.scaleX); // console.log(event.detail.scaleY); }, preview: '.img-preview', }); }, 3000) } render() { const { width, height, previewId, imageSrc } = this.props; return (