Files
szjs/pages/home/home.js

217 lines
3.9 KiB
JavaScript
Raw Normal View History

2025-03-09 23:28:40 +08:00
const app = getApp()
2025-03-07 22:27:18 +08:00
Page({
/**
* 页面的初始数据00
*/
data: {
news: [],
2025-03-09 23:28:40 +08:00
pageNum: 1,
2025-03-07 22:27:18 +08:00
bannerdata: [
"home-banner"
]
},
2025-03-09 23:28:40 +08:00
onShow() {
2025-03-09 23:40:39 +08:00
// 重置页码并重新获取数据
this.setData({
pageNum: 1,
news: []
}, () => {
this.getOrderList()
})
2025-03-09 23:28:40 +08:00
},
// =============== 页面跳转相关 ===============
2025-03-07 22:27:18 +08:00
2025-03-09 23:28:40 +08:00
// 检查登录状态并跳转
checkLoginAndNavigate(path) {
if (!wx.getStorageSync('phone')) {
wx.setStorageSync('uidFlag', false)
this.showLoginModal()
return false
}
return true
},
// 显示登录提示
showLoginModal() {
wx.showModal({
title: '提示',
content: '请先登录',
success(res) {
if (res.confirm) {
wx.switchTab({
url: '/pages/my/my'
})
}
}
})
},
// 生长曲线图
2025-03-07 22:27:18 +08:00
go_grow() {
2025-03-09 23:28:40 +08:00
if (this.checkLoginAndNavigate()) {
2025-03-07 22:27:18 +08:00
wx.navigateTo({
2025-03-09 23:28:40 +08:00
url: '/pages/grocur/grocur'
})
2025-03-07 22:27:18 +08:00
}
},
2025-03-09 23:28:40 +08:00
// 性发育图表
go_peizhen() {
2025-03-14 22:37:20 +08:00
// if (this.checkLoginAndNavigate()) {
// wx.showToast({
// title: '功能正在开发中',
// icon: 'none'
// })
// }
if (this.checkLoginAndNavigate()) {
wx.navigateTo({
url: '/pages/ghdCalculator/ghdCalculator'
2025-03-09 23:28:40 +08:00
})
}
},
2025-03-07 22:27:18 +08:00
2025-03-09 23:28:40 +08:00
// 性发育图表页面
2025-03-07 22:27:18 +08:00
go_chart() {
2025-03-09 23:28:40 +08:00
if (this.checkLoginAndNavigate()) {
2025-03-07 22:27:18 +08:00
wx.navigateTo({
2025-03-09 23:28:40 +08:00
url: '/pages/sexChart/sexChart'
})
2025-03-07 22:27:18 +08:00
}
},
2025-03-09 23:28:40 +08:00
// 身高SDS计算页面
redirectToHeightSDS() {
wx.navigateTo({
url: '/pages/heightSdsCalculator/heightSdsCalculator?category=1'
})
},
// 遗传靶身高计算页面
redirectToGeneticTargetHeight() {
wx.navigateTo({
url: '/pages/tarhei/tarhei'
})
},
// CPP预测计算
2025-03-07 22:27:18 +08:00
go_cpp() {
2025-03-09 23:28:40 +08:00
if (this.checkLoginAndNavigate()) {
2025-03-15 07:35:29 +08:00
wx.navigateTo({
url: '/pages/ghdCalculator/ghdCalculator'
2025-03-09 23:28:40 +08:00
})
2025-03-07 22:27:18 +08:00
}
},
2025-03-09 23:28:40 +08:00
// IGF-1参考值
2025-03-07 22:27:18 +08:00
go_peihu() {
2025-03-09 23:28:40 +08:00
if (this.checkLoginAndNavigate()) {
2025-03-07 22:27:18 +08:00
wx.navigateTo({
2025-03-09 23:28:40 +08:00
url: '/pages/igfrefer/igfrefer'
})
2025-03-07 22:27:18 +08:00
}
},
2025-03-09 23:28:40 +08:00
// =============== 资讯列表相关 ===============
2025-03-07 22:27:18 +08:00
2025-03-09 23:28:40 +08:00
// 获取资讯列表数据
getOrderList() {
2025-03-07 22:27:18 +08:00
wx.request({
url: app.globalData.url + 'app/Ruilaiwechat/selectRealtimeInfoList',
2025-03-09 23:28:40 +08:00
method: 'POST',
2025-03-07 22:27:18 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2025-03-09 23:28:40 +08:00
},
2025-03-07 22:27:18 +08:00
data: {
2025-03-09 23:28:40 +08:00
page: this.data.pageNum
2025-03-07 22:27:18 +08:00
},
2025-03-09 23:28:40 +08:00
success: this.handleOrderListResponse.bind(this)
})
2025-03-07 22:27:18 +08:00
},
2025-03-09 23:28:40 +08:00
// 处理资讯列表响应
handleOrderListResponse(res) {
2025-03-09 23:40:39 +08:00
if (res.data.erro !== 0) {
wx.showToast({
title: '获取数据失败',
icon: 'none'
})
return
}
2025-03-09 23:28:40 +08:00
const { lists, currentPage } = res.data
2025-03-09 23:40:39 +08:00
if (lists && lists.length > 0) {
this.setData({
news: currentPage === 1 ? lists : this.data.news.concat(lists),
pageNum: currentPage + 1
})
}
2025-03-09 23:28:40 +08:00
},
// 资讯项点击
itemclick(e) {
const { url } = e.currentTarget.dataset
wx.navigateTo({
url: `/pages/webpage/webpage?url=${url}`
2025-03-07 22:27:18 +08:00
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
2025-03-09 23:40:39 +08:00
// 下拉刷新时重置页码并重新获取数据
this.setData({
pageNum: 1,
news: []
}, () => {
this.getOrderList()
})
2025-03-07 22:27:18 +08:00
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
2025-03-09 23:40:39 +08:00
// 上拉加载更多数据
this.getOrderList()
2025-03-07 22:27:18 +08:00
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})