feat(console): confirm sign-out from desktop and mobile

Expose sign-out in the mobile topbar when the sidebar is hidden. Both entry points use the in-app confirmation before navigating to the server logout endpoint.
This commit is contained in:
翅膀 committed 2026-10-17 12:21:54 +08:00
1 parent 1c4639b07d
commit ce4be66bac
5 files changed
+48 -7

No files matched your search

+2 -1
View File
@@ -28,7 +28,7 @@
</template>
<script setup lang="ts">
import { Trash2, TriangleAlert } from "lucide-vue-next";
import { LogOut, Trash2, TriangleAlert } from "lucide-vue-next";
import {
AlertDialogCancel,
AlertDialogContent,
@@ -46,6 +46,7 @@ const { pending: request, settle, attachHost } = useConfirm();
const KIND_ICONS = {
delete: Trash2,
leave: TriangleAlert,
signOut: LogOut,
} satisfies Record<NonNullable<ConfirmOptions["kind"]>, typeof Trash2>;
// Keep the last request on screen while the close animation plays.
+42 -4
View File
@@ -21,7 +21,7 @@
</button>
</nav>
<div class="console-sidebar-footer">
<a href="/admin/logout"><LogOut :size="16" />{{ t("app.signOut") }}</a>
<button type="button" @click="signOut"><LogOut :size="16" />{{ t("app.signOut") }}</button>
</div>
</aside>
@@ -45,6 +45,19 @@
<RcButton variant="ghost" size="sm" @click="toggle"
><Languages :size="15" class="console-lang-icon" />{{ t("app.langToggle") }}</RcButton
>
<!-- The sidebar (with its sign-out) is hidden on narrow screens. -->
<RcButton
v-if="!needLogin"
variant="ghost"
size="sm"
class="console-topbar-signout"
:title="t('app.signOut')"
:aria-label="t('app.signOut')"
@click="signOut"
><LogOut :size="15" /><span class="console-signout-label">{{
t("app.signOut")
}}</span></RcButton
>
</div>
<div class="console-actions">
<RcButton v-if="view === 'overview'" variant="ghost" size="sm" @click="refreshOverview"
@@ -645,6 +658,16 @@ function restoreShownEntry(): void {
}
}
async function signOut(): Promise<void> {
const confirmed = await confirm({
title: t("confirm.signOut"),
confirmText: t("app.signOut"),
kind: "signOut",
});
// A full page load: the server clears the session and redirects.
if (confirmed) window.location.assign("/admin/logout");
}
// A newer navigation supersedes one still waiting for an answer: that
// question (like any other confirmation of this page) is cancelled first.
function supersedePending(): void {
@@ -986,16 +1009,20 @@ async function onDeleteGroup(group: Group): Promise<void> {
padding: 0.9rem 0.55rem 0.25rem;
border-top: 1px solid rgb(var(--wh-border));
}
.console-sidebar-footer a {
.console-sidebar-footer button {
display: inline-flex;
align-items: center;
gap: 0.55rem;
border: 0;
background: transparent;
padding: 0;
color: rgb(var(--wh-muted));
font: inherit;
font-size: 0.8rem;
font-weight: 700;
text-decoration: none;
cursor: pointer;
}
.console-sidebar-footer a:hover {
.console-sidebar-footer button:hover {
color: rgb(var(--wh-bad));
}
.console-main {
@@ -1047,6 +1074,9 @@ async function onDeleteGroup(group: Group): Promise<void> {
.console-status {
white-space: nowrap;
}
.console-topbar-signout {
display: none;
}
.console-mobile-nav {
display: none;
}
@@ -1184,6 +1214,9 @@ async function onDeleteGroup(group: Group): Promise<void> {
.console-sidebar {
display: none;
}
.console-topbar-signout {
display: inline-flex;
}
.console-mobile-nav {
display: block;
border-bottom: 1px solid rgb(var(--wh-border));
@@ -1229,9 +1262,14 @@ async function onDeleteGroup(group: Group): Promise<void> {
}
/* Keep the top-right tools compact so the title column stays readable. */
.console-status,
.console-signout-label,
.console-lang-icon {
display: none;
}
.console-topbar-signout {
width: 2rem;
padding-inline: 0;
}
.console-content {
width: min(100% - 1.25rem, 1240px);
}
+1 -1
View File
@@ -6,7 +6,7 @@ export interface ConfirmOptions {
/** Label of the destructive button (defaults to "Delete"). */
confirmText?: string;
/** What the action does, shown as the dialog icon (defaults to "delete"). */
kind?: "delete" | "leave";
kind?: "delete" | "leave" | "signOut";
}
interface ConfirmRequest extends ConfirmOptions {
+2
View File
@@ -446,6 +446,7 @@ const en: Dict = {
"confirm.leaveUnsaved": "Leave this page?",
"confirm.leaveUnsavedDesc": "Your unsaved changes will be lost.",
"confirm.leave": "Leave",
"confirm.signOut": "Sign out of the console?",
};
const zh: Dict = {
@@ -883,6 +884,7 @@ const zh: Dict = {
"confirm.leaveUnsaved": "确定离开此页面吗?",
"confirm.leaveUnsavedDesc": "尚未保存的修改将会丢失。",
"confirm.leave": "离开",
"confirm.signOut": "确定退出登录吗?",
};
const messages: Record<Locale, Dict> = { en, zh };