> 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.

# 附件数据列表操作菜单

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

![附件数据列表操作菜单](/img/developer-guide/plugin/extension-points/ui/attachment-list-item-operation-create.png)

## 定义方式

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

`OperationItem<T>` 由 `@halo-dev/ui-shared` 提供，请直接使用当前依赖中的类型。`priority` 和使用 `markRaw` 包装的 `component` 为必需字段；`props`、`action`、`label`、`hidden`、`permissions` 和递归的 `children` 为可选字段。

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

## 示例

此示例将实现一个下载附件到本地的操作菜单项。

```ts
import { definePlugin, type OperationItem } from "@halo-dev/ui-shared";
import { Toast, VDropdownItem } from "@halo-dev/components";
import { markRaw, type Ref } from "vue";
import type { Attachment } from "@halo-dev/api-client";

export default definePlugin({
  extensionPoints: {
    "attachment:list-item:operation:create": (
      attachment: Ref<Attachment>,
    ): OperationItem<Attachment>[] => {
      return [
        {
          priority: 10,
          component: markRaw(VDropdownItem),
          props: {},
          action: (item?: Attachment) => {
            if (!item?.status?.permalink) {
              Toast.error("该附件没有下载地址");
              return;
            }

            const a = document.createElement("a");
            a.href = item.status.permalink;
            a.download = item?.spec.displayName || item.metadata.name;
            a.click();
          },
          label: "下载",
          hidden: false,
          permissions: [],
          children: [],
        },
      ];
    },
  },
});
```

## 实现案例

- [https://github.com/halo-dev/plugin-s3](https://github.com/halo-dev/plugin-s3)

## 类型定义

### Attachment

`Attachment` 由 `@halo-dev/api-client` 提供，请直接使用当前依赖中的生成类型，不要在插件中重新定义。常用字段包括：

- `metadata.name`：附件唯一标识。
- `spec.displayName`：附件显示名称，可能为空。
- `status?.permalink`：附件公开访问地址，状态尚未计算时可能为空。
- `status?.thumbnails`：按缩略图尺寸名称索引的地址集合，可能为空。
