This commit is contained in:
mzltMpfqGS
2026-04-15 19:45:16 +08:00
commit e4a087e67e
301 changed files with 35048 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
// pages/category/category.js
// 分类逻辑处理
const api = require('../../services/api')
Page({
data: {
categoryList: [],
activeCategoryId: null,
articleList: [],
page: 1,
pageSize: 10,
hasMore: true,
loading: false
},
onLoad() {
this.loadCategoryList()
},
onPullDownRefresh() {
this.setData({ page: 1, articleList: [], hasMore: true })
this.loadArticleList()
wx.stopPullDownRefresh()
},
onReachBottom() {
if (this.data.hasMore && !this.data.loading) {
this.setData({ page: this.data.page + 1 })
this.loadArticleList()
}
},
// 加载分类列表
loadCategoryList() {
api.getCategoryList().then(res => {
if (res.code === 200) {
this.setData({ categoryList: res.data || [] })
if (res.data && res.data.length > 0) {
this.setData({ activeCategoryId: res.data[0].id })
this.loadArticleList()
}
}
})
},
// 加载文章列表
loadArticleList() {
if (this.data.loading || !this.data.hasMore) return
this.setData({ loading: true })
api.getArticleList({
categoryId: this.data.activeCategoryId,
page: this.data.page,
pageSize: this.data.pageSize
}).then(res => {
this.setData({ loading: false })
if (res.code === 200) {
const list = res.data.list || []
this.setData({
articleList: this.data.page === 1 ? list : this.data.articleList.concat(list),
hasMore: list.length >= this.data.pageSize
})
}
}).catch(() => {
this.setData({ loading: false })
})
},
// 选择分类
onCategoryChange(e) {
const index = e.detail.value
const category = this.data.categoryList[index]
if (category && category.id !== this.data.activeCategoryId) {
this.setData({
activeCategoryId: category.id,
page: 1,
articleList: [],
hasMore: true
})
this.loadArticleList()
}
},
// 跳转到文章详情
goToDetail(e) {
const articleId = e.currentTarget.dataset.id
wx.navigateTo({
url: `/pages/article-detail/article-detail?id=${articleId}`
})
}
})
/**
* @联系作者:16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
*/

View File

@@ -0,0 +1,12 @@
{
"usingComponents": {},
"navigationBarTitleText": "分类",
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark"
}
/**
* @联系作者:16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
*/

View File

@@ -0,0 +1,48 @@
<!-- pages/category/category.wxml -->
<!-- 分类视图 -->
<view class="category-container">
<!-- 分类选择器 -->
<view class="category-header">
<picker mode="selector" range="{{categoryList}}" range-key="name" bindchange="onCategoryChange">
<view class="category-picker">
<text>{{activeCategoryName || '选择分类'}}</text>
<text class="iconfont icon-arrow-down"></text>
</view>
</picker>
</view>
<!-- 文章列表 -->
<view class="article-list">
<view class="article-item" wx:for="{{articleList}}" wx:key="id" bindtap="goToDetail" data-id="{{item.id}}">
<view class="article-main">
<view class="article-info">
<text class="article-title">{{item.title}}</text>
<view class="article-meta">
<text class="author">{{item.authorName}}</text>
<text class="time">{{item.createTime}}</text>
</view>
</view>
<image class="article-cover" wx:if="{{item.coverImage}}" src="{{item.coverImage}}" mode="aspectFill" />
</view>
</view>
</view>
<!-- 加载状态 -->
<view class="loading-more" wx:if="{{loading}}">
<text>加载中...</text>
</view>
<view class="no-more" wx:if="{{!hasMore && articleList.length > 0}}">
<text>没有更多了</text>
</view>
<view class="empty-state" wx:if="{{!loading && articleList.length === 0}}">
<text class="iconfont icon-category empty-icon"></text>
<text class="empty-text">该分类暂无文章</text>
</view>
</view>
/**
* @联系作者:16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
*/

View File

@@ -0,0 +1,119 @@
/* pages/category/category.wxss */
/* 分类页面样式 */
.category-container {
min-height: 100vh;
background-color: #f5f5f5;
}
.category-header {
padding: 20rpx 30rpx;
background-color: #fff;
border-bottom: 1rpx solid #f0f0f0;
}
.category-picker {
display: flex;
align-items: center;
justify-content: center;
padding: 16rpx 30rpx;
background-color: #f5f5f5;
border-radius: 32rpx;
}
.category-picker text {
font-size: 28rpx;
color: #333;
}
.category-picker .iconfont {
margin-left: 12rpx;
font-size: 24rpx;
color: #999;
}
.article-list {
padding: 20rpx 30rpx;
}
.article-item {
background-color: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 20rpx;
}
.article-main {
display: flex;
}
.article-info {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
}
.article-title {
font-size: 30rpx;
font-weight: bold;
color: #333;
margin-bottom: 16rpx;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.article-meta {
display: flex;
gap: 20rpx;
margin-top: auto;
}
.author,
.time {
font-size: 22rpx;
color: #999;
}
.article-cover {
width: 180rpx;
height: 120rpx;
border-radius: 12rpx;
margin-left: 20rpx;
flex-shrink: 0;
}
.loading-more,
.no-more {
text-align: center;
padding: 30rpx;
font-size: 24rpx;
color: #999;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
padding: 100rpx 0;
}
.empty-icon {
font-size: 100rpx;
color: #ddd;
margin-bottom: 20rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
}
/**
* @联系作者:16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
*/