fix: 复习详情返回按钮改为返回总览

This commit is contained in:
2026-09-13 23:12:23 +08:00
parent 66c3c68394
commit 132cb706d7
4 changed files with 89 additions and 7 deletions
+16 -3
View File
@@ -4,9 +4,9 @@
v-if="showBackButton"
text
class="back-btn"
@click="router.push('/welcome')"
@click="goBack"
>
← 返回首页
← {{ backLabel }}
</el-button>
<template v-if="pageTitle">
<h1 class="head-title">{{ pageTitle }}</h1>
@@ -39,8 +39,21 @@ const route = useRoute();
const isLoginRoute = computed(() => route.path === "/login");
const showBackButton = computed(() => route.path !== "/login" && route.path !== "/welcome");
const pageTitle = computed(() => route.meta?.title as string | undefined);
// 返回目标由路由 meta 声明,未声明时回首页
const backTo = computed(() => (route.meta?.backTo as string | undefined) || "/welcome");
const backLabel = computed(() => (route.meta?.backLabel as string | undefined) || "返回首页");
// 有多个入口的页面(如复习详情)优先回到用户来路,无历史时回退到声明的上级
const backUseHistory = computed(() => route.meta?.backUseHistory === true);
const loggingOut = ref(false);
const goBack = () => {
if (backUseHistory.value && window.history.state?.back) {
router.back();
return;
}
router.push(backTo.value);
};
const handleLogout = async () => {
if (loggingOut.value) return;
loggingOut.value = true;
@@ -58,7 +71,7 @@ const handleLogout = async () => {
}
};
defineExpose({ isLoginRoute, showBackButton, pageTitle, loggingOut, handleLogout });
defineExpose({ isLoginRoute, showBackButton, pageTitle, backTo, backLabel, loggingOut, goBack, handleLogout });
</script>
<style scoped>