From 9e4a60001e0ccff6aa9abaaaeb0f439d9a0e42d6 Mon Sep 17 00:00:00 2001 From: "1054425342@qq.com" <1054425342@qq.com> Date: Wed, 24 Sep 2025 16:31:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E5=8F=96=E6=B6=88=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/DynamicIsland.vue | 6 ++ components/WaterfallLayout.vue | 79 +++++++++++++++++-- pages/index/timeShopBank.vue | 70 ++++++++++++----- pages/notes/detail.vue | 138 +++++++++++++++------------------ static/js/request.js | 4 +- 5 files changed, 191 insertions(+), 106 deletions(-) diff --git a/components/DynamicIsland.vue b/components/DynamicIsland.vue index 9190b25..e10534c 100644 --- a/components/DynamicIsland.vue +++ b/components/DynamicIsland.vue @@ -104,6 +104,7 @@ 积分:{{totalPoints||0}}积分获取规则 @@ -387,6 +388,11 @@ url: '/subPackages/other/introduction' }) }, + pointDetail(){ + uni.navigateTo({ + url:'/subPackages/user/privacyInfo?id=10222' + }) + } }, }; diff --git a/components/WaterfallLayout.vue b/components/WaterfallLayout.vue index b5cee8b..3ddb72f 100644 --- a/components/WaterfallLayout.vue +++ b/components/WaterfallLayout.vue @@ -12,7 +12,6 @@ @@ -33,16 +32,16 @@ /> {{ item.nickname }} - + @@ -55,7 +54,6 @@ @@ -79,16 +77,16 @@ }}{{ item.nickname }} - - + + @@ -91,7 +96,7 @@ 评论 ({{ noteDetail.comments.length }})评论 ({{ noteDetail.commentCount || 0 }}) @@ -143,18 +148,14 @@ mode="widthFix" :src=" !noteDetail.userLiked - ? showImg( - 'https://epic.js-dyyj.com/uploads/20250728/2f3ae212c01fa3b67be81abc5723cf5c.png' - ) - : showImg( - 'https://epic.js-dyyj.com/uploads/20250728/dd7ed269b24e84a2dd141da6ab980fd6.png' - ) + ? 'https://epic.js-dyyj.com/uploads/20250728/2f3ae212c01fa3b67be81abc5723cf5c.png' + : 'https://epic.js-dyyj.com/uploads/20250728/dd7ed269b24e84a2dd141da6ab980fd6.png' " > {{ noteDetail.likeCount || 0 }} @@ -241,52 +242,6 @@ export default { uni.hideLoading(); } }, - - // 加载模拟数据 - loadMockData() { - this.noteDetail = { - id: "mock001", - title: "首期「桃园山河令」", - content: - "一周前,我们种下了一片想象中的桃园,并向江湖发出了一封「桃园山河令」,邀请你来分享属于自己的“桃园时刻”。未曾想到,这片初生的桃园,会迎来五湖四海如此多的“桃园客”——这是我们想送给每一位「EpicSoul交响」星球上「三个桃子」粉丝的名字。这些回响,来自每一位被「三个桃子」IP故事所触动的你。因为是你们,用一个个真实、温暖的故事,让我们想象中的那片桃园,迅速地枝繁叶茂,长满了沉甸甸的果实。", - image: "https://des.dayunyuanjian.cn/epicSoul/canal-town.jpg", - tags: ["时间里的约定", "审美", "治愈系调色"], - likes: 30, - isLiked: false, - createTime: "2025-08-20 14:30:00", - user: { - id: "user001", - name: "发布者", - avatar: "/uploads/20250826/b4b7c64ce37481e75742454c037e6407.png", - isFollowed: false, - }, - comments: [ - { - id: "comment001", - content: - "我的「桃园时刻」是和发小一起玩耍,阳光透过桃叶洒下斑驳光影,空气中弥漫着桃子的香甜。我们一起摘桃子,分享秘密,笑声在桃园里回荡。", - createTime: "2025-08-20 15:00:00", - user: { - id: "user002", - name: "@小新", - avatar: "/uploads/20250826/d68433653e8b8cceba9bc4a6ab2a394d.png", - }, - }, - { - id: "comment002", - content: - "我的「桃园时刻」是和家人一起野餐,在桃树下享受美食,孩子们在周围嬉戏,欢声笑语让时光变得缓慢而美好。", - createTime: "2025-08-20 16:20:00", - user: { - id: "user003", - name: "Mr.曾", - avatar: "/uploads/20250826/d68433653e8b8cceba9bc4a6ab2a394d.png", - }, - }, - ], - }; - }, - // 预览图片 previewImage(imageUrl) { uni.previewImage({ @@ -333,36 +288,69 @@ export default { // 切换点赞状态 async toggleLike() { + if (!this.noteId) { + uni.showToast({ + title: "笔记ID不存在", + icon: "none", + }); + return; + } + try { - const action = this.noteDetail.isLiked ? "cancel" : "like"; - const res = await this.Post( - { - method: "POST", - noteId: this.noteId, - action: action, - }, - "/framework/note/like", - "DES" - ); + // 保存原始状态,用于出错时回滚 + const originalLiked = this.noteDetail.userLiked; + const originalLikeCount = this.noteDetail.likeCount || 0; - if (res.code === 200) { - this.noteDetail.isLiked = !this.noteDetail.isLiked; - this.noteDetail.likes += this.noteDetail.isLiked ? 1 : -1; + // 乐观更新UI + this.noteDetail.userLiked = !this.noteDetail.userLiked; + this.noteDetail.likeCount = + (this.noteDetail.likeCount || 0) + + (this.noteDetail.userLiked ? 1 : -1); + + // 根据当前状态决定调用哪个API + const apiUrl = this.noteDetail.userLiked + ? "/framework/noteLike/add/" + this.noteId + : "/framework/noteLike/cancel/" + this.noteId; + + const res = await this.Post({}, apiUrl, "DES"); - // 可选:更新点赞数为接口返回的准确数值 + if (res.code === 200) { + // 成功时,如果API返回了准确的点赞数,则使用API返回的数据 if (res.data && res.data.likeCount !== undefined) { - this.noteDetail.likes = res.data.likeCount; + this.noteDetail.likeCount = res.data.likeCount; } + + // 发送事件通知 timeShopBank 页面更新数据 + uni.$emit('note-like-change', { + noteId: this.noteId, + isLiked: this.noteDetail.userLiked, + likeCount: this.noteDetail.likeCount + }); + + // 可以在这里添加成功的提示或动画效果 } else { + // 失败时回滚UI状态 + this.noteDetail.userLiked = originalLiked; + this.noteDetail.likeCount = originalLikeCount; + uni.showToast({ - title: res.msg || (action === "like" ? "点赞失败" : "取消点赞失败"), + title: + res.msg || + (this.noteDetail.userLiked ? "点赞失败" : "取消点赞失败"), icon: "none", }); } } catch (error) { console.error("点赞操作失败:", error); + + // 发生异常时也需要回滚UI状态 + this.noteDetail.userLiked = !this.noteDetail.userLiked; + this.noteDetail.likeCount = + (this.noteDetail.likeCount || 0) + + (this.noteDetail.userLiked ? 1 : -1); + uni.showToast({ - title: "操作失败", + title: "网络异常,请稍后重试", icon: "none", }); } @@ -629,7 +617,7 @@ export default { } .comment-input-section-box { position: fixed; - bottom: 0; + bottom: -1px; left: 0; right: 0; z-index: 999; diff --git a/static/js/request.js b/static/js/request.js index 9ce85f7..6985869 100644 --- a/static/js/request.js +++ b/static/js/request.js @@ -9,8 +9,8 @@ const DEV_API_URL = 'https://epic.dayunyuanjian.cn'; const PROD_API_URL = 'https://epic.dayunyuanjian.cn'; const NEWAPIURL = process.env.NODE_ENV === 'development' ? DEV_API_URL : PROD_API_URL; // const DEV_API_URL_DES = 'https://des.dayunyuanjian.cn/xcx'; -const DEV_API_URL_DES = 'https://des.dayunyuanjian.cn/xcx'; -// const DEV_API_URL_DES = 'http://192.168.124.8:8083/xcx'; +// const DEV_API_URL_DES = 'https://des.dayunyuanjian.cn/xcx'; +const DEV_API_URL_DES = 'http://192.168.124.8:8083/xcx'; // const PROD_API_URL_DES = 'https://des.dayunyuanjian.cn/xcx'; const PROD_API_URL_DES = 'https://des.dayunyuanjian.cn/xcx'; const NEWAPIURL_DES = process.env.NODE_ENV === 'development' ? DEV_API_URL_DES : PROD_API_URL_DES;