mirror of
https://gitee.com/qingqing-coconut-tea/RcKtFezyRAZX
synced 2026-07-21 10:32:32 +08:00
init
This commit is contained in:
117
wechat/pages/home/home.js
Normal file
117
wechat/pages/home/home.js
Normal file
@@ -0,0 +1,117 @@
|
||||
// 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,查看完整运行演示。
|
||||
*/
|
||||
11
wechat/pages/home/home.json
Normal file
11
wechat/pages/home/home.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "首页",
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
|
||||
/**
|
||||
* @联系作者:16768118056
|
||||
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
|
||||
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
|
||||
*/
|
||||
75
wechat/pages/home/home.wxml
Normal file
75
wechat/pages/home/home.wxml
Normal file
@@ -0,0 +1,75 @@
|
||||
<!-- pages/home/home.wxml -->
|
||||
<!-- 首页视图 -->
|
||||
|
||||
<view class="home-container">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-bar">
|
||||
<input class="search-input" placeholder="请输入搜索关键词" bindconfirm="onSearch" />
|
||||
<icon type="search" class="search-icon" />
|
||||
</view>
|
||||
|
||||
<!-- 轮播图 -->
|
||||
<swiper class="banner-swiper" indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff" autoplay circular>
|
||||
<block wx:for="{{bannerList}}" wx:key="id">
|
||||
<swiper-item>
|
||||
<image src="{{item.image}}" class="banner-image" mode="aspectFill" bindtap="onBannerTap" data-index="{{index}}" />
|
||||
</swiper-item>
|
||||
</block>
|
||||
</swiper>
|
||||
|
||||
<!-- 分类导航 -->
|
||||
<view class="category-nav">
|
||||
<block wx:for="{{categoryList}}" wx:key="id">
|
||||
<view class="category-item" bindtap="goToCategory" data-id="{{item.id}}">
|
||||
<view class="category-icon">
|
||||
<text class="iconfont {{item.icon}}"></text>
|
||||
</view>
|
||||
<text class="category-name">{{item.name}}</text>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<!-- 统计数据 -->
|
||||
<view class="stats-section">
|
||||
<view class="stats-item">
|
||||
<text class="stats-value">{{stats.userCount}}</text>
|
||||
<text class="stats-label">用户总数</text>
|
||||
</view>
|
||||
<view class="stats-item">
|
||||
<text class="stats-value">{{stats.articleCount}}</text>
|
||||
<text class="stats-label">文章总数</text>
|
||||
</view>
|
||||
<view class="stats-item">
|
||||
<text class="stats-value">{{stats.commentCount}}</text>
|
||||
<text class="stats-label">评论总数</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 推荐文章 -->
|
||||
<view class="section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">推荐文章</text>
|
||||
<text class="section-more" bindtap="loadMoreArticles">查看更多 ></text>
|
||||
</view>
|
||||
<view class="article-list">
|
||||
<block wx:for="{{articleList}}" wx:key="id">
|
||||
<view class="article-item" bindtap="goToArticle" data-id="{{item.id}}">
|
||||
<image src="{{item.coverImage}}" class="article-image" mode="aspectFill" />
|
||||
<view class="article-info">
|
||||
<text class="article-title">{{item.title}}</text>
|
||||
<view class="article-meta">
|
||||
<text class="article-author">{{item.author}}</text>
|
||||
<text class="article-count">阅读 {{item.viewCount}} 点赞 {{item.likeCount}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
/**
|
||||
* @联系作者:16768118056
|
||||
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
|
||||
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
|
||||
*/
|
||||
181
wechat/pages/home/home.wxss
Normal file
181
wechat/pages/home/home.wxss
Normal file
@@ -0,0 +1,181 @@
|
||||
/* pages/home/home.wxss */
|
||||
/* 首页样式 */
|
||||
|
||||
.home-container {
|
||||
background-color: #f5f5f5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
position: relative;
|
||||
padding: 20rpx 30rpx;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
height: 70rpx;
|
||||
padding-left: 70rpx;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 35rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
position: absolute;
|
||||
left: 50rpx;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
font-size: 36rpx;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.banner-swiper {
|
||||
width: 100%;
|
||||
height: 350rpx;
|
||||
}
|
||||
|
||||
.banner-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.category-nav {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
padding: 30rpx 20rpx;
|
||||
background-color: #fff;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
width: 25%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.category-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 50%;
|
||||
background-color: #ecf5ff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 15rpx;
|
||||
}
|
||||
|
||||
.category-icon .iconfont {
|
||||
font-size: 48rpx;
|
||||
color: #409EFF;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
font-size: 26rpx;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.stats-section {
|
||||
display: flex;
|
||||
padding: 40rpx 30rpx;
|
||||
background-color: #fff;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.stats-item {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.stats-value {
|
||||
font-size: 40rpx;
|
||||
font-weight: bold;
|
||||
color: #409EFF;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.stats-label {
|
||||
font-size: 24rpx;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.section {
|
||||
background-color: #fff;
|
||||
margin-top: 20rpx;
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.section-more {
|
||||
font-size: 26rpx;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.article-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.article-item {
|
||||
display: flex;
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.article-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.article-image {
|
||||
width: 200rpx;
|
||||
height: 150rpx;
|
||||
border-radius: 8rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.article-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
font-size: 28rpx;
|
||||
color: #303133;
|
||||
font-weight: 500;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.article-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 24rpx;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
/**
|
||||
* @联系作者:16768118056
|
||||
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
|
||||
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
|
||||
*/
|
||||
Reference in New Issue
Block a user