// miniprogram/pages/home/index.js Page({ /** * 页面的初始数据 */ data: { newList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: async function (options) { const db = wx.cloud.database(); const _ = db.command; let list = await db.collection('data_news').where({ hot: 1, type: 1 }).get(); for (let i = 0; i < list.data.length; i++) { const v = list.data[i]; v.creat_time = this.format(v.creat_time || 0) } this.setData({ newList: list.data || [] }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, format: function (res) { if (!res) return "" let T = new Date(res || 0); let year = T.getFullYear(); let month = T.getMonth() + 1; let day = T.getDate(); let hour = T.getHours(); let min = T.getMinutes() + 1; let sec = T.getSeconds(); return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec); }, toDetail: function (e) { let title = e.currentTarget.dataset.title, id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/detail/detail?title=' + title + "&id=" + id, }) }, toRuins: function (e) { wx.navigateTo({ url: '/pages/ruins/index', }) }, toMarvellous: function (e) { wx.navigateTo({ url: '/pages/marvellous/index?title=' + e.currentTarget.dataset.title + "&type=" + e.currentTarget.dataset.type, }) } })