From c5bf1924a60b26d63a594fe0efa0da787eb203f6 Mon Sep 17 00:00:00 2001 From: LonelySnowman <111493458+LonelySnowman@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:49:18 +0800 Subject: [PATCH] feat: tag and category add save and continue button (#6223) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature #### What this PR does / why we need it: 文章分类和标签 Modal 添加 ”保存并继续添加” 按钮,便于连续添加。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/6127 #### Special notes for your reviewer: ![image](https://github.com/halo-dev/halo/assets/111493458/4debe13e-4002-48a8-827b-58cb74b4b074) #### Does this PR introduce a user-facing change? ```release-note 文章分类和标签页添加 "保存并继续添加" 按钮。 ``` --- .../components/CategoryEditingModal.vue | 42 +++++++++++++----- .../posts/tags/components/TagEditingModal.vue | 43 ++++++++++++++----- ui/src/locales/en.yaml | 1 + ui/src/locales/es.yaml | 1 + ui/src/locales/zh-CN.yaml | 1 + ui/src/locales/zh-TW.yaml | 1 + 6 files changed, 69 insertions(+), 20 deletions(-) diff --git a/ui/console-src/modules/contents/posts/categories/components/CategoryEditingModal.vue b/ui/console-src/modules/contents/posts/categories/components/CategoryEditingModal.vue index 84394a1fd..7ccf8b3b4 100644 --- a/ui/console-src/modules/contents/posts/categories/components/CategoryEditingModal.vue +++ b/ui/console-src/modules/contents/posts/categories/components/CategoryEditingModal.vue @@ -21,6 +21,7 @@ import { import { useQueryClient } from "@tanstack/vue-query"; import { cloneDeep } from "lodash-es"; import { useI18n } from "vue-i18n"; +import { submitForm, reset } from "@formkit/core"; const props = withDefaults( defineProps<{ @@ -65,6 +66,7 @@ const formState = ref({ const selectedParentCategory = ref(); const saving = ref(false); const modal = ref | null>(null); +const keepAddingSubmit = ref(false); const isUpdateMode = !!props.category; @@ -133,7 +135,11 @@ const handleSaveCategory = async () => { } } - modal.value?.close(); + if (keepAddingSubmit.value) { + reset("category-form"); + } else { + modal.value?.close(); + } queryClient.invalidateQueries({ queryKey: ["post-categories"] }); @@ -145,6 +151,11 @@ const handleSaveCategory = async () => { } }; +const handleSubmit = (keepAdding = false) => { + keepAddingSubmit.value = keepAdding; + submitForm("category-form"); +}; + onMounted(() => { if (props.category) { formState.value = cloneDeep(props.category); @@ -340,18 +351,29 @@ const { handleGenerateSlug } = useSlugify( diff --git a/ui/console-src/modules/contents/posts/tags/components/TagEditingModal.vue b/ui/console-src/modules/contents/posts/tags/components/TagEditingModal.vue index ec60168e5..a7b6378a3 100644 --- a/ui/console-src/modules/contents/posts/tags/components/TagEditingModal.vue +++ b/ui/console-src/modules/contents/posts/tags/components/TagEditingModal.vue @@ -26,6 +26,7 @@ import useSlugify from "@console/composables/use-slugify"; import { cloneDeep } from "lodash-es"; import { onMounted } from "vue"; import { useI18n } from "vue-i18n"; +import { submitForm, reset } from "@formkit/core"; const props = withDefaults( defineProps<{ @@ -63,6 +64,8 @@ const modal = ref | null>(null); const saving = ref(false); +const keepAddingSubmit = ref(false); + const isUpdateMode = computed(() => !!props.tag); const modalTitle = computed(() => { @@ -101,7 +104,11 @@ const handleSaveTag = async () => { }); } - modal.value?.close(); + if (keepAddingSubmit.value) { + reset("tag-form"); + } else { + modal.value?.close(); + } Toast.success(t("core.common.toast.save_success")); } catch (e) { @@ -111,6 +118,11 @@ const handleSaveTag = async () => { } }; +const handleSubmit = (keepAdding = false) => { + keepAddingSubmit.value = keepAdding; + submitForm("tag-form"); +}; + onMounted(() => { setFocus("displayNameInput"); }); @@ -250,18 +262,29 @@ const { handleGenerateSlug } = useSlugify( diff --git a/ui/src/locales/en.yaml b/ui/src/locales/en.yaml index 1757a21fe..158216d6b 100644 --- a/ui/src/locales/en.yaml +++ b/ui/src/locales/en.yaml @@ -1729,6 +1729,7 @@ core: buttons: save: Save close: Close + save_and_continue: Save and keep adding close_and_shortcut: Close (Esc) delete: Delete setting: Setting diff --git a/ui/src/locales/es.yaml b/ui/src/locales/es.yaml index 9b59ed965..8107439eb 100644 --- a/ui/src/locales/es.yaml +++ b/ui/src/locales/es.yaml @@ -1308,6 +1308,7 @@ core: buttons: save: Guardar close: Cerrar + save_and_continue: Guardar y seguir añadiendo close_and_shortcut: Cerrar (Esc) delete: Borrar setting: Configuración diff --git a/ui/src/locales/zh-CN.yaml b/ui/src/locales/zh-CN.yaml index 222bde873..bf342f3dc 100644 --- a/ui/src/locales/zh-CN.yaml +++ b/ui/src/locales/zh-CN.yaml @@ -1644,6 +1644,7 @@ core: buttons: save: 保存 close: 关闭 + save_and_continue: 保存并继续添加 close_and_shortcut: 关闭(Esc) delete: 删除 setting: 设置 diff --git a/ui/src/locales/zh-TW.yaml b/ui/src/locales/zh-TW.yaml index 2fac839b5..420e27717 100644 --- a/ui/src/locales/zh-TW.yaml +++ b/ui/src/locales/zh-TW.yaml @@ -1601,6 +1601,7 @@ core: buttons: save: 保存 close: 關閉 + save_and_continue: 保存並繼續添加 close_and_shortcut: 關閉(Esc) delete: 刪除 setting: 設置