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/theme-list-item-operation-create.md.

主题数据列表操作菜单

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

主题数据列表操作菜单

定义方式

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

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

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

示例

此示例将实现一个跳转到前台预览主题的操作菜单项。

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

export default definePlugin({
  extensionPoints: {
    "theme:list-item:operation:create": (
      theme: Ref<Theme>,
    ): OperationItem<Theme>[] => {
      return [
        {
          priority: 10,
          component: markRaw(VButton),
          props: {
            size: "sm",
          },
          action: (item?: Theme) => {
            window.open(`/?preview-theme=${item?.metadata.name}`);
          },
          label: "前台预览",
          hidden: false,
          permissions: [],
          children: [],
        },
      ];
    },
  },
});

实现案例

类型定义

Theme

Theme@halo-dev/api-client 提供,请直接使用当前依赖中的生成类型,不要根据本页重新定义:

  • metadata:主题名称、标签和注解等资源元数据。
  • spec:版本、Halo 版本范围、作者、配置引用和自定义模板等期望状态;部分属性可能为空。
  • status?:主题运行阶段、条件、位置和页面布局支持状态等观测状态,尚未计算时可能为空。