wesmiler %!s(int64=6) %!d(string=hai) anos
pai
achega
a3f1e18d5d
Modificáronse 2 ficheiros con 29 adicións e 19 borrados
  1. 3 3
      data/config/weixin.php
  2. 26 16
      public/static/weixin/js/photo.js

+ 3 - 3
data/config/weixin.php

@@ -3,11 +3,11 @@
  * 微信配置
  */
 return [
-    'debug'=> false, // 是否测试模式
+    'debug'=> true, // 是否测试模式
     'payDebug'=> false, // 微信支付测试,开启后支付金额为0.01元
     'payResult'=> false, // 是否记录支付结果
-    'openid'=> '', // 测试模式测试用户OPENID
-//    'openid'=> 'ovq0y1RsHuL3gHgxdZCTJ81E2ryk', // 测试模式测试用户OPENID
+//    'openid'=> '', // 测试模式测试用户OPENID
+    'openid'=> 'ovq0y1RsHuL3gHgxdZCTJ81E2ryk', // 测试模式测试用户OPENID
     'update_expire'=> 3*3600, // 没三个小时更新一次微信信息
     'appid'=> 'wx8c48b975e9b56508', // APPID
     'appsecret'=> 'd318b4ca843f052ad6e0b263efa2609b', // AppSecret

+ 26 - 16
public/static/weixin/js/photo.js

@@ -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) {