Browse Source

feat: add support for deleting an attachment

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/621/head^2
Ryan Wang 2 years ago
parent
commit
28da1ab736
  1. 10
      src/modules/contents/attachments/AttachmentList.vue
  2. 31
      src/modules/contents/attachments/composables/use-attachment.ts

10
src/modules/contents/attachments/AttachmentList.vue

@ -75,6 +75,7 @@ const {
handleSelectNext,
handleSelectPrevious,
handlePaginationChange,
handleDelete,
handleDeleteInBatch,
handleCheckAll,
handleSelect,
@ -632,7 +633,14 @@ onMounted(() => {
/>
</template>
<template #dropdownItems>
<VButton v-close-popper block type="danger"> 删除 </VButton>
<VButton
v-close-popper
block
type="danger"
@click="handleDelete(attachment)"
>
删除
</VButton>
</template>
</VEntity>
</li>

31
src/modules/contents/attachments/composables/use-attachment.ts

@ -28,6 +28,7 @@ interface useAttachmentControlReturn {
}) => void;
handleSelectPrevious: () => void;
handleSelectNext: () => void;
handleDelete: (attachment: Attachment) => void;
handleDeleteInBatch: () => void;
handleCheckAll: (checkAll: boolean) => void;
handleSelect: (attachment: Attachment | undefined) => void;
@ -132,10 +133,37 @@ export function useAttachmentControl(filterOptions?: {
}
};
const handleDelete = (attachment: Attachment) => {
dialog.warning({
title: "确定要删除该附件吗?",
description: "删除之后将无法恢复",
confirmType: "danger",
onConfirm: async () => {
try {
await apiClient.extension.storage.attachment.deletestorageHaloRunV1alpha1Attachment(
{
name: attachment.metadata.name,
}
);
if (
selectedAttachment.value?.metadata.name === attachment.metadata.name
) {
selectedAttachment.value = undefined;
}
selectedAttachments.value.delete(attachment);
} catch (e) {
console.error("Failed to delete attachment", e);
} finally {
await handleFetchAttachments();
}
},
});
};
const handleDeleteInBatch = () => {
dialog.warning({
title: "确定要删除所选的附件吗?",
description: "其中 20 个附件包含关联关系,删除之后将无法恢复",
description: "删除之后将无法恢复",
confirmType: "danger",
onConfirm: async () => {
try {
@ -211,6 +239,7 @@ export function useAttachmentControl(filterOptions?: {
handlePaginationChange,
handleSelectPrevious,
handleSelectNext,
handleDelete,
handleDeleteInBatch,
handleCheckAll,
handleSelect,

Loading…
Cancel
Save