Commit 9662ea89 by lijiabin

【需求 17679】 perf: 继续优化

parent 1a8cb204
...@@ -335,7 +335,7 @@ export const getSecondCommentChildren = (data: { ...@@ -335,7 +335,7 @@ export const getSecondCommentChildren = (data: {
articleId: number articleId: number
}) => { }) => {
return service.request<BackendServicePageResult<CommentItemDto>>({ return service.request<BackendServicePageResult<CommentItemDto>>({
url: `/api/cultureComment/comment/children`, url: `/api/cultureComment/getAllComment`,
method: 'POST', method: 'POST',
data, data,
}) })
......
...@@ -178,6 +178,7 @@ export interface ArticleItemDto { ...@@ -178,6 +178,7 @@ export interface ArticleItemDto {
type: ArticleTypeEnum type: ArticleTypeEnum
userId: string userId: string
viewCount: number viewCount: number
childNum: number
} }
} }
......
...@@ -298,11 +298,13 @@ ...@@ -298,11 +298,13 @@
<el-pagination <el-pagination
v-model:current-page="searchParams.current" v-model:current-page="searchParams.current"
v-model:page-size="searchParams.size" v-model:page-size="searchParams.size"
:total="total" :total="firstComentTotal"
@current-change="handleCurrentChange" @current-change="handleCurrentChange"
@size-change="changePageSize" @size-change="changePageSize"
layout="prev, pager, next, total" layout="prev, pager, next, slot"
/> >
<div>共 {{ total }} 条</div>
</el-pagination>
</div> </div>
</div> </div>
</div> </div>
...@@ -318,7 +320,7 @@ import { ...@@ -318,7 +320,7 @@ import {
getCommentChildren, getCommentChildren,
getSecondCommentList, getSecondCommentList,
} from '@/api' } from '@/api'
import { usePageSearch, useScrollTop, useHintAnimation } from '@/hooks' import { usePageSearch, useScrollTop } from '@/hooks'
import { BooleanFlag } from '@/constants' import { BooleanFlag } from '@/constants'
import type { CommentItemDto } from '@/api' import type { CommentItemDto } from '@/api'
import dayjs from 'dayjs' import dayjs from 'dayjs'
...@@ -333,7 +335,7 @@ const { ...@@ -333,7 +335,7 @@ const {
isQuestion = false, isQuestion = false,
commentId = 0, commentId = 0,
} = defineProps<{ } = defineProps<{
id: number id: number // 文章ID
defaultSize?: number defaultSize?: number
isReal: BooleanFlag isReal: BooleanFlag
isQuestion?: boolean // 如果是问题的话 展示有点不一样 isQuestion?: boolean // 如果是问题的话 展示有点不一样
...@@ -351,7 +353,6 @@ const total = defineModel<number>('total', { required: true, default: 0 }) ...@@ -351,7 +353,6 @@ const total = defineModel<number>('total', { required: true, default: 0 })
const userStore = useUserStore() const userStore = useUserStore()
const { userInfo } = storeToRefs(userStore) const { userInfo } = storeToRefs(userStore)
const userAvatar = computed(() => (isReal ? userInfo.value.avatar : userInfo.value.hiddenAvatar)) const userAvatar = computed(() => (isReal ? userInfo.value.avatar : userInfo.value.hiddenAvatar))
console.log(userAvatar)
const commentRef = useTemplateRef<HTMLElement | null>('commentRef') const commentRef = useTemplateRef<HTMLElement | null>('commentRef')
const commentDialogRef = useTemplateRef<HTMLElement | null>('commentDialogRef') const commentDialogRef = useTemplateRef<HTMLElement | null>('commentDialogRef')
const commentInputRef = useTemplateRef<HTMLElement | null>('commentInputRef') const commentInputRef = useTemplateRef<HTMLElement | null>('commentInputRef')
...@@ -361,13 +362,17 @@ const { handleBackTop } = useScrollTop(commentRef) ...@@ -361,13 +362,17 @@ const { handleBackTop } = useScrollTop(commentRef)
// 回滚到子评论框 // 回滚到子评论框
const { handleBackTop: handleBackTopChildren } = useScrollTop(commentItemRefList) const { handleBackTop: handleBackTopChildren } = useScrollTop(commentItemRefList)
const { triggerAnimation } = useHintAnimation(commentInputRef, { console.log(commentId, 'commentId')
classes: ['scale-bounce', 'highlight', 'shake-x'], const {
}) list,
searchParams,
const { list, searchParams, goToPage, loading, changePageSize, refresh, search } = usePageSearch( goToPage,
isQuestion ? getSecondCommentList : getCommentList, loading,
{ changePageSize,
refresh,
search,
total: firstComentTotal,
} = usePageSearch(isQuestion ? getSecondCommentList : getCommentList, {
defaultParams: { defaultParams: {
...(commentId ...(commentId
? { pid: commentId, sortType: 2 } ? { pid: commentId, sortType: 2 }
...@@ -399,14 +404,10 @@ const { list, searchParams, goToPage, loading, changePageSize, refresh, search } ...@@ -399,14 +404,10 @@ const { list, searchParams, goToPage, loading, changePageSize, refresh, search }
}) })
}, },
immediate, immediate,
}, })
)
const handleCurrentChange = async (e: number) => { const handleCurrentChange = async (e: number) => {
await goToPage(e) await goToPage(e)
handleBackTop() handleBackTop()
setTimeout(() => {
triggerAnimation()
}, 500)
} }
// 自己发出的评论 // 自己发出的评论
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
v-model="visible" v-model="visible"
:title="dialogTitle" :title="dialogTitle"
width="600px" width="600px"
class="comment-reply-dialog rounded-xl overflow-hidden" class="rounded-xl overflow-hidden"
:show-close="false" :show-close="false"
append-to-body append-to-body
destroy-on-close destroy-on-close
...@@ -168,7 +168,8 @@ ...@@ -168,7 +168,8 @@
<input <input
ref="bottomInputRef" ref="bottomInputRef"
v-model="bottomCommentContent" v-model="bottomCommentContent"
type="text" :autosize="{ minRows: 1, maxRows: 4 }"
type="textarea"
class="bg-transparent w-full outline-none text-sm text-gray-700 placeholder-gray-400" class="bg-transparent w-full outline-none text-sm text-gray-700 placeholder-gray-400"
:placeholder="`回复 ${parentComment?.replyUser || '...'}`" :placeholder="`回复 ${parentComment?.replyUser || '...'}`"
@keyup.enter="submitReply(parentComment?.id)" @keyup.enter="submitReply(parentComment?.id)"
...@@ -233,16 +234,14 @@ const scrollContainer = ref<HTMLElement>() ...@@ -233,16 +234,14 @@ const scrollContainer = ref<HTMLElement>()
// --- Actions --- // --- Actions ---
const { list, total, search, searchParams, goToPage, changePageSize } = usePageSearch( const { list, total, search, searchParams, goToPage, changePageSize, refresh, loading } =
getSecondCommentChildren, usePageSearch(getSecondCommentChildren, {
{
defaultParams: { defaultParams: {
articleId: articleId, articleId: articleId,
pid: 0, pid: 0,
}, },
immediate: false, immediate: false,
}, })
)
const open = async (item: CommentItemDto) => { const open = async (item: CommentItemDto) => {
// const { data } = await getSecondCommentChildren({ // const { data } = await getSecondCommentChildren({
......
...@@ -109,9 +109,10 @@ ...@@ -109,9 +109,10 @@
</el-button> </el-button>
<!-- 回答按钮保持不变 --> <!-- 回答按钮保持不变 -->
<!-- 当前最热评论的评论有几条 -->
<el-button size="small" plain @click.stop="handleComment(item, index)"> <el-button size="small" plain @click.stop="handleComment(item, index)">
<el-icon><Edit /></el-icon> <el-icon><Edit /></el-icon>
回答 {{ item.cultureCommentListVo?.childNum || 0 }}条评论
</el-button> </el-button>
<ActionMore class="ml-4" :articleDetail="item" /> <ActionMore class="ml-4" :articleDetail="item" />
...@@ -121,13 +122,13 @@ ...@@ -121,13 +122,13 @@
<!-- 右侧:统计信息 --> <!-- 右侧:统计信息 -->
<div class="flex items-center"> <div class="flex items-center">
<!-- 浏览量 --> <!-- 浏览量 -->
<el-button text class="flex items-center gap-2 text-gray-500"> <!-- <el-button text class="flex items-center gap-2 text-gray-500">
<el-icon><View /></el-icon> <el-icon><View /></el-icon>
<span class="text-sm">{{ item.viewCount || 0 }}</span> <span class="text-sm">{{ item.viewCount || 0 }}</span>
</el-button> </el-button> -->
<!-- 收藏 --> <!-- 收藏 -->
<el-button <!-- <el-button
text text
class="flex items-center gap-2 text-gray-500 transition-colors" class="flex items-center gap-2 text-gray-500 transition-colors"
@click.stop="handleCollect(item)" @click.stop="handleCollect(item)"
...@@ -136,17 +137,17 @@ ...@@ -136,17 +137,17 @@
<span class="text-sm" :class="{ 'text-blue-500': item.hasCollect }">{{ <span class="text-sm" :class="{ 'text-blue-500': item.hasCollect }">{{
item.collectionCount || 0 item.collectionCount || 0
}}</span> }}</span>
</el-button> </el-button> -->
<!-- 评论 --> <!-- 评论 -->
<el-button <!-- <el-button
text text
class="flex items-center gap-2 text-gray-500 transition-colors" class="flex items-center gap-2 text-gray-500 transition-colors"
@click.stop="handleComment(item, index)" @click.stop="handleComment(item, index)"
> >
<el-icon><ChatDotRound /></el-icon> <el-icon><ChatDotRound /></el-icon>
<span class="text-sm">{{ item.replyCount || 0 }}</span> <span class="text-sm">{{ item.cultureCommentListVo?.childNum || 0 }}</span>
</el-button> </el-button> -->
</div> </div>
</div> </div>
<Transition name="fade"> <Transition name="fade">
...@@ -154,7 +155,7 @@ ...@@ -154,7 +155,7 @@
v-show="item.showComment" v-show="item.showComment"
:ref="(e) => (commentRefList[index] = e as InstanceType<typeof Comment>)" :ref="(e) => (commentRefList[index] = e as InstanceType<typeof Comment>)"
:id="item.id" :id="item.id"
:total="item.replyCount" :total="item.cultureCommentListVo?.childNum || 0"
:defaultSize="5" :defaultSize="5"
:isReal="0" :isReal="0"
:immediate="false" :immediate="false"
...@@ -211,19 +212,14 @@ ...@@ -211,19 +212,14 @@
<script setup lang="ts"> <script setup lang="ts">
import Tabs from '@/components/common/Tabs' import Tabs from '@/components/common/Tabs'
import { Star, View, ChatDotRound, Refresh } from '@element-plus/icons-vue' import { Refresh } from '@element-plus/icons-vue'
import Comment from '@/components/common/Comment/index.vue' import Comment from '@/components/common/Comment/index.vue'
import { useScrollTop, usePageSearch } from '@/hooks' import { useScrollTop, usePageSearch } from '@/hooks'
import { TABS_REF_KEY } from '@/constants' import { TABS_REF_KEY } from '@/constants'
import PublishBox from '@/components/common/PublishBox/index.vue' import PublishBox from '@/components/common/PublishBox/index.vue'
import { ArticleTypeEnum } from '@/constants' import { ArticleTypeEnum } from '@/constants'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { import { getArticleList, addOrCanceArticlelCollect, addOrCancelToAnswerList } from '@/api'
getArticleList,
addOrCanceArticlelCollect,
addOrCancelToAnswerList,
getSecondCommentList,
} from '@/api'
import type { ArticleItemDto } from '@/api/article/types' import type { ArticleItemDto } from '@/api/article/types'
import { useQuestionStore } from '@/stores/question' import { useQuestionStore } from '@/stores/question'
import ActionMore from '@/components/common/ActionMore/index.vue' import ActionMore from '@/components/common/ActionMore/index.vue'
...@@ -271,7 +267,7 @@ const handleComment = (item: ArticleItemDto, index: number) => { ...@@ -271,7 +267,7 @@ const handleComment = (item: ArticleItemDto, index: number) => {
} }
const handleCommentSuccess = (item: ArticleItemDto) => { const handleCommentSuccess = (item: ArticleItemDto) => {
item.replyCount++ item.cultureCommentListVo.childNum++
// 同时更新下 // 同时更新下
// 如果已经添加了回答 则改为未添加 并且更新问题数量 // 如果已经添加了回答 则改为未添加 并且更新问题数量
if (item.hasAddQuestion) { if (item.hasAddQuestion) {
......
...@@ -6,18 +6,26 @@ ...@@ -6,18 +6,26 @@
<!-- 标签导航 --> <!-- 标签导航 -->
<div class="bg-white p-4 mb-6 rounded-lg shadow-sm"> <div class="bg-white p-4 mb-6 rounded-lg shadow-sm">
<div class="flex flex-wrap gap-2 mb-2"> <div class="flex flex-wrap gap-2 mb-2">
<el-tag v-for="tag in filterOptions" :key="tag.id" <el-tag
v-for="tag in filterOptions"
:key="tag.id"
:type="tag.id === searchParams.sortLogic ? 'primary' : 'info'" :type="tag.id === searchParams.sortLogic ? 'primary' : 'info'"
:effect="tag.id === searchParams.sortLogic ? 'dark' : 'plain'" class="cursor-pointer" :effect="tag.id === searchParams.sortLogic ? 'dark' : 'plain'"
@click="toggleFilter(tag.id)"> class="cursor-pointer"
@click="toggleFilter(tag.id)"
>
{{ tag.title }} {{ tag.title }}
</el-tag> </el-tag>
</div> </div>
<div class="flex flex-wrap gap-2"> <div class="flex flex-wrap gap-2">
<el-tag v-for="tag in tagList" :key="tag.id" <el-tag
v-for="tag in tagList"
:key="tag.id"
:type="searchParams.tagIdList?.includes(tag.id) ? 'primary' : 'info'" :type="searchParams.tagIdList?.includes(tag.id) ? 'primary' : 'info'"
:effect="searchParams.tagIdList?.includes(tag.id) ? 'dark' : 'plain'" class="cursor-pointer" :effect="searchParams.tagIdList?.includes(tag.id) ? 'dark' : 'plain'"
@click="toggleTag(tag.id)"> class="cursor-pointer"
@click="toggleTag(tag.id)"
>
{{ tag.title }} {{ tag.title }}
</el-tag> </el-tag>
</div> </div>
...@@ -33,40 +41,51 @@ ...@@ -33,40 +41,51 @@
{{ filterText }} {{ filterText }}
</h2> </h2>
</div> </div>
<div class="text-#999 cursor-pointer text-sm" @click=" <div
class="text-#999 cursor-pointer text-sm"
@click="
router.push({ router.push({
path: '/searchPage', path: '/searchPage',
query: { query: {
type: ArticleTypeEnum.PRACTICE, type: ArticleTypeEnum.PRACTICE,
}, },
}) })
"> "
>
查看更多 >> 查看更多 >>
</div> </div>
</div> </div>
<div class="divide-y bg-#fff"> <div class="divide-y bg-#fff">
<div @click="openArticleDetail(item.id)" v-for="item in list" :key="item.id" <div
class="p-4 hover:bg-gray-50 transition-colors cursor-pointer pl-8" > @click="openArticleDetail(item.id)"
<div class="flex gap-3 items-center h-100%" style="border-bottom: 1.5px solid #ddd;"> v-for="item in list"
:key="item.id"
class="p-4 hover:bg-gray-50 transition-colors cursor-pointer pl-8"
>
<div class="flex gap-3 items-center h-100%" style="border-bottom: 1.5px solid #ddd">
<!-- 左侧内容 --> <!-- 左侧内容 -->
<div class="flex-1"> <div class="flex-1">
<h1 class="font-medium text-gray-900 mb-2 leading-relaxed line-clamp-1 text-18px"> <h1 class="font-medium text-gray-900 mb-2 leading-relaxed line-clamp-1 text-lg">
{{ item.title }} {{ item.title }}
</h1> </h1>
<!-- 带图片的内容 --> <!-- 带图片的内容 -->
<div class="flex gap-3 mb-3 align-center" style="border-right: 1.5px solid #ddd;"> <div class="flex gap-3 mb-2 align-center">
<img v-if="item.faceUrl" :src="item.faceUrl" :alt="item.title" <img
class="w-40 h-25 object-cover rounded-lg flex-shrink-0" /> v-if="item.faceUrl"
:src="item.faceUrl"
:alt="item.title"
class="w-40 h-25 object-cover rounded-lg flex-shrink-0"
/>
<div class="flex-1 mr-4"> <div class="flex-1 mr-4">
<div class="text-gray-600 text-sm leading-relaxed line-clamp-4"> <div class="text-gray-600 text-base leading-relaxed line-clamp-4">
{{ item.content }} {{ item.content }}
</div> </div>
</div> </div>
</div> </div>
<!-- 互动数据 --> <!-- 互动数据 -->
<div class="flex items-center gap-5 text-gray-400 text-base mb-3"> <div class="flex items-center gap-5 text-gray-400 text-sm mb-2">
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
<el-icon class="text-sm"> <el-icon class="text-sm">
<View /> <View />
...@@ -111,14 +130,23 @@ ...@@ -111,14 +130,23 @@
<!-- 右侧:分页器 --> <!-- 右侧:分页器 -->
<div class="right"> <div class="right">
<div class="pagination-wrapper bg-white rounded-lg shadow-sm border border-gray-100 p-3"> <div
<el-pagination v-model:current-page="searchParams.current" v-model:page-size="searchParams.size" class="pagination-wrapper bg-white rounded-lg shadow-sm border border-gray-100 p-3"
:page-sizes="[5, 20, 1]" layout="prev, pager, next, jumper, total" :total="total" >
class="custom-pagination" @current-change=" <el-pagination
v-model:current-page="searchParams.current"
v-model:page-size="searchParams.size"
:page-sizes="[5, 20, 1]"
layout="prev, pager, next, jumper, total"
:total="total"
class="custom-pagination"
@current-change="
(e) => { (e) => {
; (handleBackTop(), goToPage(e)) ;(handleBackTop(), goToPage(e))
} }
" @size-change="changePageSize" /> "
@size-change="changePageSize"
/>
</div> </div>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment