feat: topic page aside fold

This commit is contained in:
KUN1007 2023-09-14 10:32:43 +08:00
parent 4ec4eb3222
commit e07274b7b6
8 changed files with 181 additions and 57 deletions

View file

@ -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: {
// 左侧相同标签下的其它话题

View file

@ -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<TopicDetail>()
//
const repliesData = ref<TopicReply[]>([])
/** 这里拿到的已经是后端返回回来的 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(() => {
<div class="container">
<!-- 下方可视内容区的容器 -->
<div class="content-container">
<div class="aside">
<TopicAsideNav />
<TopicOtherTag
v-if="topicData?.tags"
style="margin-bottom: 17px"
:tags="topicData.tags"
/>
<TopicMaster />
<KUNGalgameFooter />
</div>
<!-- 侧边栏 -->
<Aside />
<!-- 内容区 -->
<div class="content">
<Master v-if="topicData" :topicData="topicData" />
<Reply v-if="repliesData" :repliesData="repliesData" />
@ -165,23 +159,6 @@ onBeforeMount(() => {
box-sizing: border-box;
}
/* 左侧内容区 */
.aside {
top: 70px;
position: sticky;
/* 左侧区域的总高度 */
height: 940px;
/* 左侧区域宽度 */
width: 250px;
/* 左侧内容区为弹性盒,方便分成上下两部分 */
display: flex;
flex-shrink: 0;
flex-direction: column;
box-sizing: border-box;
color: var(--kungalgame-font-color-3);
margin-right: 5px;
}
/* 右侧内容区 */
.content {
height: 100%;

View file

@ -0,0 +1,100 @@
<script setup lang="ts">
//
import { Icon } from '@iconify/vue'
// Vue
import { ref, watch } from 'vue'
import AsideActive from './components/AsideActive.vue'
import AsideBase from './components/AsideBase.vue'
// store
import { useKUNGalgameHomeStore } from '@/store/modules/home'
import { storeToRefs } from 'pinia'
const { isActiveMainPageAside } = storeToRefs(useKUNGalgameHomeStore())
const asideWidth = ref('240px')
const handleFold = () => {
isActiveMainPageAside.value = !isActiveMainPageAside.value
}
watch(
isActiveMainPageAside,
() => {
asideWidth.value = isActiveMainPageAside.value ? '250px' : '40px'
},
{ immediate: true }
)
</script>
<template>
<!-- 侧边栏 -->
<div class="aside">
<!-- 侧边栏交互 -->
<div class="nav-aside" @click="handleFold">
<!-- fa 箭头图标字体 -->
<Icon
icon="line-md:arrow-left"
style="font-size: 17px"
v-if="isActiveMainPageAside"
/>
<Icon
icon="line-md:arrow-right"
style="font-size: 17px"
v-if="!isActiveMainPageAside"
/>
<span v-if="isActiveMainPageAside">{{
$tm('mainPage.asideActive.fold')
}}</span>
</div>
<div class="item-active" v-if="isActiveMainPageAside">
<AsideActive />
</div>
<div class="item" v-if="!isActiveMainPageAside">
<AsideBase :isActive="!isActiveMainPageAside" />
</div>
</div>
</template>
<style lang="scss" scoped>
/* 侧边栏部分 */
.aside {
/* 侧边栏距离文章区域的距离 */
margin-right: 5px;
width: v-bind('asideWidth');
/* 侧边栏相对于整体可视部分的占比 */
/* 侧边栏高度 */
height: 100%;
/* 设置侧边栏为弹性盒子 */
display: flex;
/* 方向为竖向 */
flex-direction: column;
transition: 0.5s;
span {
white-space: nowrap;
}
}
/* 侧边栏交互 */
.nav-aside {
height: 40px;
/* 内容居中(折叠左侧区域) */
display: flex;
flex-shrink: 0;
justify-content: center;
align-items: center;
text-align: center;
/* 字体设置 */
font-size: small;
color: var(--kungalgame-font-color-3);
cursor: pointer;
}
/* 激活后的左侧区域 */
.item-active {
display: flex;
flex-grow: 1;
}
/* 未激活的左侧区域 */
.item {
height: 96.6%;
}
</style>

View file

@ -0,0 +1,34 @@
<script setup lang="ts">
import TopicAsideNav from './TopicAsideNav.vue'
import TopicOtherTag from './TopicOtherTag.vue'
import TopicMaster from './TopicMaster.vue'
import KUNGalgameFooter from '@/components/KUNGalgameFooter.vue'
</script>
<template>
<div class="aside">
<TopicAsideNav />
<TopicOtherTag style="margin-bottom: 17px" />
<TopicMaster />
<KUNGalgameFooter />
</div>
</template>
<style lang="scss" scoped>
/* 左侧内容区 */
.aside {
top: 70px;
position: sticky;
/* 左侧区域的总高度 */
height: 940px;
/* 左侧区域宽度 */
width: 100%;
/* 左侧内容区为弹性盒,方便分成上下两部分 */
display: flex;
flex-shrink: 0;
flex-direction: column;
box-sizing: border-box;
color: var(--kungalgame-font-color-3);
margin-right: 5px;
}
</style>

View file

@ -0,0 +1,11 @@
<script setup lang='ts'>
</script>
<template>
<div>AsideBase</div>
</template>
<style lang='scss' scoped>
</style>

View file

@ -2,35 +2,32 @@
这里是楼主的其他话题组件
-->
<script setup lang="ts">
import { ref, onMounted, toRaw } from 'vue'
import { onMounted, ref, toRaw } from 'vue'
import { useRoute } from 'vue-router'
import { TopicAside } from '@/api/index'
// topic store
import { useKUNGalgameTopicStore } from '@/store/modules/topic'
import { useRoute } from 'vue-router'
// tags
const tags = useKUNGalgameTopicStore().currentTags
//
const route = useRoute()
// id
const tid = parseInt(route.params.tid as string)
const props = defineProps<{
tags: string[]
}>()
const tags = toRaw(props.tags)
const topicData = ref<TopicAside[]>()
onMounted(async () => {
const fetchTopicData = async () => {
topicData.value = (
await useKUNGalgameTopicStore().getRelatedTopicsByTags({
tags: tags,
tid: tid,
})
).data
})
}
fetchTopicData()
</script>
<template>