fix: 退出登录前确认正在下载的任务

This commit is contained in:
2026-10-25 07:37:08 +08:00
parent 8a23318862
commit a96eaff5fb
3 changed files with 58 additions and 7 deletions
+39 -1
View File
@@ -1,8 +1,10 @@
<script setup lang="ts">
import { ref } from "vue";
import { NButton, NIcon, NLayoutSider, NMenu } from "naive-ui";
import { NButton, NIcon, NLayoutSider, NMenu, useDialog } from "naive-ui";
import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons/ionicons5";
import { logout, type UserInfo } from "../features/auth/api";
import { loadActiveDownloadCount } from "../features/download/api";
import { ApiError } from "../shared/http";
import { isDark, toggleTheme } from "../shared/theme";
import { navOptions, type PageKey } from "./navigation";
import GridDownloadView from "../features/download/GridDownloadView.vue";
@@ -10,6 +12,7 @@ import DownloadManagerView from "../features/download/DownloadManagerView.vue";
const props = defineProps<{ user: UserInfo }>();
const emit = defineEmits<{ logout: [] }>();
const dialog = useDialog();
const page = ref<PageKey>("grid");
const expanded = ref<string[]>([]);
@@ -24,7 +27,42 @@ function onStarted(id: string) {
page.value = "tasks";
}
function askLogout(count: number) {
return new Promise<boolean>((resolve) => {
let settled = false;
const finish = (value: boolean) => {
if (settled) return;
settled = true;
resolve(value);
};
dialog.warning({
title: "退出登录",
content: `有 ${count} 个任务正在下载,退出后会暂停,重新登录后点继续`,
positiveText: "退出",
negativeText: "取消",
maskClosable: false,
onPositiveClick: () => finish(true),
onNegativeClick: () => finish(false),
onClose: () => finish(false),
});
});
}
async function signOut() {
let count = 0;
try {
count = await loadActiveDownloadCount();
} catch (error) {
if (error instanceof ApiError && error.status === 401) {
emit("logout");
return;
}
count = 0;
}
if (count > 0) {
const confirmed = await askLogout(count);
if (!confirmed) return;
}
try {
await logout();
} finally {