|
|
|
@ -200,6 +200,7 @@ import {
|
|
|
|
|
} from '@element-plus/icons-vue'
|
|
|
|
|
import { useUserStore } from '@/stores/user'
|
|
|
|
|
import { getPostDetail, likePost as likePostAPI, getComments, createComment as createCommentAPI, likeComment as likeCommentAPI } from '@/api/forum'
|
|
|
|
|
import { getUserStatsByUserId } from '@/api/user'
|
|
|
|
|
import type { Post, ApiResponse } from '@/types'
|
|
|
|
|
import { MdPreview } from 'md-editor-v3'
|
|
|
|
|
import 'md-editor-v3/lib/style.css'
|
|
|
|
@ -237,8 +238,8 @@ const comments = ref<any[]>([])
|
|
|
|
|
|
|
|
|
|
// 作者统计信息
|
|
|
|
|
const authorStats = ref({
|
|
|
|
|
postCount: 12,
|
|
|
|
|
likeCount: 234
|
|
|
|
|
postCount: 0,
|
|
|
|
|
likeCount: 0
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 计算属性
|
|
|
|
@ -310,6 +311,26 @@ const likeComment = async (comment: any) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载作者统计信息
|
|
|
|
|
const loadAuthorStats = async (userId: number) => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await getUserStatsByUserId(userId) as any as ApiResponse<{
|
|
|
|
|
totalPosts: number
|
|
|
|
|
totalLikes: number
|
|
|
|
|
totalComments: number
|
|
|
|
|
totalViews: number
|
|
|
|
|
}>
|
|
|
|
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
authorStats.value.postCount = response.data.totalPosts
|
|
|
|
|
authorStats.value.likeCount = response.data.totalLikes
|
|
|
|
|
}
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error('加载作者统计信息失败:', error)
|
|
|
|
|
// 失败时保持默认值,不显示错误消息,避免影响用户体验
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载帖子详情
|
|
|
|
|
const loadPost = async () => {
|
|
|
|
|
const postId = Number(route.params.id)
|
|
|
|
@ -332,6 +353,9 @@ const loadPost = async () => {
|
|
|
|
|
isLiked: post.value.isLiked,
|
|
|
|
|
likeCount: post.value.likeCount
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 加载作者统计信息
|
|
|
|
|
await loadAuthorStats(post.value.userId)
|
|
|
|
|
} else {
|
|
|
|
|
ElMessage.error(response.message || '加载帖子失败')
|
|
|
|
|
router.push('/forum')
|
|
|
|
|