From 45d50826b9c52da8f28167a003cda9e6f2c50c4a Mon Sep 17 00:00:00 2001
From: "1054425342@qq.com" <1054425342@qq.com>
Date: Thu, 25 Sep 2025 15:38:49 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/notes/detail.vue | 112 ++++++++++++++++++++++++++++++++++++++--
pages/notes/publish.vue | 2 +-
2 files changed, 110 insertions(+), 4 deletions(-)
diff --git a/pages/notes/detail.vue b/pages/notes/detail.vue
index 5c845b5..5a06515 100644
--- a/pages/notes/detail.vue
+++ b/pages/notes/detail.vue
@@ -221,6 +221,8 @@
编辑
+
+
@@ -289,6 +302,32 @@ export default {
this.loadCommentList(true);
}
},
+ // 微信分享配置
+ // #ifdef MP-WEIXIN
+ onShareAppMessage() {
+ // 设置分享标识符,在onShow中会检查并调用分享接口
+ this.isShared = true;
+
+ return {
+ title: this.noteDetail.title || "Epic Soul交响",
+ path: `/pages/notes/detail?id=${this.noteId}`,
+ imageUrl:
+ this.topBanner && this.topBanner.length > 0 ? this.topBanner[0] : "",
+ mpId: "wx9660f8c5776663e0",
+ };
+ },
+ onShareTimeline() {
+ // 设置分享标识符,在onShow中会检查并调用分享接口
+ this.isShared = true;
+
+ return {
+ title: this.noteDetail.title || "Epic Soul交响",
+ query: `id=2`,
+ imageUrl:
+ this.topBanner && this.topBanner.length > 0 ? this.topBanner[0] : "",
+ };
+ },
+ // #endif
data() {
return {
noteId: "",
@@ -305,6 +344,8 @@ export default {
toNickname: "", // 被回复的用户昵称
inputFocusState: false, // 输入框焦点状态
showRepliesMap: {}, // 存储每个评论的二级评论展开状态
+ isShared: false, // 分享标识符
+ shareTimer: null, // 分享定时器
noteDetail: {
id: "",
title: "",
@@ -330,7 +371,10 @@ export default {
},
onLoad(options) {
- this.userInfo = JSON.parse(uni.getStorageSync("userInfo"));
+ console.log(options, "页面的");
+ if (uni.getStorageSync("userInfo")) {
+ this.userInfo = JSON.parse(uni.getStorageSync("userInfo"));
+ }
console.log(this.userInfo);
if (options.id) {
this.noteId = options.id;
@@ -345,10 +389,53 @@ export default {
}
},
onShow() {
+ let id = uni.getStorageSync("wechat_qrcode");
+ this.noteId = this.noteId || id;
this.loadNoteDetail();
- this.userInfo = JSON.parse(uni.getStorageSync("userInfo"));
+
+ // 检查分享标识符,如果为true则调用分享接口
+ if (this.isShared) {
+ // 使用定时器延迟调用,确保页面已完全加载
+ this.shareTimer = setTimeout(() => {
+ this.recordShare();
+ this.isShared = false; // 重置分享标识符
+ }, 1000);
+ }
+ },
+
+ onHide() {
+ // 页面隐藏时清除定时器
+ if (this.shareTimer) {
+ clearTimeout(this.shareTimer);
+ this.shareTimer = null;
+ }
},
methods: {
+ // 记录分享并获得积分
+ async recordShare() {
+ try {
+ const res = await this.Post(
+ {},
+ `/framework/noteShare/add/${this.noteId}`,
+ "DES"
+ );
+
+ if (res.code === 200) {
+ uni.showToast({
+ title: "分享成功",
+ icon: "success",
+ });
+ return true;
+ } else {
+ console.warn("分享记录失败:", res.msg);
+ return false;
+ }
+ } catch (error) {
+ console.error("分享记录失败:", error);
+ return false;
+ }
+ },
+
swiperChange(e) {
this.swiperIndex = e.detail.current;
},
@@ -1191,9 +1278,28 @@ export default {
}
}
- .like-section {
+ .share-section {
margin-bottom: max(env(safe-area-inset-bottom), 24rpx);
+ display: flex;
+ align-items: center;
+ padding: 0 16rpx;
+ background: transparent;
+ border: none;
+ outline: none;
+ box-shadow: none;
+ line-height: normal;
+ border-radius: 0;
+ font-size: inherit;
+ color: inherit;
+ text-align: center;
+ min-height: auto;
+ &::after {
+ border: none;
+ }
+ }
+ .like-section {
+ margin-bottom: max(env(safe-area-inset-bottom), 24rpx);
display: flex;
align-items: center;
gap: 8rpx;
diff --git a/pages/notes/publish.vue b/pages/notes/publish.vue
index 358016a..cce3e86 100644
--- a/pages/notes/publish.vue
+++ b/pages/notes/publish.vue
@@ -193,7 +193,7 @@ export default {
// 插入快速标签
insertQuickTag(tag) {
// 检查是否已经添加了该标签
- const existingTag = this.noteForm.tags.find((t) => t.id === tag.id);
+ const existingTag = this.noteForm.tags.find((t) => t.id == tag.id);
if (!existingTag) {
this.noteForm.tags.unshift(tag);
}