changeBanner() {
uni.chooseImage({
count: "1",
success: (res) => {
console.log('res', res);
this.file = res.tempFiles[0]
this.uploadImage()
},
fail: (err) => {
console.log("err: ", JSON.stringify(err));
uni.showToast({
title: "选择图片失败",
icon: "none",
});
}
})
},
uploadImage() {
if (!this.file.length === 0) {
uni.showToast({
title: '请选择一个图片',
icon: 'none',
});
return;
}
let maxSize = 10
console.log(this.file.size / 1024 / 1024, 'this.file.size / 1024 / 1024');
if (!this.file.size / 1024 / 1024 >= maxSize) {
uni.showToast({
title: '图片不能超过10MB',
icon: 'none',
});
return;
}
uni.showLoading()
let token = uni.getStorageSync('token')
console.log(this.file.path, ' this.file.path');
uni.uploadFile({
url: 'XXXX',
filePath: this.file.path,
name: 'uploadFile',
header: {
"Authorization": ` ${token}`,
"Content-Type": "multipart/form-data"
},
formData: {
"dfsCode": "MinIO",
},
success: (res) => {
console.log(res.data);
let resObj = JSON.parse(res.data)
console.log(resObj, 'res123123', resObj.data);
let params = {
banner: JSON.stringify(resObj.data),
id: xxxx,
storeId: xxxx
}
console.log(params, 'params');
updateRoomMessage(params).then(res => {
uni.showToast({
title: '上传成功',
icon: 'success',
});
})
},
fail: (err) => {
console.error(err);
uni.showToast({
title: '上传失败',
icon: 'none',
});
},
});
},