index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const hooks_useToast = require("../../hooks/useToast.js");
  4. const api_index = require("../../api/index.js");
  5. const utils_ifApp = require("../../utils/ifApp.js");
  6. if (!Array) {
  7. const _component_up_overlay = common_vendor.resolveComponent("up-overlay");
  8. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  9. const _component_up_tabbar = common_vendor.resolveComponent("up-tabbar");
  10. const _component_up_popup = common_vendor.resolveComponent("up-popup");
  11. (_component_up_overlay + _easycom_uni_icons2 + _component_up_tabbar + _component_up_popup)();
  12. }
  13. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  14. if (!Math) {
  15. (common_vendor.unref(Comment) + _easycom_uni_icons)();
  16. }
  17. const Comment = () => "../../components/comment/index.js";
  18. const _sfc_main = {
  19. __name: "index",
  20. setup(__props) {
  21. const {
  22. Toast
  23. } = hooks_useToast.useToast();
  24. const goShuiBei = () => {
  25. alert(utils_ifApp.browser.versions.iPhone);
  26. if (utils_ifApp.browser.versions.android) {
  27. window.open("appmarket://details?id=com.tencent.mm");
  28. } else {
  29. common_vendor.index.navigateTo({
  30. url: "/pages/index/index"
  31. });
  32. }
  33. };
  34. const instance = common_vendor.getCurrentInstance();
  35. const articleId = common_vendor.ref("");
  36. const detail = common_vendor.ref(null);
  37. common_vendor.computed(() => {
  38. });
  39. common_vendor.onLoad((options) => {
  40. articleId.value = options.id || "101";
  41. fetchArticleDetail();
  42. });
  43. common_vendor.onReady(() => {
  44. common_vendor.index.onKeyboardHeightChange && common_vendor.index.onKeyboardHeightChange(listenerKeybord);
  45. });
  46. common_vendor.onShow(() => {
  47. common_vendor.index.$on("followStateChanged", handleFollowStateChanged);
  48. });
  49. common_vendor.onHide(() => {
  50. common_vendor.index.offKeyboardHeightChange && common_vendor.index.offKeyboardHeightChange(listenerKeybord);
  51. common_vendor.index.$off("followStateChanged", handleFollowStateChanged);
  52. });
  53. function listenerKeybord(res) {
  54. if (res.height === 0) {
  55. keybordHeight.value = 0;
  56. } else {
  57. common_vendor.index.getSystemInfo({
  58. success(systemRes) {
  59. const screenHeight = systemRes.screenHeight;
  60. const windowHeight = systemRes.windowHeight;
  61. const disHeight = screenHeight - windowHeight;
  62. keybordHeight.value = res.height - disHeight;
  63. }
  64. });
  65. }
  66. }
  67. async function fetchArticleDetail() {
  68. try {
  69. common_vendor.index.showLoading({
  70. title: "加载中",
  71. mask: true
  72. });
  73. const {
  74. data
  75. } = await api_index.getGoodDetailId(articleId.value);
  76. detail.value = data;
  77. common_vendor.index.hideLoading();
  78. } catch (error) {
  79. common_vendor.index.__f__("error", "at pages/article_details/index.vue:263", "fetchArticleDetail", error);
  80. common_vendor.index.hideLoading();
  81. }
  82. }
  83. const commentText = common_vendor.ref("");
  84. const showActionPopup = common_vendor.ref(false);
  85. function handleDelete() {
  86. showActionPopup.value = false;
  87. common_vendor.index.showModal({
  88. title: "提示",
  89. content: "确认删除?",
  90. success: async function(res) {
  91. if (res.confirm)
  92. ;
  93. }
  94. });
  95. }
  96. const commentType = common_vendor.ref("add");
  97. const commentInputPl = common_vendor.ref("说点什么...");
  98. function clickComment(comment) {
  99. const username = comment.userName;
  100. commentType.value = "reply";
  101. commentInputPl.value = `回复 @${username}`;
  102. keybordFocus.value = true;
  103. }
  104. const confirmHold = common_vendor.ref(true);
  105. const commentRef = common_vendor.ref();
  106. function handleInputConfirm(event) {
  107. var _a;
  108. if (((_a = commentText.value) == null ? void 0 : _a.trim()) === "") {
  109. confirmHold.value = true;
  110. return Toast({
  111. title: "有内容才能发送哦"
  112. });
  113. }
  114. confirmHold.value = false;
  115. commentRef.value.handleAddComment(commentText.value);
  116. }
  117. function inputDone() {
  118. commentText.value = "";
  119. }
  120. common_vendor.ref();
  121. const commentOffsetTop = common_vendor.ref(0);
  122. common_vendor.watch(
  123. () => detail.value,
  124. async (val, oldVal) => {
  125. if (val && !oldVal) {
  126. await common_vendor.nextTick$1();
  127. const query = common_vendor.index.createSelectorQuery().in(instance.proxy);
  128. query.select(".comment-section").boundingClientRect((data) => {
  129. if (data.top) {
  130. commentOffsetTop.value = data.top - 60;
  131. }
  132. }).exec();
  133. }
  134. }
  135. );
  136. function clickMessageIcon() {
  137. common_vendor.index.pageScrollTo({
  138. scrollTop: commentOffsetTop.value,
  139. // selector: ".fixed-view",
  140. success() {
  141. common_vendor.index.__f__("log", "at pages/article_details/index.vue:376", "success");
  142. },
  143. fail(e) {
  144. common_vendor.index.__f__("error", "at pages/article_details/index.vue:379", `scrollTo error ${e}`);
  145. }
  146. });
  147. }
  148. const collectionLoading = common_vendor.ref(false);
  149. async function handleCollection() {
  150. try {
  151. if (collectionLoading.value)
  152. return;
  153. collectionLoading.value = true;
  154. await setUserState({
  155. type: 1,
  156. bookId: detail.value.id
  157. });
  158. detail.value.collectMark = !detail.value.collectMark;
  159. if (detail.value.collectMark) {
  160. detail.value.collectCount += 1;
  161. } else {
  162. detail.value.collectCount -= 1;
  163. }
  164. collectionLoading.value = false;
  165. } catch (error) {
  166. common_vendor.index.__f__("error", "at pages/article_details/index.vue:404", "collection error", error);
  167. collectionLoading.value = false;
  168. }
  169. }
  170. const likeLoading = common_vendor.ref(false);
  171. const likeAnimation = common_vendor.ref(false);
  172. async function handleLike() {
  173. try {
  174. if (likeLoading.value)
  175. return;
  176. likeLoading.value = true;
  177. await setUserState({
  178. type: 0,
  179. bookId: detail.value.id
  180. });
  181. detail.value.likeMark = !detail.value.likeMark;
  182. if (detail.value.likeMark) {
  183. likeAnimation.value = true;
  184. detail.value.likeCount += 1;
  185. } else {
  186. likeAnimation.value = false;
  187. detail.value.likeCount -= 1;
  188. }
  189. likeLoading.value = false;
  190. } catch (error) {
  191. likeLoading.value = false;
  192. Toast({
  193. title: "点赞失败"
  194. });
  195. common_vendor.index.__f__("error", "at pages/article_details/index.vue:437", "handleLike", error);
  196. }
  197. }
  198. const keybordHeight = common_vendor.ref(0);
  199. const keybordOverlay = common_vendor.ref(true);
  200. const keybordFocus = common_vendor.ref(false);
  201. function commentInputFocus(event) {
  202. }
  203. function commentInputBlur() {
  204. keybordHeight.value = 0;
  205. keybordFocus.value = false;
  206. }
  207. function clickFooterInput() {
  208. common_vendor.index.__f__("log", "at pages/article_details/index.vue:465", "点击了底部Input");
  209. commentInputPl.value = "说点什么...";
  210. commentType.value = "add";
  211. keybordFocus.value = true;
  212. }
  213. function handleFollowStateChanged(data) {
  214. var _a;
  215. if (Number(data.userId) === Number((_a = detail.value) == null ? void 0 : _a.userId)) {
  216. detail.value.followMark = data.followMark;
  217. }
  218. }
  219. return (_ctx, _cache) => {
  220. return common_vendor.e({
  221. a: detail.value
  222. }, detail.value ? {
  223. b: detail.value.coverImage,
  224. c: common_vendor.t(detail.value.title),
  225. d: common_vendor.t(detail.value.content),
  226. e: common_vendor.t(detail.value.publishTime),
  227. f: common_vendor.t(detail.value.commentCount),
  228. g: common_vendor.sr(commentRef, "04f1b7e6-0", {
  229. "k": "commentRef"
  230. }),
  231. h: common_vendor.o(clickComment),
  232. i: common_vendor.o(clickMessageIcon),
  233. j: common_vendor.o(inputDone),
  234. k: common_vendor.p({
  235. commentType: commentType.value
  236. }),
  237. l: keybordFocus.value,
  238. m: confirmHold.value,
  239. n: commentInputPl.value,
  240. o: common_vendor.o(commentInputFocus),
  241. p: common_vendor.o(commentInputBlur),
  242. q: common_vendor.o(handleInputConfirm),
  243. r: commentText.value,
  244. s: common_vendor.o(($event) => commentText.value = $event.detail.value),
  245. t: common_vendor.o(handleInputConfirm),
  246. v: common_vendor.s(keybordHeight.value > 0 ? "--tabbar-bottom:" + keybordHeight.value + "px" : ""),
  247. w: common_vendor.o(($event) => keybordHeight.value = 0),
  248. x: common_vendor.p({
  249. show: keybordOverlay.value
  250. }),
  251. y: common_vendor.n(keybordHeight.value > 0 ? "keybord-fixed" : ""),
  252. z: common_vendor.o(goShuiBei),
  253. A: common_vendor.o(clickFooterInput),
  254. B: common_vendor.p({
  255. type: "heart",
  256. size: "24"
  257. }),
  258. C: common_vendor.t(detail.value.likeCount),
  259. D: common_vendor.o(handleLike),
  260. E: common_vendor.p({
  261. type: "star",
  262. size: "24"
  263. }),
  264. F: common_vendor.t(detail.value.collectCount),
  265. G: common_vendor.o(handleCollection),
  266. H: common_vendor.p({
  267. type: "chat",
  268. size: "24"
  269. }),
  270. I: common_vendor.t(detail.value.commentCount),
  271. J: common_vendor.o(clickMessageIcon),
  272. K: common_vendor.p({
  273. type: "closeempty",
  274. size: "28"
  275. }),
  276. L: common_vendor.o(($event) => showActionPopup.value = false),
  277. M: common_vendor.p({
  278. type: "trash",
  279. size: "28"
  280. }),
  281. N: common_vendor.o(handleDelete),
  282. O: common_vendor.o(($event) => showActionPopup.value = false),
  283. P: common_vendor.p({
  284. show: showActionPopup.value
  285. })
  286. } : {});
  287. };
  288. }
  289. };
  290. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-04f1b7e6"]]);
  291. wx.createPage(MiniProgramPage);
  292. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/article_details/index.js.map