mirror of https://github.com/halo-dev/halo-admin
refactor: post publishing (#690)
#### What type of PR is this? /kind improvement /milestone 2.0 #### What this PR does / why we need it: 重构文章发布/取消发布/放入回收站的逻辑。适配 https://github.com/halo-dev/halo/pull/2675 #### Special notes for your reviewer: 测试方式: 1. Halo 需要切换到 https://github.com/halo-dev/halo/pull/2675 的分支。 2. Console 需要 `pnpm install`。 3. 测试文章发布/取消发布/放入回收站。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/692/head
parent
fe89862552
commit
9ac9e1312d
|
@ -31,7 +31,7 @@
|
|||
"@formkit/inputs": "^1.0.0-beta.11",
|
||||
"@formkit/themes": "^1.0.0-beta.11",
|
||||
"@formkit/vue": "^1.0.0-beta.11",
|
||||
"@halo-dev/api-client": "^0.0.43",
|
||||
"@halo-dev/api-client": "^0.0.46",
|
||||
"@halo-dev/components": "workspace:*",
|
||||
"@halo-dev/console-shared": "workspace:*",
|
||||
"@halo-dev/richtext-editor": "^0.0.0-alpha.11",
|
||||
|
|
|
@ -11,7 +11,7 @@ importers:
|
|||
'@formkit/inputs': ^1.0.0-beta.11
|
||||
'@formkit/themes': ^1.0.0-beta.11
|
||||
'@formkit/vue': ^1.0.0-beta.11
|
||||
'@halo-dev/api-client': ^0.0.43
|
||||
'@halo-dev/api-client': ^0.0.46
|
||||
'@halo-dev/components': workspace:*
|
||||
'@halo-dev/console-shared': workspace:*
|
||||
'@halo-dev/richtext-editor': ^0.0.0-alpha.11
|
||||
|
@ -104,7 +104,7 @@ importers:
|
|||
'@formkit/inputs': 1.0.0-beta.11
|
||||
'@formkit/themes': 1.0.0-beta.11_tailwindcss@3.2.1
|
||||
'@formkit/vue': 1.0.0-beta.11_vjnbgdptsk6bkj7ab5a6mk2cwm
|
||||
'@halo-dev/api-client': 0.0.43
|
||||
'@halo-dev/api-client': 0.0.46
|
||||
'@halo-dev/components': link:packages/components
|
||||
'@halo-dev/console-shared': link:packages/shared
|
||||
'@halo-dev/richtext-editor': 0.0.0-alpha.11_vue@3.2.41
|
||||
|
@ -1937,8 +1937,8 @@ packages:
|
|||
- windicss
|
||||
dev: false
|
||||
|
||||
/@halo-dev/api-client/0.0.43:
|
||||
resolution: {integrity: sha512-bCh5P7AYCYA/nVbAB/t62acrtOaDs8UItFe4JmK1qfeb5vOmFT2FT9jeJFj4ABqa4t4xJxy9hnoxNm6H+iB3IQ==}
|
||||
/@halo-dev/api-client/0.0.46:
|
||||
resolution: {integrity: sha512-K2tuCv3OmYzaz9h6X5nVZbghDSd09AawORNAcoi3KuE/Uzi0n5OldO72AuJmVFxtbZqGIHt//CdBSE+cCFq08Q==}
|
||||
dev: false
|
||||
|
||||
/@halo-dev/richtext-editor/0.0.0-alpha.11_vue@3.2.41:
|
||||
|
|
|
@ -58,6 +58,7 @@ export function useAttachmentControl(filterOptions?: {
|
|||
last: false,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
totalPages: 0,
|
||||
});
|
||||
const loading = ref<boolean>(false);
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ const comments = ref<ListedCommentList>({
|
|||
last: false,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
totalPages: 0,
|
||||
});
|
||||
const loading = ref(false);
|
||||
const checkAll = ref(false);
|
||||
|
|
|
@ -34,6 +34,7 @@ const singlePages = ref<ListedSinglePageList>({
|
|||
last: false,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
totalPages: 0,
|
||||
});
|
||||
const loading = ref(false);
|
||||
const selectedPageNames = ref<string[]>([]);
|
||||
|
|
|
@ -46,6 +46,7 @@ const singlePages = ref<ListedSinglePageList>({
|
|||
last: false,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
totalPages: 0,
|
||||
});
|
||||
const loading = ref(false);
|
||||
const settingModal = ref(false);
|
||||
|
|
|
@ -35,6 +35,7 @@ const posts = ref<ListedPostList>({
|
|||
last: false,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
totalPages: 0,
|
||||
});
|
||||
const loading = ref(false);
|
||||
const checkedAll = ref(false);
|
||||
|
|
|
@ -141,27 +141,18 @@ const handlePublish = async () => {
|
|||
},
|
||||
});
|
||||
|
||||
// Get latest post
|
||||
const { data: latestPost } =
|
||||
await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
|
||||
name: postName,
|
||||
});
|
||||
|
||||
formState.value.post = latestPost;
|
||||
formState.value.post.spec.publish = true;
|
||||
formState.value.post.spec.headSnapshot = latestContent.snapshotName;
|
||||
formState.value.post.spec.releaseSnapshot =
|
||||
formState.value.post.spec.headSnapshot;
|
||||
|
||||
await apiClient.extension.post.updatecontentHaloRunV1alpha1Post({
|
||||
await apiClient.post.publishPost({
|
||||
name: postName,
|
||||
post: formState.value.post,
|
||||
headSnapshot: latestContent.snapshotName,
|
||||
});
|
||||
} else {
|
||||
formState.value.post.spec.publish = true;
|
||||
await apiClient.post.draftPost({
|
||||
const { data } = await apiClient.post.draftPost({
|
||||
postRequest: formState.value,
|
||||
});
|
||||
|
||||
await apiClient.post.publishPost({
|
||||
name: data.metadata.name,
|
||||
});
|
||||
}
|
||||
|
||||
router.push({ name: "Posts" });
|
||||
|
|
|
@ -39,7 +39,6 @@ import { usePostCategory } from "@/modules/contents/posts/categories/composables
|
|||
import { usePostTag } from "@/modules/contents/posts/tags/composables/use-post-tag";
|
||||
import { usePermission } from "@/utils/permission";
|
||||
import { onBeforeRouteLeave } from "vue-router";
|
||||
import cloneDeep from "lodash.clonedeep";
|
||||
import { postLabels } from "@/constants/labels";
|
||||
|
||||
const { currentUserHasPermission } = usePermission();
|
||||
|
@ -53,6 +52,7 @@ const posts = ref<ListedPostList>({
|
|||
last: false,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
totalPages: 0,
|
||||
});
|
||||
const loading = ref(false);
|
||||
const settingModal = ref(false);
|
||||
|
@ -239,11 +239,8 @@ const handleDelete = async (post: Post) => {
|
|||
description: "此操作会将文章放入回收站,后续可以从回收站恢复",
|
||||
confirmType: "danger",
|
||||
onConfirm: async () => {
|
||||
const postToUpdate = cloneDeep(post);
|
||||
postToUpdate.spec.deleted = true;
|
||||
await apiClient.extension.post.updatecontentHaloRunV1alpha1Post({
|
||||
name: postToUpdate.metadata.name,
|
||||
post: postToUpdate,
|
||||
await apiClient.post.recyclePost({
|
||||
name: post.metadata.name,
|
||||
});
|
||||
await handleFetchPosts();
|
||||
},
|
||||
|
|
|
@ -105,46 +105,43 @@ const handleSave = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
const handleSwitchPublish = async (publish: boolean) => {
|
||||
const handlePublish = async () => {
|
||||
if (props.onlyEmit) {
|
||||
emit("published", formState.value);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (publish) {
|
||||
publishing.value = true;
|
||||
} else {
|
||||
publishCanceling.value = true;
|
||||
}
|
||||
publishing.value = true;
|
||||
|
||||
if (publish) {
|
||||
formState.value.spec.releaseSnapshot = formState.value.spec.headSnapshot;
|
||||
}
|
||||
|
||||
const { data } =
|
||||
await apiClient.extension.post.updatecontentHaloRunV1alpha1Post({
|
||||
name: formState.value.metadata.name,
|
||||
post: {
|
||||
...formState.value,
|
||||
spec: {
|
||||
...formState.value.spec,
|
||||
publish: publish,
|
||||
},
|
||||
},
|
||||
});
|
||||
const { data } = await apiClient.post.publishPost({
|
||||
name: formState.value.metadata.name,
|
||||
});
|
||||
|
||||
formState.value = data;
|
||||
|
||||
if (publish) {
|
||||
emit("published", data);
|
||||
}
|
||||
emit("published", data);
|
||||
|
||||
handleVisibleChange(false);
|
||||
} catch (e) {
|
||||
console.error("Failed to publish post", e);
|
||||
} finally {
|
||||
publishing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleUnpublish = async () => {
|
||||
try {
|
||||
publishCanceling.value = true;
|
||||
|
||||
await apiClient.post.unpublishPost({
|
||||
name: formState.value.metadata.name,
|
||||
});
|
||||
|
||||
handleVisibleChange(false);
|
||||
} catch (e) {
|
||||
console.error("Failed to publish post", e);
|
||||
} finally {
|
||||
publishCanceling.value = false;
|
||||
}
|
||||
};
|
||||
|
@ -294,7 +291,7 @@ const { templates } = useThemeCustomTemplates("post");
|
|||
v-if="formState.metadata.labels?.[postLabels.PUBLISHED] !== 'true'"
|
||||
:loading="publishing"
|
||||
type="secondary"
|
||||
@click="handleSwitchPublish(true)"
|
||||
@click="handlePublish()"
|
||||
>
|
||||
发布
|
||||
</VButton>
|
||||
|
@ -302,7 +299,7 @@ const { templates } = useThemeCustomTemplates("post");
|
|||
v-else
|
||||
:loading="publishCanceling"
|
||||
type="danger"
|
||||
@click="handleSwitchPublish(false)"
|
||||
@click="handleUnpublish()"
|
||||
>
|
||||
取消发布
|
||||
</VButton>
|
||||
|
|
|
@ -31,6 +31,7 @@ const plugins = ref<PluginList>({
|
|||
last: false,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
totalPages: 0,
|
||||
});
|
||||
const loading = ref(false);
|
||||
const pluginInstall = ref(false);
|
||||
|
|
|
@ -44,6 +44,7 @@ const users = ref<UserList>({
|
|||
last: false,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
totalPages: 0,
|
||||
});
|
||||
const selectedUserNames = ref<string[]>([]);
|
||||
const selectedUser = ref<User>();
|
||||
|
|
Loading…
Reference in New Issue