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.
Files changed (309) hide show
  1. package/app.js +22 -0
  2. package/app.json +53 -0
  3. package/app.wxss +15 -0
  4. package/assets/file/badwords.js +63008 -0
  5. package/assets/file/rules.js +38 -0
  6. package/assets/images/emoji/smile001.png +0 -0
  7. package/assets/images/emoji/smile002.png +0 -0
  8. package/assets/images/emoji/smile003.png +0 -0
  9. package/assets/images/emoji/smile004.png +0 -0
  10. package/assets/images/emoji/smile005.png +0 -0
  11. package/assets/images/emoji/smile006.png +0 -0
  12. package/assets/images/emoji/smile007.png +0 -0
  13. package/assets/images/emoji/smile008.png +0 -0
  14. package/assets/images/emoji/smile009.png +0 -0
  15. package/assets/images/emoji/smile010.png +0 -0
  16. package/assets/images/emoji/smile011.png +0 -0
  17. package/assets/images/emoji/smile012.png +0 -0
  18. package/assets/images/emoji/smile013.png +0 -0
  19. package/assets/images/emoji/smile014.png +0 -0
  20. package/assets/images/emoji/smile015.png +0 -0
  21. package/assets/images/emoji/smile016.png +0 -0
  22. package/assets/images/emoji/smile017.png +0 -0
  23. package/assets/images/emoji/smile018.png +0 -0
  24. package/assets/images/emoji/smile019.png +0 -0
  25. package/assets/images/emoji/smile020.png +0 -0
  26. package/assets/images/emoji/smile021.png +0 -0
  27. package/assets/images/emoji/smile022.png +0 -0
  28. package/assets/images/emoji/smile023.png +0 -0
  29. package/assets/images/emoji/smile024.png +0 -0
  30. package/assets/images/emoji/smile025.png +0 -0
  31. package/assets/images/emoji/smile026.png +0 -0
  32. package/assets/images/emoji/smile027.png +0 -0
  33. package/assets/images/emoji/smile028.png +0 -0
  34. package/assets/images/emoji/smile029.png +0 -0
  35. package/assets/images/emoji/smile030.png +0 -0
  36. package/assets/images/emoji/smile031.png +0 -0
  37. package/assets/images/emoji/smile032.png +0 -0
  38. package/assets/images/emoji/smile033.png +0 -0
  39. package/assets/images/emoji/smile034.png +0 -0
  40. package/assets/images/emoji/smile035.png +0 -0
  41. package/assets/images/emoji/smile036.png +0 -0
  42. package/assets/images/emoji/smile037.png +0 -0
  43. package/assets/images/emoji/smile038.png +0 -0
  44. package/assets/images/emoji/smile039.png +0 -0
  45. package/assets/images/emoji/smile040.png +0 -0
  46. package/assets/images/emoji/smile041.png +0 -0
  47. package/assets/images/emoji/smile042.png +0 -0
  48. package/assets/images/emoji/smile043.png +0 -0
  49. package/assets/images/emoji/smile044.png +0 -0
  50. package/assets/images/emoji/smile045.png +0 -0
  51. package/assets/images/emoji/smile046.png +0 -0
  52. package/assets/images/emoji/smile047.png +0 -0
  53. package/assets/images/emoji/smile048.png +0 -0
  54. package/assets/images/emoji/smile049.png +0 -0
  55. package/assets/images/emoji/smile050.png +0 -0
  56. package/assets/images/emoji/smile051.png +0 -0
  57. package/assets/images/emoji/smile052.png +0 -0
  58. package/assets/images/icons/age1.png +0 -0
  59. package/assets/images/icons/age2.png +0 -0
  60. package/assets/images/icons/age3.png +0 -0
  61. package/assets/images/icons/attachment.png +0 -0
  62. package/assets/images/icons/clear.png +0 -0
  63. package/assets/images/icons/edit_input.png +0 -0
  64. package/assets/images/icons/header_placeholder.png +0 -0
  65. package/assets/images/icons/home_collect.png +0 -0
  66. package/assets/images/icons/home_collected.png +0 -0
  67. package/assets/images/icons/home_comment.png +0 -0
  68. package/assets/images/icons/home_like.png +0 -0
  69. package/assets/images/icons/home_liked.png +0 -0
  70. package/assets/images/icons/home_message.png +0 -0
  71. package/assets/images/icons/home_share.png +0 -0
  72. package/assets/images/icons/icon_more.png +0 -0
  73. package/assets/images/icons/input_game.png +0 -0
  74. package/assets/images/icons/logo.png +0 -0
  75. package/assets/images/icons/lv1.png +0 -0
  76. package/assets/images/icons/lv2.png +0 -0
  77. package/assets/images/icons/lv3.png +0 -0
  78. package/assets/images/icons/lv4.png +0 -0
  79. package/assets/images/icons/search.png +0 -0
  80. package/assets/images/icons/sex1.png +0 -0
  81. package/assets/images/icons/sex2.png +0 -0
  82. package/assets/images/icons/sign_empty.png +0 -0
  83. package/assets/images/icons/sign_login.png +0 -0
  84. package/assets/wheel/wheel_bg.png +0 -0
  85. package/assets/wheel/wheel_bg2.png +0 -0
  86. package/assets/wheel/wheel_fore.png +0 -0
  87. package/assets/wheel/wheel_to.png +0 -0
  88. package/components/bottomSheet/bottomSheet.js +473 -0
  89. package/components/bottomSheet/bottomSheet.json +3 -0
  90. package/components/bottomSheet/bottomSheet.wxml +73 -0
  91. package/components/bottomSheet/bottomSheet.wxss +238 -0
  92. package/components/experience-item/experience-item.js +105 -0
  93. package/components/experience-item/experience-item.json +4 -0
  94. package/components/experience-item/experience-item.wxml +39 -0
  95. package/components/experience-item/experience-item.wxss +110 -0
  96. package/components/grid-item/grid-item.js +8 -0
  97. package/components/grid-item/grid-item.json +4 -0
  98. package/components/grid-item/grid-item.wxml +62 -0
  99. package/components/grid-item/grid-item.wxss +191 -0
  100. package/components/post-item/post-item.js +1085 -0
  101. package/components/post-item/post-item.json +4 -0
  102. package/components/post-item/post-item.wxml +427 -0
  103. package/components/post-item/post-item.wxss +525 -0
  104. package/components/wiki-renderer/wiki-renderer.js +636 -0
  105. package/components/wiki-renderer/wiki-renderer.json +12 -0
  106. package/components/wiki-renderer/wiki-renderer.wxml +150 -0
  107. package/components/wiki-renderer/wiki-renderer.wxss +412 -0
  108. package/components/wiki-tabs/wiki-tabs.js +52 -0
  109. package/components/wiki-tabs/wiki-tabs.json +3 -0
  110. package/components/wiki-tabs/wiki-tabs.wxml +28 -0
  111. package/components/wiki-tabs/wiki-tabs.wxss +43 -0
  112. package/index.js +49 -0
  113. package/package.json +35 -0
  114. package/pages/addGame/addGame.js +454 -0
  115. package/pages/addGame/addGame.json +3 -0
  116. package/pages/addGame/addGame.wxml +71 -0
  117. package/pages/addGame/addGame.wxss +110 -0
  118. package/pages/addSubject/addSubject.js +199 -0
  119. package/pages/addSubject/addSubject.json +4 -0
  120. package/pages/addSubject/addSubject.wxml +78 -0
  121. package/pages/addSubject/addSubject.wxss +85 -0
  122. package/pages/commonLogin/commonLogin.js +269 -0
  123. package/pages/commonLogin/commonLogin.json +4 -0
  124. package/pages/commonLogin/commonLogin.wxml +57 -0
  125. package/pages/commonLogin/commonLogin.wxss +177 -0
  126. package/pages/copyOfficial/copyOfficial.js +25 -0
  127. package/pages/copyOfficial/copyOfficial.json +3 -0
  128. package/pages/copyOfficial/copyOfficial.wxml +22 -0
  129. package/pages/copyOfficial/copyOfficial.wxss +49 -0
  130. package/pages/demo/demo.js +23 -0
  131. package/pages/demo/demo.json +3 -0
  132. package/pages/demo/demo.wxml +8 -0
  133. package/pages/demo/demo.wxss +24 -0
  134. package/pages/game/game.js +1254 -0
  135. package/pages/game/game.json +8 -0
  136. package/pages/game/game.wxml +371 -0
  137. package/pages/game/game.wxss +672 -0
  138. package/pages/home/home.js +665 -0
  139. package/pages/home/home.json +10 -0
  140. package/pages/home/home.wxml +115 -0
  141. package/pages/home/home.wxss +231 -0
  142. package/pages/lottery-winners/lottery-winners.js +60 -0
  143. package/pages/lottery-winners/lottery-winners.json +4 -0
  144. package/pages/lottery-winners/lottery-winners.wxml +53 -0
  145. package/pages/lottery-winners/lottery-winners.wxss +127 -0
  146. package/pages/message/messageCommentsAndAt/messageCommentsAndAt.js +178 -0
  147. package/pages/message/messageCommentsAndAt/messageCommentsAndAt.json +5 -0
  148. package/pages/message/messageCommentsAndAt/messageCommentsAndAt.wxml +93 -0
  149. package/pages/message/messageCommentsAndAt/messageCommentsAndAt.wxss +177 -0
  150. package/pages/message/messageEntire/messageEntire.js +112 -0
  151. package/pages/message/messageEntire/messageEntire.json +4 -0
  152. package/pages/message/messageEntire/messageEntire.wxml +44 -0
  153. package/pages/message/messageEntire/messageEntire.wxss +88 -0
  154. package/pages/message/messageLikeAndCollect/messageLikeAndCollect.js +147 -0
  155. package/pages/message/messageLikeAndCollect/messageLikeAndCollect.json +5 -0
  156. package/pages/message/messageLikeAndCollect/messageLikeAndCollect.wxml +84 -0
  157. package/pages/message/messageLikeAndCollect/messageLikeAndCollect.wxss +166 -0
  158. package/pages/message/messageNewFans/messageNewFans.js +139 -0
  159. package/pages/message/messageNewFans/messageNewFans.json +5 -0
  160. package/pages/message/messageNewFans/messageNewFans.wxml +35 -0
  161. package/pages/message/messageNewFans/messageNewFans.wxss +85 -0
  162. package/pages/officialWebview/officialWebview.js +13 -0
  163. package/pages/officialWebview/officialWebview.json +3 -0
  164. package/pages/officialWebview/officialWebview.wxml +2 -0
  165. package/pages/officialWebview/officialWebview.wxss +1 -0
  166. package/pages/post/post.js +1856 -0
  167. package/pages/post/post.json +6 -0
  168. package/pages/post/post.wxml +694 -0
  169. package/pages/post/post.wxss +1003 -0
  170. package/pages/post-editor/post-editor.js +465 -0
  171. package/pages/post-editor/post-editor.json +4 -0
  172. package/pages/post-editor/post-editor.wxml +63 -0
  173. package/pages/post-editor/post-editor.wxss +195 -0
  174. package/pages/postDialog/postDialog.js +560 -0
  175. package/pages/postDialog/postDialog.json +6 -0
  176. package/pages/postDialog/postDialog.wxml +377 -0
  177. package/pages/postDialog/postDialog.wxss +979 -0
  178. package/pages/report-category/report-category.js +29 -0
  179. package/pages/report-category/report-category.json +4 -0
  180. package/pages/report-category/report-category.wxml +14 -0
  181. package/pages/report-category/report-category.wxss +43 -0
  182. package/pages/report-form/report-form.js +65 -0
  183. package/pages/report-form/report-form.json +3 -0
  184. package/pages/report-form/report-form.wxml +11 -0
  185. package/pages/report-form/report-form.wxss +44 -0
  186. package/pages/sevenDaySignDetail/sevenDaySignDetail.js +273 -0
  187. package/pages/sevenDaySignDetail/sevenDaySignDetail.json +3 -0
  188. package/pages/sevenDaySignDetail/sevenDaySignDetail.wxml +82 -0
  189. package/pages/sevenDaySignDetail/sevenDaySignDetail.wxss +173 -0
  190. package/pages/topic/topic.js +266 -0
  191. package/pages/topic/topic.json +6 -0
  192. package/pages/topic/topic.wxml +77 -0
  193. package/pages/topic/topic.wxss +162 -0
  194. package/pages/user/user.js +939 -0
  195. package/pages/user/user.json +5 -0
  196. package/pages/user/user.wxml +179 -0
  197. package/pages/user/user.wxss +340 -0
  198. package/pages/userDatum/userDatum.js +24 -0
  199. package/pages/userDatum/userDatum.json +4 -0
  200. package/pages/userDatum/userDatum.wxml +36 -0
  201. package/pages/userDatum/userDatum.wxss +41 -0
  202. package/pages/userGameLib/userGameLib.js +105 -0
  203. package/pages/userGameLib/userGameLib.json +4 -0
  204. package/pages/userGameLib/userGameLib.wxml +42 -0
  205. package/pages/userGameLib/userGameLib.wxss +119 -0
  206. package/pages/webview/webview.js +25 -0
  207. package/pages/webview/webview.json +3 -0
  208. package/pages/webview/webview.wxml +22 -0
  209. package/pages/webview/webview.wxss +50 -0
  210. package/pages/wheelActivivty/wheelActivivty.js +492 -0
  211. package/pages/wheelActivivty/wheelActivivty.json +8 -0
  212. package/pages/wheelActivivty/wheelActivivty.wxml +131 -0
  213. package/pages/wheelActivivty/wheelActivivty.wxss +459 -0
  214. package/pages/wiki/wiki.js +138 -0
  215. package/pages/wiki/wiki.json +6 -0
  216. package/pages/wiki/wiki.wxml +20 -0
  217. package/pages/wiki/wiki.wxss +44 -0
  218. package/request/JKRequest.js +177 -0
  219. package/services/home.js +603 -0
  220. package/towxml/config.js +291 -0
  221. package/towxml/decode.js +35 -0
  222. package/towxml/decode.json +11 -0
  223. package/towxml/decode.wxml +137 -0
  224. package/towxml/decode.wxss +0 -0
  225. package/towxml/img/img.js +98 -0
  226. package/towxml/img/img.json +3 -0
  227. package/towxml/img/img.wxml +1 -0
  228. package/towxml/img/img.wxss +0 -0
  229. package/towxml/index.js +19 -0
  230. package/towxml/latex/latex.js +53 -0
  231. package/towxml/latex/latex.json +5 -0
  232. package/towxml/latex/latex.wxml +1 -0
  233. package/towxml/latex/latex.wxss +0 -0
  234. package/towxml/parse/highlight/highlight.js +1 -0
  235. package/towxml/parse/highlight/index.js +8 -0
  236. package/towxml/parse/highlight/languages/bash.js +111 -0
  237. package/towxml/parse/highlight/languages/c-like.js +236 -0
  238. package/towxml/parse/highlight/languages/c.js +22 -0
  239. package/towxml/parse/highlight/languages/css.js +132 -0
  240. package/towxml/parse/highlight/languages/dart.js +134 -0
  241. package/towxml/parse/highlight/languages/go.js +63 -0
  242. package/towxml/parse/highlight/languages/htmlbars.js +80 -0
  243. package/towxml/parse/highlight/languages/java.js +125 -0
  244. package/towxml/parse/highlight/languages/javascript.js +265 -0
  245. package/towxml/parse/highlight/languages/json.js +52 -0
  246. package/towxml/parse/highlight/languages/less.js +148 -0
  247. package/towxml/parse/highlight/languages/nginx.js +101 -0
  248. package/towxml/parse/highlight/languages/php.js +161 -0
  249. package/towxml/parse/highlight/languages/python-repl.js +29 -0
  250. package/towxml/parse/highlight/languages/python.js +131 -0
  251. package/towxml/parse/highlight/languages/scss.js +122 -0
  252. package/towxml/parse/highlight/languages/shell.js +22 -0
  253. package/towxml/parse/highlight/languages/typescript.js +215 -0
  254. package/towxml/parse/highlight/languages/xml.js +139 -0
  255. package/towxml/parse/highlight/style/github.wxss +99 -0
  256. package/towxml/parse/highlight/style/monokai.wxss +70 -0
  257. package/towxml/parse/index.js +118 -0
  258. package/towxml/parse/markdown/index.js +67 -0
  259. package/towxml/parse/markdown/markdown.js +4 -0
  260. package/towxml/parse/markdown/plugins/echarts.js +11 -0
  261. package/towxml/parse/markdown/plugins/emoji.js +2 -0
  262. package/towxml/parse/markdown/plugins/ins.js +1 -0
  263. package/towxml/parse/markdown/plugins/latex.js +158 -0
  264. package/towxml/parse/markdown/plugins/mark.js +1 -0
  265. package/towxml/parse/markdown/plugins/sub.js +1 -0
  266. package/towxml/parse/markdown/plugins/sup.js +1 -0
  267. package/towxml/parse/markdown/plugins/todo.js +147 -0
  268. package/towxml/parse/markdown/plugins/yuml.js +20 -0
  269. package/towxml/parse/parse2/Parser.js +492 -0
  270. package/towxml/parse/parse2/Tokenizer.js +903 -0
  271. package/towxml/parse/parse2/domelementtype/index.js +55 -0
  272. package/towxml/parse/parse2/domhandler/index.js +145 -0
  273. package/towxml/parse/parse2/domhandler/node.js +474 -0
  274. package/towxml/parse/parse2/entities/decode.js +179 -0
  275. package/towxml/parse/parse2/entities/decode_codepoint.js +60 -0
  276. package/towxml/parse/parse2/entities/encode.js +77 -0
  277. package/towxml/parse/parse2/entities/escape.js +112 -0
  278. package/towxml/parse/parse2/entities/generated/decode-data-html.js +9 -0
  279. package/towxml/parse/parse2/entities/generated/decode-data-xml.js +9 -0
  280. package/towxml/parse/parse2/entities/generated/encode-html.js +12 -0
  281. package/towxml/parse/parse2/entities/index.js +137 -0
  282. package/towxml/parse/parse2/index.js +8 -0
  283. package/towxml/style/main.wxss +419 -0
  284. package/towxml/style/theme/dark.wxss +73 -0
  285. package/towxml/style/theme/light.wxss +63 -0
  286. package/towxml/table/table.js +11 -0
  287. package/towxml/table/table.json +6 -0
  288. package/towxml/table/table.wxml +24 -0
  289. package/towxml/table/table.wxss +0 -0
  290. package/towxml/todogroup/todogroup.js +20 -0
  291. package/towxml/todogroup/todogroup.json +6 -0
  292. package/towxml/todogroup/todogroup.wxml +12 -0
  293. package/towxml/todogroup/todogroup.wxss +3 -0
  294. package/towxml/towxml.js +22 -0
  295. package/towxml/towxml.json +6 -0
  296. package/towxml/towxml.wxml +5 -0
  297. package/towxml/towxml.wxss +8 -0
  298. package/towxml/yuml/yuml.js +51 -0
  299. package/towxml/yuml/yuml.json +5 -0
  300. package/towxml/yuml/yuml.wxml +5 -0
  301. package/towxml/yuml/yuml.wxss +0 -0
  302. package/utils/auth.js +17 -0
  303. package/utils/base64.js +67 -0
  304. package/utils/compressImage.js +41 -0
  305. package/utils/exp.js +49 -0
  306. package/utils/formatPost.js +18 -0
  307. package/utils/parseContent.js +191 -0
  308. package/utils/query-select.js +9 -0
  309. package/utils/sensitive.js +82 -0
@@ -0,0 +1,1085 @@
1
+ export const emojiMap = {
2
+ 1: "smile001.png",
3
+ 2: "smile002.png",
4
+ 3: "smile003.png",
5
+ 4: "smile004.png",
6
+ 5: "smile005.png",
7
+ 6: "smile006.png",
8
+ 7: "smile007.png",
9
+ 8: "smile008.png",
10
+ 9: "smile009.png",
11
+ 10: "smile010.png",
12
+ 11: "smile011.png",
13
+ 12: "smile012.png",
14
+ 13: "smile013.png",
15
+ 14: "smile014.png",
16
+ 15: "smile015.png",
17
+ 16: "smile016.png",
18
+ 17: "smile017.png",
19
+ 18: "smile018.png",
20
+ 19: "smile019.png",
21
+ 20: "smile020.png",
22
+ 21: "smile021.png",
23
+ 22: "smile022.png",
24
+ 23: "smile023.png",
25
+ 24: "smile024.png",
26
+ 25: "smile025.png",
27
+ 26: "smile026.png",
28
+ 27: "smile027.png",
29
+ 28: "smile028.png",
30
+ 29: "smile029.png",
31
+ 30: "smile030.png",
32
+ 31: "smile031.png",
33
+ 32: "smile032.png",
34
+ 33: "smile033.png",
35
+ 34: "smile034.png",
36
+ 35: "smile035.png",
37
+ 36: "smile036.png",
38
+ 37: "smile037.png",
39
+ 38: "smile038.png",
40
+ 39: "smile039.png",
41
+ 40: "smile040.png",
42
+ 41: "smile041.png",
43
+ 42: "smile042.png",
44
+ 43: "smile043.png",
45
+ 44: "smile044.png",
46
+ 45: "smile045.png",
47
+ 46: "smile046.png",
48
+ 47: "smile047.png",
49
+ 48: "smile048.png",
50
+ 49: "smile049.png",
51
+ 50: "smile050.png",
52
+ 51: "smile051.png",
53
+ 52: "smile052.png"
54
+ };
55
+
56
+ import {
57
+ followUser,
58
+ likePost,
59
+ deleteContent,
60
+ collectPost,
61
+ setUserPostTop,
62
+ queryPostVideo
63
+ } from "../../services/home"
64
+ import {
65
+ checkLogin
66
+ } from "../../utils/auth"
67
+
68
+
69
+ Component({
70
+ properties: {
71
+ item: Object,
72
+ itemType: {
73
+ type: String,
74
+ value: ''
75
+ }
76
+ },
77
+ data: {
78
+ isOwner: false,
79
+ contentParts: [],
80
+ sharedContentParts: [], // 转发原始帖解析后的内容
81
+ commentedContentParts: [], // 评论格式化内容
82
+ showFull: true,
83
+ needShowReadMore: false, // 是否需要显示全文按钮
84
+ isLongImage: false, //是否是长图
85
+ isSuperLongImage: false, //是否是超长图
86
+ isHorizonImage: false, //是否是长>宽的图
87
+ showSheet: false,
88
+ sheetActions: [{
89
+ name: '删除帖子',
90
+ color: '#ee0a24',
91
+ action: 'delete'
92
+ },
93
+ {
94
+ name: '举报',
95
+ action: 'report'
96
+ },
97
+ {
98
+ name: '收藏',
99
+ action: 'favorite'
100
+ }
101
+ ],
102
+
103
+ showPinButton: false, // 是否显示置顶按钮
104
+ isPinned: 0, // 当前帖是否置顶,1=已置顶,0=未置顶
105
+
106
+ hotContentParts: [], //热评
107
+
108
+ isCurrentPlaying: false, //当前帖子视频是否在播放
109
+
110
+ isVoteEnded: false,
111
+ isLotteryEnded: false,
112
+ },
113
+
114
+
115
+
116
+ observers: {
117
+ 'item.post.vote.end_time, item.post.lottery.end_time': function () {
118
+ this.checkActivityStatus(false);
119
+ },
120
+ 'item.shared.post.vote.end_time, item.shared.post.lottery.end_time': function () {
121
+ this.checkActivityStatus(true);
122
+ },
123
+ 'item.user.id': function (userId) {
124
+ const currentUserId = wx.getStorageSync('appuid');
125
+
126
+ this.setData({
127
+ isOwner: currentUserId && userId && Number(currentUserId) === Number(userId)
128
+ });
129
+ },
130
+ 'item.hot.comment.content': function (content) {
131
+ if (!content) return;
132
+
133
+ const parts = this.parseContent(content);
134
+
135
+ this.setData({
136
+ hotContentParts: parts
137
+ });
138
+ },
139
+ 'item.post.content': function (content) {
140
+ if (content) {
141
+ const parts = this.parseContent(content);
142
+
143
+ // 如果是转发贴,把自己的图片转成 [查看图片]
144
+ if (this.data.item.shared && this.data.item.post.imageArray?.length) {
145
+ this.data.item.post.imageArray.forEach((src, idx) => {
146
+ parts.push({
147
+ text: '[查看图片]',
148
+ type: 'view_img',
149
+ src,
150
+ index: idx,
151
+ from: 'post',
152
+ color: '#406ce3'
153
+ });
154
+ });
155
+ }
156
+
157
+ if (this.data.item.post.title) {
158
+ parts.unshift({
159
+ text: this.data.item.post.title,
160
+ color: '#000',
161
+ type: 'title'
162
+ });
163
+ if (this.data.item.post.vote) {
164
+ parts.push({
165
+ type: 'vote',
166
+ voteData: this.data.item.post.vote
167
+ });
168
+ };
169
+ // 再补一个换行(确保标题独占一行)
170
+ parts.splice(1, 0, {
171
+ type: 'br'
172
+ });
173
+ }
174
+
175
+ this.setData({
176
+ contentParts: parts
177
+ }, () => {
178
+ this.checkNeedShowReadMore();
179
+ });
180
+
181
+ }
182
+ },
183
+ 'item.shared.post.content': function (content) {
184
+ if (content) {
185
+ const parts = this.parseContent(content);
186
+ this.setData({
187
+ sharedContentParts: parts
188
+ });
189
+ }
190
+ },
191
+ 'item.commented': function (commentedArr) {
192
+ if (Array.isArray(commentedArr) && commentedArr.length > 0) {
193
+ const commented = commentedArr[0]; // 取第一个对象
194
+ const parts = [];
195
+
196
+ // 添加 @user.nickname
197
+ if (commented.user?.nickname) {
198
+ parts.push({
199
+ text: `@${commented.user.nickname}`,
200
+ color: '#406ce3',
201
+ type: 'at',
202
+ userId: commented.user.id
203
+ });
204
+ }
205
+
206
+ // 如果有 reply_nickname
207
+ if (commented.post?.reply_nickname) {
208
+ parts.push({
209
+ text: ' 回复 ',
210
+ color: '#333'
211
+ });
212
+ parts.push({
213
+ text: `@${commented.post.reply_nickname}`,
214
+ color: '#406ce3'
215
+ });
216
+ }
217
+
218
+ // 补冒号
219
+ if (commented.post?.status !== 3) {
220
+ parts.push({
221
+ text: ': ',
222
+ color: '#333'
223
+ });
224
+ }
225
+
226
+ // 拼接正文
227
+ if (commented.post?.content) {
228
+
229
+ parts.push(...this.parseContent(commented.post.content));
230
+ }
231
+ if (commented.post?.status === 3) {
232
+ parts.push({
233
+ text: '[原文已被删除]',
234
+ color: '#999',
235
+ type: 'deleted'
236
+ });
237
+ }
238
+
239
+ // 图片数组转成 [查看图片]
240
+ if (commented.post?.images) {
241
+ const imgArray = commented.post.images.split(',');
242
+ imgArray.forEach((src, idx) => {
243
+ parts.push({
244
+ text: '[查看图片]',
245
+ type: 'view_img',
246
+ src,
247
+ index: idx,
248
+ from: 'commented',
249
+ color: '#406ce3'
250
+ });
251
+ });
252
+ }
253
+
254
+ this.setData({
255
+ // needShowReadMore: commented.post.content.length > 200,
256
+ commentedContentParts: parts
257
+ });
258
+ }
259
+ }
260
+ },
261
+ methods: {
262
+
263
+ checkActivityStatus(isShared) {
264
+ const post = isShared ? this.data.item?.shared?.post : this.data.item?.post;
265
+ if (!post) return;
266
+
267
+ const now = Math.floor(Date.now() / 1000); // 当前时间(秒)
268
+
269
+ let isVoteEnded = false;
270
+ let isLotteryEnded = false;
271
+
272
+ // 投票判断
273
+ if (post.vote && post.vote.end_time) {
274
+ isVoteEnded = now >= Number(post.vote.end_time);
275
+ }
276
+
277
+ // 抽奖判断
278
+ if (post.lottery && post.lottery.end_time) {
279
+ isLotteryEnded = now >= Number(post.lottery.end_time);
280
+ }
281
+
282
+ this.setData({
283
+ isVoteEnded,
284
+ isLotteryEnded
285
+ });
286
+ },
287
+
288
+ // 链接跳转
289
+ onJumpUrlTap(e) {
290
+ const url = e.currentTarget.dataset.url;
291
+
292
+ if (!url) return;
293
+ this.triggerEvent('pauseAllVideo')
294
+
295
+ wx.navigateTo({
296
+ url: `/pages/webview/webview?url=${encodeURIComponent(url)}`
297
+ });
298
+ },
299
+ /** 点击 #话题# 跳转 */
300
+ onTopicTap(e) {
301
+ const topicText = e.currentTarget.dataset.topic;
302
+ const topicName = topicText.replace(/#/g, ''); // 去掉首尾 #
303
+ this.triggerEvent('pauseAllVideo')
304
+
305
+ wx.navigateTo({
306
+ url: `/pages/topic/topic?topic_name=${encodeURIComponent(topicName)}`
307
+ });
308
+ },
309
+ gotoWiki(e) {
310
+ const gameId = e.currentTarget.dataset.id
311
+ const name = e.currentTarget.dataset.name
312
+ wx.navigateTo({
313
+ url: `/pages/wiki/wiki?game_id=${gameId}&name=${encodeURIComponent(name)}`
314
+ })
315
+ },
316
+ /** 点击 @某人 跳转 */
317
+ onUserTap(e) {
318
+ const userId = e.currentTarget.dataset.userid;
319
+ if (!userId) return;
320
+ this.triggerEvent('pauseAllVideo')
321
+
322
+ wx.navigateTo({
323
+ url: `/pages/user/user?id=${userId}`
324
+ });
325
+ },
326
+ gotoGameCenter(e) {
327
+ const gameId = e.currentTarget.dataset.id;
328
+ this.triggerEvent('pauseAllVideo')
329
+
330
+ wx.navigateTo({
331
+ url: `/pages/game/game?id=${gameId}`
332
+ });
333
+ },
334
+ goDetail(e) {
335
+
336
+ if (e.target.dataset.video === '1') return
337
+ const postId = e.currentTarget.dataset.id;
338
+ this.triggerEvent('pauseAllVideo')
339
+
340
+
341
+ wx.navigateTo({
342
+ url: `/pages/post/post?id=${postId}`
343
+ });
344
+ },
345
+ goUserDetail(e) {
346
+ const userId = e.currentTarget.dataset.id;
347
+ this.triggerEvent('pauseAllVideo')
348
+
349
+
350
+ wx.navigateTo({
351
+ url: `/pages/user/user?id=${userId}`
352
+ // url: '/pages/customNavPage/customNavPage'
353
+
354
+ });
355
+ },
356
+
357
+ goSharedDetail(e) {
358
+ if (e.target.dataset.video === '1') return
359
+
360
+ const postId = e.currentTarget.dataset.id;
361
+ this.triggerEvent('pauseAllVideo')
362
+
363
+
364
+ wx.navigateTo({
365
+ url: `/pages/post/post?id=${postId}`
366
+ });
367
+ },
368
+ // 关注点击
369
+ onFollowTap(e) {
370
+ this.triggerEvent('pauseAllVideo')
371
+ if (!checkLogin()) return;
372
+
373
+ const user = e.currentTarget.dataset.user;
374
+ const userId = user.id;
375
+ const isFans = user.is_fans ?? 0;
376
+ const nType = isFans === 1 ? 2 : 1;
377
+
378
+ // 调用接口
379
+ followUser(userId, nType).then(res => {
380
+ if (res.code === 0) {
381
+ // 通知父组件
382
+ this.triggerEvent('followChanged', {
383
+ userId,
384
+ isFans: nType === 1 ? 1 : 0
385
+ });
386
+ }
387
+ });
388
+ },
389
+ // 转发点击
390
+ shareTap() {
391
+ this.triggerEvent('pauseAllVideo')
392
+ if (!checkLogin()) return;
393
+
394
+ this.triggerEvent('shareTap', {
395
+ item: this.data.item
396
+ })
397
+
398
+ },
399
+ // 评论点击
400
+ commonTap() {
401
+ this.triggerEvent('pauseAllVideo')
402
+ if (!checkLogin()) return;
403
+
404
+ this.triggerEvent('commentTap', {
405
+ item: this.data.item
406
+ })
407
+ },
408
+ // 点赞点击
409
+ likeTap(e) {
410
+ this.triggerEvent('pauseAllVideo')
411
+ if (!checkLogin()) return;
412
+
413
+ const post = this.data.item.post;
414
+ const isLiked = post.is_like === 1;
415
+ const newLikeStatus = isLiked ? 0 : 1;
416
+ const newLikeCount = isLiked ? post.like_count - 1 : post.like_count + 1;
417
+
418
+ // 1️⃣ 立即更新前端数据(防止点击后延迟)
419
+ this.setData({
420
+ 'item.post.is_like': newLikeStatus,
421
+ 'item.post.like_count': newLikeCount
422
+ });
423
+
424
+ // 2️⃣ 动画效果(缩放+回弹)
425
+ const animation = wx.createAnimation({
426
+ duration: 200,
427
+ timingFunction: 'ease-in-out'
428
+ });
429
+ animation.scale(1.5).step();
430
+ animation.scale(1.0).step();
431
+
432
+ this.setData({
433
+ likeAnimation: animation.export()
434
+ });
435
+
436
+ // 3️⃣ 调用后端接口(type: 1点赞, 2取消点赞)
437
+ likePost(post.id, newLikeStatus === 1 ? 1 : 2).then(res => {
438
+
439
+ if (res.code !== 0) {
440
+ // 如果失败,回滚状态
441
+ this.setData({
442
+ 'item.post.is_like': isLiked ? 1 : 0,
443
+ 'item.post.like_count': post.like_count
444
+ });
445
+
446
+
447
+
448
+
449
+ } else {
450
+ const pages = getCurrentPages();
451
+
452
+ pages.forEach(page => {
453
+ // 首页:更新 posts 中对应用户的 is_fans
454
+ if (page.route === 'pages/home/home') {
455
+
456
+ const posts = page.data.posts.map(p => {
457
+ if (p.post.id === post.id) {
458
+ p.post.is_like = newLikeStatus;
459
+ p.post.like_count = newLikeCount
460
+ }
461
+ return p;
462
+ });
463
+ page.setData({
464
+ posts
465
+ });
466
+ }
467
+
468
+
469
+
470
+
471
+ })
472
+
473
+
474
+ }
475
+ });
476
+ },
477
+
478
+
479
+
480
+ onImageLoad(e) {
481
+ const {
482
+ width,
483
+ height
484
+ } = e.detail;
485
+ if (height / width > 3 && height / width <= 4) {
486
+ this.setData({
487
+ isLongImage: true
488
+ });
489
+ } else if (height / width < 1) {
490
+ this.setData({
491
+ isHorizonImage: true
492
+ });
493
+ } else if (height / width > 4) {
494
+ this.setData({
495
+ isSuperLongImage: true
496
+ });
497
+ }
498
+
499
+ },
500
+ // 转发文字中的 [查看图片] 点击
501
+ onPreviewImage(e) {
502
+ const src = e.currentTarget.dataset.src;
503
+ wx.previewImage({
504
+ current: src, // 当前显示图片的http链接
505
+ urls: [src] // 需要预览的图片http链接列表
506
+ });
507
+ },
508
+
509
+ // 查看大图
510
+ previewImageMultiple(e) {
511
+ const {
512
+ type,
513
+ index,
514
+ from
515
+ } = e.currentTarget.dataset;
516
+ let imgList = [];
517
+ if (type === 'shared') {
518
+ imgList = this.data.item.shared.post.imageArray;
519
+ } else if (type === 'commented') {
520
+ imgList = this.data.item.commented.post.imageArray;
521
+ } else {
522
+ imgList = this.data.item.post.imageArray;
523
+ }
524
+
525
+ wx.previewImage({
526
+ current: imgList[index],
527
+ urls: imgList
528
+ });
529
+ },
530
+
531
+ pushWithLineBreak(parts, text) {
532
+ const segments = text.split(/(\r\n|\n|\r)/);
533
+ segments.forEach(seg => {
534
+ if (seg === '\n' || seg === '\r' || seg === '\r\n') {
535
+ parts.push({
536
+ type: 'br'
537
+ });
538
+ } else if (seg.length > 0) {
539
+ parts.push({
540
+ text: seg,
541
+ color: '#333'
542
+ });
543
+ }
544
+ });
545
+ },
546
+ checkNeedShowReadMore() {
547
+ // 先展开,测量真实高度
548
+ this.setData({
549
+ showFull: true
550
+ }, () => {
551
+ const query = this.createSelectorQuery();
552
+ query.select('#postContent').boundingClientRect(rect => {
553
+ if (!rect) return;
554
+
555
+ const maxHeight = this.rpxToPx(270); // 6 行 px 高
556
+
557
+ const need = rect.height > maxHeight;
558
+
559
+ this.setData({
560
+ needShowReadMore: need,
561
+ showFull: false // 测完高度后再折叠回去
562
+ });
563
+ }).exec();
564
+ });
565
+ },
566
+
567
+ // rpx 转 px(你已经在用这个技巧)
568
+ rpxToPx(rpx) {
569
+ return rpx * wx.getWindowInfo().windowWidth / 750;
570
+ },
571
+ parseContent(content) {
572
+
573
+ const parts = [];
574
+
575
+
576
+ const regex = /(#[^#]+#)|(\{@(.*?)\|(\d+)\})|<font bold=true>|<font bold=false>|<sign_line>|<feature_blog>|<img src='([^']+)'>|<click_img src='[^']+' text='([^']+)'>|<color_grey text='([^']+)'>|<local_img src='([^']+).image'>|<jump_url url='([^']+)'>|(\[\/\d+\])|{\$([^|]+)\|([^}]+)}|{\?([^|]+)\|([^}]+)}/g;
577
+
578
+ let lastIndex = 0,
579
+ match;
580
+ while ((match = regex.exec(content)) !== null) {
581
+ if (match.index > lastIndex) {
582
+ const plainText = content.slice(lastIndex, match.index);
583
+ this.pushWithLineBreak(parts, plainText);
584
+ }
585
+
586
+ if (match[1]) {
587
+ // #话题#
588
+ parts.push({
589
+ text: match[1],
590
+ color: '#406ce3',
591
+ type: 'topic'
592
+ });
593
+ } else if (match[2]) {
594
+ // @用户(带id)
595
+ parts.push({
596
+ text: `@${match[3]}`,
597
+ color: '#406ce3',
598
+ type: 'at',
599
+ userId: match[4] // 从 {@nickname|userId} 中提取的id
600
+ });
601
+ } else if (match[5]) {
602
+ parts.push({
603
+ text: '[图片]',
604
+ src: match[5],
605
+ type: 'img'
606
+ });
607
+ } else if (match[6]) {
608
+ parts.push({
609
+ text: match[6],
610
+ src: match[6],
611
+ type: 'click_img'
612
+ });
613
+ } else if (match[7]) {
614
+ parts.push({
615
+ text: match[7],
616
+ color: '#999'
617
+ });
618
+ } else if (match[8]) {
619
+ parts.push({
620
+ text: '',
621
+ src: match[8],
622
+ type: 'local_img'
623
+ });
624
+ } else if (match[9]) {
625
+ parts.push({
626
+ text: '§网页链接',
627
+ url: match[9],
628
+ type: 'jump_url',
629
+ color: '#406ce3'
630
+ });
631
+ } else if (match[10]) {
632
+ const code = match[10].match(/\[\/(\d+)\]/)[1];
633
+ const file = emojiMap[code];
634
+ if (file) {
635
+ parts.push({
636
+ type: 'emoji',
637
+ src: `../../assets/images/emoji/${file}`
638
+ });
639
+ } else {
640
+ parts.push({
641
+ text: match[10],
642
+ color: '#333'
643
+ });
644
+ }
645
+ } else if (match[11] && match[12]) {
646
+ parts.push({
647
+ text: `$${match[11]}`,
648
+ gameId: match[12],
649
+ type: 'game',
650
+ color: '#406ce3'
651
+ });
652
+ } else if (match[13] && match[14]) {
653
+ parts.push({
654
+ text: `?${match[13]}`,
655
+ guideName: match[13],
656
+ guideGameId: match[14],
657
+ type: 'guide',
658
+ color: '#406ce3'
659
+ });
660
+ } else if (match[0] === '<font bold=true>') {
661
+ parts.push({
662
+ text: '',
663
+ bold: true
664
+ });
665
+ } else if (match[0] === '<font bold=false>') {
666
+ parts.push({
667
+ text: '',
668
+ bold: false
669
+ });
670
+ } else if (match[0] === '<sign_line>') {
671
+ parts.push({
672
+ text: '————',
673
+ type: 'line'
674
+ });
675
+ } else if (match[0] === '<feature_blog>') {
676
+ parts.push({
677
+ text: '[加精]',
678
+ type: 'feature'
679
+ });
680
+ }
681
+
682
+ lastIndex = regex.lastIndex;
683
+ }
684
+
685
+ if (lastIndex < content.length) {
686
+ const plainText = content.slice(lastIndex);
687
+ this.pushWithLineBreak(parts, plainText);
688
+ }
689
+ return parts;
690
+ },
691
+
692
+ showFull() {
693
+ this.setData({
694
+ showFull: true,
695
+ needShowReadMore: false,
696
+ _stopCheckMore: true // 增加一个标记
697
+ });
698
+ },
699
+
700
+ // 点击更多按钮
701
+ onMoreTap() {
702
+ this.triggerEvent('pauseAllVideo')
703
+ if (!checkLogin()) return;
704
+
705
+ this.triggerEvent('moreTap', {
706
+
707
+ item: this.data.item
708
+ });
709
+ },
710
+
711
+ // 点击更多按钮
712
+ // onMoreTap() {
713
+ // const currentUserId = wx.getStorageSync('appuid'); // 当前登录用户id
714
+ // const isOwner = this.data.item.user.id === currentUserId;
715
+
716
+ // // 获取当前页面信息
717
+ // const pages = getCurrentPages();
718
+ // const currentPage = pages[pages.length - 1];
719
+ // const isUserCenterPage = currentPage.route === 'pages/user/user'; // 根据你的路由修改
720
+
721
+ // // 判断是否显示置顶按钮
722
+ // const showPinButton = isUserCenterPage && isOwner;
723
+ // const isPinned = this.data.item.post.is_user_top === 1;
724
+
725
+ // this.setData({
726
+ // showSheet: true,
727
+ // isOwner,
728
+ // showPinButton,
729
+ // isPinned
730
+ // });
731
+ // },
732
+
733
+ onPinTap() {
734
+ const post = this.data.item.post;
735
+ const type = this.data.isPinned ? 2 : 1; // 1置顶,2取消置顶
736
+
737
+ wx.showLoading({
738
+ title: '处理中...'
739
+ });
740
+ setUserPostTop(post.id, type).then(res => {
741
+ wx.hideLoading();
742
+ if (res.code === 0) {
743
+ wx.showToast({
744
+ title: type === 1 ? '置顶成功' : '取消置顶成功',
745
+ icon: 'success'
746
+ });
747
+
748
+ // 更新当前组件状态
749
+ this.setData({
750
+ 'item.post.is_user_top': type === 1 ? 1 : 0,
751
+ isPinned: type === 1 ? 1 : 0
752
+ });
753
+
754
+ this.onCloseSheet();
755
+
756
+ // 如果置顶,则需要移动帖子到列表第一位,取消其他帖子置顶,并滚动到顶部
757
+ if (type === 1) {
758
+ const pages = getCurrentPages();
759
+ const currentPage = pages[pages.length - 1];
760
+
761
+ if (currentPage.route === 'pages/user/user') {
762
+ let postsData = currentPage.data.posts;
763
+
764
+ if (Array.isArray(postsData)) {
765
+ // 先取消其他帖子置顶
766
+ postsData = postsData.map(p => {
767
+ if (p.post.id !== post.id && p.post.is_user_top === 1) {
768
+ p.post.is_user_top = 0;
769
+ }
770
+ return p;
771
+ });
772
+
773
+ // 找到当前帖子在数组中的索引
774
+ const currentIndex = postsData.findIndex(p => p.post.id === post.id);
775
+ if (currentIndex > -1) {
776
+ const [pinnedPost] = postsData.splice(currentIndex, 1);
777
+ pinnedPost.post.is_user_top = 1
778
+ // 插入到数组第一个位置
779
+ postsData.unshift(pinnedPost);
780
+ }
781
+
782
+ currentPage.setData({
783
+ posts: postsData
784
+ });
785
+
786
+ // 页面滚动到顶部
787
+ wx.pageScrollTo({
788
+ scrollTop: 0,
789
+ duration: 300
790
+ });
791
+ } else if (postsData && typeof postsData === 'object') {
792
+ const newPostsObj = {};
793
+ Object.keys(postsData).forEach(key => {
794
+ if (Array.isArray(postsData[key])) {
795
+ // 取消其他帖子置顶
796
+ let arr = postsData[key].map(p => {
797
+ if (p.post.id !== post.id && p.post.is_user_top === 1) {
798
+ p.post.is_user_top = 0;
799
+ }
800
+ return p;
801
+ });
802
+
803
+ // 将当前帖子移动到第一个
804
+ const currentIndex = arr.findIndex(p => p.post.id === post.id);
805
+ if (currentIndex > -1) {
806
+ const [pinnedPost] = arr.splice(currentIndex, 1);
807
+ pinnedPost.post.is_user_top = 1
808
+ arr.unshift(pinnedPost);
809
+ }
810
+
811
+ newPostsObj[key] = arr;
812
+ } else {
813
+ newPostsObj[key] = postsData[key];
814
+ }
815
+ });
816
+
817
+ currentPage.setData({
818
+ posts: newPostsObj
819
+ });
820
+
821
+ wx.pageScrollTo({
822
+ scrollTop: 0,
823
+ duration: 300
824
+ });
825
+ }
826
+ }
827
+ }
828
+ } else {
829
+ wx.showToast({
830
+ title: res.msg || '操作失败',
831
+ icon: 'error'
832
+ });
833
+ }
834
+ });
835
+ },
836
+ // 关闭弹窗
837
+ onCloseSheet() {
838
+ this.setData({
839
+ showSheet: false
840
+ });
841
+ },
842
+
843
+ // 弹窗选项点击
844
+ onDelete() {
845
+ const postId = this.data.item.post.id;
846
+ deleteContent(postId).then(res => {
847
+ if (res.code === 0) {
848
+ wx.showToast({
849
+ title: '删除成功',
850
+ icon: 'success'
851
+ });
852
+
853
+ // 删除父页面列表里的帖子(兼容数组和对象)
854
+ const pages = getCurrentPages();
855
+ const currentPage = pages[pages.length - 1]; // 当前页
856
+
857
+ const postsData = currentPage.data.posts;
858
+ if (Array.isArray(postsData)) {
859
+ // posts 是数组
860
+ currentPage.setData({
861
+ posts: postsData.filter(p => p.post.id !== postId)
862
+ });
863
+ } else if (postsData && typeof postsData === 'object') {
864
+ // posts 是对象,每个 value 都可能是帖子数组
865
+ const newPosts = {};
866
+ Object.keys(postsData).forEach(key => {
867
+ if (Array.isArray(postsData[key])) {
868
+ newPosts[key] = postsData[key].filter(p => p.post.id !== postId);
869
+ } else {
870
+ newPosts[key] = postsData[key]; // 保留原值
871
+ }
872
+ });
873
+ currentPage.setData({
874
+ posts: newPosts
875
+ });
876
+ }
877
+
878
+
879
+ this.triggerEvent('deletePost', {
880
+ post: this.data.item.post
881
+ });
882
+ this.onCloseSheet();
883
+ } else {
884
+ wx.showToast({
885
+ title: res.msg || '删除失败',
886
+ icon: 'error'
887
+ });
888
+ }
889
+ });
890
+ },
891
+
892
+ // 举报帖子
893
+ onReport() {
894
+ this.triggerEvent('pauseAllVideo')
895
+
896
+
897
+ wx.navigateTo({
898
+ url: `/pages/report-category/report-category?postId=${this.data.item.post.id}`,
899
+ })
900
+
901
+ this.triggerEvent('reportPost', {
902
+ post: this.data.item.post
903
+ });
904
+ this.onCloseSheet();
905
+ },
906
+
907
+ // 收藏/取消收藏
908
+ onFavorite() {
909
+ const post = this.data.item.post;
910
+ const nType = post.is_collect === 1 ? 2 : 1; // 1收藏,2取消收藏
911
+
912
+ collectPost(post.id, nType).then(res => {
913
+ if (res.code === 0) {
914
+ wx.showToast({
915
+ title: nType === 1 ? '已收藏' : '取消收藏',
916
+ icon: 'success'
917
+ });
918
+
919
+ // 更新本地状态
920
+ this.setData({
921
+ 'item.post.is_collect': nType === 1 ? 1 : 0
922
+ });
923
+
924
+ this.onCloseSheet();
925
+ } else {
926
+ wx.showToast({
927
+ title: res.msg || (nType === 1 ? '收藏失败' : '取消收藏失败'),
928
+ icon: 'error'
929
+ });
930
+ }
931
+ });
932
+ },
933
+
934
+ onHotLike() {
935
+ this.triggerEvent('pauseAllVideo')
936
+ if (!checkLogin()) return;
937
+
938
+ const hot = this.data.item.hot;
939
+ const comment = hot.comment;
940
+
941
+ const isLiked = comment.is_like === 1;
942
+ const newStatus = isLiked ? 0 : 1;
943
+ const newCount = isLiked ?
944
+ comment.like_count - 1 :
945
+ comment.like_count + 1;
946
+
947
+ // 立即更新 UI
948
+ this.setData({
949
+ 'item.hot.comment.is_like': newStatus,
950
+ 'item.hot.comment.like_count': newCount
951
+ });
952
+ likePost(comment.id, newStatus === 1 ? 1 : 2).then(res => {
953
+ if (res.code !== 0) {
954
+ // 回滚
955
+ this.setData({
956
+ 'item.hot.comment.is_like': isLiked ? 1 : 0,
957
+ 'item.hot.comment.like_count': comment.like_count
958
+ });
959
+ }
960
+ });
961
+ },
962
+
963
+
964
+ // 获取视频链接
965
+ async onBannerVideoPlay(e) {
966
+
967
+ const id = e.currentTarget.dataset.id;
968
+ const type = e.currentTarget.dataset.type;
969
+ const sharedId = e.currentTarget.dataset.sharedid;
970
+
971
+ // 是否是带转发的原始帖的视频
972
+ const isShared = type === 'shared'
973
+ let getVideoId = isShared ? sharedId : id
974
+
975
+ try {
976
+ const res = await queryPostVideo(getVideoId);
977
+
978
+ if (res.code === 0 && res.data) {
979
+ let key = isShared ? 'item.shared.post.videoUrl' : 'item.post.videoUrl';
980
+
981
+ this.setData({
982
+ [key]: res.data,
983
+ isCurrentPlaying: true
984
+ }, () => {
985
+ // 2️⃣ video 渲染完成后再创建 IntersectionObserver
986
+ this.setupVideoObserver();
987
+ })
988
+
989
+ // 此处传的是外层唯一id,也就是当且贴id
990
+ this.triggerEvent('videoPlay', {
991
+ id
992
+ });
993
+
994
+
995
+ } else {
996
+ throw new Error('无视频地址');
997
+ }
998
+ } catch (err) {
999
+ wx.showToast({
1000
+ title: '视频加载失败',
1001
+ icon: 'none'
1002
+ });
1003
+ } finally {}
1004
+ },
1005
+
1006
+ setupVideoObserver() {
1007
+ const postId = this.data.item.post.id;
1008
+ const observer = this.createIntersectionObserver({
1009
+ thresholds: [0.6] // 关注完全不可见
1010
+ });
1011
+
1012
+ observer.relativeToViewport({
1013
+ top: 0,
1014
+ bottom: 0
1015
+ }).observe(
1016
+ `#bannerVideo-${postId}`,
1017
+ (res) => {
1018
+ const videoContext = wx.createVideoContext(`bannerVideo-${postId}`, this);
1019
+ if (res.intersectionRatio <= 0.6) {
1020
+ videoContext.pause();
1021
+ }
1022
+ }
1023
+ );
1024
+ },
1025
+
1026
+
1027
+ handlePlayVideo() {
1028
+
1029
+ const id = this.data.item.post.id;
1030
+ const videoContext = wx.createVideoContext(`bannerVideo-${id}`, this);
1031
+
1032
+ // 统一逻辑:播放前先通知父页面暂停其他视频
1033
+
1034
+ this.triggerEvent('videoPlay', {
1035
+ id
1036
+ });
1037
+
1038
+ // 播放自己
1039
+ videoContext.play();
1040
+
1041
+ // 标记自己为当前播放的视频
1042
+ this.setData({
1043
+ isCurrentPlaying: true
1044
+ });
1045
+ },
1046
+ // 视频暂停事件
1047
+ onVideoPause(e) {
1048
+ this.setData({
1049
+ isCurrentPlaying: false
1050
+ });
1051
+ },
1052
+ // 父页面传进来的暂停事件
1053
+ pauseVideo() {
1054
+ const videoContext = wx.createVideoContext(`bannerVideo-${this.data.item.post.id}`, this);
1055
+ videoContext.pause();
1056
+ },
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+ },
1070
+
1071
+
1072
+
1073
+ // pageLifetimes: {
1074
+ // hide() {
1075
+ // wx.nextTick(() => {
1076
+ // this.pauseVideo();
1077
+ // });
1078
+ // },
1079
+ // show() {
1080
+ // wx.nextTick(() => {
1081
+ // this.pauseVideo();
1082
+ // });
1083
+ // }
1084
+ // }
1085
+ });