saveAndUpload function wxshowLoading title数据上传中 masktrue 保存邮件编号和图片到数据库 const mailNumber = thisdatamailNumber; const images = thisdataimages;
saveAndUpload: function() { wx.showLoading({ title:'数据上传中...', mask:true }) // 保存邮件编号和图片到数据库 const mailNumber = this.data.mailNumber; const images = this.data.images; const describe = this.data.describe; // Get the current date var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate();
// Array to store the uploaded file URLs
var uploadedFileURLs = [];
// 加载图片到云存储
for (var i = 0; i < images.length; i++) {
wx.cloud.uploadFile({
cloudPath: 'myImage/' + year + "-" + month + "-" + day + '/' + new Date().getTime() + "_" + Math.floor(Math.random() * 1000) + i + ".jpg",
filePath: images[i],
success: function(res) {
console.log('Upload successful: ', res.fileID);
uploadedFileURLs.push(res.fileID);
if (uploadedFileURLs.length === images.length) {
// 调用云函数上传数据
wx.cloud.callFunction({
name: 'addData',
data: {
mailNumber: mailNumber,
images: uploadedFileURLs,
describe: describe,
date: date
},
success: function(res) {
console.log('Data uploaded successfully: ', res);
wx.showToast({
title: '上传成功',
})
},
fail: function(err) {
console.error('Data upload failed: ', err);
wx.showToast({
title: '上传失败',
})
}
}).then(res=>{
console.log(res)
wx.hideLoading({
complete:(res)=>{},
})
});
}
},
fail: function(err) {
console.error('Upload failed: ', err);
}
});
}
原文地址: https://www.cveoy.top/t/topic/h0JA 著作权归作者所有。请勿转载和采集!