// pages/home/home.js Page({ data: { //存放轮播图数据的列表 lunboList: [], msgList: [ { title: "上海今日全市进行抗原检测 明日全市进行核酸检测" }, { title: "苏州发现奥密克戎新变异株 与全球已知毒株均不同源" }, { title: "美工作组抵华 参与东航事故调查" }, { title: "上海昨日新增本土确诊425例、无症状8581例" }, ], news_list: [], }, onLoad: function (options) { // 获取轮播图数据 wx.cloud.database().collection('homepage').get() .then(res => { // console.log('轮播图数据:', res) this.setData({ lunboList: res.data }) }) .catch(res => { console.log('获取失败', res) }) // 获取新闻列表数据 this.getList() }, // 点击事件-去往详情页 gotoDetail(event) { // console.log('用户点击的新闻id:', event.currentTarget.dataset.id) wx.navigateTo({ url: '/pages/news-detail/news-detail?id=' + event.currentTarget.dataset.id, }) }, // 获取新闻列表数据 getList(page) { wx.showLoading({ title: '加载中...', }) let len = this.data.news_list.length console.log('当前list长度', len) wx.cloud.database().collection('neidi-news') .skip(len) .get() .then(res => { wx.hideLoading() console.log('新闻列表请求成功:', res) let datalist = res.data if (datalist.length <= 0) { wx.showToast({ title: '数据全部加载完毕', icon: 'none' }) } this.setData({ news_list: this.data.news_list.concat(res.data), news_image: res.data.news_img, }) }) .catch(res => { console.log('新闻列表请求失败', res) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getList() }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })