// pages/record/upImg/upImg.js
var detailPics = [];
Page({
data: {
detailPics: [], //多张图片临时路径
count:9, //最多选择图片的张数,默认9张
},
onLoad: function (options) {
},
/**
* 上传详细图片
*/
uploadDetailImage: function() { //这里是选取图片的方法
var that = this;
if (detailPics.length >= that.data.count) {
wx.showToast({
title: '最多选择' + that.data.count + '张!',
})
return;
}
wx.chooseImage({
count: that.data.count - detailPics.length, // 最多可以选择的图片张数,默认9
sizeType:'compressed', // original 原图,compressed 压缩图,默认二者都有
success: function(res) {
var imgs = res.tempFilePaths;
for (var i = 0; i < imgs.length; i++) {
detailPics.push(imgs[i])
}
that.setData({
detailPics:detailPics
})
},
})
},
/**长按删除 */
bindlongpressimg(e){
let that = this
var deleID = e.currentTarget.dataset.id //获取点击项目的内容
console.log(deleID)
detailPics.splice(deleID,1)
that.setData({
detailPics:detailPics
})
},
/**上传 */
//多张图片上传
upLode: function() {
wx.showLoading({
title: '上传中...',
mask: true,
})
for(let i=0; i<detailPics.length; i++){
wx.cloud.uploadFile({
cloudPath: 'manage/record/' + i + '.png', // 上传至云端的路径
filePath: detailPics[i], // 小程序临时文件路径
success: res => {
// 返回文件 ID
console.log("上传成功" + res.fileID)
},
fail: console.error
})
}
wx.hideLoading()
},
})