feat: post editor page supports the parameter of returnToView (#698)

#### What type of PR is this?

/kind feature
/milestone 2.0

#### What this PR does / why we need it:

文章和独立页面的编辑页面支持 `returnTo` 参数,用于指定发布完成之后的跳转地址。

#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/2724

#### Special notes for your reviewer:

/cc @halo-dev/sig-halo-console 

测试方式:

1. 选择任意文章进入编辑页面。
2. 在地址栏添加 `&returnTo=http://localhost:8090`
3. 发布文章,观察是否跳转到了 `http://localhost:8090`

#### Does this PR introduce a user-facing change?

```release-note
文章和独立页面的编辑页面支持 `returnTo` 参数。
```
pull/701/head
Ryan Wang 2022-11-21 15:14:28 +08:00 committed by GitHub
parent 9175cd63e5
commit 062e45477c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -108,6 +108,8 @@ const handleSave = async () => {
}
};
const returnToView = useRouteQuery<string>("returnToView");
const handlePublish = async () => {
try {
publishing.value = true;
@ -117,6 +119,7 @@ const handlePublish = async () => {
if (isUpdateMode.value) {
const { name: singlePageName } = formState.value.page.metadata;
const { permalink } = formState.value.page.status || {};
await apiClient.singlePage.updateSinglePageContent({
name: singlePageName,
@ -126,6 +129,12 @@ const handlePublish = async () => {
await apiClient.singlePage.publishSinglePage({
name: singlePageName,
});
if (returnToView.value && permalink) {
window.location.href = permalink;
} else {
router.push({ name: "SinglePages" });
}
} else {
formState.value.page.spec.publish = true;
await apiClient.singlePage.draftSinglePage({
@ -134,8 +143,6 @@ const handlePublish = async () => {
}
Toast.success("发布成功");
router.push({ name: "SinglePages" });
} catch (error) {
console.error("Failed to publish single page", error);
Toast.error("发布失败,请重试");

View File

@ -109,6 +109,8 @@ const handleSave = async () => {
}
};
const returnToView = useRouteQuery<string>("returnToView");
const handlePublish = async () => {
try {
publishing.value = true;
@ -118,6 +120,7 @@ const handlePublish = async () => {
if (isUpdateMode.value) {
const { name: postName } = formState.value.post.metadata;
const { permalink } = formState.value.post.status || {};
await apiClient.post.updatePostContent({
name: postName,
@ -127,6 +130,12 @@ const handlePublish = async () => {
await apiClient.post.publishPost({
name: postName,
});
if (returnToView.value === "true" && permalink) {
window.location.href = permalink;
} else {
router.push({ name: "Posts" });
}
} else {
const { data } = await apiClient.post.draftPost({
postRequest: formState.value,
@ -138,8 +147,6 @@ const handlePublish = async () => {
}
Toast.success("发布成功", { duration: 2000 });
router.push({ name: "Posts" });
} catch (error) {
console.error("Failed to publish post", error);
Toast.error("发布失败,请重试");