DAMIEDEISU 2022-03-05 10:33 采纳率: 0%
浏览 42

为什么我的小程序里的async没有实现呢

大概就是 先把图片上传到云数据库 然后返回地址 在提交事件里面将返回的地址与表单一同提交

info_submit:function(e){
console.log("提交表单:",e.detail.value)
if (e.detail.value.title.length == 0) {
wx.showToast({
title: '标题不能为空噢~',
icon: 'none',
duration: 1500
})
setTimeout(function () {
wx.hideToast()
}, 2000)
}else if (e.detail.value.type.length == 0) {
wx.showToast({
title: '请选择一个物品种类噢',
icon: 'none',
duration: 1500
})
setTimeout(function () {
wx.hideToast()
}, 2000)
}else if (e.detail.value.location.length == 0) {
wx.showToast({
title: '请选择一个区域噢',
icon: 'none',
duration: 1500
})
setTimeout(function () {
wx.hideToast()
}, 2000)
}else if (e.detail.value.contact.length == 0) {
wx.showToast({
title: '请至少留下一个联系方式噢',
icon: 'none',
duration: 1500
})
setTimeout(function () {
wx.hideToast()
}, 2000)
}else if (this.data.imageList == 0) {
wx.showToast({
title: '请至少添加一张图片噢',
icon: 'none',
duration: 1500,
})
setTimeout(function () {
wx.hideToast()
}, 2000)
}else{
this.setData({
title:e.detail.value.title,
type:e.detail.value.type,
location:e.detail.value.location,
contact:e.detail.value.contact,
})
this.issueNotice();}
},
uploadimages(){
return new Promise((resolve,reject)=>{
var that = this;
let openid = app.globalData.openid || wx.getStorageSync('openid');
for (let i = 0; i < this.data.imageList.length; i++) {
let imgeList=this.data.imageList[i];
let suffix = /.\w+$/.exec(imgeList)[0];
wx.cloud.uploadFile({
cloudPath:new Date().getTime() + suffix,//云存储图片名字
filePath:imgeList,//临时路径
success: res => {
console.log('上传图片成功:', res)
that.setData({
cloud_imageList: this.data.cloud_imageList.concat(res.fileID),//云存储图片路径,可以把这个路径存到集合,要用的时候再取出来
});
console.log("文件地址",that.data.cloud_imageList)}
})
}resolve()
})
},
uploadAll(){
return new Promise((resolve,reject)=>{
let that=this;
let fileID = that.data.cloud_imageList;
db.collection("carts").add({
data: {
"title": this.data.title,
"type":this.data.type,
"location": this.data.location,
"contact":this.data.contact,
"imageList": fileID
},
success: function (res) {
console.log(res)
this.setData({
title:"",
type:"",
location:"",
contact:"",
})
wx.showToast({
title: '提交成功',
icon: 'none',
duration: 1500
})
},
fail: function () {
wx.showToast({
title: '提交失败.请重新尝试',
icon: 'none',
duration: 1500
})
}
})
resolve();
})
},
async issueNotice() {
await this.uploadimages();
await this.uploadAll();
},
})

  • 写回答

2条回答 默认 最新

  • 在下月亮有何贵干 优质创作者: 前端开发技术领域 2022-03-05 21:19
    关注

    我没记错的话,小程序不支持

    评论 编辑记录

报告相同问题?

问题事件

  • 修改了问题 3月5日
  • 创建了问题 3月5日