143 lines
3.1 KiB
JavaScript
143 lines
3.1 KiB
JavaScript
// pages/home/home.js
|
||
let newsType = 'neidi-news'
|
||
Page({
|
||
data: {
|
||
navState: 0,//导航状态
|
||
//存放轮播图数据的列表
|
||
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()
|
||
},
|
||
navSwitch(e) {
|
||
let index = e.currentTarget.dataset.index
|
||
this.setData({
|
||
navState: index,
|
||
})
|
||
if (index == 0) {
|
||
wx.navigateTo({
|
||
url: '/pages/home/home',
|
||
})
|
||
}else if (index == 1) {
|
||
wx.navigateTo({
|
||
url: '/pages/xg/xg',
|
||
})
|
||
}else if (index == 2) {
|
||
wx.navigateTo({
|
||
url: '/pages/tw/tw',
|
||
})
|
||
}else if (index == 3) {
|
||
wx.navigateTo({
|
||
url: '/pages/gj/gj',
|
||
})
|
||
}else if (index == 4) {
|
||
wx.navigateTo({
|
||
url: '/pages/junshi/junshi',
|
||
})
|
||
}
|
||
},
|
||
// 获取新闻列表数据
|
||
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)
|
||
})
|
||
},
|
||
// 点击事件-去往详情页
|
||
gotoDetail(event) {
|
||
// console.log('用户点击的新闻id:', event.currentTarget.dataset.id)
|
||
wx.navigateTo({
|
||
url: '/pages/news-detail/news-detail?id=' + event.currentTarget.dataset.id + '&newsType=' + newsType,
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom: function () {
|
||
this.getList()
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage: function () {
|
||
|
||
}
|
||
}) |