index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const uni_modules_zPaging_components_zPaging_js_hooks_useZPaging = require("../../uni_modules/z-paging/components/z-paging/js/hooks/useZPaging.js");
  4. require("../../uni_modules/uview-plus/index.js");
  5. const hooks_useToast = require("../../hooks/useToast.js");
  6. const uni_modules_uviewPlus_libs_function_index = require("../../uni_modules/uview-plus/libs/function/index.js");
  7. if (!Array) {
  8. const _component_up_avatar = common_vendor.resolveComponent("up-avatar");
  9. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  10. const _easycom_z_paging2 = common_vendor.resolveComponent("z-paging");
  11. const _component_up_action_sheet = common_vendor.resolveComponent("up-action-sheet");
  12. (_component_up_avatar + _easycom_uni_icons2 + _easycom_z_paging2 + _component_up_action_sheet)();
  13. }
  14. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  15. const _easycom_z_paging = () => "../../uni_modules/z-paging/components/z-paging/z-paging.js";
  16. if (!Math) {
  17. (_easycom_uni_icons + _easycom_z_paging)();
  18. }
  19. const _sfc_main = {
  20. __name: "index",
  21. props: {
  22. /**
  23. * @param add 新增评论
  24. * @param reply 回复评论
  25. */
  26. commentType: {
  27. type: String,
  28. default: "add"
  29. }
  30. },
  31. emits: ["clickComment", "moveMessageTop", "inputDone"],
  32. setup(__props, { emit: __emit }) {
  33. const { Toast } = hooks_useToast.useToast();
  34. const emit = __emit;
  35. const showActionSheet = common_vendor.ref(false);
  36. function closeActionSheet() {
  37. showActionSheet.value = false;
  38. }
  39. function clickActionSheet(item) {
  40. if (item.value === 0) {
  41. handleDeleteComment();
  42. } else if (item.value === 1) {
  43. let comment = null;
  44. if (pressTwoLevelId.value !== 0) {
  45. const result = findCommentById(pressTwoLevelId.value, "two");
  46. if (result && result.twoItem) {
  47. comment = result.twoItem;
  48. }
  49. } else if (pressOneLevelId.value !== 0) {
  50. comment = findCommentById(pressOneLevelId.value, "one");
  51. }
  52. if (comment) {
  53. handleClickComment(comment);
  54. }
  55. }
  56. showActionSheet.value = false;
  57. }
  58. async function handleDeleteComment() {
  59. try {
  60. await deleteComment(deleteId.value);
  61. Toast({ title: "删除成功" });
  62. removeItemComment();
  63. } catch (error) {
  64. common_vendor.index.__f__("error", "at components/comment/index.vue:236", "deleteComment", error);
  65. } finally {
  66. pressOneLevelId.value = pressTwoLevelId.value = deleteId.value = 0;
  67. }
  68. }
  69. function removeItemComment() {
  70. if (pressOneLevelId.value !== 0 && pressTwoLevelId.value === 0) {
  71. const oneItem = findCommentById(pressOneLevelId.value, "one");
  72. if (oneItem) {
  73. const itemIndex = oneCommentList.value.findIndex(
  74. (v) => v.id === oneItem.id
  75. );
  76. if (itemIndex !== -1) {
  77. oneCommentList.value.splice(itemIndex, 1);
  78. }
  79. }
  80. } else if (pressTwoLevelId.value !== 0) {
  81. const result = findCommentById(pressTwoLevelId.value, "two");
  82. if (result && result.oneItem && result.twoItem) {
  83. const twoIndex = result.oneItem.replyList.findIndex(
  84. (two) => two.id === result.twoItem.id
  85. );
  86. if (twoIndex !== -1) {
  87. result.oneItem.replyList.splice(twoIndex, 1);
  88. }
  89. }
  90. }
  91. }
  92. function findCommentById(id, type = "one") {
  93. if (type === "one") {
  94. return oneCommentList.value.find((item) => item.id === id) || null;
  95. } else if (type === "two") {
  96. for (const oneItem of oneCommentList.value) {
  97. if (Array.isArray(oneItem.replyList)) {
  98. const twoItem = oneItem.replyList.find((two) => two.id === id);
  99. if (twoItem) {
  100. return { oneItem, twoItem };
  101. }
  102. }
  103. }
  104. return null;
  105. }
  106. return null;
  107. }
  108. const deleteId = common_vendor.ref(0);
  109. const pressOneLevelId = common_vendor.ref(0);
  110. const pressTwoLevelId = common_vendor.ref(0);
  111. function longpress(event) {
  112. var _a, _b, _c;
  113. if ((_a = event.currentTarget.dataset) == null ? void 0 : _a.twoLevelId) {
  114. deleteId.value = pressTwoLevelId.value = event.currentTarget.dataset.twoLevelId;
  115. } else if ((_b = event.currentTarget.dataset) == null ? void 0 : _b.oneLevelId) {
  116. deleteId.value = pressOneLevelId.value = (_c = event.currentTarget.dataset) == null ? void 0 : _c.oneLevelId;
  117. }
  118. showActionSheet.value = true;
  119. }
  120. const actionList = common_vendor.computed(() => {
  121. return [
  122. { name: "删除", value: 0 },
  123. { name: "回复", value: 1 }
  124. ];
  125. });
  126. const articleId = common_vendor.ref("");
  127. common_vendor.onLoad((options) => {
  128. if (!options.id)
  129. return;
  130. articleId.value = options.id;
  131. });
  132. const oneCommentList = common_vendor.ref([]);
  133. const parentId = common_vendor.ref(0);
  134. const currentReplyId = common_vendor.ref(0);
  135. const replyId = common_vendor.ref(0);
  136. const oneLevelId = common_vendor.ref(0);
  137. function handleClickComment(comment) {
  138. if (comment.parentId === 0) {
  139. currentReplyId.value = comment.id;
  140. parentId.value = comment.id;
  141. oneLevelId.value = comment.id;
  142. } else {
  143. currentReplyId.value = comment.id;
  144. parentId.value = comment.parentId;
  145. oneLevelId.value = comment.oneLevelId;
  146. }
  147. replyId.value = comment.userId;
  148. emit("clickComment", comment);
  149. }
  150. function closeF2() {
  151. }
  152. const paging = common_vendor.ref(null);
  153. uni_modules_zPaging_components_zPaging_js_hooks_useZPaging.useZPaging(paging);
  154. function queryList(page, pageSize) {
  155. }
  156. common_vendor.ref(false);
  157. const likeAnimationIds = common_vendor.ref([]);
  158. function toUserPage(id) {
  159. common_vendor.index.navigateTo({ url: `/pages/user/personal?id=${id}` });
  160. }
  161. return (_ctx, _cache) => {
  162. return {
  163. a: common_vendor.f(oneCommentList.value, (oneItem, k0, i0) => {
  164. return common_vendor.e({
  165. a: common_vendor.o(($event) => toUserPage(oneItem.userId), oneItem.id),
  166. b: "05fcfa07-1-" + i0 + ",05fcfa07-0",
  167. c: common_vendor.p({
  168. shape: "circle",
  169. src: oneItem.usePicture
  170. }),
  171. d: common_vendor.t(oneItem.userName),
  172. e: oneItem.authorMark
  173. }, oneItem.authorMark ? {} : {}, {
  174. f: common_vendor.o(($event) => toUserPage(oneItem.userId), oneItem.id),
  175. g: common_vendor.t(oneItem.content),
  176. h: common_vendor.t(common_vendor.unref(uni_modules_uviewPlus_libs_function_index.timeFormat)(oneItem.createTime, "yyyy-mm-dd")),
  177. i: common_vendor.o(longpress, oneItem.id),
  178. j: oneItem.id,
  179. k: common_vendor.o(($event) => handleClickComment(oneItem), oneItem.id),
  180. l: !oneItem.likeMark,
  181. m: likeAnimationIds.value.includes(oneItem.id) ? 1 : "",
  182. n: likeAnimationIds.value.includes(oneItem.id) ? 1 : "",
  183. o: "05fcfa07-2-" + i0 + ",05fcfa07-0",
  184. p: oneItem.likeMark,
  185. q: likeAnimationIds.value.includes(oneItem.id) ? 1 : "",
  186. r: likeAnimationIds.value.includes(oneItem.id) ? 1 : "",
  187. s: "05fcfa07-3-" + i0 + ",05fcfa07-0",
  188. t: common_vendor.t(oneItem.likeCount),
  189. v: common_vendor.n(oneItem.replyList && oneItem.replyList.length > 0 ? "child" : ""),
  190. w: oneItem.replyList && oneItem.replyList.length > 0
  191. }, oneItem.replyList && oneItem.replyList.length > 0 ? common_vendor.e({
  192. x: common_vendor.f(oneItem.replyList, (twoItem, idx, i1) => {
  193. return common_vendor.e({
  194. a: "05fcfa07-4-" + i0 + "-" + i1 + ",05fcfa07-0",
  195. b: common_vendor.p({
  196. shape: "circle",
  197. size: "25",
  198. src: twoItem.usePicture
  199. }),
  200. c: common_vendor.t(twoItem.userName),
  201. d: twoItem.authorMark
  202. }, twoItem.authorMark ? {} : {}, {
  203. e: twoItem.replyMark
  204. }, twoItem.replyMark ? {
  205. f: common_vendor.t(twoItem.replyName),
  206. g: common_vendor.t(twoItem.content)
  207. } : {
  208. h: common_vendor.t(twoItem.content)
  209. }, {
  210. i: common_vendor.t(common_vendor.unref(uni_modules_uviewPlus_libs_function_index.timeFormat)(twoItem.createTime, "yyyy-mm-dd")),
  211. j: common_vendor.o(longpress, idx),
  212. k: twoItem.id,
  213. l: !twoItem.likeMark,
  214. m: likeAnimationIds.value.includes(twoItem.id) ? 1 : "",
  215. n: likeAnimationIds.value.includes(twoItem.id) ? 1 : "",
  216. o: "05fcfa07-5-" + i0 + "-" + i1 + ",05fcfa07-0",
  217. p: twoItem.likeMark,
  218. q: likeAnimationIds.value.includes(twoItem.id) ? 1 : "",
  219. r: likeAnimationIds.value.includes(twoItem.id) ? 1 : "",
  220. s: "05fcfa07-6-" + i0 + "-" + i1 + ",05fcfa07-0",
  221. t: common_vendor.t(twoItem.likeCount),
  222. v: idx
  223. });
  224. }),
  225. y: oneItem.id,
  226. z: common_vendor.p({
  227. customPrefix: "iconfont",
  228. size: "18",
  229. color: "#2E2E2E"
  230. }),
  231. A: common_vendor.p({
  232. customPrefix: "iconfont",
  233. size: "18",
  234. color: "#FF2442"
  235. }),
  236. B: oneItem.replyList && oneItem.replyList.length > 0 && oneItem.replyPage.hasMore && oneItem.replyCount > 1
  237. }, oneItem.replyList && oneItem.replyList.length > 0 && oneItem.replyPage.hasMore && oneItem.replyCount > 1 ? {} : {}) : {}, {
  238. C: oneItem.id
  239. });
  240. }),
  241. b: common_vendor.p({
  242. customPrefix: "iconfont",
  243. size: "18",
  244. color: "#2E2E2E"
  245. }),
  246. c: common_vendor.p({
  247. customPrefix: "iconfont",
  248. size: "18",
  249. color: "#FF2442"
  250. }),
  251. d: common_vendor.sr(paging, "05fcfa07-0", {
  252. "k": "paging"
  253. }),
  254. e: common_vendor.o(closeF2),
  255. f: common_vendor.o(queryList),
  256. g: common_vendor.o(($event) => oneCommentList.value = $event),
  257. h: common_vendor.p({
  258. ["use-page-scroll"]: true,
  259. modelValue: oneCommentList.value
  260. }),
  261. i: common_vendor.o(closeActionSheet),
  262. j: common_vendor.o(clickActionSheet),
  263. k: common_vendor.p({
  264. actions: actionList.value,
  265. closeOnClickOverlay: true,
  266. cancelText: "取消",
  267. show: showActionSheet.value
  268. })
  269. };
  270. };
  271. }
  272. };
  273. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-05fcfa07"]]);
  274. wx.createComponent(Component);
  275. //# sourceMappingURL=../../../.sourcemap/mp-weixin/components/comment/index.js.map