Skip to content

Commit

Permalink
feat: add download feature for attachment (#5496)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/kind feature
/area ui
/milestone 2.14.0

#### What this PR does / why we need it:

附件支持下载。

<img width="471" alt="image" src="https://github.com/halo-dev/halo/assets/21301288/97909ef8-8117-4ea9-aa15-73295a1b7b01">


#### Which issue(s) this PR fixes:

Fixes #5476

#### Special notes for your reviewer:

测试方式:

1. 上传若干附件。
2. 测试下载功能是否符合预期。

#### Does this PR introduce a user-facing change?

```release-note
为附件添加下载功能
```
  • Loading branch information
ruibaby committed Mar 11, 2024
1 parent 029eb95 commit b4729b9
Showing 1 changed file with 24 additions and 0 deletions.
Expand Up @@ -7,6 +7,7 @@ import {
Toast,
VDropdownItem,
Dialog,
VDropdownDivider,
} from "@halo-dev/components";
import { computed, ref } from "vue";
import type { Attachment } from "@halo-dev/api-client";
Expand Down Expand Up @@ -101,6 +102,29 @@ const { operationItems } = useOperationItemExtensionPoint<Attachment>(
{
priority: 20,
component: markRaw(VDropdownItem),
label: t("core.common.buttons.download"),
action: () => {
const { permalink } = attachment.value.status || {};
if (!permalink) {
throw new Error("Attachment has no permalink");
}
const a = document.createElement("a");
a.href = permalink;
a.download = attachment.value.spec.displayName || "unknown";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
},
{
priority: 30,
component: markRaw(VDropdownDivider),
},
{
priority: 40,
component: markRaw(VDropdownItem),
props: {
type: "danger",
},
Expand Down

0 comments on commit b4729b9

Please sign in to comment.