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('注册成功')
|
ui.showToast('注册成功')
|
||||||
}
|
}
|
||||||
emit('close')
|
emit('close')
|
||||||
// Reload page data after auth change
|
if (ui.pendingAction) {
|
||||||
window.location.reload()
|
ui.runPendingAction()
|
||||||
|
} else {
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMsg.value = e?.message || (mode.value === 'login' ? '登录失败,请检查用户名和密码' : '注册失败,请重试')
|
errorMsg.value = e?.message || (mode.value === 'login' ? '登录失败,请检查用户名和密码' : '注册失败,请重试')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -490,7 +490,7 @@ const showBrandHint = computed(() =>
|
|||||||
|
|
||||||
function goUploadQr() {
|
function goUploadQr() {
|
||||||
if (!authStore.isLoggedIn) {
|
if (!authStore.isLoggedIn) {
|
||||||
ui.openLogin()
|
ui.openLogin(() => goUploadQr())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (recipe.value._id) {
|
if (recipe.value._id) {
|
||||||
@@ -606,7 +606,7 @@ function getCardRecipeName() {
|
|||||||
// ---- Favorite ----
|
// ---- Favorite ----
|
||||||
async function handleToggleFavorite() {
|
async function handleToggleFavorite() {
|
||||||
if (!authStore.isLoggedIn) {
|
if (!authStore.isLoggedIn) {
|
||||||
ui.openLogin()
|
ui.openLogin(() => handleToggleFavorite())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!recipe.value._id) {
|
if (!recipe.value._id) {
|
||||||
@@ -625,7 +625,7 @@ async function handleToggleFavorite() {
|
|||||||
// ---- Save to diary ----
|
// ---- Save to diary ----
|
||||||
async function saveToDiary() {
|
async function saveToDiary() {
|
||||||
if (!authStore.isLoggedIn) {
|
if (!authStore.isLoggedIn) {
|
||||||
ui.openLogin()
|
ui.openLogin(() => saveToDiary())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const name = prompt('保存为我的配方,名称:', recipe.value.name)
|
const name = prompt('保存为我的配方,名称:', recipe.value.name)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export const useUiStore = defineStore('ui', () => {
|
|||||||
const currentSection = ref('search')
|
const currentSection = ref('search')
|
||||||
const showLoginModal = ref(false)
|
const showLoginModal = ref(false)
|
||||||
const toasts = ref([])
|
const toasts = ref([])
|
||||||
|
const pendingAction = ref(null)
|
||||||
|
|
||||||
let toastId = 0
|
let toastId = 0
|
||||||
|
|
||||||
@@ -20,7 +21,10 @@ export const useUiStore = defineStore('ui', () => {
|
|||||||
}, duration)
|
}, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
function openLogin() {
|
function openLogin(afterLogin) {
|
||||||
|
if (afterLogin) {
|
||||||
|
pendingAction.value = afterLogin
|
||||||
|
}
|
||||||
showLoginModal.value = true
|
showLoginModal.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,13 +32,23 @@ export const useUiStore = defineStore('ui', () => {
|
|||||||
showLoginModal.value = false
|
showLoginModal.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runPendingAction() {
|
||||||
|
if (pendingAction.value) {
|
||||||
|
const action = pendingAction.value
|
||||||
|
pendingAction.value = null
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentSection,
|
currentSection,
|
||||||
showLoginModal,
|
showLoginModal,
|
||||||
toasts,
|
toasts,
|
||||||
|
pendingAction,
|
||||||
showSection,
|
showSection,
|
||||||
showToast,
|
showToast,
|
||||||
openLogin,
|
openLogin,
|
||||||
closeLogin,
|
closeLogin,
|
||||||
|
runPendingAction,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user