From 72e5912f420d751b7c4b73b0236c1cfb4d1eac17 Mon Sep 17 00:00:00 2001 From: linju Date: Thu, 23 Feb 2023 15:21:17 +0800 Subject: [PATCH] =?UTF-8?q?1.1.5=20=E6=9B=B4=E6=96=B0=20=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=AB=AF=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=98=AF=E4=BD=BF=E7=94=A8=E5=BE=AE=E4=BF=A1=E7=9A=84=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E5=88=99=E4=B8=8D=E5=86=8D=E8=B0=83=E7=94=A8=E8=A3=81?= =?UTF-8?q?=E5=89=AA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-id-pages/changelog.md | 2 + .../uni-id-pages-avatar.vue | 164 ++++++++---------- 2 files changed, 73 insertions(+), 93 deletions(-) diff --git a/uni_modules/uni-id-pages/changelog.md b/uni_modules/uni-id-pages/changelog.md index d8697ff..effc153 100644 --- a/uni_modules/uni-id-pages/changelog.md +++ b/uni_modules/uni-id-pages/changelog.md @@ -1,3 +1,5 @@ +## 1.1.5(2023-02-23) +- 更新 微信小程序端 更新头像信息,如果是使用微信的头像则不再调用裁剪接口 ## 1.1.4(2023-02-21) - 修复 部分情况下 `uniIdRedirectUrl` 参数无效的问题 ## 1.1.3(2023-02-20) diff --git a/uni_modules/uni-id-pages/components/uni-id-pages-avatar/uni-id-pages-avatar.vue b/uni_modules/uni-id-pages/components/uni-id-pages-avatar/uni-id-pages-avatar.vue index 5f0cc66..1cb3d4e 100644 --- a/uni_modules/uni-id-pages/components/uni-id-pages-avatar/uni-id-pages-avatar.vue +++ b/uni_modules/uni-id-pages/components/uni-id-pages-avatar/uni-id-pages-avatar.vue @@ -71,31 +71,8 @@ let avatar_file = { extname: avatarUrl.split('.')[avatarUrl.split('.').length - 1], name:'', - url:avatarUrl + url:'' } - - // 裁剪 - let filePath = await new Promise((callback) => { - wx.cropImage({ - src:avatarUrl, - cropScale:"1:1", - success: res => { - callback(res.tempFilePath) - }, - fail(e){ - console.error(e) - uni.showModal({ - content: 'wx.cropImage ' + e.errMsg, - showCancel: false, - confirmText:"跳过裁剪", - complete() { - callback(avatarUrl) - } - }); - } - }) - }) - //上传到服务器 let cloudPath = this.userInfo._id + '' + Date.now() avatar_file.name = cloudPath @@ -107,7 +84,7 @@ let { fileID } = await uniCloud.uploadFile({ - filePath, + filePath:avatarUrl, cloudPath, fileType: "image" }); @@ -116,82 +93,83 @@ }catch(e){ console.error(e); } + console.log('avatar_file',avatar_file); this.setAvatarFile(avatar_file) }, uploadAvatarImg(res) { - // #ifdef MP-WEIXIN return false // 微信小程序走 bindchooseavatar方法 // #endif - if(!this.hasLogin){ - return uni.navigateTo({ - url:'/uni_modules/uni-id-pages/pages/login/login-withoutpwd' - }) + // #ifndef MP-WEIXIN + if(!this.hasLogin){ + return uni.navigateTo({ + url:'/uni_modules/uni-id-pages/pages/login/login-withoutpwd' + }) } - - const crop = { - quality: 100, - width: 600, - height: 600, - resize: true - }; - uni.chooseImage({ - count: 1, - crop, - success: async (res) => { - let tempFile = res.tempFiles[0], - avatar_file = { - // #ifdef H5 - extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1], - // #endif - // #ifndef H5 - extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1] - // #endif - }, - filePath = res.tempFilePaths[0] - - //非app端剪裁头像,app端用内置的原生裁剪 - // #ifndef APP-PLUS - filePath = await new Promise((callback) => { - // #ifdef H5 - if (!this.isPC) { - uni.navigateTo({ - url: '/uni_modules/uni-id-pages/pages/userinfo/cropImage/cropImage?path=' + - filePath + `&options=${JSON.stringify(crop)}`, - animationType: "fade-in", - events: { - success: url => { - callback(url) - } - }, - complete(e) { - // console.log(e); - } - }); - } - // #endif - }) - // #endif - - let cloudPath = this.userInfo._id + '' + Date.now() - avatar_file.name = cloudPath - uni.showLoading({ - title: "更新中", - mask: true - }); - let { - fileID - } = await uniCloud.uploadFile({ - filePath, - cloudPath, - fileType: "image" - }); - avatar_file.url = fileID - uni.hideLoading() - this.setAvatarFile(avatar_file) - } - }) + const crop = { + quality: 100, + width: 600, + height: 600, + resize: true + }; + uni.chooseImage({ + count: 1, + crop, + success: async (res) => { + let tempFile = res.tempFiles[0], + avatar_file = { + // #ifdef H5 + extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1], + // #endif + // #ifndef H5 + extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1] + // #endif + }, + filePath = res.tempFilePaths[0] + + //非app端剪裁头像,app端用内置的原生裁剪 + // #ifndef APP-PLUS + filePath = await new Promise((callback) => { + // #ifdef H5 + if (!this.isPC) { + uni.navigateTo({ + url: '/uni_modules/uni-id-pages/pages/userinfo/cropImage/cropImage?path=' + + filePath + `&options=${JSON.stringify(crop)}`, + animationType: "fade-in", + events: { + success: url => { + callback(url) + } + }, + complete(e) { + // console.log(e); + } + }); + } + // #endif + }) + // #endif + + let cloudPath = this.userInfo._id + '' + Date.now() + avatar_file.name = cloudPath + uni.showLoading({ + title: "更新中", + mask: true + }); + let { + fileID + } = await uniCloud.uploadFile({ + filePath, + cloudPath, + fileType: "image" + }); + avatar_file.url = fileID + uni.hideLoading() + this.setAvatarFile(avatar_file) + } + }) + // #endif } } } -- GitLab