mirror of https://github.com/halo-dev/halo
refactor: use patch api to refactor category drag-and-drop sorting feature (#6461)
#### 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
c2ac19f9d3
commit
d78547f963
|
@ -40,9 +40,20 @@ const handleUpdateInBatch = useDebounceFn(async () => {
|
||||||
try {
|
try {
|
||||||
batchUpdating.value = true;
|
batchUpdating.value = true;
|
||||||
const promises = categoriesToUpdate.map((category) =>
|
const promises = categoriesToUpdate.map((category) =>
|
||||||
coreApiClient.content.category.updateCategory({
|
coreApiClient.content.category.patchCategory({
|
||||||
name: category.metadata.name,
|
name: category.metadata.name,
|
||||||
category: category,
|
jsonPatchInner: [
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/children",
|
||||||
|
value: category.spec.children || [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/priority",
|
||||||
|
value: category.spec.priority || 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { setFocus } from "@/formkit/utils/focus";
|
||||||
import { FormType } from "@/types/slug";
|
import { FormType } from "@/types/slug";
|
||||||
import useSlugify from "@console/composables/use-slugify";
|
import useSlugify from "@console/composables/use-slugify";
|
||||||
import { useThemeCustomTemplates } from "@console/modules/interface/themes/composables/use-theme";
|
import { useThemeCustomTemplates } from "@console/modules/interface/themes/composables/use-theme";
|
||||||
|
import { reset, submitForm } from "@formkit/core";
|
||||||
import type { Category } from "@halo-dev/api-client";
|
import type { Category } from "@halo-dev/api-client";
|
||||||
import {
|
import {
|
||||||
IconRefreshLine,
|
IconRefreshLine,
|
||||||
|
@ -21,7 +22,6 @@ import {
|
||||||
import { useQueryClient } from "@tanstack/vue-query";
|
import { useQueryClient } from "@tanstack/vue-query";
|
||||||
import { cloneDeep } from "lodash-es";
|
import { cloneDeep } from "lodash-es";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { submitForm, reset } from "@formkit/core";
|
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
@ -109,28 +109,30 @@ const handleSaveCategory = async () => {
|
||||||
parentCategory = data;
|
parentCategory = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const priority = parentCategory?.spec.children
|
formState.value.spec.priority = parentCategory?.spec.children
|
||||||
? parentCategory.spec.children.length + 1
|
? parentCategory.spec.children.length + 1
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
formState.value.spec.priority = priority;
|
|
||||||
|
|
||||||
const { data: createdCategory } =
|
const { data: createdCategory } =
|
||||||
await coreApiClient.content.category.createCategory({
|
await coreApiClient.content.category.createCategory({
|
||||||
category: formState.value,
|
category: formState.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (parentCategory) {
|
if (parentCategory) {
|
||||||
parentCategory.spec.children = Array.from(
|
await coreApiClient.content.category.patchCategory({
|
||||||
new Set([
|
|
||||||
...(parentCategory.spec.children || []),
|
|
||||||
createdCategory.metadata.name,
|
|
||||||
])
|
|
||||||
);
|
|
||||||
|
|
||||||
await coreApiClient.content.category.updateCategory({
|
|
||||||
name: selectedParentCategory.value,
|
name: selectedParentCategory.value,
|
||||||
category: parentCategory,
|
jsonPatchInner: [
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/children",
|
||||||
|
value: Array.from(
|
||||||
|
new Set([
|
||||||
|
...(parentCategory.spec.children || []),
|
||||||
|
createdCategory.metadata.name,
|
||||||
|
])
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue