feat:增加查询博客相邻记录功能
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { cloudService } from './index'
|
import { cloudService } from './index'
|
||||||
import { IBlog, IBlogCategory, IBlogComment, IBlogSearch, IBlogStats, IQueryBlog } from '@/types/blog'
|
import { IBlog, IBlogAdjacent, IBlogCategory, IBlogComment, IBlogSearch, IBlogStats, IQueryBlog } from '@/types/blog'
|
||||||
|
|
||||||
import qs from 'qs'
|
import qs from 'qs'
|
||||||
import { IPageRecord } from '@/types'
|
import { IPageRecord } from '@/types'
|
||||||
@@ -52,6 +52,12 @@ export const queryLatestBlogApi = (): Promise<IBlog[]> =>
|
|||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const queryBlogAdjacentApi = (blogId: number): Promise<IBlogAdjacent[]> =>
|
||||||
|
cloudService({
|
||||||
|
url: `/blog-api/blog/${blogId}/adjacent`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
|
||||||
export const queryBlogCommentApi = (blogId: number): Promise<IBlogComment[]> =>
|
export const queryBlogCommentApi = (blogId: number): Promise<IBlogComment[]> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: `/blog-api/blog/${blogId}/comment`,
|
url: `/blog-api/blog/${blogId}/comment`,
|
||||||
|
|||||||
@@ -31,6 +31,42 @@
|
|||||||
<span>-------------本文结束♥感谢您的阅读♥给个五星好评吧~~-------------</span>
|
<span>-------------本文结束♥感谢您的阅读♥给个五星好评吧~~-------------</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="blog-navigation">
|
||||||
|
<el-row :gutter="20">
|
||||||
|
<!-- 上一篇 -->
|
||||||
|
<el-col :span="12">
|
||||||
|
<div class="nav-item prev">
|
||||||
|
<el-icon><ArrowLeft /></el-icon>
|
||||||
|
<span class="label">上一篇:</span>
|
||||||
|
<router-link v-if="blogStore.blogAdjacentList[0].id !== 0"
|
||||||
|
:to="`/overview/detail/${blogStore.blogAdjacentList[0].id}`"
|
||||||
|
class="blog-navigation-title">
|
||||||
|
{{ blogStore.blogAdjacentList[0].title }}
|
||||||
|
</router-link>
|
||||||
|
<span v-else>
|
||||||
|
已经是第一篇了~
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<!-- 下一篇 -->
|
||||||
|
<el-col :span="12">
|
||||||
|
<div class="nav-item next">
|
||||||
|
<el-icon><ArrowRight /></el-icon>
|
||||||
|
<router-link v-if="blogStore.blogAdjacentList[1].id !== 0"
|
||||||
|
:to="`/overview/detail/${blogStore.blogAdjacentList[1].id}`"
|
||||||
|
class="blog-navigation-title">
|
||||||
|
{{ blogStore.blogAdjacentList[1].title }}
|
||||||
|
</router-link>
|
||||||
|
<span v-else>
|
||||||
|
已经是最后一篇了~
|
||||||
|
</span>
|
||||||
|
<span class="label">下一篇:</span>
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</div>
|
||||||
|
|
||||||
<blog-comment-edit :parent-id="0"/>
|
<blog-comment-edit :parent-id="0"/>
|
||||||
|
|
||||||
<blog-comment />
|
<blog-comment />
|
||||||
@@ -38,6 +74,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
|
||||||
import BlogLabel from '@/components/Content/BlogLabel.vue'
|
import BlogLabel from '@/components/Content/BlogLabel.vue'
|
||||||
import BlogCommentEdit from '@/components/Comment/BlogCommentEdit.vue'
|
import BlogCommentEdit from '@/components/Comment/BlogCommentEdit.vue'
|
||||||
import BlogComment from '@/components/Comment/BlogComment.vue'
|
import BlogComment from '@/components/Comment/BlogComment.vue'
|
||||||
@@ -47,7 +84,7 @@ import { useBlogStore } from '@/store/blog.ts'
|
|||||||
import { useAppStore } from '@/store/app'
|
import { useAppStore } from '@/store/app'
|
||||||
import { getBasicBlog } from '@/utils/blog/blogUtil.ts'
|
import { getBasicBlog } from '@/utils/blog/blogUtil.ts'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { onMounted } from 'vue'
|
import { onMounted, watch } from 'vue'
|
||||||
|
|
||||||
const blogStore = useBlogStore()
|
const blogStore = useBlogStore()
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
@@ -57,11 +94,61 @@ const currentUrl = new URL(window.location.href)
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const blogId = route.params.id as number
|
const blogId = route.params.id as number
|
||||||
|
await refreshBlog(blogId)
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(() => route.params.id, async (newValue, oldValue) => {
|
||||||
|
if (newValue !== oldValue) {
|
||||||
|
await refreshBlog(newValue as number)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const refreshBlog = async (blogId: number) => {
|
||||||
blogStore.currentBlogId = blogId
|
blogStore.currentBlogId = blogId
|
||||||
await blogStore.queryBlogById(blogId)
|
await blogStore.queryBlogById(blogId)
|
||||||
})
|
await blogStore.queryBlogAdjacent(blogId)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
@use "@/styles/blog/blog.detail.module.scss";
|
@use "@/styles/blog/blog.detail.module.scss";
|
||||||
|
|
||||||
|
.blog-navigation {
|
||||||
|
width: 100%;
|
||||||
|
background-color: var(--color-copyright-bg);
|
||||||
|
|
||||||
|
.nav-item {
|
||||||
|
padding: 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blog-navigation-title {
|
||||||
|
color: var(--el-text-color-primary);
|
||||||
|
text-decoration: none;
|
||||||
|
transition: color 0.3s;
|
||||||
|
font-weight: 500;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.prev {
|
||||||
|
flex-direction: row;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.next {
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ const blogSummaryInfo = reactive({
|
|||||||
* 监听路由变化 如果当前是查看博客 则需要显示博客目录
|
* 监听路由变化 如果当前是查看博客 则需要显示博客目录
|
||||||
*/
|
*/
|
||||||
watch(() => router.currentRoute.value.path, (path) => {
|
watch(() => router.currentRoute.value.path, (path) => {
|
||||||
blogSummaryInfo.isBlogDetail = path.includes('/blog/detail')
|
blogSummaryInfo.isBlogDetail = path.includes('/detail')
|
||||||
if (blogSummaryInfo.isBlogDetail) {
|
if (blogSummaryInfo.isBlogDetail) {
|
||||||
blogSummaryInfo.activePanelName = 'Catalog'
|
blogSummaryInfo.activePanelName = 'Catalog'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import {
|
import {
|
||||||
IBlog, IBlogCategory, IBlogComment,
|
IBlog, IBlogAdjacent, IBlogCategory, IBlogComment,
|
||||||
IBlogLatest, IBlogNestedComment, IBlogSearch, IBlogStats, INewBlog, IQueryBlog
|
IBlogLatest, IBlogNestedComment, IBlogSearch, IBlogStats, INewBlog, IQueryBlog
|
||||||
} from '@/types/blog'
|
} from '@/types/blog'
|
||||||
import {
|
import {
|
||||||
addBlogCommentApi,
|
addBlogCommentApi, queryBlogAdjacentApi,
|
||||||
queryBlogApi, queryBlogByConditionApi, queryBlogByIdApi,
|
queryBlogApi, queryBlogByConditionApi, queryBlogByIdApi,
|
||||||
queryBlogCategoryApi, queryBlogCommentApi, queryBlogStatsApi, queryLatestBlogApi, searchBlogApi
|
queryBlogCategoryApi, queryBlogCommentApi, queryBlogStatsApi, queryLatestBlogApi, searchBlogApi
|
||||||
} from '@/apis/blog.ts'
|
} from '@/apis/blog.ts'
|
||||||
@@ -50,6 +50,7 @@ export const useBlogStore = defineStore('blog', {
|
|||||||
blogCategoryList: [] as IBlogCategory[],
|
blogCategoryList: [] as IBlogCategory[],
|
||||||
blogStats: {} as IBlogStats,
|
blogStats: {} as IBlogStats,
|
||||||
latestBlogList: [] as IBlogLatest[],
|
latestBlogList: [] as IBlogLatest[],
|
||||||
|
blogAdjacentList: [{ id: 0, title: '' }, { id: 0, title: '' }] as IBlogAdjacent[],
|
||||||
queryBlog: {} as IQueryBlog,
|
queryBlog: {} as IQueryBlog,
|
||||||
searchBlogKeyword: '',
|
searchBlogKeyword: '',
|
||||||
isSearching: false,
|
isSearching: false,
|
||||||
@@ -84,6 +85,9 @@ export const useBlogStore = defineStore('blog', {
|
|||||||
await this.queryBlogComment(this.currentBlogId)
|
await this.queryBlogComment(this.currentBlogId)
|
||||||
this.blogNestedCommentList = flattenToTwoLevel(this.blogCommentList)
|
this.blogNestedCommentList = flattenToTwoLevel(this.blogCommentList)
|
||||||
},
|
},
|
||||||
|
async queryBlogAdjacent(blogId: number) {
|
||||||
|
this.blogAdjacentList = await queryBlogAdjacentApi(blogId)
|
||||||
|
},
|
||||||
async queryBlogComment(blogId: number) {
|
async queryBlogComment(blogId: number) {
|
||||||
this.blogCommentList = await queryBlogCommentApi(blogId)
|
this.blogCommentList = await queryBlogCommentApi(blogId)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -245,6 +245,11 @@ $sub-title-font-size: 1rem;
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|
||||||
|
.md-editor-catalog-active {
|
||||||
|
background-color: var(--color-copyright-bg);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
span {
|
span {
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ span, input {
|
|||||||
--color-card-bg: #FFFFFF;
|
--color-card-bg: #FFFFFF;
|
||||||
--color-scroll-card-bg: #F8F9FA;
|
--color-scroll-card-bg: #F8F9FA;
|
||||||
--color-copyright-bg: #F8F8F8;
|
--color-copyright-bg: #F8F8F8;
|
||||||
|
--color-navigation-bg: #F8F8F8;
|
||||||
--color-border-bg: #F5F5F5;
|
--color-border-bg: #F5F5F5;
|
||||||
--color-text: #000000;
|
--color-text: #000000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ export interface IBlogCategory {
|
|||||||
count: number;
|
count: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IBlogAdjacent {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IBlogStats {
|
export interface IBlogStats {
|
||||||
blogCount: number;
|
blogCount: number;
|
||||||
categoryCount: number;
|
categoryCount: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user