feat: 去掉停止按钮,等待中的任务也能暂停
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NButton, NCheckbox, NEmpty, NIcon, NInputNumber, NProgress, NTag, NTooltip, useDialog, useMessage } from "naive-ui";
|
||||
import { ChevronBackOutline, FolderOpenOutline, HelpCircleOutline, PauseOutline, PlayOutline, StopCircleOutline, TrashOutline } from "@vicons/ionicons5";
|
||||
import { ChevronBackOutline, FolderOpenOutline, HelpCircleOutline, PauseOutline, PlayOutline, TrashOutline } from "@vicons/ionicons5";
|
||||
import { ApiError, revealLocal } from "../../shared/http";
|
||||
import { cancelJob, deleteJob, loadDownloadSettings, loadJobs, pauseJob, resumeJob, saveDownloadSettings, updateConcurrency, type DownloadJob } from "./api";
|
||||
import { deleteJob, loadDownloadSettings, loadJobs, pauseJob, resumeJob, saveDownloadSettings, updateConcurrency, type DownloadJob } from "./api";
|
||||
|
||||
const props = defineProps<{ focusId: string }>();
|
||||
const message = useMessage();
|
||||
@@ -25,7 +25,7 @@ const doneJobs = computed(() => jobs.value.filter((job) => job.status === "done"
|
||||
const visible = computed(() => (tab.value === "active" ? activeJobs.value : doneJobs.value));
|
||||
const opened = computed(() => jobs.value.find((job) => job.id === openedId.value) ?? null);
|
||||
const selectedVisible = computed(() => visible.value.filter((job) => selectedIds.value.includes(job.id)));
|
||||
const pauseTargets = computed(() => selectedVisible.value.filter((job) => job.status === "running" && !job.stopping));
|
||||
const pauseTargets = computed(() => selectedVisible.value.filter((job) => canPause(job)));
|
||||
const resumeTargets = computed(() =>
|
||||
selectedVisible.value.filter((job) => job.status !== "running" && job.status !== "done" && job.status !== "queued"),
|
||||
);
|
||||
@@ -212,15 +212,6 @@ async function pause(job: DownloadJob) {
|
||||
}
|
||||
}
|
||||
|
||||
async function stop(job: DownloadJob) {
|
||||
try {
|
||||
await cancelJob(job.id);
|
||||
await refresh();
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "停止失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function resume(job: DownloadJob) {
|
||||
try {
|
||||
await resumeJob(job.id);
|
||||
@@ -237,7 +228,11 @@ async function openDir(job: DownloadJob) {
|
||||
}
|
||||
|
||||
function inProgress(job: DownloadJob) {
|
||||
return Boolean(job.stopping) || job.status === "running" || job.status === "queued";
|
||||
return Boolean(job.stopping) || job.status === "running";
|
||||
}
|
||||
|
||||
function canPause(job: DownloadJob) {
|
||||
return !job.stopping && (job.status === "running" || job.status === "queued");
|
||||
}
|
||||
|
||||
function confirmDelete(job: DownloadJob) {
|
||||
@@ -301,7 +296,7 @@ function resumeSelected() {
|
||||
function confirmDeleteSelected() {
|
||||
const targets = deleteTargets.value;
|
||||
if (!targets.length) {
|
||||
message.info("正在下载的任务要先停止才能删除");
|
||||
message.info("正在下载的任务要先暂停才能删除");
|
||||
return;
|
||||
}
|
||||
dialog.warning({
|
||||
@@ -350,28 +345,11 @@ async function removeJob(job: DownloadJob, files: boolean) {
|
||||
<n-tag size="small" :type="opened.status === 'running' ? 'info' : opened.status === 'done' ? 'success' : opened.status === 'paused' ? 'warning' : 'default'">
|
||||
{{ statusLabel(opened) }}
|
||||
</n-tag>
|
||||
<template v-if="opened.status === 'running'">
|
||||
<n-button v-if="!opened.stopping" size="small" @click="pause(opened)">
|
||||
<template #icon><n-icon><PauseOutline /></n-icon></template>
|
||||
暂停
|
||||
</n-button>
|
||||
<n-button size="small" @click="stop(opened)">
|
||||
<template #icon><n-icon><StopCircleOutline /></n-icon></template>
|
||||
停止
|
||||
</n-button>
|
||||
</template>
|
||||
<template v-else-if="opened.status === 'paused'">
|
||||
<n-button size="small" type="primary" secondary @click="resume(opened)">
|
||||
<template #icon><n-icon><PlayOutline /></n-icon></template>
|
||||
继续
|
||||
</n-button>
|
||||
<n-button size="small" @click="stop(opened)">
|
||||
<template #icon><n-icon><StopCircleOutline /></n-icon></template>
|
||||
停止
|
||||
</n-button>
|
||||
</template>
|
||||
<n-button v-else-if="opened.status === 'queued'" size="small" @click="stop(opened)">取消</n-button>
|
||||
<n-button v-else-if="opened.status !== 'done'" size="small" type="primary" secondary @click="resume(opened)">
|
||||
<n-button v-if="canPause(opened)" size="small" @click="pause(opened)">
|
||||
<template #icon><n-icon><PauseOutline /></n-icon></template>
|
||||
暂停
|
||||
</n-button>
|
||||
<n-button v-else-if="opened.status !== 'done' && !inProgress(opened)" size="small" type="primary" secondary @click="resume(opened)">
|
||||
<template #icon><n-icon><PlayOutline /></n-icon></template>
|
||||
继续
|
||||
</n-button>
|
||||
@@ -507,30 +485,11 @@ async function removeJob(job: DownloadJob, files: boolean) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="task-actions" @click.stop>
|
||||
<template v-if="job.status === 'running'">
|
||||
<n-button v-if="!job.stopping" size="small" @click="pause(job)">
|
||||
<template #icon><n-icon><PauseOutline /></n-icon></template>
|
||||
暂停
|
||||
</n-button>
|
||||
<n-button size="small" @click="stop(job)">
|
||||
<template #icon><n-icon><StopCircleOutline /></n-icon></template>
|
||||
停止
|
||||
</n-button>
|
||||
</template>
|
||||
<template v-else-if="job.status === 'paused'">
|
||||
<n-button size="small" type="primary" secondary @click="resume(job)">
|
||||
<template #icon><n-icon><PlayOutline /></n-icon></template>
|
||||
继续
|
||||
</n-button>
|
||||
<n-button size="small" @click="stop(job)">
|
||||
<template #icon><n-icon><StopCircleOutline /></n-icon></template>
|
||||
停止
|
||||
</n-button>
|
||||
</template>
|
||||
<n-button v-else-if="job.status === 'queued'" size="small" @click="stop(job)">
|
||||
取消
|
||||
<n-button v-if="canPause(job)" size="small" @click="pause(job)">
|
||||
<template #icon><n-icon><PauseOutline /></n-icon></template>
|
||||
暂停
|
||||
</n-button>
|
||||
<n-button v-else-if="job.status !== 'done'" size="small" type="primary" secondary @click="resume(job)">
|
||||
<n-button v-else-if="job.status !== 'done' && !inProgress(job)" size="small" type="primary" secondary @click="resume(job)">
|
||||
<template #icon><n-icon><PlayOutline /></n-icon></template>
|
||||
继续
|
||||
</n-button>
|
||||
|
||||
Reference in New Issue
Block a user