diff --git a/frontend/src/components/LoginModal.vue b/frontend/src/components/LoginModal.vue index 0a1b2b9..9481c4d 100644 --- a/frontend/src/components/LoginModal.vue +++ b/frontend/src/components/LoginModal.vue @@ -104,8 +104,11 @@ async function submit() { ui.showToast('注册成功') } emit('close') - // Reload page data after auth change - window.location.reload() + if (ui.pendingAction) { + ui.runPendingAction() + } else { + window.location.reload() + } } catch (e) { errorMsg.value = e?.message || (mode.value === 'login' ? '登录失败,请检查用户名和密码' : '注册失败,请重试') } finally { diff --git a/frontend/src/components/RecipeDetailOverlay.vue b/frontend/src/components/RecipeDetailOverlay.vue index 354e52f..0fdb13b 100644 --- a/frontend/src/components/RecipeDetailOverlay.vue +++ b/frontend/src/components/RecipeDetailOverlay.vue @@ -490,7 +490,7 @@ const showBrandHint = computed(() => function goUploadQr() { if (!authStore.isLoggedIn) { - ui.openLogin() + ui.openLogin(() => goUploadQr()) return } if (recipe.value._id) { @@ -606,7 +606,7 @@ function getCardRecipeName() { // ---- Favorite ---- async function handleToggleFavorite() { if (!authStore.isLoggedIn) { - ui.openLogin() + ui.openLogin(() => handleToggleFavorite()) return } if (!recipe.value._id) { @@ -625,7 +625,7 @@ async function handleToggleFavorite() { // ---- Save to diary ---- async function saveToDiary() { if (!authStore.isLoggedIn) { - ui.openLogin() + ui.openLogin(() => saveToDiary()) return } const name = prompt('保存为我的配方,名称:', recipe.value.name) diff --git a/frontend/src/stores/ui.js b/frontend/src/stores/ui.js index d767041..1cb63e9 100644 --- a/frontend/src/stores/ui.js +++ b/frontend/src/stores/ui.js @@ -5,6 +5,7 @@ export const useUiStore = defineStore('ui', () => { const currentSection = ref('search') const showLoginModal = ref(false) const toasts = ref([]) + const pendingAction = ref(null) let toastId = 0 @@ -20,7 +21,10 @@ export const useUiStore = defineStore('ui', () => { }, duration) } - function openLogin() { + function openLogin(afterLogin) { + if (afterLogin) { + pendingAction.value = afterLogin + } showLoginModal.value = true } @@ -28,13 +32,23 @@ export const useUiStore = defineStore('ui', () => { showLoginModal.value = false } + function runPendingAction() { + if (pendingAction.value) { + const action = pendingAction.value + pendingAction.value = null + action() + } + } + return { currentSection, showLoginModal, toasts, + pendingAction, showSection, showToast, openLogin, closeLogin, + runPendingAction, } })