From e07274b7b68fefb056f33d735e0c17a397d0c202 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Thu, 14 Sep 2023 10:32:43 +0800 Subject: [PATCH] feat: topic page aside fold --- src/store/modules/topic.ts | 5 + src/views/topic/KUNGalgameTopicPage.vue | 65 ++++-------- src/views/topic/aside/Aside.vue | 100 ++++++++++++++++++ .../topic/aside/components/AsideActive.vue | 34 ++++++ .../topic/aside/components/AsideBase.vue | 11 ++ .../aside/{ => components}/TopicAsideNav.vue | 0 .../aside/{ => components}/TopicMaster.vue | 0 .../aside/{ => components}/TopicOtherTag.vue | 23 ++-- 8 files changed, 181 insertions(+), 57 deletions(-) create mode 100644 src/views/topic/aside/Aside.vue create mode 100644 src/views/topic/aside/components/AsideActive.vue create mode 100644 src/views/topic/aside/components/AsideBase.vue rename src/views/topic/aside/{ => components}/TopicAsideNav.vue (100%) rename src/views/topic/aside/{ => components}/TopicMaster.vue (100%) rename src/views/topic/aside/{ => components}/TopicOtherTag.vue (92%) diff --git a/src/store/modules/topic.ts b/src/store/modules/topic.ts index 671ec15f..8d5cbd4c 100644 --- a/src/store/modules/topic.ts +++ b/src/store/modules/topic.ts @@ -46,6 +46,9 @@ interface Topic { replyRequest: TopicReplyRequestData // 评论的缓存 commentDraft: CommentDraft + + // 当前页面话题的 tags,用于获取相关话题 + currentTags: string[] } export const useKUNGalgameTopicStore = defineStore({ @@ -74,6 +77,8 @@ export const useKUNGalgameTopicStore = defineStore({ to_uid: 0, content: '', }, + + currentTags: [], }), actions: { // 左侧相同标签下的其它话题 diff --git a/src/views/topic/KUNGalgameTopicPage.vue b/src/views/topic/KUNGalgameTopicPage.vue index ca38eaf6..a7f729f5 100644 --- a/src/views/topic/KUNGalgameTopicPage.vue +++ b/src/views/topic/KUNGalgameTopicPage.vue @@ -8,19 +8,12 @@ import { defineAsyncComponent, onBeforeMount, computed, + provide, } from 'vue' import { onBeforeRouteLeave } from 'vue-router' -import TopicAsideNav from './aside/TopicAsideNav.vue' - -// 相同标签下的其它话题 -import TopicOtherTag from './aside/TopicOtherTag.vue' - -// 楼主的其它话题 -import TopicMaster from './aside/TopicMaster.vue' - -// 导入 Footer -import KUNGalgameFooter from '@/components/KUNGalgameFooter.vue' +// Aside +import Aside from './aside/Aside.vue' import Master from './components/Master.vue' import Reply from './components/Reply.vue' // 异步导入回复面板 @@ -48,6 +41,9 @@ const topicStore = useKUNGalgameTopicStore() const requestData = storeToRefs(useKUNGalgameTopicStore()) +const { showKUNGalgamePageWidth } = storeToRefs(settingsStore) +const { isShowAdvance, isEdit, currentTags } = storeToRefs(topicStore) + // 在组件挂载时调用 fetchTopics 获取话题数据(watch 大法好!) // watch( // [requestData.keywords, requestData.sortField, requestData.sortOrder], @@ -63,28 +59,33 @@ const tid = computed(() => { // 单个话题数据 const topicData = ref() - // 单个话题的回复数据 const repliesData = ref([]) -/** 这里拿到的已经是后端返回回来的 data 数据了 */ -onMounted(async () => { +const fetchTopicData = async () => { // 获取单个话题的数据 const topicResponseData = ( await useKUNGalgameTopicStore().getTopicByTid(tid.value) ).data - topicData.value = topicResponseData +} +const fetchReplyData = async () => { // 懒加载获取单个话题下面的回复数据 const replyResponseData = ( await useKUNGalgameTopicStore().getReplies(tid.value) ).data repliesData.value = replyResponseData -}) +} -const { showKUNGalgamePageWidth } = storeToRefs(settingsStore) -const { isShowAdvance, isEdit } = storeToRefs(topicStore) +/** 这里拿到的已经是后端返回回来的 data 数据了 */ +onMounted(async () => { + await fetchTopicData() + await fetchReplyData() + if (topicData.value?.tags) { + currentTags.value = topicData.value?.tags + } +}) /* 话题界面的页面宽度 */ const topicPageWidth = computed(() => { @@ -115,17 +116,10 @@ onBeforeMount(() => {
-
- - - - -
+ +