wesmiler 6 år sedan
förälder
incheckning
9dd1a63138
1 ändrade filer med 18 tillägg och 40 borttagningar
  1. 18 40
      public/static/weixin/js/papers.js

+ 18 - 40
public/static/weixin/js/papers.js

@@ -458,35 +458,23 @@ var app = new Vue({
                 // maxCropBoxHeight: imgHeight,
                 preview: '.preview_' + id,
                 crop: function (data) {
-                    /*var cropData = {
-                        x: Math.round(data.x),
-                        y: Math.round(data.y),
-                        height: Math.round(data.height),
-                        width: Math.round(data.width),
-                        rotate: Math.round(data.rotate),
-                    };*/
-
-
                     _this.cropParams.id = id;
                     _this.cropParams.cropData = {
-                        width: data.width*20,
-                        // width: imgWidth*20,
-                        height: data.height*20,
-                        // height: imgHeight*20,
+                        width: data.width,
+                        height: data.height,
                         rotate: data.rotate,
                         imageSmoothingQuality: 'high',
                         fillColor: '#fff',
                     };
-                    // _this.picList[id].cropData = cropData;
                 }
             }
 
             if (_this.jc != null) {
                 $image.cropper(options);
-                $image.cropper('replace', _this.cropParams.blobUrl);
+                $image.cropper('replace', _this.cropParams.old_url);
             } else {
                 $image.cropper(options);
-                _this.jc = $image.cropper('replace', _this.cropParams.blobUrl);
+                _this.jc = $image.cropper('replace', _this.cropParams.old_url);
             }
 
         },
@@ -514,14 +502,6 @@ var app = new Vue({
                 step--;
                 step < min_step && (step = max_step);
             }
-            //img.setAttribute('step', step);
-            /*var canvas = document.getElementById('pic_' + pid);
-            if (canvas == null) {
-                img.style.display = 'none';
-                canvas = document.createElement('canvas');
-                canvas.setAttribute('id', 'pic_' + pid);
-                img.parentNode.appendChild(canvas);
-            }  */
             //旋转角度以弧度值为参数
             var degree = step * 90 * Math.PI / 180;
             var ctx = canvas.getContext('2d');
@@ -589,36 +569,33 @@ var app = new Vue({
                 $image = $("#cropImg");
                 var id = _this.cropParams.id;
                 var canvas = $image.cropper('getCroppedCanvas', _this.cropParams.cropData);
-                var url = canvas.toDataURL('image/jpeg');
-                _this.picList[id].url = url;
-                _this.picList[id].preview = url;
-                // _this.picList[id].fileData = _this.dataURLtoFile(e, e.name);
-
-                setTimeout(function(){
-                    $.hideLoading();
-                    $("#cropImg").cropper('destroy');
-                    _this.jc = null;
-                    $("#cropImg").remove();
-                }, 300)
-                /*var url = canvas.toBlob(function(e){
-                    //console.log(e);  //生成Blob的图片格式
+                var url = canvas.toBlob(function(e){
+                    //生成Blob的图片格式
                     if(e != null){
                         var timestamp = Date.parse(new Date());
                         e.name=timestamp+".png";
                         url = URL.createObjectURL(e);
                         _this.picList[id].url = url;
                         _this.picList[id].preview = url;
-                        // _this.picList[id].fileData = _this.dataURLtoFile(e, e.name);
+                        _this.picList[id].fileData = _this.dataURLtoFile(e, e.name);
 
                         setTimeout(function(){
                             $.hideLoading();
                             $("#cropImg").cropper('destroy');
                             _this.jc = null;
                             $("#cropImg").remove();
-                        }, 300)
+                        }, 500)
+                    }else{
+                        $.hideLoading();
+                        $.showLoading('图片处理失败请刷新重试');
+                        setTimeout(function(){
+                            $("#cropImg").cropper('destroy');
+                            _this.jc = null;
+                            $("#cropImg").remove();
+                        }, 1000);
                     }
 
-                },"image/jpeg");*/
+                },"image/jpeg");
 
             }
         },
@@ -719,6 +696,7 @@ var app = new Vue({
                                     id: id,
                                     url: base64,
                                     preview: base64,
+                                    old_url: base64,
                                     blobUrl: blobUrl,
                                     name: file.name,
                                     file_size: file.size,