先传图片 再传文字,我这样写的,怎么不行呢?
uploadImages: function (e) {
var that = this;
return new Promise(function (resolve, reject) {
var cloudPathp = [];
imgeList.forEach((item, i) => {
cloudPathp.push(that.data.count + '_' + i + imgeList[i].match(/.[^.]+?$/)[0])
})
imgeList.forEach((item, i) => {
var cloudPath = cloudPathp[i];
var filePath = imgeList[i];
wx.cloud.uploadFile({
cloudPath,
filePath,
success: res => {
wx.showLoading(),
console.log('[上传文件] 成功:', cloudPath, res)
fileIDD.push(res.fileID)
fileList[i] = res.fileID;
app.globalData.cloudPath = cloudPath
app.globalData.imagePath = filePath
console.log('指定地点1:', fileIDD)
},
fail: e => {
console.error('[上传文件] 失败:', e)
wx.showToast({
icon: 'none',
title: '上传失败',
})
},
complete: () => {
wx.hideLoading()
}
})
})
});
},
publishTopic: function (e) {
var that = this;
return new Promise(function (resolve, reject) {
var data = {
image: fileList,
content: that.data.text,
xqmc: that.data.objectArray1[that.data.brandindex1].brand,
leix: that.data.objectArray[that.data.brandindex].brand,
phone: e.detail.value.phone,
comment: [],
userId: wx.getStorageSync('userId'),
username: wx.getStorageSync('username'),
avatar: wx.getStorageSync('avatar'),
id: Number(that.data.count) + 1,
shareNum: 0,
commentNum: 0,
validStatus: 0,
validTime: 0
}
console.log('dataimage:', data.image.length)
console.log('publishTopic:', resolve)
if (data.content) {
db.collection('funnys').add({
data: data,
success: res => {
wx.showToast({
title: '发布成功',
})
setTimeout(() => {
wx.switchTab({
url: '../index/index',
})
}, 1000)
},
fail: e => {
wx.showToast({
title: '发布错误',
})
console.log(e)
}
})
} else {
wx.showToast({
title: '请填写文字',
icon: 'none'
})
}
});
},
formSubmit: function (e) {
var that = this;
that.uploadImages().then(that.publishTopic(e));
},