feat: support for deleting post

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/613/head
Ryan Wang 2022-09-19 20:36:15 +08:00
parent 3fbe8bd0a5
commit 1f5c67a629
1 changed files with 28 additions and 8 deletions

View File

@ -37,7 +37,6 @@ import { apiClient } from "@halo-dev/admin-shared";
import { formatDatetime } from "@/utils/date"; import { formatDatetime } from "@/utils/date";
import { usePostCategory } from "@/modules/contents/posts/categories/composables/use-post-category"; import { usePostCategory } from "@/modules/contents/posts/categories/composables/use-post-category";
import { usePostTag } from "@/modules/contents/posts/tags/composables/use-post-tag"; import { usePostTag } from "@/modules/contents/posts/tags/composables/use-post-tag";
import cloneDeep from "lodash.clonedeep";
import { postLabels } from "@/constants/labels"; import { postLabels } from "@/constants/labels";
enum PostPhase { enum PostPhase {
@ -217,17 +216,32 @@ const handleDelete = async (post: Post) => {
title: "是否确认删除该文章?", title: "是否确认删除该文章?",
confirmType: "danger", confirmType: "danger",
onConfirm: async () => { onConfirm: async () => {
const postToUpdate = cloneDeep(post); await apiClient.extension.post.deletecontentHaloRunV1alpha1Post({
postToUpdate.spec.deleted = true; name: post.metadata.name,
await apiClient.extension.post.updatecontentHaloRunV1alpha1Post({
name: postToUpdate.metadata.name,
post: postToUpdate,
}); });
await handleFetchPosts(); await handleFetchPosts();
}, },
}); });
}; };
const handleDeleteInBatch = async () => {
dialog.warning({
title: "是否确认删除选中的文章?",
confirmType: "danger",
onConfirm: async () => {
await Promise.all(
selectedPostNames.value.map((name) => {
return apiClient.extension.post.deletecontentHaloRunV1alpha1Post({
name,
});
})
);
await handleFetchPosts();
selectedPostNames.value.length = 0;
},
});
};
watch(selectedPostNames, (newValue) => { watch(selectedPostNames, (newValue) => {
checkedAll.value = newValue.length === posts.value.items?.length; checkedAll.value = newValue.length === posts.value.items?.length;
}); });
@ -445,8 +459,9 @@ function handleContributorFilterItemChange(user?: User) {
</div> </div>
</div> </div>
<VSpace v-else> <VSpace v-else>
<VButton type="default">设置</VButton> <VButton type="danger" @click="handleDeleteInBatch">
<VButton type="danger">删除</VButton> 删除
</VButton>
</VSpace> </VSpace>
</div> </div>
<div class="mt-4 flex sm:mt-0"> <div class="mt-4 flex sm:mt-0">
@ -843,6 +858,11 @@ function handleContributorFilterItemChange(user?: User) {
/> />
</template> </template>
</VEntityField> </VEntityField>
<VEntityField v-if="post?.post?.metadata.deletionTimestamp">
<template #description>
<VStatusDot v-tooltip="``" state="warning" animate />
</template>
</VEntityField>
<VEntityField <VEntityField
:description=" :description="
formatDatetime(post.post.metadata.creationTimestamp) formatDatetime(post.post.metadata.creationTimestamp)