var FilePaths = []
let promiseArr = [];
for (let i = 0;i< this.data.imgList.length ; i++) {
let promise = new Promise((resolve, reject) => {
var randstring = Math.floor(Math.random() * 100).toString() + '.png'
randstring = randstring
wx.cloud.uploadFile({
cloudPath: 'newsImages/' + randstring,
filePath: this.data.imgList[i], // 文件路径
success: res => {
// get resource ID
console.log(res.fileID)
FilePaths[i] = res.fileID
resolve(res);
},
fail: err => {
reject(error);
}
})
})
promiseArr.push(promise)
}
this.setData({
imgList1: FilePaths
})
console.log(this.data.imgList1)
// Promise.all(promiseArr).then((result) => { // this.data.imgList1是云空间的文件路径吗?
// if (this.data.imgList1.length!= 0) {
// this.setData({
// imgList1: this.data.imgList1.concat(FilePaths)
// })
//} else {
// this.setData({
// imgList1: FilePaths
//})
// console.log(this.data.imgList1[0])
//}
// wx.hideLoading()
// })
/*云数据库记录*/
const db = wx.cloud.database({
env: 'env-1gz2buk367a05f5c'
})
//const diliId = db.collection('enginerInformation')
var util=require('../../utils/util.js')
var date=util.formatTime(new Date());
var data1={
pictureFileId1:FilePaths,
tuban:this.data.tuban,
beiZhu:e.detail.value.beiZhu,
date:date}
db.collection('enginerInformation').add({
data:data1,
success: function(res) {
// res 是一个对象,其中有 _id 字段标记刚创建的记录的 id
console.log(res)
}
}),