feat: 退出时选择离开系统或删除账号

This commit is contained in:
Nixevol
2026-11-18 10:16:29 +08:00
parent bb23521e9b
commit 3670a76dfe
4 changed files with 88 additions and 40 deletions
+43 -25
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from "vue";
import { NButton, NDropdown, NIcon, NLayout, NLayoutSider, NMenu, NTooltip, useDialog } from "naive-ui";
import { NButton, NIcon, NLayout, NLayoutSider, NMenu, NModal, NRadio, NRadioGroup, NTooltip } from "naive-ui";
import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons/ionicons5";
import { isDark, toggleTheme } from "../shared/theme";
import { navOptions, type PageKey } from "./navigation";
@@ -11,10 +11,11 @@ import TrainingsView from "../features/trainings/TrainingsView.vue";
const props = defineProps<{ employeeId: string }>();
const emit = defineEmits<{ logout: []; revoke: [] }>();
const dialog = useDialog();
const page = ref<PageKey>(pageFromHash());
const collapsed = ref(window.innerWidth < 800);
const holdOpen = ref(false);
const leaveOpen = ref(false);
const leaveChoice = ref<"logout" | "revoke" | null>(null);
const pages = new Set<PageKey>(["home", "history", "exams", "trainings"]);
function hashName() {
@@ -73,28 +74,21 @@ onUnmounted(() => {
window.removeEventListener("hashchange", onHashChange);
});
const logoutOptions = [
{ label: "退出当前系统", key: "logout" },
{ label: "注销当前账号", key: "revoke" },
];
function onMenu(key: string) {
if (key === "home" || key === "history" || key === "exams" || key === "trainings") show(key);
}
function onLogout(key: string) {
if (key !== "revoke") {
emit("logout");
return;
}
dialog.warning({
title: "注销当前账号",
content: "注销后所有设备都会退出,正在进行的学习会停止,已保存的密码和登录凭证也会清除。",
positiveText: "注销",
negativeText: "取消",
positiveButtonProps: { type: "error" },
onPositiveClick: () => emit("revoke"),
});
function openLeave() {
leaveChoice.value = null;
leaveOpen.value = true;
}
function confirmLeave() {
const choice = leaveChoice.value;
if (!choice) return;
leaveOpen.value = false;
if (choice === "revoke") emit("revoke");
else emit("logout");
}
</script>
@@ -139,11 +133,9 @@ function onLogout(key: string) {
</template>
{{ isDark ? "切换到日间" : "切换到夜间" }}
</n-tooltip>
<n-dropdown trigger="click" placement="top-end" :options="logoutOptions" @select="onLogout">
<n-button class="logout-btn" quaternary circle size="small" aria-label="退出">
<template #icon><n-icon><LogOutOutline /></n-icon></template>
</n-button>
</n-dropdown>
<n-button class="logout-btn" quaternary circle size="small" aria-label="退出" @click="openLeave">
<template #icon><n-icon><LogOutOutline /></n-icon></template>
</n-button>
</div>
</div>
</n-layout-sider>
@@ -153,5 +145,31 @@ function onLogout(key: string) {
<ExamsView v-else-if="page === 'exams'" />
<TrainingsView v-else />
</n-layout>
<n-modal
v-model:show="leaveOpen"
preset="card"
title="退出"
:style="{ width: 'min(440px, calc(100vw - 32px))' }"
:mask-closable="false"
>
<n-radio-group v-model:value="leaveChoice" class="leave-choices">
<n-radio value="logout">退出系统</n-radio>
<n-radio value="revoke">注销账号</n-radio>
</n-radio-group>
<p v-if="leaveChoice === 'logout'" class="leave-note">定时计划和已开始的任务不会受影响。</p>
<p v-else-if="leaveChoice === 'revoke'" class="leave-note">会从平台删除这个账号,定时任务和已开始的任务会一并删除。</p>
<template #footer>
<div class="modal-actions">
<n-button @click="leaveOpen = false">取消</n-button>
<n-button
:type="leaveChoice === 'revoke' ? 'error' : 'primary'"
:disabled="leaveChoice === null"
@click="confirmLeave"
>
{{ leaveChoice === "revoke" ? "注销账号" : "退出系统" }}
</n-button>
</div>
</template>
</n-modal>
</n-layout>
</template>