From 2f898ef12d149ac0b2a38fcb06171c9fb165edd7 Mon Sep 17 00:00:00 2001 From: wuxw <928255095@qq.com> Date: Tue, 24 Sep 2024 13:21:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vc-upload-async/vc-upload-async.vue | 62 +++++++++--------- conf/config.js | 8 +-- lib/java110/utils/translate-image.js | 64 ++++++++++++++++--- manifest.json | 4 +- 4 files changed, 91 insertions(+), 47 deletions(-) diff --git a/components/vc-upload-async/vc-upload-async.vue b/components/vc-upload-async/vc-upload-async.vue index 19a3149..c37e5ee 100644 --- a/components/vc-upload-async/vc-upload-async.vue +++ b/components/vc-upload-async/vc-upload-async.vue @@ -10,7 +10,7 @@ - + @@ -21,17 +21,22 @@ + + + + \ No newline at end of file diff --git a/conf/config.js b/conf/config.js index 46c3def..cdeae9f 100644 --- a/conf/config.js +++ b/conf/config.js @@ -15,16 +15,16 @@ const baseUrl = '/'; // #ifndef H5 //服务器域名 小程序 或者 app 时 后端地址 -const baseUrl = 'http://demo.homecommunity.cn/'; +const baseUrl = 'https://wuye.yunxiaowuye.com/'; // #endif -let commonBaseUrl = 'http://demo.homecommunity.cn/'; +let commonBaseUrl = 'https://wuye.yunxiaowuye.com/'; //商城的url -let mallUrl = 'https://mallapp.huilinwan.cn/'; +let mallUrl = 'https://mallapp.yunxiaowuye.com/'; //商城小程序ID -let mallMinAppId = "wx7a01aad34e06840f"; +let mallMinAppId = "wxa4211361ca1e1bfb"; //默认的小区ID和名称,用户还没有登录时显示的小区信息 diff --git a/lib/java110/utils/translate-image.js b/lib/java110/utils/translate-image.js index e0518cc..271af2d 100644 --- a/lib/java110/utils/translate-image.js +++ b/lib/java110/utils/translate-image.js @@ -1,3 +1,6 @@ + + + /** * 压缩 @@ -8,7 +11,17 @@ */ -export function translate(imgSrc, callback) { +export function translate(that, imgSrc, callback) { + // #ifndef H5 + imageToBease64(that, imgSrc, callback) + // #endif + + // #ifdef H5 + translateH5(imgSrc, callback) + // #endif +} + +export function translateH5(imgSrc, callback) { var img = new Image(); @@ -62,21 +75,52 @@ export function translate(imgSrc, callback) { canvas = null; - // var blob = base64ToBlob(base64); - - // console.log(333); - // console.log(base64) - - //Blob对象转blob地址 - - // var blobUrl = window.URL.createObjectURL(blob); - callback(base64); } } + +/** + * 图片转base64 + * + * @param imageUrl 图片地址 + * @param callback 回调 + */ +function imageToBease64(that, imageUrl, callback) { + wx.getImageInfo({ + src: imageUrl, + success(imgData) { + const query = that.createSelectorQuery(); + query.select('#materCanvas').fields({ + node: true, + size: true + }) + .exec(res => { + const canvas = res[0].node; + const ctx = canvas.getContext('2d'); + const image = canvas.createImage(); + canvas.width = imgData.width; + canvas.height = imgData.height; + + image.src = imgData.path; + image.onload = function() { + const canvasWidth = imgData.width; // 获取图片宽度 + const canvasHeight = imgData.height; // 获取图片高度 + ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight); // 绘制图片 + + //压缩比例 + let quality = 0.3; + let base64 = canvas.toDataURL('image/jpeg', quality); + callback(base64); + } + }); + } + }); + +} + /** * base转Blob对象 diff --git a/manifest.json b/manifest.json index 4e46be8..e5b78bb 100644 --- a/manifest.json +++ b/manifest.json @@ -59,12 +59,12 @@ "quickapp" : {}, "mp-weixin" : { "usingComponents" : true, - "appid" : "wxad57531dabaed887", + "appid" : "wx7e46e694ab977a6b", "setting" : { "urlCheck" : false, "es6" : false }, - "navigateToMiniProgramAppIDList" : [ "wx7a01aad34e06840f" ], //商城小程序AppId + "navigateToMiniProgramAppIDList" : [ "wxa4211361ca1e1bfb" ], //商城小程序AppId "permission" : { "scope.userLocation" : { "desc" : "你的位置信息将用于小程序位置接口的效果展示"