效果圖數(shù)據(jù):依賴接口wx.upload、chooseImage與preview 數(shù)據(jù)請求通過LeanCloud完成 圖片選擇:https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-picture.html#wxchooseimageobject 前端處理:1.保存images數(shù)組為已選擇圖片 2.選擇了更多圖片后concat數(shù)組 3.預(yù)覽圖集 4.leancloud上傳多圖,目測順序一致 js代碼
const AV = require('../../../utils/av-weapp.js')
var that;
Page({
data: {
images: [],
uploadedImages: [],
imageWidth: getApp().screenWidth / 4 - 10
},
onLoad: function (options) {
that = this;
var objectId = options.objectId;
console.log(objectId);
},
chooseImage: function () {
// 選擇圖片
wx.chooseImage({
sizeType: ['compressed'],
sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機(jī),默認(rèn)二者都有
success: function (res) {
// 返回選定照片的本地文件路徑列表,tempFilePath可以作為img標(biāo)簽的src屬性顯示圖片
var tempFilePaths = res.tempFilePaths;
console.log(tempFilePaths);
that.setData({
images: that.data.images.concat(tempFilePaths)
});
}
})
},
previewImage: function () {
// 預(yù)覽圖集
wx.previewImage({
urls: that.data.images
});
},
submit: function () {
// 提交圖片,事先遍歷圖集數(shù)組
that.data.images.forEach(function (tempFilePath) {
new AV.File('file-name', {
blob: {
uri: tempFilePath,
},
}).save().then(
// file => console.log(file.url())
|