// pages/change/change.js var app = getApp() Page({ data: { feed: [], change1: '', change2: '', tempFilePaths: [], t:'', c:'', nowCount:0,//当前的图片上传个数 index:0, url:[] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this var aid=options.aid console.log(options); console.log(options.aid); wx.cloud.database().collection('tiezi') .doc(aid) .get({ success(res) { console.log("请求成功", res.data) console.log("请求成功", res.data.url.length) // 将查询返回的结果赋值给本地数组 that.setData({ feed: res.data, nowCount:res.data.url.length, tempFilePaths: res.data.url, url:res.data.url, t:res.data.title, c:res.data.content }) }, fail(res) { console.log("请求失败", res) } }) }, // 获取修改后的内容 change1: function(e) { this.setData({ change1: e.detail.value }) }, change: function(e) { this.setData({ change2: e.detail.value }) }, //图片的上传 chooseImage:function(e){ let that = this; wx.chooseImage({ count: 3, // 默认最多3张图片,可自行更改 sizeType: ['original', 'compressed'],// 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: res => { wx.showToast({ title: '正在上传...', icon: 'loading', mask: true, duration: 1000 }) // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 let tempFilePath = res.tempFilePaths; console.log(tempFilePath); let nowCount = that.data.nowCount; let tempFilePaths = that.data.tempFilePaths; if(that.data.nowCount + tempFilePath.length >=3){ let i = 0; while(nowCount<3){//还可以继续上传图片 tempFilePaths.push(tempFilePath[i]); i++; nowCount++; } that.setData({ nowCount:3, tempFilePaths:tempFilePaths }) }else{ let i = 0; while(i{ console.log(res); wx.showLoading({ title: '修改成功...', }) wx.redirectTo({ url: '../answer/answer?aid='+aid, }) wx.hideLoading() }).catch(res=>{ console.log(res); }) }else{ //将所有的内容上传到云端去 for(i=l;i { count++; url.push(res.fileID); console.log('上传图片'); console.log(i,url); if(count==that.data.nowCount){ console.log(url); } },fail:res=>{ console.log(res); } }) } wx.cloud.init({ env:"cloud1-8g5wmepxce8a3b8a", }) let aid=wx.getStorageSync ("aid") console.log(aid); wx.cloud.database().collection('tiezi') .doc(aid) .update({ data:{ title:content1, content: content, url:url } }).then(res=>{ console.log(res); wx.showLoading({ title: '修改成功...', }) wx.redirectTo({ url: '../answer/answer?aid='+aid, }) wx.hideLoading() }).catch(res=>{ console.log(res); }) } }, })