fix: 退出登录补防抖加载

This commit is contained in:
2026-08-05 21:45:40 +08:00
parent 370d8e7769
commit 4e8aa15b71
2 changed files with 34 additions and 6 deletions
+13 -6
View File
@@ -20,6 +20,7 @@
type="success"
plain
class="logout-btn"
:loading="loggingOut"
@click="handleLogout"
>
退出登录
@@ -28,7 +29,7 @@
</template>
<script setup lang="ts">
import { computed } from "vue";
import { computed, ref } from "vue";
import { useRoute } from "vue-router";
import { ElMessage } from "element-plus";
import router from "@/router";
@@ -38,20 +39,26 @@ 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);
const loggingOut = ref(false);
const handleLogout = async () => {
if (loggingOut.value) return;
loggingOut.value = true;
try {
await logout();
} catch {
// 后端退出失败时,仍然清理前端登录态,避免用户被卡住。
} finally {
try {
await logout();
} catch {
// 后端退出失败时,仍然清理前端登录态,避免用户被卡住。
}
localStorage.removeItem("isLoggedIn");
ElMessage.success("已退出登录");
await router.push("/login");
} finally {
loggingOut.value = false;
}
};
defineExpose({ isLoginRoute, showBackButton, pageTitle, handleLogout });
defineExpose({ isLoginRoute, showBackButton, pageTitle, loggingOut, handleLogout });
</script>
<style scoped>