mirror of https://github.com/halo-dev/halo
refactor: improve part of the page operation logic using the patch api (#6463)
#### 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
62bc168184
commit
ddd59680e9
|
@ -23,7 +23,6 @@ import {
|
||||||
VStatusDot,
|
VStatusDot,
|
||||||
} from "@halo-dev/components";
|
} from "@halo-dev/components";
|
||||||
import { useQuery } from "@tanstack/vue-query";
|
import { useQuery } from "@tanstack/vue-query";
|
||||||
import { cloneDeep } from "lodash-es";
|
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
|
||||||
|
@ -132,12 +131,17 @@ const handleRecovery = async (singlePage: SinglePage) => {
|
||||||
confirmText: t("core.common.buttons.confirm"),
|
confirmText: t("core.common.buttons.confirm"),
|
||||||
cancelText: t("core.common.buttons.cancel"),
|
cancelText: t("core.common.buttons.cancel"),
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
const singlePageToUpdate = cloneDeep(singlePage);
|
await coreApiClient.content.singlePage.patchSinglePage({
|
||||||
singlePageToUpdate.spec.deleted = false;
|
name: singlePage.metadata.name,
|
||||||
await coreApiClient.content.singlePage.updateSinglePage({
|
jsonPatchInner: [
|
||||||
name: singlePageToUpdate.metadata.name,
|
{
|
||||||
singlePage: singlePageToUpdate,
|
op: "add",
|
||||||
|
path: "/spec/deleted",
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await refetch();
|
await refetch();
|
||||||
|
|
||||||
Toast.success(t("core.common.toast.recovery_success"));
|
Toast.success(t("core.common.toast.recovery_success"));
|
||||||
|
@ -164,15 +168,15 @@ const handleRecoveryInBatch = async () => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return coreApiClient.content.singlePage.updateSinglePage({
|
return coreApiClient.content.singlePage.patchSinglePage({
|
||||||
name: singlePage.metadata.name,
|
name: singlePage.metadata.name,
|
||||||
singlePage: {
|
jsonPatchInner: [
|
||||||
...singlePage,
|
{
|
||||||
spec: {
|
op: "add",
|
||||||
...singlePage.spec,
|
path: "/spec/deleted",
|
||||||
deleted: false,
|
value: false,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -237,15 +237,15 @@ const handleDeleteInBatch = async () => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return coreApiClient.content.singlePage.updateSinglePage({
|
return coreApiClient.content.singlePage.patchSinglePage({
|
||||||
name: page.metadata.name,
|
name: page.metadata.name,
|
||||||
singlePage: {
|
jsonPatchInner: [
|
||||||
...page,
|
{
|
||||||
spec: {
|
op: "add",
|
||||||
...page.spec,
|
path: "/spec/deleted",
|
||||||
deleted: true,
|
value: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,7 +19,6 @@ import {
|
||||||
VStatusDot,
|
VStatusDot,
|
||||||
} from "@halo-dev/components";
|
} from "@halo-dev/components";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/vue-query";
|
import { useMutation, useQueryClient } from "@tanstack/vue-query";
|
||||||
import { cloneDeep } from "lodash-es";
|
|
||||||
import type { Ref } from "vue";
|
import type { Ref } from "vue";
|
||||||
import { computed, inject, ref } from "vue";
|
import { computed, inject, ref } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
@ -71,24 +70,21 @@ const isPublishing = computed(() => {
|
||||||
|
|
||||||
const { mutate: changeVisibleMutation } = useMutation({
|
const { mutate: changeVisibleMutation } = useMutation({
|
||||||
mutationFn: async (singlePage: SinglePage) => {
|
mutationFn: async (singlePage: SinglePage) => {
|
||||||
const { data } = await coreApiClient.content.singlePage.getSinglePage({
|
return await coreApiClient.content.singlePage.patchSinglePage({
|
||||||
name: singlePage.metadata.name,
|
name: singlePage.metadata.name,
|
||||||
});
|
jsonPatchInner: [
|
||||||
data.spec.visible = data.spec.visible === "PRIVATE" ? "PUBLIC" : "PRIVATE";
|
|
||||||
await coreApiClient.content.singlePage.updateSinglePage(
|
|
||||||
{
|
{
|
||||||
name: singlePage.metadata.name,
|
op: "add",
|
||||||
singlePage: data,
|
path: "/spec/visible",
|
||||||
|
value: singlePage.spec.visible === "PRIVATE" ? "PUBLIC" : "PRIVATE",
|
||||||
},
|
},
|
||||||
{
|
],
|
||||||
mute: true,
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
await queryClient.invalidateQueries({ queryKey: ["singlePages"] });
|
|
||||||
},
|
},
|
||||||
retry: 3,
|
retry: 3,
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
Toast.success(t("core.common.toast.operation_success"));
|
Toast.success(t("core.common.toast.operation_success"));
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["singlePages"] });
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
Toast.error(t("core.common.toast.operation_failed"));
|
Toast.error(t("core.common.toast.operation_failed"));
|
||||||
|
@ -103,12 +99,17 @@ const handleDelete = async () => {
|
||||||
confirmText: t("core.common.buttons.confirm"),
|
confirmText: t("core.common.buttons.confirm"),
|
||||||
cancelText: t("core.common.buttons.cancel"),
|
cancelText: t("core.common.buttons.cancel"),
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
const singlePageToUpdate = cloneDeep(props.singlePage.page);
|
await coreApiClient.content.singlePage.patchSinglePage({
|
||||||
singlePageToUpdate.spec.deleted = true;
|
|
||||||
await coreApiClient.content.singlePage.updateSinglePage({
|
|
||||||
name: props.singlePage.page.metadata.name,
|
name: props.singlePage.page.metadata.name,
|
||||||
singlePage: singlePageToUpdate,
|
jsonPatchInner: [
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/deleted",
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await queryClient.invalidateQueries({ queryKey: ["singlePages"] });
|
await queryClient.invalidateQueries({ queryKey: ["singlePages"] });
|
||||||
|
|
||||||
Toast.success(t("core.common.toast.delete_success"));
|
Toast.success(t("core.common.toast.delete_success"));
|
||||||
|
@ -195,6 +196,7 @@ const handleDelete = async () => {
|
||||||
<VStatusDot :text="$t('core.common.tooltips.publishing')" animate />
|
<VStatusDot :text="$t('core.common.tooltips.publishing')" animate />
|
||||||
</template>
|
</template>
|
||||||
</VEntityField>
|
</VEntityField>
|
||||||
|
<HasPermission :permissions="['system:singlepages:manage']">
|
||||||
<VEntityField>
|
<VEntityField>
|
||||||
<template #description>
|
<template #description>
|
||||||
<IconEye
|
<IconEye
|
||||||
|
@ -211,6 +213,8 @@ const handleDelete = async () => {
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</VEntityField>
|
</VEntityField>
|
||||||
|
</HasPermission>
|
||||||
|
|
||||||
<VEntityField v-if="singlePage?.page?.spec.deleted">
|
<VEntityField v-if="singlePage?.page?.spec.deleted">
|
||||||
<template #description>
|
<template #description>
|
||||||
<VStatusDot
|
<VStatusDot
|
||||||
|
|
Loading…
Reference in New Issue