93 lines
3.1 KiB
JavaScript
93 lines
3.1 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
if (!Array) {
|
|
const _easycom_up_button2 = common_vendor.resolveComponent("up-button");
|
|
_easycom_up_button2();
|
|
}
|
|
const _easycom_up_button = () => "../../node-modules/uview-plus/components/u-button/u-button.js";
|
|
if (!Math) {
|
|
(CommentItem + _easycom_up_button)();
|
|
}
|
|
const CommentItem = () => "./CommentItem.js";
|
|
const _sfc_main = {
|
|
__name: "discuss",
|
|
setup(__props) {
|
|
const post = common_vendor.ref({
|
|
title: "这是一个讨论帖子",
|
|
content: "这是帖子的内容,大家可以在评论区讨论。"
|
|
});
|
|
const comments = common_vendor.ref([
|
|
{ id: 1, username: "Alice", avatar: "https://via.placeholder.com/50", text: "非常好的帖子!", replies: [], showReplyForm: false, replyText: "" },
|
|
{ id: 2, username: "Bob", avatar: "https://via.placeholder.com/50", text: "同意楼上的观点!", replies: [], showReplyForm: false, replyText: "" }
|
|
]);
|
|
const newComment = common_vendor.ref("");
|
|
const addComment = () => {
|
|
const newId = comments.value.length + 1;
|
|
comments.value.push({
|
|
id: newId,
|
|
username: "匿名用户",
|
|
avatar: "https://via.placeholder.com/50",
|
|
text: newComment.value,
|
|
replies: [],
|
|
showReplyForm: false,
|
|
replyText: ""
|
|
});
|
|
newComment.value = "";
|
|
};
|
|
const handleReply = (commentId, replyText) => {
|
|
const comment = findCommentById(comments.value, commentId);
|
|
if (comment) {
|
|
const newReplyId = comment.replies.length + 1;
|
|
comment.replies.push({
|
|
id: newReplyId,
|
|
username: "匿名用户",
|
|
avatar: "https://via.placeholder.com/50",
|
|
text: replyText,
|
|
replies: [],
|
|
showReplyForm: false,
|
|
replyText: ""
|
|
});
|
|
}
|
|
};
|
|
const findCommentById = (comments2, id) => {
|
|
for (const comment of comments2) {
|
|
if (comment.id === id) {
|
|
return comment;
|
|
}
|
|
const reply = findCommentById(comment.replies, id);
|
|
if (reply) {
|
|
return reply;
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
return (_ctx, _cache) => {
|
|
return {
|
|
a: common_vendor.t(post.value.title),
|
|
b: common_vendor.t(post.value.content),
|
|
c: common_vendor.f(comments.value, (comment, k0, i0) => {
|
|
return {
|
|
a: comment.id,
|
|
b: common_vendor.o(handleReply, comment.id),
|
|
c: "9635802b-0-" + i0,
|
|
d: common_vendor.p({
|
|
comment
|
|
})
|
|
};
|
|
}),
|
|
d: newComment.value,
|
|
e: common_vendor.o(($event) => newComment.value = $event.detail.value),
|
|
f: common_vendor.o(addComment),
|
|
g: common_vendor.p({
|
|
size: "large",
|
|
type: "primary",
|
|
shape: "circle",
|
|
text: "发表"
|
|
})
|
|
};
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-9635802b"], ["__file", "C:/Users/33043/Desktop/文件/work/newStud学习/greenStu/pages/discuss/discuss.vue"]]);
|
|
wx.createPage(MiniProgramPage);
|