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,101 @@
// pages/my-favorite/my-favorite.js
// 我的收藏逻辑处理
const app = getApp()
const api = require('../../services/api')
Page({
data: {
favoriteList: [],
page: 1,
pageSize: 10,
hasMore: true,
loading: false
},
onLoad() {
this.checkLogin()
},
onShow() {
this.checkLogin()
},
onPullDownRefresh() {
this.setData({ page: 1, favoriteList: [], hasMore: true })
this.loadFavoriteList()
wx.stopPullDownRefresh()
},
onReachBottom() {
if (this.data.hasMore && !this.data.loading) {
this.setData({ page: this.data.page + 1 })
this.loadFavoriteList()
}
},
checkLogin() {
const userInfo = wx.getStorageSync('userInfo')
if (!userInfo) {
wx.redirectTo({ url: '/pages/login/login' })
return
}
this.loadFavoriteList()
},
loadFavoriteList() {
if (this.data.loading || !this.data.hasMore) return
this.setData({ loading: true })
api.getMyFavoriteList({
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({
favoriteList: this.data.page === 1 ? list : this.data.favoriteList.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}`
})
},
onCancelFavorite(e) {
const articleId = e.currentTarget.dataset.id
wx.showModal({
title: '提示',
content: '确定要取消收藏吗?',
success: res => {
if (res.confirm) {
api.updateFavorite({ articleId, isFavorite: false }).then(result => {
if (result.code === 200) {
wx.showToast({ title: '已取消收藏', icon: 'success' })
this.setData({ page: 1, favoriteList: [], hasMore: true })
this.loadFavoriteList()
} else {
wx.showToast({ title: result.message || '操作失败', icon: 'none' })
}
})
}
}
})
}
})
/**
* @联系作者: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,39 @@
<!-- pages/my-favorite/my-favorite.wxml -->
<!-- 我的收藏视图 -->
<view class="my-favorite-container">
<view class="favorite-list">
<view class="favorite-item" wx:for="{{favoriteList}}" wx:key="id">
<view class="item-main" bindtap="goToDetail" data-id="{{item.articleId}}">
<image class="item-cover" wx:if="{{item.coverImage}}" src="{{item.coverImage}}" mode="aspectFill" />
<view class="item-info">
<text class="item-title">{{item.title}}</text>
<view class="item-meta">
<text class="author">{{item.authorName}}</text>
<text class="time">{{item.createTime}}</text>
</view>
</view>
</view>
<view class="item-actions">
<view class="action-btn cancel" bindtap="onCancelFavorite" data-id="{{item.articleId}}">取消收藏</view>
</view>
</view>
</view>
<view class="loading-more" wx:if="{{loading}}">
<text>加载中...</text>
</view>
<view class="no-more" wx:if="{{!hasMore && favoriteList.length > 0}}">
<text>没有更多了</text>
</view>
<view class="empty-state" wx:if="{{!loading && favoriteList.length === 0}}">
<text class="iconfont icon-favorite empty-icon"></text>
<text class="empty-text">暂无收藏</text>
</view>
</view>
/**
* @联系作者:16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
*/

View File

@@ -0,0 +1,104 @@
/* pages/my-favorite/my-favorite.wxss */
/* 我的收藏样式 */
.my-favorite-container {
min-height: 100vh;
background-color: #f5f5f5;
padding: 20rpx 30rpx;
}
.favorite-item {
background-color: #fff;
border-radius: 16rpx;
margin-bottom: 20rpx;
overflow: hidden;
}
.item-main {
display: flex;
padding: 24rpx;
}
.item-cover {
width: 160rpx;
height: 120rpx;
border-radius: 12rpx;
margin-right: 20rpx;
flex-shrink: 0;
}
.item-info {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
}
.item-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;
}
.item-meta {
display: flex;
gap: 20rpx;
margin-top: auto;
}
.author,
.time {
font-size: 22rpx;
color: #999;
}
.item-actions {
display: flex;
border-top: 1rpx solid #f0f0f0;
}
.action-btn {
flex: 1;
text-align: center;
padding: 24rpx;
font-size: 28rpx;
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;
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,查看完整运行演示。
*/