Files
mzltMpfqGS e4a087e67e init
2026-04-15 19:45:16 +08:00

118 lines
3.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/home/home.js
// 首页逻辑处理
const app = getApp()
Page({
data: {
// 轮播图数据
bannerList: [
{ id: 1, image: '/static/images/banner1.jpg', url: '' },
{ id: 2, image: '/static/images/banner2.jpg', url: '' },
{ id: 3, image: '/static/images/banner3.jpg', url: '' }
],
// 分类数据
categoryList: [
{ id: 1, name: '美食', icon: 'icon-food' },
{ id: 2, name: '旅游', icon: 'icon-travel' },
{ id: 3, name: '电影', icon: 'icon-movie' },
{ id: 4, name: '出行', icon: 'icon-transport' },
{ id: 5, name: '购物', icon: 'icon-shop' },
{ id: 6, name: '教育', icon: 'icon-edu' }
],
// 推荐文章
articleList: [
{ id: 1, title: 'Vue3 Composition API 完全指南', coverImage: '/static/images/article1.jpg', author: '张三', viewCount: 1024, likeCount: 128 },
{ id: 2, title: 'JavaScript 高级程序设计', coverImage: '/static/images/article2.jpg', author: '李四', viewCount: 856, likeCount: 96 },
{ id: 3, title: 'CSS Grid 布局详解', coverImage: '/static/images/article3.jpg', author: '王五', viewCount: 512, likeCount: 64 }
],
// 统计数据
stats: {
userCount: 1234,
articleCount: 3567,
commentCount: 12890
},
// 搜索关键词
searchKey: ''
},
onLoad() {
this.loadHomeData()
},
onShow() {
// 每次显示时刷新数据
},
onPullDownRefresh() {
this.loadHomeData()
wx.stopPullDownRefresh()
},
// 加载首页数据
loadHomeData() {
wx.showLoading({ title: '加载中...' })
// 模拟加载数据
setTimeout(() => {
this.setData({
bannerList: this.data.bannerList,
categoryList: this.data.categoryList,
articleList: this.data.articleList
})
wx.hideLoading()
}, 500)
},
// 跳转到文章详情
goToArticle(e) {
const id = e.currentTarget.dataset.id
wx.navigateTo({
url: '/pages/article-detail/article-detail?id=' + id
})
},
// 跳转到分类页面
goToCategory(e) {
const id = e.currentTarget.dataset.id
wx.navigateTo({
url: '/pages/category/category?id=' + id
})
},
// 搜索
onSearch(e) {
const key = e.detail.value
if (!key) {
wx.showToast({ title: '请输入搜索关键词', icon: 'none' })
return
}
wx.navigateTo({
url: '/pages/search-result/search-result?key=' + key
})
},
// 查看更多文章
loadMoreArticles() {
wx.navigateTo({
url: '/pages/article-list/article-list'
})
},
// 用户点击轮播图
onBannerTap(e) {
const index = e.currentTarget.dataset.index
const banner = this.data.bannerList[index]
if (banner.url) {
wx.navigateTo({
url: banner.url
})
}
}
})
/**
* @联系作者16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415查看完整运行演示。
*/