For AI agents: the complete documentation index is available at https://docs.halo.run/llms.txt, the full documentation bundle is available at https://docs.halo.run/llms-full.txt, and this page is available as Markdown at https://docs.halo.run/developer-guide/plugin/extension-points/ui/comment-list-item-operation-create.md.

评论数据列表操作菜单

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

评论数据列表操作菜单

定义方式

export default definePlugin({
  extensionPoints: {
    "comment:list-item:operation:create": (
      comment: Ref<ListedComment>,
    ): OperationItem<ListedComment>[] => {
      return [
        {
          priority: 10,
          component: markRaw(VDropdownItem),
          props: {},
          action: (item?: ListedComment) => {
            // do something
          },
          label: "foo",
          hidden: false,
          permissions: [],
          children: [],
        },
      ];
    },
  },
});

OperationItem<T>@halo-dev/ui-shared 提供,请直接使用当前依赖中的类型。priority 和使用 markRaw 包装的 component 为必需字段;propsactionlabelhiddenpermissions 和递归的 children 为可选字段。

priority 越小,操作项的显示位置越靠前(内置操作项通常以 0、10、20… 依次排列,如需插入到内置项之间,可选择中间值)。

示例

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

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

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

类型定义

ListedComment

ListedComment@halo-dev/api-client 提供,请直接使用当前依赖中的生成类型。它包含:

  • comment:评论资源。
  • owner:解析后的评论者信息。
  • stats:评论回复等统计数据。
  • subject?:解析后的评论主体,无法解析时可能为空。