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,189 @@
// pages/article-list/article-list.js
// 文章列表逻辑处理
const app = getApp()
const api = require('../../services/api')
Page({
data: {
categoryId: null,
tagId: null,
keyword: '',
articleList: [],
categoryList: [],
tagList: [],
page: 1,
pageSize: 10,
hasMore: true,
loading: false,
selectedCategory: null,
selectedTag: null,
sortBy: 'createTime',
sortOrder: 'desc'
},
onLoad(options) {
if (options.categoryId) {
this.setData({ categoryId: options.categoryId })
}
if (options.tagId) {
this.setData({ tagId: options.tagId })
}
if (options.keyword) {
this.setData({ keyword: options.keyword })
}
this.loadCategoryList()
this.loadArticleList()
},
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 || [] })
}
})
},
// 加载文章列表
loadArticleList() {
if (this.data.loading || !this.data.hasMore) return
this.setData({ loading: true })
const params = {
page: this.data.page,
pageSize: this.data.pageSize,
sortBy: this.data.sortBy,
sortOrder: this.data.sortOrder
}
if (this.data.categoryId) {
params.categoryId = this.data.categoryId
}
if (this.data.tagId) {
params.tagId = this.data.tagId
}
if (this.data.keyword) {
params.keyword = this.data.keyword
}
api.getArticleList(params).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 })
})
},
// 跳转到文章详情
goToDetail(e) {
const articleId = e.currentTarget.dataset.id
wx.navigateTo({
url: `/pages/article-detail/article-detail?id=${articleId}`
})
},
// 选择分类
onCategoryChange(e) {
const index = e.detail.value
const category = this.data.categoryList[index]
this.setData({
selectedCategory: category,
categoryId: category ? category.id : null,
page: 1,
articleList: [],
hasMore: true
})
this.loadArticleList()
},
// 选择标签
onTagChange(e) {
const index = e.detail.value
const tag = this.data.tagList[index]
this.setData({
selectedTag: tag,
tagId: tag ? tag.id : null,
page: 1,
articleList: [],
hasMore: true
})
this.loadArticleList()
},
// 排序方式变更
onSortChange(e) {
const value = e.detail.value
const [sortBy, sortOrder] = value.split(':')
this.setData({
sortBy,
sortOrder,
page: 1,
articleList: [],
hasMore: true
})
this.loadArticleList()
},
// 收藏文章
onFavorite(e) {
if (!app.checkLogin()) return
const articleId = e.currentTarget.dataset.id
const articleList = this.data.articleList
const index = articleList.findIndex(item => item.id === articleId)
if (index === -1) return
const article = articleList[index]
const isFavorite = !article.isFavorite
api.updateFavorite({ articleId, isFavorite }).then(res => {
if (res.code === 200) {
article.isFavorite = isFavorite
article.favoriteCount = isFavorite ? article.favoriteCount + 1 : article.favoriteCount - 1
this.setData({ [`articleList[${index}]`]: article })
wx.showToast({
title: isFavorite ? '收藏成功' : '取消收藏',
icon: 'success'
})
}
})
},
// 分享文章
onShareAppMessage(e) {
const article = e.target.dataset.article
return {
title: article.title,
path: `/pages/article-detail/article-detail?id=${article.id}`,
imageUrl: article.coverImage
}
}
})
/**
* @联系作者: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,102 @@
<!-- pages/article-list/article-list.wxml -->
<!-- 文章列表视图 -->
<view class="article-list-container">
<!-- 搜索和筛选区域 -->
<view class="filter-bar">
<view class="search-box">
<input class="search-input" placeholder="搜索文章" bindinput="onSearchInput" value="{{keyword}}" />
<icon type="search" size="18" color="#999" bindtap="onSearch" />
</view>
</view>
<!-- 分类标签 -->
<scroll-view class="category-scroll" scroll-x="true">
<view class="category-list">
<view class="category-item {{!selectedCategory ? 'active' : ''}}" bindtap="onCategoryTap" data-id="{{null}}">
全部
</view>
<view
class="category-item {{selectedCategory && selectedCategory.id === item.id ? 'active' : ''}}"
wx:for="{{categoryList}}"
wx:key="id"
bindtap="onCategoryTap"
data-id="{{item}}"
>
{{item.name}}
</view>
</view>
</scroll-view>
<!-- 排序选项 -->
<view class="sort-bar">
<view class="sort-item {{sortBy === 'createTime' ? 'active' : ''}}" bindtap="onSortTap" data-sort="createTime">
最新
</view>
<view class="sort-item {{sortBy === 'viewCount' ? 'active' : ''}}" bindtap="onSortTap" data-sort="viewCount">
最热
</view>
<view class="sort-item {{sortBy === 'favoriteCount' ? 'active' : ''}}" bindtap="onSortTap" data-sort="favoriteCount">
收藏
</view>
</view>
<!-- 文章列表 -->
<view class="article-list">
<block wx:for="{{articleList}}" wx:key="id">
<view class="article-item" bindtap="goToDetail" data-id="{{item.id}}">
<view class="article-content">
<image class="article-cover" wx:if="{{item.coverImage}}" src="{{item.coverImage}}" mode="aspectFill" />
<view class="article-info">
<text class="article-title">{{item.title}}</text>
<text class="article-summary">{{item.summary}}</text>
<view class="article-meta">
<view class="meta-item">
<text class="iconfont icon-user"></text>
<text>{{item.authorName}}</text>
</view>
<view class="meta-item">
<text class="iconfont icon-view"></text>
<text>{{item.viewCount}}</text>
</view>
<view class="meta-item">
<text class="iconfont icon-favorite"></text>
<text>{{item.favoriteCount}}</text>
</view>
<view class="meta-item">
<text class="iconfont icon-comment"></text>
<text>{{item.commentCount}}</text>
</view>
</view>
<view class="article-tags" wx:if="{{item.tags && item.tags.length > 0}}">
<text class="tag" wx:for="{{item.tags}}" wx:for-item="tag" wx:key="id">{{tag.name}}</text>
</view>
</view>
</view>
<view class="article-actions">
<view class="action-btn" catchtap="onFavorite" data-id="{{item.id}}">
<text class="iconfont {{item.isFavorite ? 'icon-favorite-fill' : 'icon-favorite'}}"></text>
</view>
</view>
</view>
</block>
</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-article empty-icon"></text>
<text class="empty-text">暂无文章</text>
</view>
</view>
/**
* @联系作者:16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
*/

View File

@@ -0,0 +1,224 @@
/* pages/article-list/article-list.wxss */
/* 文章列表样式 */
.article-list-container {
min-height: 100vh;
background-color: #f5f5f5;
}
.filter-bar {
padding: 20rpx 30rpx;
background-color: #fff;
}
.search-box {
display: flex;
align-items: center;
background-color: #f5f5f5;
border-radius: 32rpx;
padding: 16rpx 24rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
color: #333;
}
.category-scroll {
background-color: #fff;
white-space: nowrap;
padding: 0 20rpx 20rpx;
}
.category-list {
display: flex;
gap: 20rpx;
}
.category-item {
display: inline-block;
padding: 12rpx 28rpx;
font-size: 26rpx;
color: #666;
background-color: #f5f5f5;
border-radius: 28rpx;
white-space: nowrap;
}
.category-item.active {
background-color: #667eea;
color: #fff;
}
.sort-bar {
display: flex;
padding: 20rpx 30rpx;
background-color: #fff;
margin-bottom: 20rpx;
}
.sort-item {
flex: 1;
text-align: center;
font-size: 28rpx;
color: #666;
padding: 16rpx 0;
position: relative;
}
.sort-item.active {
color: #667eea;
font-weight: bold;
}
.sort-item.active::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 40rpx;
height: 4rpx;
background-color: #667eea;
border-radius: 2rpx;
}
.article-list {
padding: 0 20rpx;
}
.article-item {
background-color: #fff;
border-radius: 16rpx;
margin-bottom: 20rpx;
overflow: hidden;
}
.article-content {
display: flex;
padding: 24rpx;
}
.article-cover {
width: 200rpx;
height: 160rpx;
border-radius: 12rpx;
margin-right: 24rpx;
flex-shrink: 0;
}
.article-info {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
}
.article-title {
font-size: 30rpx;
font-weight: bold;
color: #333;
margin-bottom: 12rpx;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.article-summary {
font-size: 24rpx;
color: #999;
margin-bottom: 16rpx;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
flex: 1;
}
.article-meta {
display: flex;
gap: 24rpx;
margin-bottom: 12rpx;
}
.meta-item {
display: flex;
align-items: center;
font-size: 22rpx;
color: #999;
}
.meta-item .iconfont {
margin-right: 6rpx;
font-size: 24rpx;
}
.article-tags {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
}
.tag {
padding: 4rpx 12rpx;
font-size: 20rpx;
color: #667eea;
background-color: rgba(102, 126, 234, 0.1);
border-radius: 8rpx;
}
.article-actions {
display: flex;
justify-content: flex-end;
padding: 0 24rpx 20rpx;
}
.action-btn {
padding: 12rpx 20rpx;
}
.action-btn .iconfont {
font-size: 36rpx;
color: #999;
}
.action-btn .icon-favorite-fill {
color: #F56C6C;
}
.loading-more,
.no-more {
text-align: center;
padding: 30rpx;
font-size: 24rpx;
color: #999;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
}
.empty-icon {
font-size: 120rpx;
color: #ddd;
margin-bottom: 30rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
}
/**
* @联系作者:16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
*/