From 0e28e55d3b25df79b174deca810456b126cfff3c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?=
<15778543+xufeiyang6017@user.noreply.gitee.com>
Date: Wed, 28 Jan 2026 13:25:30 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=9B=8B=E5=90=A7=E9=A1=B5?=
=?UTF-8?q?=E9=9D=A2=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/eggbar/create-post.js | 10 ++-
pages/eggbar/eggbar.js | 138 +++++++++++++++++++++++++++++++--
pages/eggbar/eggbar.wxml | 2 +-
pages/evaluate2/one.wxml | 2 +-
server-example/server-mysql.js | 84 ++++++++++++++++++++
5 files changed, 224 insertions(+), 12 deletions(-)
diff --git a/pages/eggbar/create-post.js b/pages/eggbar/create-post.js
index 2ea6a48..bffa7d8 100644
--- a/pages/eggbar/create-post.js
+++ b/pages/eggbar/create-post.js
@@ -24,7 +24,10 @@ Page({
this.setData({
hotTopics: [
{ id: 1, name: '今天你吃蛋了么?', count: 123 },
- { id: 2, name: '日常分享', count: 456 }
+ { id: 2, name: '日常分享', count: 456 },
+ { id: 3, name: '鸡蛋行情', count: 789 },
+ { id: 4, name: '养殖经验', count: 321 },
+ { id: 5, name: '美食分享', count: 654 }
]
});
}
@@ -34,7 +37,10 @@ Page({
this.setData({
hotTopics: [
{ id: 1, name: '今天你吃蛋了么?', count: 123 },
- { id: 2, name: '日常分享', count: 456 }
+ { id: 2, name: '日常分享', count: 456 },
+ { id: 3, name: '鸡蛋行情', count: 789 },
+ { id: 4, name: '养殖经验', count: 321 },
+ { id: 5, name: '美食分享', count: 654 }
]
});
});
diff --git a/pages/eggbar/eggbar.js b/pages/eggbar/eggbar.js
index 5fedadc..68bcd62 100644
--- a/pages/eggbar/eggbar.js
+++ b/pages/eggbar/eggbar.js
@@ -43,11 +43,34 @@ Page({
loadHotTopics() {
API.getHotTopics().then(res => {
- this.setData({
- hotTopics: res.data || []
- });
+ if (res.data && res.data.length > 0) {
+ this.setData({
+ hotTopics: res.data
+ });
+ } else {
+ // 使用默认热门话题
+ this.setData({
+ hotTopics: [
+ { id: 1, name: '今天你吃蛋了么?', count: 123 },
+ { id: 2, name: '日常分享', count: 456 },
+ { id: 3, name: '鸡蛋行情', count: 789 },
+ { id: 4, name: '养殖经验', count: 321 },
+ { id: 5, name: '美食分享', count: 654 }
+ ]
+ });
+ }
}).catch(err => {
console.error('加载热门话题失败:', err);
+ // 出错时使用默认热门话题
+ this.setData({
+ hotTopics: [
+ { id: 1, name: '今天你吃蛋了么?', count: 123 },
+ { id: 2, name: '日常分享', count: 456 },
+ { id: 3, name: '鸡蛋行情', count: 789 },
+ { id: 4, name: '养殖经验', count: 321 },
+ { id: 5, name: '美食分享', count: 654 }
+ ]
+ });
});
},
@@ -64,18 +87,117 @@ Page({
page: this.data.page,
pageSize: this.data.pageSize
}).then(res => {
- const newPosts = res.data || [];
+ // 正确处理后端返回的响应格式
+ let newPosts = res.data && res.data.posts ? res.data.posts : [];
+
+ // 如果是第一页且没有数据,使用默认动态数据
+ if (this.data.page === 1 && (!newPosts || newPosts.length === 0)) {
+ newPosts = [
+ {
+ id: 1,
+ user_id: '1',
+ content: '今天的鸡蛋质量真好,客户都很满意!',
+ images: [],
+ likes: 12,
+ comments: 3,
+ created_at: new Date().toISOString(),
+ username: '鸡蛋养殖户',
+ avatar: '',
+ liked: false
+ },
+ {
+ id: 2,
+ user_id: '2',
+ content: '分享一下我的养殖经验,希望对大家有帮助',
+ images: [],
+ likes: 8,
+ comments: 5,
+ created_at: new Date().toISOString(),
+ username: '养殖专家',
+ avatar: '',
+ liked: false
+ },
+ {
+ id: 3,
+ user_id: '3',
+ content: '鸡蛋行情不错,今天卖了个好价钱',
+ images: [],
+ likes: 15,
+ comments: 2,
+ created_at: new Date().toISOString(),
+ username: '蛋商小王',
+ avatar: '',
+ liked: false
+ }
+ ];
+ }
+
+ // 根据后端返回的分页信息判断是否还有更多数据
+ const shouldHasMore = res.data && res.data.pagination ?
+ this.data.page < res.data.pagination.totalPages :
+ this.data.page < 3;
+
this.setData({
posts: this.data.page === 1 ? newPosts : [...this.data.posts, ...newPosts],
loading: false,
- hasMore: newPosts.length >= this.data.pageSize,
+ hasMore: shouldHasMore,
page: this.data.page + 1
});
}).catch(err => {
console.error('加载动态失败:', err);
- this.setData({
- loading: false
- });
+
+ // 出错时使用默认动态数据
+ if (this.data.page === 1) {
+ // 当页码大于3时,设置hasMore为false,显示"暂无更多动态"提示
+ const shouldHasMore = this.data.page < 3;
+
+ this.setData({
+ posts: [
+ {
+ id: 1,
+ user_id: '1',
+ content: '今天的鸡蛋质量真好,客户都很满意!',
+ images: [],
+ likes: 12,
+ comments: 3,
+ created_at: new Date().toISOString(),
+ username: '鸡蛋养殖户',
+ avatar: '',
+ liked: false
+ },
+ {
+ id: 2,
+ user_id: '2',
+ content: '分享一下我的养殖经验,希望对大家有帮助',
+ images: [],
+ likes: 8,
+ comments: 5,
+ created_at: new Date().toISOString(),
+ username: '养殖专家',
+ avatar: '',
+ liked: false
+ },
+ {
+ id: 3,
+ user_id: '3',
+ content: '鸡蛋行情不错,今天卖了个好价钱',
+ images: [],
+ likes: 15,
+ comments: 2,
+ created_at: new Date().toISOString(),
+ username: '蛋商小王',
+ avatar: '',
+ liked: false
+ }
+ ],
+ loading: false,
+ hasMore: shouldHasMore
+ });
+ } else {
+ this.setData({
+ loading: false
+ });
+ }
});
},
diff --git a/pages/eggbar/eggbar.wxml b/pages/eggbar/eggbar.wxml
index 1f5aa69..5bdeceb 100644
--- a/pages/eggbar/eggbar.wxml
+++ b/pages/eggbar/eggbar.wxml
@@ -63,7 +63,7 @@
- 没有更多内容了
+ 暂无更多动态
diff --git a/pages/evaluate2/one.wxml b/pages/evaluate2/one.wxml
index f76f3ac..4180588 100644
--- a/pages/evaluate2/one.wxml
+++ b/pages/evaluate2/one.wxml
@@ -1,7 +1,7 @@