跳到主要内容
版本:2.20.0-SNAPSHOT

评论数据列表操作菜单

此扩展点用于扩展评论数据列表的操作菜单项。

评论数据列表操作菜单

定义方式

export default definePlugin({
extensionPoints: {
"comment:list-item:operation:create": (
comment: Ref<ListedComment>
): OperationItem<ListedComment>[] | Promise<OperationItem<ListedComment>[]> => {
return [
{
priority: 10,
component: markRaw(VDropdownItem),
props: {},
action: (item?: ListedComment) => {
// do something
},
label: "foo",
hidden: false,
permissions: [],
children: [],
},
];
},
},
});
OperationItem
export interface OperationItem<T> {
priority: number; // 排序优先级
component: Raw<Component>; // 菜单项组件
props?: Record\<string, unknown\>; // 菜单项组件属性
action?: (item?: T) => void; // 菜单项点击事件
label?: string; // 菜单项标题
hidden?: boolean; // 菜单项是否隐藏
permissions?: string[]; // 菜单项 UI 权限
children?: OperationItem<T>[]; // 子菜单项
}

示例

此示例将实现一个操作菜单项。

import type { ListedComment } from "@halo-dev/api-client";
import { VDropdownItem } from "@halo-dev/components";
import { definePlugin } from "@halo-dev/console-shared";
import { markRaw } from "vue";

export default definePlugin({
extensionPoints: {
"comment:list-item:operation:create": () => {
return [
{
priority: 21,
component: markRaw(VDropdownItem),
label: "测试评论菜单",
visible: true,
permissions: [],
action: async (comment: ListedComment) => {
console.log(comment)
},
},
];
},
},
});

类型定义

ListedComment

export interface ListedComment {
comment:{
apiVersion: "content.halo.run/v1alpha1"
kind: "Comment"
metadata: {
annotations: {}
creationTimestamp: string
labels: {}
name: string // 评论的唯一标识
version: number
}
spec: {
allowNotification: boolean; // 是否允许通知
approved: boolean;
approvedTime: string;
content: string; // 最终渲染的文本
creationTime: string; // 创建时间
hidden: boolean;
ipAddress: string; // 评论者 IP 地址
lastReadTime: string;
owner: { // 创建者信息
annotations: {};
displayName: string;
kind: string;
name: string;
};
priority: number; // 排序字段
raw: string; // 原始文本,一般用于给编辑器使用
subjectRef: { // 引用关联,比如文章、自定义页面
group: string;
kind: string;
name: string;
version: string;
};
top: boolean; // 是否置顶
userAgent: string; // 评论者 UserAgent 信息
}
status: {
hasNewReply: boolean; // 是否有新回复
lastReplyTime: string;
observedVersion: number;
replyCount: number; // 回复数量
unreadReplyCount: number;
visibleReplyCount: number;
}
}
owner: { // 创建者信息
avatar: string; // 头像
displayName: string; // 描述
email: string; // 邮箱
kind: string;
name: string; // 创建者的唯一标识
}
stats: {
upvote: number;
}
subject: {
apiVersion: string;
kind: string;
metadata: Metadata;
}
}