From 0a8a88b9462ac07068c25f71f6f072292876c7e9 Mon Sep 17 00:00:00 2001 From: ice909 Date: Wed, 4 Sep 2024 10:14:16 +0800 Subject: [PATCH] feat: optimize post-op code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 减少defineModel使用 之前有点滥用 --- src/pages/thread/post-op.vue | 53 ++++++++++++++++++---------------- src/pages/thread/send-post.vue | 17 +++++------ src/pages/thread/thread.vue | 43 +++++++++++++-------------- 3 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/pages/thread/post-op.vue b/src/pages/thread/post-op.vue index 7dbb5c0..862f4c9 100644 --- a/src/pages/thread/post-op.vue +++ b/src/pages/thread/post-op.vue @@ -118,21 +118,22 @@ const prompt = usePromptStore() const threadInfo = defineModel("threadInfo", { required: true }) const post = defineModel("post", { required: true }) -const showLoginDialog = defineModel("showLoginDialog", { required: true }) -const threadClosed = defineModel("threadClosed", { required: true }) -const isReply = defineModel("isReply", { required: true }) -const replyId = defineModel("replyId", { required: true }) -const replyUserId = defineModel("replyUserId", { required: true }) -const replyNickName = defineModel("replyNickName", { required: true }) -const refreshScroll = defineModel("refreshScroll", { required: true }) -const postRefresh = defineModel("postRefresh", { required: true }) +const replyInfo = defineModel<{ + isReply: boolean, + replyId: number, + replyUserId: number, + replyNickName: string +}>("replyInfo", { required: true }) +const scrollToRostDivider = defineModel("scrollToRostDivider", { required: true }) const winnowPosts = defineModel("winnowPosts", { required: true }) -const winnowPostsRefresh = defineModel("winnowPostsRefresh", { required: true }) -defineProps<{ - isModerator: boolean +const props = defineProps<{ + isModerator: boolean, + threadClosed: boolean }>() +const emit = defineEmits(['login', 'postRefresh', 'winnowPostsRefresh']) + // 版主操作 // 版主删除评论对话框 const showModeratorDelPostDialog = ref(false) @@ -197,9 +198,9 @@ const moderatorDelDialogClosed = async (action: string) => { }) if (!data.code) { prompt.showToast("success", "删除成功") - refreshScroll.value = false - postRefresh.value++ - winnowPostsRefresh.value++ + scrollToRostDivider.value = false + emit("postRefresh") + emit("winnowPostsRefresh") } return true } @@ -234,7 +235,7 @@ const moderatorWinnowDialogClosed = async (action: string) => { } else { prompt.showToast("success", "精选成功") } - winnowPostsRefresh.value++ + emit("winnowPostsRefresh") Taro.pageScrollTo({ selector: ".post-divider", offsetTop: -100 @@ -270,8 +271,8 @@ const authorDelPost = async () => { const { data } = await DeleteThreadPost(post.value.id) if (!data.code) { prompt.showToast("success", "删除成功") - refreshScroll.value = false - postRefresh.value++ + scrollToRostDivider.value = false + emit("postRefresh") } } @@ -289,7 +290,7 @@ const userPostAction = ref({ { name: "举报", callback: async () => { if (!account.is_login) { - showLoginDialog.value = true + emit("login") return } const { data } = await ReportType() @@ -323,23 +324,25 @@ const reportPost = async () => { const replyBtnClicked = () => { if (!account.is_login) { - showLoginDialog.value = true + emit("login") return } - if (threadClosed.value) { + if (props.threadClosed) { prompt.showToast("warn", "帖子已关闭") return } - isReply.value = true - replyId.value = post.value.id - replyUserId.value = post.value.post_user_id - replyNickName.value = post.value.user.nickname + replyInfo.value = { + isReply: true, + replyId: post.value.id, + replyUserId: post.value.post_user_id, + replyNickName: post.value.user.nickname + } } // 点赞评论 const likeBtnClicked = async () => { if (!account.is_login) { - showLoginDialog.value = true + emit("login") return } const { data } = await ThreadUP(post.value.id, "pid") diff --git a/src/pages/thread/send-post.vue b/src/pages/thread/send-post.vue index c6b5b68..e5fd057 100644 --- a/src/pages/thread/send-post.vue +++ b/src/pages/thread/send-post.vue @@ -7,9 +7,9 @@ @verify="postCaptcha.verify"> - + 回复: - {{ replyNickName }} + {{ replyInfo.replyNickName }} @@ -28,7 +28,7 @@