From 005dc09a3a803b121c06c18229a6633ad238dfbb Mon Sep 17 00:00:00 2001 From: LonelySnowman <2438490168@qq.com> Date: Sun, 30 Jun 2024 18:08:45 +0800 Subject: [PATCH 1/2] feat: tag and category add save and continue button --- .../components/CategoryEditingModal.vue | 23 ++++++++++++++++-- .../posts/tags/components/TagEditingModal.vue | 24 +++++++++++++++++-- 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, 47 insertions(+), 4 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 84394a1fdb..fed0e08019 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); @@ -345,12 +356,20 @@ const { handleGenerateSlug } = useSlugify( :loading="saving" type="secondary" :text="$t('core.common.buttons.submit')" - @submit="$formkit.submit('category-form')" + @submit="handleSubmit" > {{ $t("core.common.buttons.cancel_and_shortcut") }} + + {{ $t("core.common.buttons.save_and_continue") }} + 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 ec60168e54..616e190b1d 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"); }); @@ -255,12 +267,20 @@ const { handleGenerateSlug } = useSlugify( :loading="saving" type="secondary" :text="$t('core.common.buttons.submit')" - @submit="$formkit.submit('tag-form')" + @submit="handleSubmit" > {{ $t("core.common.buttons.cancel_and_shortcut") }} + + {{ $t("core.common.buttons.save_and_continue") }} + diff --git a/ui/src/locales/en.yaml b/ui/src/locales/en.yaml index f0aca3625d..0886afe81e 100644 --- a/ui/src/locales/en.yaml +++ b/ui/src/locales/en.yaml @@ -1671,6 +1671,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 9b59ed9651..8107439eba 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 e39b65b16b..486a202bba 100644 --- a/ui/src/locales/zh-CN.yaml +++ b/ui/src/locales/zh-CN.yaml @@ -1588,6 +1588,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 195e6d9868..ecd526a485 100644 --- a/ui/src/locales/zh-TW.yaml +++ b/ui/src/locales/zh-TW.yaml @@ -1545,6 +1545,7 @@ core: buttons: save: 保存 close: 關閉 + save_and_continue: 保存並繼續添加 close_and_shortcut: 關閉(Esc) delete: 刪除 setting: 設置 From 85c16cf4091d6df022de5040694d611a3572d8fd Mon Sep 17 00:00:00 2001 From: LonelySnowman <2438490168@qq.com> Date: Mon, 1 Jul 2024 22:41:56 +0800 Subject: [PATCH 2/2] feat: change button position and loading status --- .../components/CategoryEditingModal.vue | 37 ++++++++++--------- .../posts/tags/components/TagEditingModal.vue | 37 ++++++++++--------- 2 files changed, 40 insertions(+), 34 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 fed0e08019..7ccf8b3b4d 100644 --- a/ui/console-src/modules/contents/posts/categories/components/CategoryEditingModal.vue +++ b/ui/console-src/modules/contents/posts/categories/components/CategoryEditingModal.vue @@ -351,26 +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 616e190b1d..a7b6378a31 100644 --- a/ui/console-src/modules/contents/posts/tags/components/TagEditingModal.vue +++ b/ui/console-src/modules/contents/posts/tags/components/TagEditingModal.vue @@ -262,26 +262,29 @@ const { handleGenerateSlug } = useSlugify(