From aee39906a43c5b21ab1f93e601699de55a05733c Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 26 Jun 2024 11:52:48 +0800 Subject: [PATCH] refactor: preserve post title when opening settings (#6122) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /area ui /kind improvement /milestone 2.17.x #### What this PR does / why we need it: 在文章编辑页面,打开文章设置时,支持保存标题,防止已修改的标题恢复为之前的值。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/6058 #### Does this PR introduce a user-facing change? ```release-note 优化文章编辑页面自动保存标题的功能 ``` --- .../modules/contents/pages/SinglePageEditor.vue | 16 ++++++++++++++++ .../modules/contents/posts/PostEditor.vue | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/ui/console-src/modules/contents/pages/SinglePageEditor.vue b/ui/console-src/modules/contents/pages/SinglePageEditor.vue index 630da00f5..649882b11 100644 --- a/ui/console-src/modules/contents/pages/SinglePageEditor.vue +++ b/ui/console-src/modules/contents/pages/SinglePageEditor.vue @@ -311,11 +311,27 @@ const handleFetchContent = async () => { // SinglePage settings const handleOpenSettingModal = async () => { + if (isTitleChanged.value) { + await coreApiClient.content.singlePage.patchSinglePage({ + name: formState.value.page.metadata.name, + jsonPatchInner: [ + { + op: "add", + path: "/spec/title", + value: + formState.value.page.spec.title || t("core.page_editor.untitled"), + }, + ], + }); + isTitleChanged.value = false; + } + const { data: latestSinglePage } = await coreApiClient.content.singlePage.getSinglePage({ name: formState.value.page.metadata.name, }); formState.value.page = latestSinglePage; + settingModal.value = true; }; diff --git a/ui/console-src/modules/contents/posts/PostEditor.vue b/ui/console-src/modules/contents/posts/PostEditor.vue index db6a52819..13f210102 100644 --- a/ui/console-src/modules/contents/posts/PostEditor.vue +++ b/ui/console-src/modules/contents/posts/PostEditor.vue @@ -330,10 +330,26 @@ const handleFetchContent = async () => { }; const handleOpenSettingModal = async () => { + if (isTitleChanged.value) { + await coreApiClient.content.post.patchPost({ + name: formState.value.post.metadata.name, + jsonPatchInner: [ + { + op: "add", + path: "/spec/title", + value: + formState.value.post.spec.title || t("core.post_editor.untitled"), + }, + ], + }); + isTitleChanged.value = false; + } + const { data: latestPost } = await coreApiClient.content.post.getPost({ name: formState.value.post.metadata.name, }); formState.value.post = latestPost; + settingModal.value = true; };