Resume pending action after login (favorite, diary, QR upload)
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 1m4s
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 1m4s
Add pendingAction callback to UI store. When user clicks favorite, save-to-diary, or upload QR while not logged in, the action is stored and automatically executed after successful login/register instead of reloading the page. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -104,8 +104,11 @@ async function submit() {
|
||||
ui.showToast('注册成功')
|
||||
}
|
||||
emit('close')
|
||||
// Reload page data after auth change
|
||||
if (ui.pendingAction) {
|
||||
ui.runPendingAction()
|
||||
} else {
|
||||
window.location.reload()
|
||||
}
|
||||
} catch (e) {
|
||||
errorMsg.value = e?.message || (mode.value === 'login' ? '登录失败,请检查用户名和密码' : '注册失败,请重试')
|
||||
} finally {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user