无法使用云存储下载或者预览功能,引入的uni-id-pages组件,里面的个人中心页面,头像可以进行上传,裁切,但是裁切点击确定后,页面不显示头像,提示更新成功。
uploadAvatarImg(res) {
// #ifdef MP-WEIXIN
return false // 微信小程序走 bindchooseavatar方法
// #endif
// #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) => {
console.log('img',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]
console.log('file',filePath);
//非app端剪裁头像,app端用内置的原生裁剪
// #ifdef H5
if (!this.isPC) {
filePath = await new Promise((callback) => {
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
let cloudPath = this.userInfo._id + '/' + Date.now()+ '.' + avatar_file.extname
avatar_file.name = cloudPath
uni.showLoading({
title: "更新中",
mask: true
});
console.log('filepath',filePath);
console.log('cloudpaht',cloudPath);
let {
fileID
} = await uniCloud.uploadFile({
filePath,
cloudPath,
cloudPathAsRealPath: true, // 阿里云支持云端文件夹路径时,需要写这个属性
onUploadProgress: (progressEvent) => {
console.log(progressEvent);
}
});
console.log('fileId',fileID);
avatar_file.url = fileID
uni.hideLoading()
this.setAvatarFile(avatar_file)
}
})
// #endif