|
|
@@ -472,6 +472,7 @@ var app = new Vue({
|
|
|
_this.cropParams = data;
|
|
|
_this.cropParams.id = id;
|
|
|
_this.cropParams.type = type;
|
|
|
+ _this.cropParams.resize = 0;
|
|
|
if (_this.cropParams.url == '') {
|
|
|
$.toast('请重新添加图片');
|
|
|
return false;
|
|
|
@@ -486,9 +487,8 @@ var app = new Vue({
|
|
|
}
|
|
|
var iWidth = $("body").outerWidth();
|
|
|
var iHeight = $("body").height()-130;
|
|
|
- $image = $("#cropImg");
|
|
|
-
|
|
|
var cropWidth = $('body').width();
|
|
|
+ $image = $("#cropImg");
|
|
|
$("#cropBox").popup();
|
|
|
_this.options = {
|
|
|
// aspectRatio: 0,
|
|
|
@@ -554,8 +554,6 @@ var app = new Vue({
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- //_this.cropSize();
|
|
|
-
|
|
|
},
|
|
|
// 预览
|
|
|
picPreview: function(id, data){
|
|
|
@@ -601,6 +599,7 @@ var app = new Vue({
|
|
|
$("body").css('overflowY','scroll');
|
|
|
$("#cropImg").cropper('destroy');
|
|
|
this.jc = null;
|
|
|
+ this.cropParams.resize = 0;
|
|
|
$("#cropImg").remove();
|
|
|
}
|
|
|
},
|
|
|
@@ -615,11 +614,23 @@ var app = new Vue({
|
|
|
}else{
|
|
|
$("#cropImg").cropper("rotate", 90);
|
|
|
}
|
|
|
+ this.cropParams.resize = 0;
|
|
|
+ var data = $("#cropImg").cropper('getContainerData');
|
|
|
+ var cdata = $("#cropImg").cropper('getCanvasData');
|
|
|
+ $("#cropImg").cropper('setCropBoxData', {
|
|
|
+ width: cdata.width,
|
|
|
+ height: cdata.height,
|
|
|
+ top: data.height-cdata.height>0? (data.height-cdata.height)/2 : 0,
|
|
|
+ left: data.width-cdata.width>0? (data.width-cdata.width)/2 : 0
|
|
|
+ });
|
|
|
},
|
|
|
// 适应
|
|
|
cropSize: function(){
|
|
|
var _this = this;
|
|
|
var data = _this.cropParams.data;
|
|
|
+ if(_this.cropParams.resize>=2){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if(data.height<data.width){
|
|
|
$("#cropImg").cropper("rotate", 90);
|
|
|
_this.cropParams.cropData.rotate = 90;
|
|
|
@@ -628,8 +639,6 @@ var app = new Vue({
|
|
|
var size = data.height<data.width? data.height: data.width;
|
|
|
var iWidth = $("body").outerWidth();
|
|
|
var iHeight = $("body").height()-130;
|
|
|
- console.log(data);
|
|
|
- console.log(size);
|
|
|
if(size<iWidth){
|
|
|
var rate = iWidth/size;
|
|
|
$("#cropImg").cropper("zoom", rate);
|
|
|
@@ -637,16 +646,16 @@ var app = new Vue({
|
|
|
var rate = iWidth/cwidth;
|
|
|
$("#cropImg").cropper("zoom", rate);
|
|
|
}
|
|
|
-
|
|
|
- $("#cropImg").cropper(_this.options);
|
|
|
+ _this.cropParams.resize++;
|
|
|
var data = $("#cropImg").cropper('getContainerData');
|
|
|
- console.log(data);
|
|
|
- console.log(iWidth);
|
|
|
- console.log(iHeight);
|
|
|
- $("#cropImg").cropper('setData', {
|
|
|
- width: data.width,
|
|
|
- height: data.height
|
|
|
+ var cdata = $("#cropImg").cropper('getCanvasData');
|
|
|
+ $("#cropImg").cropper('setCropBoxData', {
|
|
|
+ width: cdata.width,
|
|
|
+ height: cdata.height,
|
|
|
+ top: data.height-cdata.height>0? (data.height-cdata.height)/2 : 0,
|
|
|
+ left: data.width-cdata.width>0? (data.width-cdata.width)/2 : 0
|
|
|
});
|
|
|
+
|
|
|
},
|
|
|
// 确定剪切
|
|
|
cropConfirm: function () {
|
|
|
@@ -681,15 +690,15 @@ var app = new Vue({
|
|
|
$.closePopup();
|
|
|
$.hideLoading();
|
|
|
_this.cropParams = {};
|
|
|
- $("#cropImg").cropper('destroy');
|
|
|
_this.jc = null;
|
|
|
+ $("#cropImg").cropper('destroy');
|
|
|
$("#cropImg").remove();
|
|
|
}, 200);
|
|
|
}else{
|
|
|
$.closePopup();
|
|
|
- _this.cropParams = {};
|
|
|
$.hideLoading();
|
|
|
$.showLoading('图片处理失败,请重新上传');
|
|
|
+ _this.cropParams = {};
|
|
|
setTimeout(function(){
|
|
|
$.hideLoading();
|
|
|
}, 1000);
|
|
|
@@ -704,6 +713,7 @@ var app = new Vue({
|
|
|
$image = $("#cropImg");
|
|
|
$image.cropper(this.options);
|
|
|
this.jc = $image.cropper('replace', this.cropParams.old_url);
|
|
|
+ this.cropParams.resize = false;
|
|
|
},
|
|
|
// 旋转图片处理
|
|
|
rotateImg: function(img, direction,canvas) {
|