提交 72e5912f 编写于 作者: DCloud_JSON's avatar DCloud_JSON

1.1.5 更新 微信小程序端 更新头像信息,如果是使用微信的头像则不再调用裁剪接口

上级 df2fb27c
## 1.1.5(2023-02-23)
- 更新 微信小程序端 更新头像信息,如果是使用微信的头像则不再调用裁剪接口
## 1.1.4(2023-02-21) ## 1.1.4(2023-02-21)
- 修复 部分情况下 `uniIdRedirectUrl` 参数无效的问题 - 修复 部分情况下 `uniIdRedirectUrl` 参数无效的问题
## 1.1.3(2023-02-20) ## 1.1.3(2023-02-20)
......
...@@ -71,31 +71,8 @@ ...@@ -71,31 +71,8 @@
let avatar_file = { let avatar_file = {
extname: avatarUrl.split('.')[avatarUrl.split('.').length - 1], extname: avatarUrl.split('.')[avatarUrl.split('.').length - 1],
name:'', 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() let cloudPath = this.userInfo._id + '' + Date.now()
avatar_file.name = cloudPath avatar_file.name = cloudPath
...@@ -107,7 +84,7 @@ ...@@ -107,7 +84,7 @@
let { let {
fileID fileID
} = await uniCloud.uploadFile({ } = await uniCloud.uploadFile({
filePath, filePath:avatarUrl,
cloudPath, cloudPath,
fileType: "image" fileType: "image"
}); });
...@@ -116,82 +93,83 @@ ...@@ -116,82 +93,83 @@
}catch(e){ }catch(e){
console.error(e); console.error(e);
} }
console.log('avatar_file',avatar_file);
this.setAvatarFile(avatar_file) this.setAvatarFile(avatar_file)
}, },
uploadAvatarImg(res) { uploadAvatarImg(res) {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
return false // 微信小程序走 bindchooseavatar方法 return false // 微信小程序走 bindchooseavatar方法
// #endif // #endif
if(!this.hasLogin){ // #ifndef MP-WEIXIN
return uni.navigateTo({ if(!this.hasLogin){
url:'/uni_modules/uni-id-pages/pages/login/login-withoutpwd' return uni.navigateTo({
}) url:'/uni_modules/uni-id-pages/pages/login/login-withoutpwd'
})
} }
const crop = {
const crop = { quality: 100,
quality: 100, width: 600,
width: 600, height: 600,
height: 600, resize: true
resize: true };
}; uni.chooseImage({
uni.chooseImage({ count: 1,
count: 1, crop,
crop, success: async (res) => {
success: async (res) => { let tempFile = res.tempFiles[0],
let tempFile = res.tempFiles[0], avatar_file = {
avatar_file = { // #ifdef H5
// #ifdef H5 extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1], // #endif
// #endif // #ifndef H5
// #ifndef H5 extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1] // #endif
// #endif },
}, filePath = res.tempFilePaths[0]
filePath = res.tempFilePaths[0]
//非app端剪裁头像,app端用内置的原生裁剪
//非app端剪裁头像,app端用内置的原生裁剪 // #ifndef APP-PLUS
// #ifndef APP-PLUS filePath = await new Promise((callback) => {
filePath = await new Promise((callback) => { // #ifdef H5
// #ifdef H5 if (!this.isPC) {
if (!this.isPC) { uni.navigateTo({
uni.navigateTo({ url: '/uni_modules/uni-id-pages/pages/userinfo/cropImage/cropImage?path=' +
url: '/uni_modules/uni-id-pages/pages/userinfo/cropImage/cropImage?path=' + filePath + `&options=${JSON.stringify(crop)}`,
filePath + `&options=${JSON.stringify(crop)}`, animationType: "fade-in",
animationType: "fade-in", events: {
events: { success: url => {
success: url => { callback(url)
callback(url) }
} },
}, complete(e) {
complete(e) { // console.log(e);
// console.log(e); }
} });
}); }
} // #endif
// #endif })
}) // #endif
// #endif
let cloudPath = this.userInfo._id + '' + Date.now()
let cloudPath = this.userInfo._id + '' + Date.now() avatar_file.name = cloudPath
avatar_file.name = cloudPath uni.showLoading({
uni.showLoading({ title: "更新中",
title: "更新中", mask: true
mask: true });
}); let {
let { fileID
fileID } = await uniCloud.uploadFile({
} = await uniCloud.uploadFile({ filePath,
filePath, cloudPath,
cloudPath, fileType: "image"
fileType: "image" });
}); avatar_file.url = fileID
avatar_file.url = fileID uni.hideLoading()
uni.hideLoading() this.setAvatarFile(avatar_file)
this.setAvatarFile(avatar_file) }
} })
}) // #endif
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册