From 2fdc26d2416a499fcfd5f51c78220c728ff8014b Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Sun, 1 Oct 2023 17:19:09 +0800 Subject: [PATCH] feat: upvote --- src/api/topic/index.ts | 12 ++++ src/api/topic/types/action.ts | 9 +++ src/api/topic/types/topic.ts | 1 + src/language/en.ts | 2 + src/language/zh.ts | 1 + src/store/modules/topic.ts | 15 ++++ .../article/components/ArticleContent.vue | 6 +- src/views/bylaw/Bylaw.vue | 16 +++-- src/views/topic/components/Master.vue | 8 ++- src/views/topic/components/MasterFooter.vue | 72 ++++++++++++++++--- 10 files changed, 121 insertions(+), 21 deletions(-) diff --git a/src/api/topic/index.ts b/src/api/topic/index.ts index 3af21aa6..781282f6 100644 --- a/src/api/topic/index.ts +++ b/src/api/topic/index.ts @@ -55,6 +55,18 @@ export async function getTopicByTidApi( } } +// 推话题 +export async function updateTopicUpvoteApi( + request: Action.TopicUpvoteTopicRequestData +): Promise { + const queryParams = objectToQueryParams(request, 'tid') + const url = `/topics/${request.tid}/upvote?${queryParams}` + + const response = fetchPut(url) + + return response +} + // 点赞话题 export async function updateTopicLikeApi( request: Action.TopicLikeTopicRequestData diff --git a/src/api/topic/types/action.ts b/src/api/topic/types/action.ts index 06a9bdf5..4380ae83 100644 --- a/src/api/topic/types/action.ts +++ b/src/api/topic/types/action.ts @@ -2,6 +2,12 @@ * 这是用户对话题的操作,推,点赞,点踩等 */ +// 推,推操作不可撤销 +export interface TopicUpvoteTopicRequestData { + tid: number + to_uid: number +} + // 点赞 export interface TopicLikeTopicRequestData { tid: number @@ -9,5 +15,8 @@ export interface TopicLikeTopicRequestData { isPush: boolean } +// 推话题响应数据的格式 +export type TopicUpvoteTopicResponseData = KUNGalgameResponseData<{}> + // 点赞话题响应数据的格式 export type TopicLikeTopicResponseData = KUNGalgameResponseData<{}> diff --git a/src/api/topic/types/topic.ts b/src/api/topic/types/topic.ts index 484c3e60..c804d81b 100644 --- a/src/api/topic/types/topic.ts +++ b/src/api/topic/types/topic.ts @@ -29,6 +29,7 @@ export interface TopicDetail { status: number share: number[] category: string[] + popularity: number } // 更新话题的请求数据 diff --git a/src/language/en.ts b/src/language/en.ts index f39994f4..ddefe1f5 100644 --- a/src/language/en.ts +++ b/src/language/en.ts @@ -211,6 +211,8 @@ export default { publish: 'Confirm to publish?', publishSuccess: 'Publish Successfully', publishCancel: 'Cancel Publish', + upvote: + 'Are you sure you want to upvote this topic? This will cost you 17 Moe Moe Points', rewrite: 'Confirm to Rewrite?', rewriteSuccess: 'Rewrite Successfully', rewriteCancel: 'Cancel Rewrite', diff --git a/src/language/zh.ts b/src/language/zh.ts index cf37f86b..c6bc1561 100644 --- a/src/language/zh.ts +++ b/src/language/zh.ts @@ -210,6 +210,7 @@ export default { publish: '确认发布吗?', publishSuccess: '发布成功', publishCancel: '取消发布', + upvote: '您确定推这个话题吗,这将会消耗您 17 萌萌点', rewrite: '确认 Rewrite 吗?', rewriteSuccess: 'Rewrite 成功', rewriteCancel: '取消 Rewrite', diff --git a/src/store/modules/topic.ts b/src/store/modules/topic.ts index f1d49a11..0b4f12f3 100644 --- a/src/store/modules/topic.ts +++ b/src/store/modules/topic.ts @@ -13,6 +13,9 @@ import { // 点赞等动作 import { + updateTopicUpvoteApi, + TopicUpvoteTopicRequestData, + TopicUpvoteTopicResponseData, updateTopicLikeApi, TopicLikeTopicRequestData, TopicLikeTopicResponseData, @@ -107,6 +110,18 @@ export const useKUNGalgameTopicStore = defineStore({ return await getTopicByTidApi(tid) }, + // 推话题 + async updateTopicUpvote( + tid: number, + toUid: number + ): Promise { + const requestData: TopicUpvoteTopicRequestData = { + tid: tid, + to_uid: toUid, + } + return await updateTopicUpvoteApi(requestData) + }, + // 点赞话题 async updateTopicLike( tid: number, diff --git a/src/views/Home/content/article/components/ArticleContent.vue b/src/views/Home/content/article/components/ArticleContent.vue index 67488c69..4360f87d 100644 --- a/src/views/Home/content/article/components/ArticleContent.vue +++ b/src/views/Home/content/article/components/ArticleContent.vue @@ -93,11 +93,11 @@ onBeforeUnmount(() => {