mirror of https://github.com/halo-dev/halo
refactor: improve part of the post operation logic using the patch api (#6464)
#### What type of PR is this? /area ui /kind improvement /milestone 2.19.x #### What this PR does / why we need it: 使用 patch 接口重构文章的恢复、可见性修改等逻辑。 #### Which issue(s) this PR fixes: None #### Special notes for your reviewer: 测试文章删除、恢复、可见性修改功能是否符合预期。 #### Does this PR introduce a user-facing change? ```release-note 使用 patch 接口重构文章的恢复、可见性修改等逻辑。 ```pull/6470/head
parent
d78547f963
commit
d011beb89b
|
@ -23,7 +23,6 @@ import {
|
|||
VStatusDot,
|
||||
} from "@halo-dev/components";
|
||||
import { useQuery } from "@tanstack/vue-query";
|
||||
import { cloneDeep } from "lodash-es";
|
||||
import { ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import PostTag from "./tags/components/PostTag.vue";
|
||||
|
@ -132,11 +131,15 @@ const handleRecovery = async (post: Post) => {
|
|||
confirmText: t("core.common.buttons.confirm"),
|
||||
cancelText: t("core.common.buttons.cancel"),
|
||||
onConfirm: async () => {
|
||||
const postToUpdate = cloneDeep(post);
|
||||
postToUpdate.spec.deleted = false;
|
||||
await coreApiClient.content.post.updatePost({
|
||||
name: postToUpdate.metadata.name,
|
||||
post: postToUpdate,
|
||||
await coreApiClient.content.post.patchPost({
|
||||
name: post.metadata.name,
|
||||
jsonPatchInner: [
|
||||
{
|
||||
op: "add",
|
||||
path: "/spec/deleted",
|
||||
value: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await refetch();
|
||||
|
@ -157,23 +160,23 @@ const handleRecoveryInBatch = async () => {
|
|||
onConfirm: async () => {
|
||||
await Promise.all(
|
||||
selectedPostNames.value.map((name) => {
|
||||
const post = posts.value?.find(
|
||||
const isPostExist = posts.value?.some(
|
||||
(item) => item.post.metadata.name === name
|
||||
)?.post;
|
||||
);
|
||||
|
||||
if (!post) {
|
||||
if (!isPostExist) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return coreApiClient.content.post.updatePost({
|
||||
name: post.metadata.name,
|
||||
post: {
|
||||
...post,
|
||||
spec: {
|
||||
...post.spec,
|
||||
deleted: false,
|
||||
return coreApiClient.content.post.patchPost({
|
||||
name: name,
|
||||
jsonPatchInner: [
|
||||
{
|
||||
op: "add",
|
||||
path: "/spec/deleted",
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
);
|
||||
|
|
|
@ -185,6 +185,7 @@ const { startFields, endFields } = useEntityFieldItemExtensionPoint<ListedPost>(
|
|||
priority: 30,
|
||||
position: "end",
|
||||
component: markRaw(VisibleField),
|
||||
permissions: ["system:posts:manage"],
|
||||
props: {
|
||||
post: props.post,
|
||||
},
|
||||
|
|
|
@ -17,24 +17,21 @@ withDefaults(
|
|||
|
||||
const { mutate: changeVisibleMutation } = useMutation({
|
||||
mutationFn: async (post: Post) => {
|
||||
const { data } = await coreApiClient.content.post.getPost({
|
||||
return await coreApiClient.content.post.patchPost({
|
||||
name: post.metadata.name,
|
||||
jsonPatchInner: [
|
||||
{
|
||||
op: "add",
|
||||
path: "/spec/visible",
|
||||
value: post.spec.visible === "PRIVATE" ? "PUBLIC" : "PRIVATE",
|
||||
},
|
||||
],
|
||||
});
|
||||
data.spec.visible = data.spec.visible === "PRIVATE" ? "PUBLIC" : "PRIVATE";
|
||||
await coreApiClient.content.post.updatePost(
|
||||
{
|
||||
name: post.metadata.name,
|
||||
post: data,
|
||||
},
|
||||
{
|
||||
mute: true,
|
||||
}
|
||||
);
|
||||
await queryClient.invalidateQueries({ queryKey: ["posts"] });
|
||||
},
|
||||
retry: 3,
|
||||
onSuccess: () => {
|
||||
Toast.success(t("core.common.toast.operation_success"));
|
||||
queryClient.invalidateQueries({ queryKey: ["posts"] });
|
||||
},
|
||||
onError: () => {
|
||||
Toast.error(t("core.common.toast.operation_failed"));
|
||||
|
|
Loading…
Reference in New Issue