wesmiler 6 лет назад
Родитель
Сommit
ae30da0fb8
1 измененных файлов с 14 добавлено и 1 удалено
  1. 14 1
      public/static/weixin/js/photo.js

+ 14 - 1
public/static/weixin/js/photo.js

@@ -435,6 +435,15 @@ var app = new Vue({
         dataBlobtoFile: function (dataurl, filename) {//将base64转换为文件
             return new File([dataurl], filename, {type: 'image/jpeg'});
         },
+        //
+        dataURLtoBlob: function(dataurl) {
+            var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
+                bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
+            while (n--) {
+                u8arr[n] = bstr.charCodeAt(n);
+            }
+            return new Blob([u8arr], {type: mime});
+        },
         // 删除图片
         picDel: function (id) {
             var fileId = $("#pic_" + id).attr('data-id');
@@ -662,19 +671,23 @@ var app = new Vue({
                 var url = canvas.toDataURL('image/jepg');
                 var timestamp = Date.parse(new Date());
                 var name = timestamp + ".jpg";
-                alert(33)
+                alert(url)
                 if(_this.cropParams.type>0 && id>=0){
                     alert(34)
                     _this.picList[id] = _this.cropParams;
                     _this.picList[id].url = url;
                     _this.picList[id].preview = url;
 
+                    var blob = _this.dataURLtoBlob(url);
+                    _this.picList[id].fileData = _this.dataBlobtoFile(blob, name);
                     // _this.picList[id].fileData = _this.dataURLtoFile(url, name);
                 }else{
                     alert(341)
                     var data = _this.cropParams;
                     data.url = url;
                     data.preview = url;
+                    var blob = _this.dataURLtoBlob(url);
+                    _this.picList[id].fileData = _this.dataBlobtoFile(blob, name);
                     // data.fileData = _this.dataURLtoFile(url, name);
                     _this.picList.push(data);
                 }