diff --git a/uni_modules/uni-id-pages/changelog.md b/uni_modules/uni-id-pages/changelog.md index d8697ff1d0ed96532bf660a7ab0842ac78469934..effc153a03c0ed4f7166fb090cba8349246075fe 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 5f0cc6644eec4458a3a485683a1f52541100724f..1cb3d4ef6d22e5d1f3ee5165778524f0c1710f04 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 } } }