欢迎来到258分享网,纯净的网络源码分享基地!

258资源分享网

全部作品
全部作品
网站源码
微信源码
素材特效
源码插件
视频教程
建站学院
热门搜索: 织梦  农业种植  农业  安全设置  官方
258资源分享 > 建站学院 > 微信开发 > 微信心邮小程序开发实战(二)-信箱功能(BMOB后端)

推荐下载

HTML5响应式自适应网咯设计

2020-05-12   浏览:791

HTML5自适应律师工作室类网

2020-04-04   浏览:655

高端HTML5响应式企业通用网

2020-05-06   浏览:560

html5响应式外贸网站英文版

2020-05-08   浏览:548

HTML5影视传媒文化公司类网

2020-05-12   浏览:545

微信心邮小程序开发实战(二)-信箱功能(BMOB后端)

发布时间:2021-01-06   241

微信心邮小程序开发实战(二)-信箱功能(BMOB后端)

信箱功能

第一步:在微信小程序开发工具Pages建立信箱文件 mail/ ├── mail.js ├── mail.json ├── mail.wxml └── mail.wxss 1. mail.js

页面显示时查询数据

把查询的数据setData到模版页面

//index.js //获取应用实例 var common = require('../template/getCode.js') var Bmob = require("../../utils/bmob.js"); var that; var molist; var app = getApp() Page({ data: { moodList: [], limit: 6, loading: false, windowHeight1: 0, windowWidth1: 0, scrollTop: { scroll_top1: 0, goTop_show: false } }, onLoad: function (e) { that = this; that.setData({ loading: false }) }, //页面显示时执行 onShow: function () { molist = new Array(); var myInterval = setInterval(getReturn, 500);//半秒定时查询 //获取服务端数据 function getReturn() { wx.getStorage({ key: 'user_id', success: function (ress) {//根据User_id查询 if (ress.data) { clearInterval(myInterval)//清楚定时查询 var Diary = Bmob.Object.extend("Diary"); var query = new Bmob.Query(Diary); query.equalTo("is_hide", "1"); query.descending("createdAt"); query.include("publisher"); // 查询所有数据 query.find({ success: function (results) {//数据查询成功 that.setData({ loading: true }); //数据重新初始化 for (var i = 0; i < results.length; i++) { var publisherId = results[i].get("publisher").id; var title = results[i].get("title"); var content = results[i].get("content"); var id = results[i].id; var createdAt = results[i].createdAt; var _url; var likeNum = results[i].get("likeNum"); var commentNum = results[i].get("commentNum"); var pic = results[i].get("pic"); if (pic) { _url = results[i].get("pic")._url; } else { _url = null; } var name = results[i].get("publisher").get("nickname"); var userPic = results[i].get("publisher").get("userPic"); var liker = results[i].get("liker"); var isLike = 0; for (var j = 0; j < liker.length; j++) { if (liker[j] == ress.data) { isLike = 1; break; } } var jsonA; if (pic) { jsonA = '{"title":"' + title + '","content":"' + content + '","id":"' + id + '","avatar":"' + userPic + '","created_at":"' + createdAt + '","attachment":"' + _url + '","likes":"' + likeNum + '","comments":"' + commentNum + '","is_liked":"' + isLike + '","username":"' + name + '"}' } else { jsonA = '{"title":"' + title + '","content":"' + content + '","id":"' + id + '","avatar":"' + userPic + '","created_at":"' + createdAt + '","likes":"' + likeNum + '","comments":"' + commentNum + '","is_liked":"' + isLike + '","username":"' + name + '"}'; } var jsonB = JSON.parse(jsonA); //每条数据重新写入到数组 molist.push(jsonB) that.setData({ moodList: molist, loading: true }) } }, error: function (error) { common.dataLoading(error, "loading"); that.setData({ loading: true }) console.log(error) } }); } }, fail: function (error) { console.log("失败") } }) } }, //分享页面 onShareAppMessage: function () { return { title: '心邮', desc: '倾诉烦恼,邮寄心情,分享快乐', path: '/pages/index/index' } }, onPullDownRefresh: function () { wx.stopPullDownRefresh() }, scrollTopFun: function (e) { if (e.detail.scrollTop > 300) { this.setData({ 'scrollTop.goTop_show': true }); } else { this.setData({ 'scrollTop.goTop_show': false }); } }, goTopFun: function (e) { var _top = this.data.scrollTop.scroll_top1;//发现设置scroll-top值不能和上一次的值一样,否则无效,所以这里加了个判断 if (_top == 1) { _top = 0; } else { _top = 1; } this.setData({ 'scrollTop.scroll_top1': _top }); this.onShow(); } }) 2. mail.wxml写入