From e80a2ad1269122fa2d1dbeb2e2e4130644ecbf55 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 13 Jul 2020 12:47:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9IE=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E4=B8=8D=E6=94=AF=E6=8C=81toBlob=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E6=88=96=E6=96=B9=E6=B3=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/system/user/profile/avatar.html | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/ruoyi-admin/src/main/resources/templates/system/user/profile/avatar.html b/ruoyi-admin/src/main/resources/templates/system/user/profile/avatar.html index 06388c3e..4034ba49 100644 --- a/ruoyi-admin/src/main/resources/templates/system/user/profile/avatar.html +++ b/ruoyi-admin/src/main/resources/templates/system/user/profile/avatar.html @@ -214,29 +214,48 @@ $(window).load(function() { }); function submitHandler() { - if(!croppable){ - $.modal.alertWarning("裁剪框加载中,请稍后..."); - return - } - cropper.getCroppedCanvas().toBlob(function(img){ - var formdata = new FormData(); - formdata.append("avatarfile", img); - $.ajax({ - url: ctx + "system/user/profile/updateAvatar", - data: formdata, - type: "post", - processData: false, - contentType: false, - success: function(result) { - $.operate.saveSuccess(result); - } - }) - }); + if (!croppable) { + $.modal.alertWarning("裁剪框加载中,请稍后..."); + return + } + cropper.getCroppedCanvas().toBlob(function(img) { + var formdata = new FormData(); + formdata.append("avatarfile", img); + $.ajax({ + url: ctx + "system/user/profile/updateAvatar", + data: formdata, + type: "post", + processData: false, + contentType: false, + success: function(result) { + $.operate.saveSuccess(result); + } + }) + }); } -$(window).resize(function(){ - $('.imageBox').height($(window).height()-80); +$(window).resize(function() { + $('.imageBox').height($(window).height() - 80); }).resize(); + +if (!HTMLCanvasElement.prototype.toBlob) { + Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', { + value: function(callback, type, quality) { + var canvas = this; + setTimeout(function() { + var binStr = atob(canvas.toDataURL(type, quality).split(',')[1]); + var len = binStr.length; + var arr = new Uint8Array(len); + for (var i = 0; i < len; i++) { + arr[i] = binStr.charCodeAt(i); + } + callback(new Blob([arr], { + type: type || 'image/png' + })); + }); + } + }); +}