mirror of https://github.com/halo-dev/halo
feat: add download feature for attachment (#5496)
#### 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 https://github.com/halo-dev/halo/issues/5476 #### Special notes for your reviewer: 测试方式: 1. 上传若干附件。 2. 测试下载功能是否符合预期。 #### Does this PR introduce a user-facing change? ```release-note 为附件添加下载功能 ```pull/5421/head
parent
029eb952f1
commit
b4729b9dab
|
@ -7,6 +7,7 @@ import {
|
||||||
Toast,
|
Toast,
|
||||||
VDropdownItem,
|
VDropdownItem,
|
||||||
Dialog,
|
Dialog,
|
||||||
|
VDropdownDivider,
|
||||||
} from "@halo-dev/components";
|
} from "@halo-dev/components";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
import type { Attachment } from "@halo-dev/api-client";
|
import type { Attachment } from "@halo-dev/api-client";
|
||||||
|
@ -101,6 +102,29 @@ const { operationItems } = useOperationItemExtensionPoint<Attachment>(
|
||||||
{
|
{
|
||||||
priority: 20,
|
priority: 20,
|
||||||
component: markRaw(VDropdownItem),
|
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: {
|
props: {
|
||||||
type: "danger",
|
type: "danger",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue