|
|
|
@ -7,6 +7,11 @@ let _url_origin = getUrl2()
|
|
|
|
|
// let _url_origin = `http://47.96.87.25:48080`;
|
|
|
|
|
|
|
|
|
|
if (!window.Cropper) {
|
|
|
|
|
$.ajaxSetup({
|
|
|
|
|
cache: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('head').append($('<link rel="stylesheet" type="text/css" />')
|
|
|
|
|
.attr('href', `${_url_origin}/react/public/js/cropper/cropper.min.css`));
|
|
|
|
|
|
|
|
|
@ -61,7 +66,14 @@ function save_avatar(){
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
props 说明:
|
|
|
|
|
imageId 源图片标签的id
|
|
|
|
|
previewId crop后预览dom的id
|
|
|
|
|
imageSrc 源图片src
|
|
|
|
|
width 数字格式
|
|
|
|
|
height 数字格式
|
|
|
|
|
*/
|
|
|
|
|
class Cropper extends Component {
|
|
|
|
|
state = {
|
|
|
|
|
};
|
|
|
|
@ -70,26 +82,31 @@ class Cropper extends Component {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
},
|
|
|
|
|
this.options = {
|
|
|
|
|
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)
|
|
|
|
|
preview: this.props.previewId ? `#${this.props.previewId}` : '.img-preview',
|
|
|
|
|
}
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
const image = document.getElementById(this.props.imageId || '__image');
|
|
|
|
|
this.cropper = new window.Cropper(image, this.options);
|
|
|
|
|
}, 1000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renew = (image) => {
|
|
|
|
|
this.cropper && this.cropper.destroy();
|
|
|
|
|
this.cropper = new window.Cropper(image, this.options);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
render() {
|
|
|
|
|
|
|
|
|
|
const { width, height, previewId, imageSrc } = this.props;
|
|
|
|
@ -98,8 +115,8 @@ class Cropper extends Component {
|
|
|
|
|
{/* This rule is very important, please do not ignore this! */}
|
|
|
|
|
<style>{`
|
|
|
|
|
.wrapper {
|
|
|
|
|
width: ${ width || '500px'};
|
|
|
|
|
height: ${ height || '500px'};
|
|
|
|
|
width: ${ (width+'px') || '500px'};
|
|
|
|
|
height: ${ (height+'px') || '500px'};
|
|
|
|
|
}
|
|
|
|
|
img {
|
|
|
|
|
max-width: 100%;
|
|
|
|
@ -113,7 +130,7 @@ class Cropper extends Component {
|
|
|
|
|
`}</style>
|
|
|
|
|
<div className="wrapper">
|
|
|
|
|
{/* http://localhost:3007/images/footNavLogo.png 图片转了后不对 */}
|
|
|
|
|
<img id="image" src={`${imageSrc || "/images/testPicture.jpg"}`}></img>
|
|
|
|
|
<img id={this.props.imageId || "__image"} src={`${imageSrc || "/images/testPicture.jpg"}`}></img>
|
|
|
|
|
</div>
|
|
|
|
|
{/* background: 'aquamarine',
|
|
|
|
|
'border-radius': '128px'
|
|
|
|
@ -124,7 +141,7 @@ class Cropper extends Component {
|
|
|
|
|
{/* <img id="showImg" src="http://localhost:3007/images/testPicture.jpg"></img> */}
|
|
|
|
|
|
|
|
|
|
{/* <div id="canvasWrap"></div> */}
|
|
|
|
|
<button onClick={save_avatar.bind(this)}>save </button>
|
|
|
|
|
{/* <button onClick={save_avatar.bind(this)}>save </button> */}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|