From b4729b9dab5cadced51e5de54a3e004e9471b459 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 11 Mar 2024 16:28:08 +0800 Subject: [PATCH] feat: add download feature for attachment (#5496) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature /area ui /milestone 2.14.0 #### What this PR does / why we need it: 附件支持下载。 image #### 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 为附件添加下载功能 ``` --- .../components/AttachmentListItem.vue | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ui/console-src/modules/contents/attachments/components/AttachmentListItem.vue b/ui/console-src/modules/contents/attachments/components/AttachmentListItem.vue index 9542716929..4dcb1ad41d 100644 --- a/ui/console-src/modules/contents/attachments/components/AttachmentListItem.vue +++ b/ui/console-src/modules/contents/attachments/components/AttachmentListItem.vue @@ -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"; @@ -101,6 +102,29 @@ const { operationItems } = useOperationItemExtensionPoint( { 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", },