fix: 下载管理可以删除未在进行中的任务
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NButton, NEmpty, NIcon, NInputNumber, NProgress, NTag, NTooltip, useMessage } from "naive-ui";
|
||||
import { ChevronBackOutline, FolderOpenOutline, HelpCircleOutline, PauseOutline, PlayOutline, StopCircleOutline } from "@vicons/ionicons5";
|
||||
import { NButton, NEmpty, NIcon, NInputNumber, NProgress, NTag, NTooltip, useDialog, useMessage } from "naive-ui";
|
||||
import { ChevronBackOutline, FolderOpenOutline, HelpCircleOutline, PauseOutline, PlayOutline, StopCircleOutline, TrashOutline } from "@vicons/ionicons5";
|
||||
import { ApiError, openLocal, revealLocal } from "../../shared/http";
|
||||
import { cancelJob, loadDownloadSettings, loadJobs, pauseJob, resumeJob, saveDownloadSettings, type DownloadJob } from "./api";
|
||||
import { cancelJob, deleteJob, loadDownloadSettings, loadJobs, pauseJob, resumeJob, saveDownloadSettings, type DownloadJob } from "./api";
|
||||
|
||||
const props = defineProps<{ focusId: string }>();
|
||||
const message = useMessage();
|
||||
const dialog = useDialog();
|
||||
const jobs = ref<DownloadJob[]>([]);
|
||||
const maxJobs = ref(2);
|
||||
const tab = ref<"active" | "done">("active");
|
||||
@@ -160,6 +161,33 @@ async function openDir(job: DownloadJob) {
|
||||
const revealed = await revealLocal(job.csvPath).catch(() => false);
|
||||
if (!revealed) message.info(job.csvPath);
|
||||
}
|
||||
|
||||
function inProgress(job: DownloadJob) {
|
||||
return Boolean(job.stopping) || job.status === "running" || job.status === "queued";
|
||||
}
|
||||
|
||||
function confirmDelete(job: DownloadJob) {
|
||||
dialog.warning({
|
||||
title: "删除任务",
|
||||
content: "是否同时删除这个任务的下载文件夹?",
|
||||
positiveText: "同时删除",
|
||||
negativeText: "只删除任务",
|
||||
maskClosable: false,
|
||||
onPositiveClick: () => removeJob(job, true),
|
||||
onNegativeClick: () => removeJob(job, false),
|
||||
});
|
||||
}
|
||||
|
||||
async function removeJob(job: DownloadJob, files: boolean) {
|
||||
try {
|
||||
await deleteJob(job.id, files);
|
||||
if (openedId.value === job.id) openedId.value = "";
|
||||
message.success("已删除任务");
|
||||
await refresh();
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "删除失败");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -205,6 +233,10 @@ async function openDir(job: DownloadJob) {
|
||||
<n-button size="small" quaternary @click="openDir(opened)">
|
||||
<template #icon><n-icon><FolderOpenOutline /></n-icon></template>
|
||||
</n-button>
|
||||
<n-button v-if="!inProgress(opened)" size="small" @click="confirmDelete(opened)">
|
||||
<template #icon><n-icon><TrashOutline /></n-icon></template>
|
||||
删除
|
||||
</n-button>
|
||||
</div>
|
||||
<div v-else class="head-actions">
|
||||
<span class="limit-label">同时任务</span>
|
||||
@@ -315,6 +347,10 @@ async function openDir(job: DownloadJob) {
|
||||
<n-button size="small" quaternary @click="openDir(job)">
|
||||
<template #icon><n-icon><FolderOpenOutline /></n-icon></template>
|
||||
</n-button>
|
||||
<n-button v-if="!inProgress(job)" size="small" @click="confirmDelete(job)">
|
||||
<template #icon><n-icon><TrashOutline /></n-icon></template>
|
||||
删除
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<n-progress
|
||||
|
||||
@@ -35,6 +35,7 @@ export interface DownloadJob {
|
||||
csvPath: string;
|
||||
failures: { id: string; message: string }[];
|
||||
createdAt: string;
|
||||
stopping?: boolean;
|
||||
}
|
||||
|
||||
export function loadMeta() {
|
||||
@@ -72,6 +73,11 @@ export function pauseJob(id: string) {
|
||||
return api<DownloadJob>(`/api/download/jobs/${id}/pause`, { method: "POST" });
|
||||
}
|
||||
|
||||
export function deleteJob(id: string, files: boolean) {
|
||||
const flag = files ? "true" : "false";
|
||||
return api<unknown>(`/api/download/jobs/${encodeURIComponent(id)}?files=${flag}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function loadDownloadSettings() {
|
||||
return api<{ maxConcurrentJobs: number }>("/api/download/settings");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user