diff --git a/src/api/halo.ts b/src/api/halo.ts index 4a0af96..0b434c8 100644 --- a/src/api/halo.ts +++ b/src/api/halo.ts @@ -14,6 +14,7 @@ import type { IComment, ICommentListReq, ICommentListRes, + ICommentReplyListRes, ILink, ILinkGroup, ILinkListRes, @@ -44,9 +45,8 @@ const COMMENT_WIDGET_CAPTCHA_COOKIES = 'comment-widget-captcha'; */ export function getPostList(params: IPostListReq) { return http.Get>('/apis/api.content.halo.run/v1alpha1/posts', { - query: params, cacheFor: 0, - meta: { requestFrom: RequestFrom.Halo } + meta: { requestFrom: RequestFrom.Halo, query: params } }); } @@ -92,9 +92,8 @@ export function getCategoryList(params: ICategoryListReq) { */ export function getCategoryPostList(name: string, params: IPostListReq) { return http.Get>(`/apis/api.content.halo.run/v1alpha1/categories/${name}/posts`, { - query: params, cacheFor: 0, - meta: { requestFrom: RequestFrom.Halo } + meta: { requestFrom: RequestFrom.Halo, query: params } }); } @@ -137,7 +136,7 @@ export function getPostCommentList(params: ICommentListReq) { * 评论回复列表 */ export function getPostCommentReplyList(commentName: string, params: ICommentListReq) { - return http.Get>(`/apis/api.halo.run/v1alpha1/comments/${commentName}/reply`, { + return http.Get>(`/apis/api.halo.run/v1alpha1/comments/${commentName}/reply`, { params, cacheFor: 0, meta: { requestFrom: RequestFrom.Halo } @@ -159,6 +158,8 @@ export interface IAddCommentReq { }; /** 验证码,提交时转入 X-Captcha-Code 头 */ captchaCode?: string; + /** 回复的回复:被引用回复(CommentReply)的 name */ + quoteReply?: string; } /** diff --git a/src/api/types/halo.ts b/src/api/types/halo.ts index e4a2bf4..49af333 100644 --- a/src/api/types/halo.ts +++ b/src/api/types/halo.ts @@ -235,6 +235,8 @@ export interface IComment { status?: { hasReply?: boolean replyCount?: number + /** 可见回复数(公开接口按审核可见统计) */ + visibleReplyCount?: number visibleTime?: string } replies?: IListResult @@ -264,12 +266,19 @@ export interface ICommentReply { } } +/** 评论回复列表响应(分页) */ +export type ICommentReplyListRes = IListResult + export interface ICommentListReq { page?: number size?: number sort?: string[] /** 主题名称(文章 name) */ name?: string + /** 是否携带该评论的部分回复(默认 false) */ + withReplies?: boolean + /** 携带回复条数(仅 withReplies=true 时生效,默认 10) */ + replySize?: number [key: string]: unknown } diff --git a/src/components/uh-comment-item/uh-comment-item.vue b/src/components/uh-comment-item/uh-comment-item.vue index 7786acc..18918c0 100644 --- a/src/components/uh-comment-item/uh-comment-item.vue +++ b/src/components/uh-comment-item/uh-comment-item.vue @@ -4,10 +4,10 @@ import relativeTime from 'dayjs/plugin/relativeTime' import { checkAvatarUrl } from '@/utils/url' import { useSettingStore } from '@/store/setting' - import type { IComment } from '@/api/types/halo' + import type { ICommentReply } from '@/api/types/halo' const props = withDefaults(defineProps<{ - comment : IComment + comment : ICommentReply isChild ?: boolean useActions ?: boolean useSolid ?: boolean @@ -15,6 +15,8 @@ disallowComment ?: boolean postName ?: string classItem ?: string[] + /** 回复引用名映射(quoteReply name -> 被引用人 displayName),命中时显示「回复 @xxx」 */ + quoteReplyMap ?: Record }>(), { isChild: false, useActions: true, @@ -23,11 +25,12 @@ disallowComment: false, postName: '', classItem: () => [], + quoteReplyMap: () => ({}), }) const emit = defineEmits<{ - (e : 'on-comment', data : { type : string, comment : IComment }) : void + (e : 'on-comment', data : { type : string, comment : ICommentReply }) : void (e : 'on-copy', raw : string) : void - (e : 'on-detail', comment : IComment) : void + (e : 'on-detail', comment : ICommentReply) : void }>() dayjs.extend(relativeTime) dayjs.locale('zh-cn') @@ -37,6 +40,15 @@ const avatar = computed(() => checkAvatarUrl(props.comment.spec.owner.avatar)) + /** 引用回复标识(被引用人在父级已加载回复映射中可查到时显示) */ + const quoteReplyText = computed(() => { + const quoteName = props.comment.spec.quoteReply + if (!quoteName) + return '' + const displayName = props.quoteReplyMap[quoteName] + return displayName ? `回复 @${displayName}` : '' + }) + /** 评论时间 */ const createTimeText = computed(() => { const time = props.comment.spec.creationTime @@ -77,11 +89,12 @@ {{ comment.spec.owner.displayName }} - {{ quoteReplyText }} + {{ createTimeText }} - + 回复 diff --git a/src/components/uh-comment-list/uh-comment-list.vue b/src/components/uh-comment-list/uh-comment-list.vue index a22de15..8540ea5 100644 --- a/src/components/uh-comment-list/uh-comment-list.vue +++ b/src/components/uh-comment-list/uh-comment-list.vue @@ -1,8 +1,8 @@ diff --git a/src/components/uh-notify-dialog/uh-notify-dialog.vue b/src/components/uh-notify-dialog/uh-notify-dialog.vue index 5089c21..0e7ce42 100644 --- a/src/components/uh-notify-dialog/uh-notify-dialog.vue +++ b/src/components/uh-notify-dialog/uh-notify-dialog.vue @@ -78,21 +78,23 @@