From 51edb891ca721a3d0c4aa754958babcc78e2fd27 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Sun, 27 Aug 2023 22:27:13 +0800 Subject: [PATCH] feat: topic page --- src/api/edit/index.ts | 2 +- src/api/topic/index.ts | 10 ++-- src/api/topic/types/topic.ts | 11 ++-- src/router/modules/topic.ts | 3 +- src/store/modules/topic.ts | 22 ++++++-- src/views/edit/components/Button.vue | 9 +++- src/views/topic/KUNGalgameTopicPage.vue | 2 +- .../topic/content/KUNGalgameTopicContent.vue | 49 ++++++++++++------ .../content/components/KUNGalgamerInfo.vue | 1 + src/views/topic/content/components/Master.vue | 13 ++--- src/views/topic/content/components/Reply.vue | 51 ++++++++++++++----- src/views/topic/content/components/Time.vue | 4 +- .../topic/content/components/TopicContent.vue | 31 ----------- .../topic/content/components/TopicFooter.vue | 13 ++--- 14 files changed, 128 insertions(+), 93 deletions(-) delete mode 100644 src/views/topic/content/components/TopicContent.vue diff --git a/src/api/edit/index.ts b/src/api/edit/index.ts index 5b9466c0..2aa75963 100644 --- a/src/api/edit/index.ts +++ b/src/api/edit/index.ts @@ -15,7 +15,7 @@ export async function postEditNewTopicApi( newTopicData ) - // 返回创建好的话题数据 + // 返回创建好的话题 tid return response } catch (error) { // 处理错误 diff --git a/src/api/topic/index.ts b/src/api/topic/index.ts index 27669b22..2aad74f9 100644 --- a/src/api/topic/index.ts +++ b/src/api/topic/index.ts @@ -7,7 +7,7 @@ const topicURLs = { } // 获取单个话题 -export async function getTopicByTid( +export async function getTopicByTidApi( tid: number ): Promise { try { @@ -23,8 +23,8 @@ export async function getTopicByTid( } // 根据话题 id 获取话题回复 -export async function getRepliesByPid( - request: Topic.ReplyRequestData +export async function getRepliesByPidApi( + request: Topic.TopicReplyRequestData ): Promise { try { const url = `${topicURLs.getRepliesByPid}/${request.tid}/reply` @@ -39,8 +39,8 @@ export async function getRepliesByPid( } // 获取一个回复下面的评论 -export async function getCommentsByReplyRid( - request: Topic.ReplyRequestData +export async function getCommentsByReplyRidApi( + request: Topic.TopicReplyRequestData ): Promise { try { const url = `${topicURLs.getRepliesByPid}/${request.tid}/reply` diff --git a/src/api/topic/types/topic.ts b/src/api/topic/types/topic.ts index cd652e51..09bff714 100644 --- a/src/api/topic/types/topic.ts +++ b/src/api/topic/types/topic.ts @@ -42,13 +42,16 @@ export interface TopicReplyRequestData { export interface TopicReply { rid: number tid: number + floor: number r_user: TopicUserInfo to_user: TopicToUserInfo - edited: string + edited: number content: string + upvote: number likes: number dislikes: number - tags: string + tags: string[] + time: number cid: number[] } @@ -58,5 +61,5 @@ export interface TopicComment {} // 获取单个话题响应数据的格式 export type TopicDetailResponseData = KUNGalgameResponseData -// 单个话题回复响应数据的格式 -export type TopicReplyResponseData = KUNGalgameResponseData +// 单个话题回复响应数据的格式,返回的是多条回复数据,是一个数组 +export type TopicReplyResponseData = KUNGalgameResponseData diff --git a/src/router/modules/topic.ts b/src/router/modules/topic.ts index dbf382c0..8556dbf2 100644 --- a/src/router/modules/topic.ts +++ b/src/router/modules/topic.ts @@ -7,11 +7,10 @@ const topic: RouteRecordRaw[] = [ { path: '/topic', component: Layout, - redirect: '/topic/:tid', children: [ { name: 'Topic', - path: 'index', + path: ':tid', // 路由懒加载 component: () => import('@/views/topic/KUNGalgameTopicPage.vue'), // 使路由参数作为组件的 props 传递 diff --git a/src/store/modules/topic.ts b/src/store/modules/topic.ts index 460a5128..af003042 100644 --- a/src/store/modules/topic.ts +++ b/src/store/modules/topic.ts @@ -1,8 +1,12 @@ /* 话题详情的 store */ import { defineStore } from 'pinia' -import { getRepliesByPid } from '@/api/index' -import { TopicReplyRequestData, TopicReplyResponseData } from '@/api/index' +import { getRepliesByPidApi, getTopicByTidApi } from '@/api/index' +import { + TopicDetailResponseData, + TopicReplyRequestData, + TopicReplyResponseData, +} from '@/api/index' // 回复的缓存 interface ReplyDraft { @@ -59,6 +63,18 @@ export const useKUNGalgameTopicStore = defineStore({ }, }), actions: { + // 获取单个话题 + getTopicByTid(tid: number): Promise { + return new Promise((resolve, reject) => { + getTopicByTidApi(tid) + .then((res) => { + resolve(res) + }) + .catch((error) => { + reject(error) + }) + }) + }, // 获取回复 getReplies(tid: number): Promise { return new Promise((resolve, reject) => { @@ -69,7 +85,7 @@ export const useKUNGalgameTopicStore = defineStore({ sortField: this.replyRequest.sortField, sortOrder: this.replyRequest.sortOrder, } - getRepliesByPid(requestData) + getRepliesByPidApi(requestData) .then((res) => { resolve(res) }) diff --git a/src/views/edit/components/Button.vue b/src/views/edit/components/Button.vue index 29c71c7e..d93e4c78 100644 --- a/src/views/edit/components/Button.vue +++ b/src/views/edit/components/Button.vue @@ -41,8 +41,15 @@ const handlePublish = async () => { // 获取创建好话题的 tid const tid = createdTopic.data.tid + console.log(tid) + // 将用户 push 进对应 tid 话题的详情页面 - router.push({ name: 'Topic', params: { tid } }) + router.push({ + name: 'Topic', + params: { + tid: tid, + }, + }) message.info('AlertInfo.edit.publishSuccess') // 清除数据,并不再保存数据,因为此时该话题已被发布,这里使用 pinia 自带的 $reset 重置状态 diff --git a/src/views/topic/KUNGalgameTopicPage.vue b/src/views/topic/KUNGalgameTopicPage.vue index 5ddcb682..f4c13acd 100644 --- a/src/views/topic/KUNGalgameTopicPage.vue +++ b/src/views/topic/KUNGalgameTopicPage.vue @@ -38,9 +38,9 @@ onBeforeMount(() => {