southnote-mini-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.js +22 -0
- package/app.json +53 -0
- package/app.wxss +15 -0
- package/assets/file/badwords.js +63008 -0
- package/assets/file/rules.js +38 -0
- package/assets/images/emoji/smile001.png +0 -0
- package/assets/images/emoji/smile002.png +0 -0
- package/assets/images/emoji/smile003.png +0 -0
- package/assets/images/emoji/smile004.png +0 -0
- package/assets/images/emoji/smile005.png +0 -0
- package/assets/images/emoji/smile006.png +0 -0
- package/assets/images/emoji/smile007.png +0 -0
- package/assets/images/emoji/smile008.png +0 -0
- package/assets/images/emoji/smile009.png +0 -0
- package/assets/images/emoji/smile010.png +0 -0
- package/assets/images/emoji/smile011.png +0 -0
- package/assets/images/emoji/smile012.png +0 -0
- package/assets/images/emoji/smile013.png +0 -0
- package/assets/images/emoji/smile014.png +0 -0
- package/assets/images/emoji/smile015.png +0 -0
- package/assets/images/emoji/smile016.png +0 -0
- package/assets/images/emoji/smile017.png +0 -0
- package/assets/images/emoji/smile018.png +0 -0
- package/assets/images/emoji/smile019.png +0 -0
- package/assets/images/emoji/smile020.png +0 -0
- package/assets/images/emoji/smile021.png +0 -0
- package/assets/images/emoji/smile022.png +0 -0
- package/assets/images/emoji/smile023.png +0 -0
- package/assets/images/emoji/smile024.png +0 -0
- package/assets/images/emoji/smile025.png +0 -0
- package/assets/images/emoji/smile026.png +0 -0
- package/assets/images/emoji/smile027.png +0 -0
- package/assets/images/emoji/smile028.png +0 -0
- package/assets/images/emoji/smile029.png +0 -0
- package/assets/images/emoji/smile030.png +0 -0
- package/assets/images/emoji/smile031.png +0 -0
- package/assets/images/emoji/smile032.png +0 -0
- package/assets/images/emoji/smile033.png +0 -0
- package/assets/images/emoji/smile034.png +0 -0
- package/assets/images/emoji/smile035.png +0 -0
- package/assets/images/emoji/smile036.png +0 -0
- package/assets/images/emoji/smile037.png +0 -0
- package/assets/images/emoji/smile038.png +0 -0
- package/assets/images/emoji/smile039.png +0 -0
- package/assets/images/emoji/smile040.png +0 -0
- package/assets/images/emoji/smile041.png +0 -0
- package/assets/images/emoji/smile042.png +0 -0
- package/assets/images/emoji/smile043.png +0 -0
- package/assets/images/emoji/smile044.png +0 -0
- package/assets/images/emoji/smile045.png +0 -0
- package/assets/images/emoji/smile046.png +0 -0
- package/assets/images/emoji/smile047.png +0 -0
- package/assets/images/emoji/smile048.png +0 -0
- package/assets/images/emoji/smile049.png +0 -0
- package/assets/images/emoji/smile050.png +0 -0
- package/assets/images/emoji/smile051.png +0 -0
- package/assets/images/emoji/smile052.png +0 -0
- package/assets/images/icons/age1.png +0 -0
- package/assets/images/icons/age2.png +0 -0
- package/assets/images/icons/age3.png +0 -0
- package/assets/images/icons/attachment.png +0 -0
- package/assets/images/icons/clear.png +0 -0
- package/assets/images/icons/edit_input.png +0 -0
- package/assets/images/icons/header_placeholder.png +0 -0
- package/assets/images/icons/home_collect.png +0 -0
- package/assets/images/icons/home_collected.png +0 -0
- package/assets/images/icons/home_comment.png +0 -0
- package/assets/images/icons/home_like.png +0 -0
- package/assets/images/icons/home_liked.png +0 -0
- package/assets/images/icons/home_message.png +0 -0
- package/assets/images/icons/home_share.png +0 -0
- package/assets/images/icons/icon_more.png +0 -0
- package/assets/images/icons/input_game.png +0 -0
- package/assets/images/icons/logo.png +0 -0
- package/assets/images/icons/lv1.png +0 -0
- package/assets/images/icons/lv2.png +0 -0
- package/assets/images/icons/lv3.png +0 -0
- package/assets/images/icons/lv4.png +0 -0
- package/assets/images/icons/search.png +0 -0
- package/assets/images/icons/sex1.png +0 -0
- package/assets/images/icons/sex2.png +0 -0
- package/assets/images/icons/sign_empty.png +0 -0
- package/assets/images/icons/sign_login.png +0 -0
- package/assets/wheel/wheel_bg.png +0 -0
- package/assets/wheel/wheel_bg2.png +0 -0
- package/assets/wheel/wheel_fore.png +0 -0
- package/assets/wheel/wheel_to.png +0 -0
- package/components/bottomSheet/bottomSheet.js +473 -0
- package/components/bottomSheet/bottomSheet.json +3 -0
- package/components/bottomSheet/bottomSheet.wxml +73 -0
- package/components/bottomSheet/bottomSheet.wxss +238 -0
- package/components/experience-item/experience-item.js +105 -0
- package/components/experience-item/experience-item.json +4 -0
- package/components/experience-item/experience-item.wxml +39 -0
- package/components/experience-item/experience-item.wxss +110 -0
- package/components/grid-item/grid-item.js +8 -0
- package/components/grid-item/grid-item.json +4 -0
- package/components/grid-item/grid-item.wxml +62 -0
- package/components/grid-item/grid-item.wxss +191 -0
- package/components/post-item/post-item.js +1085 -0
- package/components/post-item/post-item.json +4 -0
- package/components/post-item/post-item.wxml +427 -0
- package/components/post-item/post-item.wxss +525 -0
- package/components/wiki-renderer/wiki-renderer.js +636 -0
- package/components/wiki-renderer/wiki-renderer.json +12 -0
- package/components/wiki-renderer/wiki-renderer.wxml +150 -0
- package/components/wiki-renderer/wiki-renderer.wxss +412 -0
- package/components/wiki-tabs/wiki-tabs.js +52 -0
- package/components/wiki-tabs/wiki-tabs.json +3 -0
- package/components/wiki-tabs/wiki-tabs.wxml +28 -0
- package/components/wiki-tabs/wiki-tabs.wxss +43 -0
- package/index.js +49 -0
- package/package.json +35 -0
- package/pages/addGame/addGame.js +454 -0
- package/pages/addGame/addGame.json +3 -0
- package/pages/addGame/addGame.wxml +71 -0
- package/pages/addGame/addGame.wxss +110 -0
- package/pages/addSubject/addSubject.js +199 -0
- package/pages/addSubject/addSubject.json +4 -0
- package/pages/addSubject/addSubject.wxml +78 -0
- package/pages/addSubject/addSubject.wxss +85 -0
- package/pages/commonLogin/commonLogin.js +269 -0
- package/pages/commonLogin/commonLogin.json +4 -0
- package/pages/commonLogin/commonLogin.wxml +57 -0
- package/pages/commonLogin/commonLogin.wxss +177 -0
- package/pages/copyOfficial/copyOfficial.js +25 -0
- package/pages/copyOfficial/copyOfficial.json +3 -0
- package/pages/copyOfficial/copyOfficial.wxml +22 -0
- package/pages/copyOfficial/copyOfficial.wxss +49 -0
- package/pages/demo/demo.js +23 -0
- package/pages/demo/demo.json +3 -0
- package/pages/demo/demo.wxml +8 -0
- package/pages/demo/demo.wxss +24 -0
- package/pages/game/game.js +1254 -0
- package/pages/game/game.json +8 -0
- package/pages/game/game.wxml +371 -0
- package/pages/game/game.wxss +672 -0
- package/pages/home/home.js +665 -0
- package/pages/home/home.json +10 -0
- package/pages/home/home.wxml +115 -0
- package/pages/home/home.wxss +231 -0
- package/pages/lottery-winners/lottery-winners.js +60 -0
- package/pages/lottery-winners/lottery-winners.json +4 -0
- package/pages/lottery-winners/lottery-winners.wxml +53 -0
- package/pages/lottery-winners/lottery-winners.wxss +127 -0
- package/pages/message/messageCommentsAndAt/messageCommentsAndAt.js +178 -0
- package/pages/message/messageCommentsAndAt/messageCommentsAndAt.json +5 -0
- package/pages/message/messageCommentsAndAt/messageCommentsAndAt.wxml +93 -0
- package/pages/message/messageCommentsAndAt/messageCommentsAndAt.wxss +177 -0
- package/pages/message/messageEntire/messageEntire.js +112 -0
- package/pages/message/messageEntire/messageEntire.json +4 -0
- package/pages/message/messageEntire/messageEntire.wxml +44 -0
- package/pages/message/messageEntire/messageEntire.wxss +88 -0
- package/pages/message/messageLikeAndCollect/messageLikeAndCollect.js +147 -0
- package/pages/message/messageLikeAndCollect/messageLikeAndCollect.json +5 -0
- package/pages/message/messageLikeAndCollect/messageLikeAndCollect.wxml +84 -0
- package/pages/message/messageLikeAndCollect/messageLikeAndCollect.wxss +166 -0
- package/pages/message/messageNewFans/messageNewFans.js +139 -0
- package/pages/message/messageNewFans/messageNewFans.json +5 -0
- package/pages/message/messageNewFans/messageNewFans.wxml +35 -0
- package/pages/message/messageNewFans/messageNewFans.wxss +85 -0
- package/pages/officialWebview/officialWebview.js +13 -0
- package/pages/officialWebview/officialWebview.json +3 -0
- package/pages/officialWebview/officialWebview.wxml +2 -0
- package/pages/officialWebview/officialWebview.wxss +1 -0
- package/pages/post/post.js +1856 -0
- package/pages/post/post.json +6 -0
- package/pages/post/post.wxml +694 -0
- package/pages/post/post.wxss +1003 -0
- package/pages/post-editor/post-editor.js +465 -0
- package/pages/post-editor/post-editor.json +4 -0
- package/pages/post-editor/post-editor.wxml +63 -0
- package/pages/post-editor/post-editor.wxss +195 -0
- package/pages/postDialog/postDialog.js +560 -0
- package/pages/postDialog/postDialog.json +6 -0
- package/pages/postDialog/postDialog.wxml +377 -0
- package/pages/postDialog/postDialog.wxss +979 -0
- package/pages/report-category/report-category.js +29 -0
- package/pages/report-category/report-category.json +4 -0
- package/pages/report-category/report-category.wxml +14 -0
- package/pages/report-category/report-category.wxss +43 -0
- package/pages/report-form/report-form.js +65 -0
- package/pages/report-form/report-form.json +3 -0
- package/pages/report-form/report-form.wxml +11 -0
- package/pages/report-form/report-form.wxss +44 -0
- package/pages/sevenDaySignDetail/sevenDaySignDetail.js +273 -0
- package/pages/sevenDaySignDetail/sevenDaySignDetail.json +3 -0
- package/pages/sevenDaySignDetail/sevenDaySignDetail.wxml +82 -0
- package/pages/sevenDaySignDetail/sevenDaySignDetail.wxss +173 -0
- package/pages/topic/topic.js +266 -0
- package/pages/topic/topic.json +6 -0
- package/pages/topic/topic.wxml +77 -0
- package/pages/topic/topic.wxss +162 -0
- package/pages/user/user.js +939 -0
- package/pages/user/user.json +5 -0
- package/pages/user/user.wxml +179 -0
- package/pages/user/user.wxss +340 -0
- package/pages/userDatum/userDatum.js +24 -0
- package/pages/userDatum/userDatum.json +4 -0
- package/pages/userDatum/userDatum.wxml +36 -0
- package/pages/userDatum/userDatum.wxss +41 -0
- package/pages/userGameLib/userGameLib.js +105 -0
- package/pages/userGameLib/userGameLib.json +4 -0
- package/pages/userGameLib/userGameLib.wxml +42 -0
- package/pages/userGameLib/userGameLib.wxss +119 -0
- package/pages/webview/webview.js +25 -0
- package/pages/webview/webview.json +3 -0
- package/pages/webview/webview.wxml +22 -0
- package/pages/webview/webview.wxss +50 -0
- package/pages/wheelActivivty/wheelActivivty.js +492 -0
- package/pages/wheelActivivty/wheelActivivty.json +8 -0
- package/pages/wheelActivivty/wheelActivivty.wxml +131 -0
- package/pages/wheelActivivty/wheelActivivty.wxss +459 -0
- package/pages/wiki/wiki.js +138 -0
- package/pages/wiki/wiki.json +6 -0
- package/pages/wiki/wiki.wxml +20 -0
- package/pages/wiki/wiki.wxss +44 -0
- package/request/JKRequest.js +177 -0
- package/services/home.js +603 -0
- package/towxml/config.js +291 -0
- package/towxml/decode.js +35 -0
- package/towxml/decode.json +11 -0
- package/towxml/decode.wxml +137 -0
- package/towxml/decode.wxss +0 -0
- package/towxml/img/img.js +98 -0
- package/towxml/img/img.json +3 -0
- package/towxml/img/img.wxml +1 -0
- package/towxml/img/img.wxss +0 -0
- package/towxml/index.js +19 -0
- package/towxml/latex/latex.js +53 -0
- package/towxml/latex/latex.json +5 -0
- package/towxml/latex/latex.wxml +1 -0
- package/towxml/latex/latex.wxss +0 -0
- package/towxml/parse/highlight/highlight.js +1 -0
- package/towxml/parse/highlight/index.js +8 -0
- package/towxml/parse/highlight/languages/bash.js +111 -0
- package/towxml/parse/highlight/languages/c-like.js +236 -0
- package/towxml/parse/highlight/languages/c.js +22 -0
- package/towxml/parse/highlight/languages/css.js +132 -0
- package/towxml/parse/highlight/languages/dart.js +134 -0
- package/towxml/parse/highlight/languages/go.js +63 -0
- package/towxml/parse/highlight/languages/htmlbars.js +80 -0
- package/towxml/parse/highlight/languages/java.js +125 -0
- package/towxml/parse/highlight/languages/javascript.js +265 -0
- package/towxml/parse/highlight/languages/json.js +52 -0
- package/towxml/parse/highlight/languages/less.js +148 -0
- package/towxml/parse/highlight/languages/nginx.js +101 -0
- package/towxml/parse/highlight/languages/php.js +161 -0
- package/towxml/parse/highlight/languages/python-repl.js +29 -0
- package/towxml/parse/highlight/languages/python.js +131 -0
- package/towxml/parse/highlight/languages/scss.js +122 -0
- package/towxml/parse/highlight/languages/shell.js +22 -0
- package/towxml/parse/highlight/languages/typescript.js +215 -0
- package/towxml/parse/highlight/languages/xml.js +139 -0
- package/towxml/parse/highlight/style/github.wxss +99 -0
- package/towxml/parse/highlight/style/monokai.wxss +70 -0
- package/towxml/parse/index.js +118 -0
- package/towxml/parse/markdown/index.js +67 -0
- package/towxml/parse/markdown/markdown.js +4 -0
- package/towxml/parse/markdown/plugins/echarts.js +11 -0
- package/towxml/parse/markdown/plugins/emoji.js +2 -0
- package/towxml/parse/markdown/plugins/ins.js +1 -0
- package/towxml/parse/markdown/plugins/latex.js +158 -0
- package/towxml/parse/markdown/plugins/mark.js +1 -0
- package/towxml/parse/markdown/plugins/sub.js +1 -0
- package/towxml/parse/markdown/plugins/sup.js +1 -0
- package/towxml/parse/markdown/plugins/todo.js +147 -0
- package/towxml/parse/markdown/plugins/yuml.js +20 -0
- package/towxml/parse/parse2/Parser.js +492 -0
- package/towxml/parse/parse2/Tokenizer.js +903 -0
- package/towxml/parse/parse2/domelementtype/index.js +55 -0
- package/towxml/parse/parse2/domhandler/index.js +145 -0
- package/towxml/parse/parse2/domhandler/node.js +474 -0
- package/towxml/parse/parse2/entities/decode.js +179 -0
- package/towxml/parse/parse2/entities/decode_codepoint.js +60 -0
- package/towxml/parse/parse2/entities/encode.js +77 -0
- package/towxml/parse/parse2/entities/escape.js +112 -0
- package/towxml/parse/parse2/entities/generated/decode-data-html.js +9 -0
- package/towxml/parse/parse2/entities/generated/decode-data-xml.js +9 -0
- package/towxml/parse/parse2/entities/generated/encode-html.js +12 -0
- package/towxml/parse/parse2/entities/index.js +137 -0
- package/towxml/parse/parse2/index.js +8 -0
- package/towxml/style/main.wxss +419 -0
- package/towxml/style/theme/dark.wxss +73 -0
- package/towxml/style/theme/light.wxss +63 -0
- package/towxml/table/table.js +11 -0
- package/towxml/table/table.json +6 -0
- package/towxml/table/table.wxml +24 -0
- package/towxml/table/table.wxss +0 -0
- package/towxml/todogroup/todogroup.js +20 -0
- package/towxml/todogroup/todogroup.json +6 -0
- package/towxml/todogroup/todogroup.wxml +12 -0
- package/towxml/todogroup/todogroup.wxss +3 -0
- package/towxml/towxml.js +22 -0
- package/towxml/towxml.json +6 -0
- package/towxml/towxml.wxml +5 -0
- package/towxml/towxml.wxss +8 -0
- package/towxml/yuml/yuml.js +51 -0
- package/towxml/yuml/yuml.json +5 -0
- package/towxml/yuml/yuml.wxml +5 -0
- package/towxml/yuml/yuml.wxss +0 -0
- package/utils/auth.js +17 -0
- package/utils/base64.js +67 -0
- package/utils/compressImage.js +41 -0
- package/utils/exp.js +49 -0
- package/utils/formatPost.js +18 -0
- package/utils/parseContent.js +191 -0
- package/utils/query-select.js +9 -0
- package/utils/sensitive.js +82 -0
|
@@ -0,0 +1,939 @@
|
|
|
1
|
+
import {
|
|
2
|
+
queryUserInfo,
|
|
3
|
+
queryUserPosts,
|
|
4
|
+
queryUserComments,
|
|
5
|
+
queryUsercollections,
|
|
6
|
+
followUser,
|
|
7
|
+
|
|
8
|
+
deleteContent,
|
|
9
|
+
collectPost,
|
|
10
|
+
setUserPostTop
|
|
11
|
+
} from "../../services/home";
|
|
12
|
+
import formatUTC from "../../utils/formatPost";
|
|
13
|
+
|
|
14
|
+
Page({
|
|
15
|
+
data: {
|
|
16
|
+
userId: 0,
|
|
17
|
+
userDetail: {},
|
|
18
|
+
active: 0, // 顶级 tab
|
|
19
|
+
subActive: 0, // 子 tab
|
|
20
|
+
navBarHeight: 0,
|
|
21
|
+
|
|
22
|
+
subTabs: [{
|
|
23
|
+
title: "全部",
|
|
24
|
+
filter: 1
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
title: "热门",
|
|
28
|
+
filter: 2
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
title: "原创",
|
|
32
|
+
filter: 3
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
|
|
36
|
+
posts: {
|
|
37
|
+
1: [],
|
|
38
|
+
2: [],
|
|
39
|
+
3: []
|
|
40
|
+
},
|
|
41
|
+
page: {
|
|
42
|
+
1: 1,
|
|
43
|
+
2: 1,
|
|
44
|
+
3: 1
|
|
45
|
+
},
|
|
46
|
+
hasMore: {
|
|
47
|
+
1: true,
|
|
48
|
+
2: true,
|
|
49
|
+
3: true
|
|
50
|
+
},
|
|
51
|
+
loading: {
|
|
52
|
+
1: false,
|
|
53
|
+
2: false,
|
|
54
|
+
3: false
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
comments: [],
|
|
58
|
+
commentsPage: 1,
|
|
59
|
+
commentsHasMore: true,
|
|
60
|
+
commentsLoading: false,
|
|
61
|
+
|
|
62
|
+
collections: [],
|
|
63
|
+
collectionsPage: 1,
|
|
64
|
+
collectionsHasMore: true,
|
|
65
|
+
collectionsLoading: false,
|
|
66
|
+
|
|
67
|
+
moreSheetVisible: false,
|
|
68
|
+
moreSheetItem: {},
|
|
69
|
+
isOwner: false, //当前cell是否是自己
|
|
70
|
+
|
|
71
|
+
currentPlayingVideoId: null, //当前播放视频帖子id
|
|
72
|
+
|
|
73
|
+
},
|
|
74
|
+
onShareAppMessage() {
|
|
75
|
+
const {
|
|
76
|
+
userId,
|
|
77
|
+
userDetail
|
|
78
|
+
} = this.data;
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
title: userDetail?.nickname || '查看用户主页',
|
|
82
|
+
path: `/pages/user/user?id=${userId}` // 携带用户ID
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
onPreviewAvatar(e) {
|
|
87
|
+
const url = e.currentTarget.dataset.url;
|
|
88
|
+
if (!url) return;
|
|
89
|
+
|
|
90
|
+
wx.previewImage({
|
|
91
|
+
current: url, // 当前预览的图片
|
|
92
|
+
urls: [url] // 图片列表
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
onLoad(options) {
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
const userId = options.id;
|
|
100
|
+
const sys = wx.getWindowInfo();
|
|
101
|
+
this.setData({
|
|
102
|
+
userId,
|
|
103
|
+
navBarHeight: sys.statusBarHeight + 44
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
this.queryUserInfo(userId);
|
|
107
|
+
this.queryUserPosts(1); // 默认加载 “全部”
|
|
108
|
+
|
|
109
|
+
const currentUserId = wx.getStorageSync('appuid'); // 当前登录用户id
|
|
110
|
+
const isOwner = userId === currentUserId;
|
|
111
|
+
this.setData({
|
|
112
|
+
isOwner
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
async queryUserInfo(userId) {
|
|
118
|
+
try {
|
|
119
|
+
const res = await queryUserInfo(userId);
|
|
120
|
+
if (res?.code === 0) {
|
|
121
|
+
this.setData({
|
|
122
|
+
userDetail: res.data
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
wx.setNavigationBarTitle({
|
|
126
|
+
title: res.data.user?.nickname || '主页'
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
} catch (err) {
|
|
130
|
+
console.error(err);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
// --- 帖子 ---
|
|
135
|
+
async queryUserPosts(filter, append = true) {
|
|
136
|
+
if (this.data.loading[filter] || !this.data.hasMore[filter]) return;
|
|
137
|
+
|
|
138
|
+
const {
|
|
139
|
+
userId,
|
|
140
|
+
page,
|
|
141
|
+
posts
|
|
142
|
+
} = this.data;
|
|
143
|
+
const nextPage = append ? (page[filter] || 1) : 1;
|
|
144
|
+
|
|
145
|
+
this.setData({
|
|
146
|
+
[`loading.${filter}`]: true
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const res = await queryUserPosts(userId, nextPage, filter);
|
|
151
|
+
if (!Array.isArray(res.data.posts)) res.data.posts = [];
|
|
152
|
+
|
|
153
|
+
if (res?.code === 0) {
|
|
154
|
+
const list = res.data.posts.map(item => {
|
|
155
|
+
const p = item.post || {};
|
|
156
|
+
const shared = item.shared;
|
|
157
|
+
return {
|
|
158
|
+
user: res.data.user,
|
|
159
|
+
...item,
|
|
160
|
+
post: {
|
|
161
|
+
...p,
|
|
162
|
+
imageArray: p.images ? p.images.split(",") : [],
|
|
163
|
+
formatTime: formatUTC(p.created_at)
|
|
164
|
+
},
|
|
165
|
+
shared: shared?.post ? {
|
|
166
|
+
...shared,
|
|
167
|
+
post: {
|
|
168
|
+
...shared.post,
|
|
169
|
+
imageArray: shared.post.images ? shared.post.images.split(",") : [],
|
|
170
|
+
formatTime: formatUTC(shared.post.created_at)
|
|
171
|
+
}
|
|
172
|
+
} : shared
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const got = list.length > 0;
|
|
177
|
+
|
|
178
|
+
if (append) {
|
|
179
|
+
// ✅ 只追加新数据,保持旧数据不变
|
|
180
|
+
const currentLength = posts[filter]?.length || 0;
|
|
181
|
+
const update = {};
|
|
182
|
+
list.forEach((item, idx) => {
|
|
183
|
+
update[`posts.${filter}[${currentLength + idx}]`] = item;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
this.setData({
|
|
187
|
+
...update,
|
|
188
|
+
[`page.${filter}`]: got ? nextPage + 1 : nextPage,
|
|
189
|
+
[`hasMore.${filter}`]: got
|
|
190
|
+
});
|
|
191
|
+
} else {
|
|
192
|
+
// 首次加载直接覆盖
|
|
193
|
+
this.setData({
|
|
194
|
+
[`posts.${filter}`]: list,
|
|
195
|
+
[`page.${filter}`]: got ? nextPage + 1 : nextPage,
|
|
196
|
+
[`hasMore.${filter}`]: got
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
} else {
|
|
201
|
+
this.setData({
|
|
202
|
+
[`hasMore.${filter}`]: false
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
} catch (err) {
|
|
207
|
+
console.error("queryUserPosts error", err);
|
|
208
|
+
} finally {
|
|
209
|
+
this.setData({
|
|
210
|
+
[`loading.${filter}`]: false
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
// --- 点评 ---
|
|
216
|
+
async queryUserComments() {
|
|
217
|
+
if (this.data.commentsLoading || !this.data.commentsHasMore) return;
|
|
218
|
+
const {
|
|
219
|
+
userId,
|
|
220
|
+
commentsPage
|
|
221
|
+
} = this.data;
|
|
222
|
+
|
|
223
|
+
this.setData({
|
|
224
|
+
commentsLoading: true
|
|
225
|
+
});
|
|
226
|
+
try {
|
|
227
|
+
const res = await queryUserComments(userId, commentsPage);
|
|
228
|
+
if (!Array.isArray(res.data.posts)) {
|
|
229
|
+
res.data.posts = []
|
|
230
|
+
}
|
|
231
|
+
if (res?.code === 0) {
|
|
232
|
+
const list = res.data.posts.map(item => {
|
|
233
|
+
const p = item.comment || {};
|
|
234
|
+
const shared = item.shared || {};
|
|
235
|
+
return {
|
|
236
|
+
user: res.data.user,
|
|
237
|
+
...item,
|
|
238
|
+
post: {
|
|
239
|
+
...p,
|
|
240
|
+
imageArray: p.images ? p.images.split(",") : [],
|
|
241
|
+
formatTime: formatUTC(p.created_at)
|
|
242
|
+
},
|
|
243
|
+
shared: shared.post ? {
|
|
244
|
+
...shared,
|
|
245
|
+
post: {
|
|
246
|
+
...shared.post,
|
|
247
|
+
imageArray: shared.post.images ?
|
|
248
|
+
shared.post.images.split(",") : [],
|
|
249
|
+
formatTime: formatUTC(shared.post.created_at)
|
|
250
|
+
}
|
|
251
|
+
} : null
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const got = list.length > 0;
|
|
256
|
+
this.setData({
|
|
257
|
+
comments: [...this.data.comments, ...list],
|
|
258
|
+
commentsPage: got ? commentsPage + 1 : commentsPage,
|
|
259
|
+
commentsHasMore: got
|
|
260
|
+
});
|
|
261
|
+
} else {
|
|
262
|
+
this.setData({
|
|
263
|
+
commentsHasMore: false
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
} catch (err) {
|
|
267
|
+
console.error(err);
|
|
268
|
+
} finally {
|
|
269
|
+
this.setData({
|
|
270
|
+
commentsLoading: false
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
// --- 收藏 ---
|
|
276
|
+
async queryUserCollections() {
|
|
277
|
+
if (this.data.collectionsLoading || !this.data.collectionsHasMore) return;
|
|
278
|
+
const {
|
|
279
|
+
userId,
|
|
280
|
+
collectionsPage
|
|
281
|
+
} = this.data;
|
|
282
|
+
|
|
283
|
+
this.setData({
|
|
284
|
+
collectionsLoading: true
|
|
285
|
+
});
|
|
286
|
+
try {
|
|
287
|
+
const res = await queryUsercollections(userId, collectionsPage);
|
|
288
|
+
if (res?.code === 0 && Array.isArray(res.data)) {
|
|
289
|
+
const list = res.data.map(item => {
|
|
290
|
+
const p = item.post || {};
|
|
291
|
+
return {
|
|
292
|
+
...item,
|
|
293
|
+
post: {
|
|
294
|
+
...p,
|
|
295
|
+
imageArray: p.images ? p.images.split(",") : [],
|
|
296
|
+
formatTime: formatUTC(p.created_at)
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const got = list.length > 0;
|
|
302
|
+
this.setData({
|
|
303
|
+
collections: [...this.data.collections, ...list],
|
|
304
|
+
collectionsPage: got ? collectionsPage + 1 : collectionsPage,
|
|
305
|
+
collectionsHasMore: got
|
|
306
|
+
});
|
|
307
|
+
} else {
|
|
308
|
+
this.setData({
|
|
309
|
+
collectionsHasMore: false
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
} catch (err) {
|
|
313
|
+
console.error(err);
|
|
314
|
+
} finally {
|
|
315
|
+
this.setData({
|
|
316
|
+
collectionsLoading: false
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
onSubChange(e) {
|
|
322
|
+
const index = e.detail.index;
|
|
323
|
+
const filter = this.data.subTabs[index].filter;
|
|
324
|
+
this.setData({
|
|
325
|
+
subActive: index
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
if (this.data.posts[filter].length === 0) {
|
|
329
|
+
this.queryUserPosts(filter);
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
|
|
333
|
+
onChange(e) {
|
|
334
|
+
const index = e.detail.index;
|
|
335
|
+
this.setData({
|
|
336
|
+
active: index
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
if (index === 0) {
|
|
340
|
+
const filter = this.data.subTabs[this.data.subActive].filter;
|
|
341
|
+
if (this.data.posts[filter].length === 0) {
|
|
342
|
+
this.queryUserPosts(filter);
|
|
343
|
+
}
|
|
344
|
+
} else if (index === 1 && this.data.comments.length === 0) {
|
|
345
|
+
this.queryUserComments();
|
|
346
|
+
} else if (index === 2 && this.data.collections.length === 0) {
|
|
347
|
+
this.queryUserCollections();
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
loadMore(e) {
|
|
352
|
+
const filter = Number(e.currentTarget.dataset.filter);
|
|
353
|
+
this.queryUserPosts(filter);
|
|
354
|
+
},
|
|
355
|
+
|
|
356
|
+
onReachBottom() {
|
|
357
|
+
const {
|
|
358
|
+
active,
|
|
359
|
+
subActive,
|
|
360
|
+
subTabs
|
|
361
|
+
} = this.data;
|
|
362
|
+
|
|
363
|
+
if (active === 0) {
|
|
364
|
+
const filter = subTabs[subActive].filter;
|
|
365
|
+
this.queryUserPosts(filter, true);
|
|
366
|
+
} else if (active === 1) {
|
|
367
|
+
this.queryUserComments();
|
|
368
|
+
} else if (active === 2) {
|
|
369
|
+
this.queryUserCollections();
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
gotoUserDatum(e) {
|
|
374
|
+
const user = this.data.userDetail.user
|
|
375
|
+
this.onPauseAllVideo()
|
|
376
|
+
wx.navigateTo({
|
|
377
|
+
url: '/pages/userDatum/userDatum?user=' + encodeURIComponent(JSON.stringify(user))
|
|
378
|
+
})
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
gotoUserGameLib(e) {
|
|
382
|
+
const user = this.data.userDetail.user
|
|
383
|
+
this.onPauseAllVideo()
|
|
384
|
+
wx.navigateTo({
|
|
385
|
+
url: '/pages/userGameLib/userGameLib?user_id=' + user.id
|
|
386
|
+
})
|
|
387
|
+
},
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
gotoGameCenter(e) {
|
|
391
|
+
const id = e.currentTarget.dataset.id;
|
|
392
|
+
this.onPauseAllVideo()
|
|
393
|
+
wx.navigateTo({
|
|
394
|
+
url: `/pages/game/game?id=${id}`
|
|
395
|
+
});
|
|
396
|
+
},
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
onFollowTap(e) {
|
|
400
|
+
const user = e.currentTarget.dataset.user;
|
|
401
|
+
const userId = user.id;
|
|
402
|
+
const isFans = user.is_fans ?? 0;
|
|
403
|
+
const nType = isFans === 1 ? 2 : 1; // 1关注,2取消关注
|
|
404
|
+
|
|
405
|
+
followUser(userId, nType).then(res => {
|
|
406
|
+
if (res.code === 0) {
|
|
407
|
+
// 更新当前页面 userDetail
|
|
408
|
+
this.setData({
|
|
409
|
+
'userDetail.user.is_fans': isFans === 1 ? 0 : 1
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const pages = getCurrentPages();
|
|
413
|
+
|
|
414
|
+
pages.forEach(page => {
|
|
415
|
+
// 首页:更新 posts 中对应用户的 is_fans
|
|
416
|
+
if (page.route === 'pages/home/home') {
|
|
417
|
+
|
|
418
|
+
const posts = page.data.posts.map(p => {
|
|
419
|
+
if (p.user.id === user.id) {
|
|
420
|
+
p.user.is_fans = isFans === 1 ? 0 : 1; // 修改关注状态
|
|
421
|
+
}
|
|
422
|
+
return p;
|
|
423
|
+
});
|
|
424
|
+
page.setData({
|
|
425
|
+
posts
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// 用户详情页:更新 userDetail
|
|
430
|
+
|
|
431
|
+
if (page.route === 'pages/user/user') {
|
|
432
|
+
|
|
433
|
+
if (page.data.userDetail?.user?.id === user.id) {
|
|
434
|
+
page.setData({
|
|
435
|
+
'userDetail.user.is_fans': isFans === 1 ? 0 : 1
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// 帖子详情页:更新 item.user.is_fans
|
|
441
|
+
if (page.route === 'pages/post/post') {
|
|
442
|
+
|
|
443
|
+
if (page.data.item?.user?.id === user.id) {
|
|
444
|
+
page.setData({
|
|
445
|
+
'item.user.is_fans': isFans === 1 ? 0 : 1
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
wx.showToast({
|
|
452
|
+
title: nType === 1 ? '关注成功' : '已取消关注',
|
|
453
|
+
icon: 'success'
|
|
454
|
+
});
|
|
455
|
+
} else {
|
|
456
|
+
wx.showToast({
|
|
457
|
+
title: res.message || '操作失败',
|
|
458
|
+
icon: 'none'
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}).catch((err) => {
|
|
462
|
+
wx.showToast({
|
|
463
|
+
title: err,
|
|
464
|
+
icon: 'none'
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
// 底部弹窗
|
|
470
|
+
|
|
471
|
+
onMoreTap(e) {
|
|
472
|
+
const index = e.currentTarget.dataset.index; // 当前帖子在列表中的索引
|
|
473
|
+
|
|
474
|
+
const item = e.detail.item;
|
|
475
|
+
const currentUserId = wx.getStorageSync('appuid'); // 当前登录用户id
|
|
476
|
+
const isOwner = item.user.id === currentUserId;
|
|
477
|
+
this.setData({
|
|
478
|
+
isOwner,
|
|
479
|
+
moreSheetVisible: true,
|
|
480
|
+
moreSheetItem: item,
|
|
481
|
+
currentPostIndex: index
|
|
482
|
+
|
|
483
|
+
});
|
|
484
|
+
},
|
|
485
|
+
|
|
486
|
+
onPinTap() {
|
|
487
|
+
const post = this.data.moreSheetItem.post;
|
|
488
|
+
const type = this.data.isPinned ? 2 : 1; // 1置顶,2取消置顶
|
|
489
|
+
|
|
490
|
+
wx.showLoading({
|
|
491
|
+
title: '处理中...'
|
|
492
|
+
});
|
|
493
|
+
setUserPostTop(post.id, type).then(res => {
|
|
494
|
+
wx.hideLoading();
|
|
495
|
+
if (res.code === 0) {
|
|
496
|
+
wx.showToast({
|
|
497
|
+
title: type === 1 ? '置顶成功' : '取消置顶成功',
|
|
498
|
+
icon: 'success'
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// 更新当前组件状态
|
|
502
|
+
this.setData({
|
|
503
|
+
'item.post.is_user_top': type === 1 ? 1 : 0,
|
|
504
|
+
isPinned: type === 1 ? 1 : 0
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
this.onCloseMoreSheet();
|
|
508
|
+
|
|
509
|
+
// 如果置顶,则需要移动帖子到列表第一位,取消其他帖子置顶,并滚动到顶部
|
|
510
|
+
if (type === 1) {
|
|
511
|
+
const pages = getCurrentPages();
|
|
512
|
+
const currentPage = pages[pages.length - 1];
|
|
513
|
+
|
|
514
|
+
if (currentPage.route === 'pages/user/user') {
|
|
515
|
+
let postsData = currentPage.data.posts;
|
|
516
|
+
|
|
517
|
+
if (Array.isArray(postsData)) {
|
|
518
|
+
// 先取消其他帖子置顶
|
|
519
|
+
postsData = postsData.map(p => {
|
|
520
|
+
if (p.post.id !== post.id && p.post.is_user_top === 1) {
|
|
521
|
+
p.post.is_user_top = 0;
|
|
522
|
+
}
|
|
523
|
+
return p;
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// 找到当前帖子在数组中的索引
|
|
527
|
+
const currentIndex = postsData.findIndex(p => p.post.id === post.id);
|
|
528
|
+
if (currentIndex > -1) {
|
|
529
|
+
const [pinnedPost] = postsData.splice(currentIndex, 1);
|
|
530
|
+
pinnedPost.post.is_user_top = 1
|
|
531
|
+
// 插入到数组第一个位置
|
|
532
|
+
postsData.unshift(pinnedPost);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
currentPage.setData({
|
|
536
|
+
posts: postsData
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// 页面滚动到顶部
|
|
540
|
+
wx.pageScrollTo({
|
|
541
|
+
scrollTop: 0,
|
|
542
|
+
duration: 300
|
|
543
|
+
});
|
|
544
|
+
} else if (postsData && typeof postsData === 'object') {
|
|
545
|
+
const newPostsObj = {};
|
|
546
|
+
Object.keys(postsData).forEach(key => {
|
|
547
|
+
if (Array.isArray(postsData[key])) {
|
|
548
|
+
// 取消其他帖子置顶
|
|
549
|
+
let arr = postsData[key].map(p => {
|
|
550
|
+
if (p.post.id !== post.id && p.post.is_user_top === 1) {
|
|
551
|
+
p.post.is_user_top = 0;
|
|
552
|
+
}
|
|
553
|
+
return p;
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
// 将当前帖子移动到第一个
|
|
557
|
+
const currentIndex = arr.findIndex(p => p.post.id === post.id);
|
|
558
|
+
if (currentIndex > -1) {
|
|
559
|
+
const [pinnedPost] = arr.splice(currentIndex, 1);
|
|
560
|
+
pinnedPost.post.is_user_top = 1
|
|
561
|
+
arr.unshift(pinnedPost);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
newPostsObj[key] = arr;
|
|
565
|
+
} else {
|
|
566
|
+
newPostsObj[key] = postsData[key];
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
currentPage.setData({
|
|
571
|
+
posts: newPostsObj
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
wx.pageScrollTo({
|
|
575
|
+
scrollTop: 0,
|
|
576
|
+
duration: 300
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
} else {
|
|
582
|
+
wx.showToast({
|
|
583
|
+
title: res.msg || '操作失败',
|
|
584
|
+
icon: 'error'
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
},
|
|
589
|
+
// 关闭弹窗
|
|
590
|
+
onCloseMoreSheet() {
|
|
591
|
+
this.setData({
|
|
592
|
+
moreSheetVisible: false
|
|
593
|
+
});
|
|
594
|
+
},
|
|
595
|
+
|
|
596
|
+
// 弹窗选项点击
|
|
597
|
+
onDelete() {
|
|
598
|
+
const postId = this.data.moreSheetItem.post.id;
|
|
599
|
+
deleteContent(postId).then(res => {
|
|
600
|
+
if (res.code === 0) {
|
|
601
|
+
wx.showToast({
|
|
602
|
+
title: '删除成功',
|
|
603
|
+
icon: 'success'
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
// 删除父页面列表里的帖子(兼容数组和对象)
|
|
607
|
+
const pages = getCurrentPages();
|
|
608
|
+
const currentPage = pages[pages.length - 1]; // 当前页
|
|
609
|
+
|
|
610
|
+
const postsData = currentPage.data.posts;
|
|
611
|
+
if (Array.isArray(postsData)) {
|
|
612
|
+
// posts 是数组
|
|
613
|
+
currentPage.setData({
|
|
614
|
+
posts: postsData.filter(p => p.post.id !== postId)
|
|
615
|
+
});
|
|
616
|
+
} else if (postsData && typeof postsData === 'object') {
|
|
617
|
+
// posts 是对象,每个 value 都可能是帖子数组
|
|
618
|
+
const newPosts = {};
|
|
619
|
+
Object.keys(postsData).forEach(key => {
|
|
620
|
+
if (Array.isArray(postsData[key])) {
|
|
621
|
+
newPosts[key] = postsData[key].filter(p => p.post.id !== postId);
|
|
622
|
+
} else {
|
|
623
|
+
newPosts[key] = postsData[key]; // 保留原值
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
currentPage.setData({
|
|
627
|
+
posts: newPosts
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
this.triggerEvent('deletePost', {
|
|
633
|
+
post: this.data.moreSheetItem.post
|
|
634
|
+
});
|
|
635
|
+
this.onCloseMoreSheet();
|
|
636
|
+
} else {
|
|
637
|
+
wx.showToast({
|
|
638
|
+
title: res.msg || '删除失败',
|
|
639
|
+
icon: 'error'
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
},
|
|
644
|
+
|
|
645
|
+
// 举报帖子
|
|
646
|
+
onReport() {
|
|
647
|
+
this.onPauseAllVideo()
|
|
648
|
+
wx.navigateTo({
|
|
649
|
+
url: `/pages/report-category/report-category?postId=${this.data.moreSheetItem.post.id}`,
|
|
650
|
+
})
|
|
651
|
+
|
|
652
|
+
this.triggerEvent('reportPost', {
|
|
653
|
+
post: this.data.moreSheetItem.post
|
|
654
|
+
});
|
|
655
|
+
this.onCloseMoreSheet();
|
|
656
|
+
},
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
// 收藏/取消收藏
|
|
660
|
+
async onFavorite() {
|
|
661
|
+
const post = this.data.moreSheetItem.post;
|
|
662
|
+
const nType = post.is_collect === 1 ? 2 : 1;
|
|
663
|
+
|
|
664
|
+
wx.showLoading({
|
|
665
|
+
title: nType === 1 ? '收藏中...' : '取消中...'
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
try {
|
|
669
|
+
const res = await collectPost(post.id, nType);
|
|
670
|
+
wx.hideLoading();
|
|
671
|
+
|
|
672
|
+
if (res.code === 0) {
|
|
673
|
+
wx.showToast({
|
|
674
|
+
title: nType === 1 ? '已收藏' : '取消收藏',
|
|
675
|
+
icon: 'success'
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
// 更新弹窗
|
|
679
|
+
this.setData({
|
|
680
|
+
'moreSheetItem.post.is_collect': nType === 1 ? 1 : 0
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
// 同步更新 posts 列表
|
|
684
|
+
const {
|
|
685
|
+
posts
|
|
686
|
+
} = this.data;
|
|
687
|
+
if (Array.isArray(posts)) {
|
|
688
|
+
const newPosts = posts.map(p => p.post.id === post.id ? {
|
|
689
|
+
...p,
|
|
690
|
+
post: {
|
|
691
|
+
...p.post,
|
|
692
|
+
is_collect: nType === 1 ? 1 : 0
|
|
693
|
+
}
|
|
694
|
+
} : p);
|
|
695
|
+
this.setData({
|
|
696
|
+
posts: newPosts
|
|
697
|
+
});
|
|
698
|
+
} else if (posts && typeof posts === 'object') {
|
|
699
|
+
const newPosts = {};
|
|
700
|
+
Object.keys(posts).forEach(key => {
|
|
701
|
+
newPosts[key] = posts[key].map(p => p.post.id === post.id ? {
|
|
702
|
+
...p,
|
|
703
|
+
post: {
|
|
704
|
+
...p.post,
|
|
705
|
+
is_collect: nType === 1 ? 1 : 0
|
|
706
|
+
}
|
|
707
|
+
} : p);
|
|
708
|
+
});
|
|
709
|
+
this.setData({
|
|
710
|
+
posts: newPosts
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// 可选:同步其他页面(首页 / 帖子详情页)
|
|
715
|
+
const pages = getCurrentPages();
|
|
716
|
+
pages.forEach(pg => {
|
|
717
|
+
if (!pg?.data?.posts) return;
|
|
718
|
+
const pgPosts = pg.data.posts;
|
|
719
|
+
if (Array.isArray(pgPosts)) {
|
|
720
|
+
pg.setData({
|
|
721
|
+
posts: pgPosts.map(p => p.post.id === post.id ? {
|
|
722
|
+
...p,
|
|
723
|
+
post: {
|
|
724
|
+
...p.post,
|
|
725
|
+
is_collect: nType === 1 ? 1 : 0
|
|
726
|
+
}
|
|
727
|
+
} : p)
|
|
728
|
+
});
|
|
729
|
+
} else if (typeof pgPosts === 'object') {
|
|
730
|
+
const newObj = {};
|
|
731
|
+
Object.keys(pgPosts).forEach(k => {
|
|
732
|
+
newObj[k] = pgPosts[k].map(p => p.post.id === post.id ? {
|
|
733
|
+
...p,
|
|
734
|
+
post: {
|
|
735
|
+
...p.post,
|
|
736
|
+
is_collect: nType === 1 ? 1 : 0
|
|
737
|
+
}
|
|
738
|
+
} : p);
|
|
739
|
+
});
|
|
740
|
+
pg.setData({
|
|
741
|
+
posts: newObj
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
this.onCloseMoreSheet();
|
|
746
|
+
} else {
|
|
747
|
+
wx.showToast({
|
|
748
|
+
title: res.msg || (nType === 1 ? '收藏失败' : '取消收藏失败'),
|
|
749
|
+
icon: 'error'
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
} catch (err) {
|
|
754
|
+
wx.hideLoading();
|
|
755
|
+
wx.showToast({
|
|
756
|
+
title: '网络错误,请稍后重试',
|
|
757
|
+
icon: 'error'
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
},
|
|
761
|
+
|
|
762
|
+
onFollowChanged(e) {
|
|
763
|
+
const {
|
|
764
|
+
userId,
|
|
765
|
+
isFans
|
|
766
|
+
} = e.detail;
|
|
767
|
+
|
|
768
|
+
// 更新顶部用户信息
|
|
769
|
+
if (this.data.userDetail?.user?.id === userId) {
|
|
770
|
+
this.setData({
|
|
771
|
+
'userDetail.user.is_fans': isFans ? 1 : 0
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// 更新帖子列表里的关注状态
|
|
776
|
+
const updatedPosts = {};
|
|
777
|
+
if (Array.isArray(this.data.posts)) {
|
|
778
|
+
// 如果 posts 是数组
|
|
779
|
+
updatedPosts.posts = this.data.posts.map(p => {
|
|
780
|
+
if (p.user.id === userId) {
|
|
781
|
+
p.user.is_fans = isFans ? 1 : 0;
|
|
782
|
+
}
|
|
783
|
+
return p;
|
|
784
|
+
});
|
|
785
|
+
} else if (this.data.posts && typeof this.data.posts === 'object') {
|
|
786
|
+
// 如果 posts 是对象,每个 value 都是数组
|
|
787
|
+
Object.keys(this.data.posts).forEach(key => {
|
|
788
|
+
updatedPosts[`posts.${key}`] = this.data.posts[key].map(p => {
|
|
789
|
+
if (p.user.id === userId) {
|
|
790
|
+
p.user.is_fans = isFans ? 1 : 0;
|
|
791
|
+
}
|
|
792
|
+
return p;
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
this.setData(updatedPosts);
|
|
798
|
+
|
|
799
|
+
wx.showToast({
|
|
800
|
+
title: isFans ? '关注成功' : '已取消关注',
|
|
801
|
+
icon: 'success'
|
|
802
|
+
});
|
|
803
|
+
},
|
|
804
|
+
|
|
805
|
+
onVideoPlay(e) {
|
|
806
|
+
const postId = e.detail.id;
|
|
807
|
+
const prevId = this.data.currentPlayingVideoId;
|
|
808
|
+
|
|
809
|
+
// 第一次播放 or 点击同一个视频
|
|
810
|
+
if (!prevId || prevId === postId) {
|
|
811
|
+
this.setData({
|
|
812
|
+
currentPlayingVideoId: postId
|
|
813
|
+
});
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
const {
|
|
818
|
+
active
|
|
819
|
+
} = this.data;
|
|
820
|
+
let prevComponent = null;
|
|
821
|
+
|
|
822
|
+
/* ================= 一级 tab:帖子 ================= */
|
|
823
|
+
if (active === 0) {
|
|
824
|
+
const {
|
|
825
|
+
subActive,
|
|
826
|
+
subTabs,
|
|
827
|
+
posts
|
|
828
|
+
} = this.data;
|
|
829
|
+
const filter = subTabs[subActive].filter; // 1 / 2 / 3
|
|
830
|
+
const list = posts[filter] || [];
|
|
831
|
+
|
|
832
|
+
const idx = list.findIndex(
|
|
833
|
+
item => item.post?.id === prevId
|
|
834
|
+
);
|
|
835
|
+
|
|
836
|
+
if (idx !== -1) {
|
|
837
|
+
prevComponent = this.selectComponent(
|
|
838
|
+
`#postItem-${filter}-${idx}`
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/* ================= 一级 tab:评论 ================= */
|
|
844
|
+
else if (active === 1) {
|
|
845
|
+
const {
|
|
846
|
+
comments
|
|
847
|
+
} = this.data;
|
|
848
|
+
|
|
849
|
+
const idx = comments.findIndex(
|
|
850
|
+
item => item.post?.id === prevId
|
|
851
|
+
);
|
|
852
|
+
|
|
853
|
+
if (idx !== -1) {
|
|
854
|
+
prevComponent = this.selectComponent(
|
|
855
|
+
`#postItem-${idx}`
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/* ================= 一级 tab:收藏 ================= */
|
|
861
|
+
else if (active === 2) {
|
|
862
|
+
const {
|
|
863
|
+
collections
|
|
864
|
+
} = this.data;
|
|
865
|
+
|
|
866
|
+
const idx = collections.findIndex(
|
|
867
|
+
item => item.post?.id === prevId
|
|
868
|
+
);
|
|
869
|
+
|
|
870
|
+
if (idx !== -1) {
|
|
871
|
+
prevComponent = this.selectComponent(
|
|
872
|
+
`#postItem-${idx}`
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// 暂停上一个视频
|
|
878
|
+
if (prevComponent && typeof prevComponent.pauseVideo === 'function') {
|
|
879
|
+
prevComponent.pauseVideo();
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// 记录当前播放的视频
|
|
883
|
+
this.setData({
|
|
884
|
+
currentPlayingVideoId: postId
|
|
885
|
+
});
|
|
886
|
+
},
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
onPauseAllVideo() {
|
|
891
|
+
const postId = this.data.currentPlayingVideoId;
|
|
892
|
+
if (!postId) return;
|
|
893
|
+
|
|
894
|
+
let prevComponent = null;
|
|
895
|
+
|
|
896
|
+
// 一级 tab:帖子
|
|
897
|
+
if (this.data.active === 0) {
|
|
898
|
+
const filter = this.data.subTabs?.[this.data.subActive]?.filter || 1;
|
|
899
|
+
const list = this.data.posts[filter] || [];
|
|
900
|
+
const idx = list.findIndex(item => item.post?.id === postId);
|
|
901
|
+
if (idx !== -1) {
|
|
902
|
+
prevComponent = this.selectComponent(`#postItem-${filter}-${idx}`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
// 一级 tab:评论
|
|
906
|
+
else if (this.data.active === 1) {
|
|
907
|
+
const idx = this.data.comments.findIndex(item => item.post?.id === postId);
|
|
908
|
+
if (idx !== -1) {
|
|
909
|
+
prevComponent = this.selectComponent(`#postItem-${idx}`);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
// 一级 tab:收藏
|
|
913
|
+
else if (this.data.active === 2) {
|
|
914
|
+
const idx = this.data.collections.findIndex(item => item.post?.id === postId);
|
|
915
|
+
if (idx !== -1) {
|
|
916
|
+
prevComponent = this.selectComponent(`#postItem-${idx}`);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// 暂停视频
|
|
921
|
+
if (prevComponent && typeof prevComponent.pauseVideo === 'function') {
|
|
922
|
+
prevComponent.pauseVideo();
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// 清掉当前播放标记
|
|
926
|
+
this.setData({
|
|
927
|
+
currentPlayingVideoId: null
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
});
|