Page({ /** * 页面的初始数据 */ //分类1 data: { title: '', content: '', question_id:'', feed_source_img:'', feed_source_name:'', tempFilePaths: [], nowCount:0,//当前的图片上传个数 index:0, nickName:"", avatarUrl:"", feed:[], pinglun:[], comment_num:0, good_num:0 }, bindPickerChange:function(e){ console.log(e) this.setData({ index: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 { that.setData({ value1:'', value2:'', tempFilePaths:[], nowCount:0 }) wx.showToast({ title: '发布成功', }) }, }) },fail:function(e){ wx.hideLoading({ success: (res) => { wx.showToast({ title: '网络异常', }) that.setData({ value1:'', value2:'', tempFilePaths:[], nowCount:0 }) }, }) console.log(e); } })*/ let a=wx.getStorageSync ("nickName") let b=wx.getStorageSync ("avatarUrl") wx.cloud.database().collection('tiezi').add({ data: { title:title, content:content, openid:that.data.openid, url:url, createTime: wx.cloud.database().serverDate(), feed_source_img:b, feed_source_name:a, pinglun:pl, comment_num:0, good_num:0 } }) wx.hideLoading({ success: (res) => { that.setData({ value1:'', value2:'', tempFilePaths:[], nowCount:0 }) wx.showToast({ title: '发布成功', })}}) }else{ //将所有的内容上传到云端去 for(i=0;i { count++; url.push(res.fileID); console.log('上传图片'); console.log(i,url); if(count==that.data.nowCount){ console.log(url); /* wx.cloud.callFunction({ name:'love_upload', data:{ title:title, content:content, openid:that.data.openid, url:url, type:parseInt(that.data.index)+1 },success:function(e){ console.log(e); wx.hideLoading({ success: (res) => { that.setData({ value1:'', value2:'', tempFilePaths:[], nowCount:0 }) wx.showToast({ title: '发布成功', }) }, }) },fail:function(e){ wx.hideLoading({ success: (res) => { wx.showToast({ title: '网络异常', }) that.setData({ value1:'', value2:'', tempFilePaths:[], nowCount:0 }) }, }) console.log(e); } })*/ let a=wx.getStorageSync ("nickName") let b=wx.getStorageSync ("avatarUrl") let pl=[]; wx.cloud.database().collection('tiezi').add({ data: { title:title, content:content, openid:that.data.openid, url:url, createTime: wx.cloud.database().serverDate(), feed_source_img:b, feed_source_name:a, pinglun:pl, comment_num:0, good_num:0 } }) wx.hideLoading({ success: (res) => { that.setData({ value1:'', value2:'', tempFilePaths:[], nowCount:0 }) wx.showToast({ title: '发布成功', })}}) } },fail:res=>{ console.log(res); } }) } } wx.switchTab({ url: '../forum/forum', }) }, blur:function(e){ console.log(e); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let loveSort = wx.getStorageSync('loveSort') console.log(loveSort) this.setData({ loveSort:loveSort }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, onAdd_s: function () { wx.cloud.init({ env: 'cloud1-8g5wmepxce8a3b8a' }); const db = wx.cloud.database() db.collection('tiezi').add({ data: { title:title, content:content, openid:that.data.openid, url:[], }, success: res => { // 在返回结果中会包含新创建的记录的 _id this.setData({ counterId: res._id, count: 1 }) wx.showToast({ title: '成功扔进树洞~', }) console.log('[数据库] [留言] 成功,记录 _id: ', res._id) }, fail: err => { wx.showToast({ icon: 'none', title: '种种原因树洞拒绝了~' }) console.error('[数据库] [新增记录] 失败:', err) } }) } })