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-field-create.md.

评论数据列表显示字段

此扩展点在 Halo 2.28.0 中引入,用于扩展评论数据列表的显示字段。

插件返回的字段会按 position 分别显示在列表项的 start(左侧)或 end(右侧)区域,并渲染在该区域内置内容之前。同一区域内的字段按 priority 升序排列;hidden 为 true,或当前用户不具备 permissions 中声明的任一权限时,字段不会渲染。

扩展点接收当前评论的 ListedComment 响应式引用。列表数据更新时,字段会使用最新的评论数据重新渲染。

定义方式

export default definePlugin({
  extensionPoints: {
    "comment:list-item:field:create": (
      comment: Ref<ListedComment>,
    ): EntityFieldItem[] => {
      return [
        {
          priority: 0,
          position: "start",
          component: markRaw(FooComponent),
          props: {},
          permissions: [],
          hidden: false,
        },
      ];
    },
  },
});
EntityFieldItem
export interface EntityFieldItem {
  priority: number;
  position: "start" | "end";
  component: Raw<Component>;
  props?: Record\<string, unknown\>;
  permissions?: string[];
  hidden?: boolean;
}

示例

此示例将在评论列表右侧显示评论的资源名称(评论 ID)。

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

export default definePlugin({
  extensionPoints: {
    "comment:list-item:field:create": (comment: Ref<ListedComment>) => {
      return [
        {
          priority: 0,
          position: "end",
          component: markRaw(VEntityField),
          props: {
            description: comment.value.comment.metadata.name,
          },
          permissions: [],
          hidden: false,
        },
      ];
    },
  },
});

类型定义

ListedComment

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

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