feat: 未知进度不显示进度条并增加任务详情
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NButton, NEmpty, NIcon, NInputNumber, NProgress, NTag, NTooltip, useMessage } from "naive-ui";
|
||||
import { FolderOpenOutline, HelpCircleOutline, PauseOutline, PlayOutline, StopCircleOutline } from "@vicons/ionicons5";
|
||||
import { ChevronBackOutline, FolderOpenOutline, HelpCircleOutline, PauseOutline, PlayOutline, StopCircleOutline } from "@vicons/ionicons5";
|
||||
import { ApiError, openLocal } from "../../shared/http";
|
||||
import { cancelJob, loadDownloadSettings, loadJobs, pauseJob, resumeJob, saveDownloadSettings, type DownloadJob } from "./api";
|
||||
|
||||
@@ -10,11 +10,13 @@ const message = useMessage();
|
||||
const jobs = ref<DownloadJob[]>([]);
|
||||
const maxJobs = ref(2);
|
||||
const tab = ref<"active" | "done">("active");
|
||||
const openedId = ref("");
|
||||
let timer = 0;
|
||||
|
||||
const activeJobs = computed(() => jobs.value.filter((job) => job.status !== "done"));
|
||||
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 statusText: Record<string, string> = {
|
||||
queued: "等待中",
|
||||
@@ -56,11 +58,35 @@ function scanning(job: DownloadJob) {
|
||||
return Boolean(job.wholeCity) && job.listingDone === false;
|
||||
}
|
||||
|
||||
function hasProgress(job: DownloadJob) {
|
||||
return !scanning(job) && job.total > 0;
|
||||
}
|
||||
|
||||
function percent(job: DownloadJob) {
|
||||
if (scanning(job) || !job.total) return 0;
|
||||
if (!hasProgress(job)) return 0;
|
||||
return Math.min(100, Math.round((job.completed / job.total) * 100));
|
||||
}
|
||||
|
||||
function formatSize(bytes?: number) {
|
||||
const size = bytes || 0;
|
||||
if (size < 1024) return `${size} B`;
|
||||
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;
|
||||
if (size < 1024 * 1024 * 1024) return `${(size / 1024 / 1024).toFixed(1)} MB`;
|
||||
return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
||||
}
|
||||
|
||||
function gridLabel(job: DownloadJob) {
|
||||
return job.gridSize === "GRID50" ? "50米" : "20米";
|
||||
}
|
||||
|
||||
function openDetail(job: DownloadJob) {
|
||||
openedId.value = job.id;
|
||||
}
|
||||
|
||||
function closeDetail() {
|
||||
openedId.value = "";
|
||||
}
|
||||
|
||||
function countText(job: DownloadJob) {
|
||||
const written = `已写入 ${job.writtenRows} 行`;
|
||||
const progress = scanning(job)
|
||||
@@ -124,10 +150,48 @@ async function openDir(job: DownloadJob) {
|
||||
<template>
|
||||
<section class="page">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<h2>下载管理</h2>
|
||||
<div class="head-title">
|
||||
<n-button v-if="opened" quaternary size="small" @click="closeDetail">
|
||||
<template #icon><n-icon><ChevronBackOutline /></n-icon></template>
|
||||
返回
|
||||
</n-button>
|
||||
<h2>{{ opened ? opened.name : "下载管理" }}</h2>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<div v-if="opened" class="head-actions">
|
||||
<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.message !== '正在停止'" 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)">
|
||||
<template #icon><n-icon><PlayOutline /></n-icon></template>
|
||||
继续
|
||||
</n-button>
|
||||
<n-button size="small" quaternary @click="openFile(opened)">打开</n-button>
|
||||
<n-button size="small" quaternary @click="openDir(opened)">
|
||||
<template #icon><n-icon><FolderOpenOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</div>
|
||||
<div v-else class="head-actions">
|
||||
<span class="limit-label">同时任务</span>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
@@ -145,7 +209,42 @@ async function openDir(job: DownloadJob) {
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
<div class="tabs">
|
||||
<div v-if="opened" class="task-list">
|
||||
<div class="detail">
|
||||
<n-progress
|
||||
v-if="hasProgress(opened)"
|
||||
:percentage="percent(opened)"
|
||||
:processing="opened.status === 'running'"
|
||||
/>
|
||||
<div class="form-row"><label>任务号</label><span>{{ opened.id }}</span></div>
|
||||
<div class="form-row"><label>状态</label><span>{{ statusLabel(opened) }}</span></div>
|
||||
<div class="form-row"><label>说明</label><span>{{ opened.message || "—" }}</span></div>
|
||||
<div class="form-row"><label>网络</label><span>{{ opened.network === "NR" ? "5G" : "4G" }}</span></div>
|
||||
<div class="form-row"><label>地市</label><span>{{ opened.cityName }}</span></div>
|
||||
<div class="form-row"><label>月份</label><span>{{ opened.month }}</span></div>
|
||||
<div class="form-row"><label>栅格</label><span>{{ gridLabel(opened) }}</span></div>
|
||||
<div class="form-row"><label>范围</label><span>{{ opened.wholeCity ? "整个地市" : "区域表" }}</span></div>
|
||||
<div class="form-row"><label>并发</label><span>{{ opened.concurrency || 1 }}</span></div>
|
||||
<div class="form-row">
|
||||
<label>进度</label>
|
||||
<span v-if="scanning(opened)">已完成 {{ opened.completed }},已读取 {{ opened.discovered || 0 }}</span>
|
||||
<span v-else>{{ opened.completed }}/{{ opened.total }}</span>
|
||||
</div>
|
||||
<div class="form-row"><label>失败</label><span>{{ opened.failed }}</span></div>
|
||||
<div class="form-row"><label>已写入</label><span>{{ opened.writtenRows }} 行</span></div>
|
||||
<div class="form-row"><label>文件大小</label><span>{{ formatSize(opened.fileBytes) }}</span></div>
|
||||
<div class="form-row"><label>开始时间</label><span>{{ opened.createdAt.replace("T", " ") }}</span></div>
|
||||
<div v-if="opened.duplicateCount" class="form-row"><label>重复</label><span>已去掉 {{ opened.duplicateCount }} 个</span></div>
|
||||
<div class="form-row form-top">
|
||||
<label>保存位置</label>
|
||||
<span class="path">{{ opened.csvPath }}</span>
|
||||
</div>
|
||||
<ul v-if="opened.failures?.length" class="fail-list">
|
||||
<li v-for="item in opened.failures" :key="item.id">{{ item.id }}:{{ item.message }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="tabs">
|
||||
<button class="tab" :class="{ on: tab === 'active' }" type="button" @click="tab = 'active'">
|
||||
未完成<em>{{ activeJobs.length }}</em>
|
||||
</button>
|
||||
@@ -153,19 +252,20 @@ async function openDir(job: DownloadJob) {
|
||||
已完成<em>{{ doneJobs.length }}</em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="task-list">
|
||||
<div v-if="!opened" class="task-list">
|
||||
<article
|
||||
v-for="job in visible"
|
||||
:key="job.id"
|
||||
class="task"
|
||||
class="task clickable"
|
||||
:class="{ focus: job.id === props.focusId }"
|
||||
@click="openDetail(job)"
|
||||
>
|
||||
<div class="task-top">
|
||||
<div>
|
||||
<h3>{{ job.name }}</h3>
|
||||
<div class="sub">{{ countText(job) }}</div>
|
||||
</div>
|
||||
<div class="task-actions">
|
||||
<div class="task-actions" @click.stop>
|
||||
<n-tag size="small" :type="job.status === 'running' ? 'info' : job.status === 'done' ? 'success' : job.status === 'paused' ? 'warning' : 'default'">
|
||||
{{ statusLabel(job) }}
|
||||
</n-tag>
|
||||
@@ -203,6 +303,7 @@ async function openDir(job: DownloadJob) {
|
||||
</div>
|
||||
</div>
|
||||
<n-progress
|
||||
v-if="hasProgress(job)"
|
||||
style="margin-top: 10px"
|
||||
:percentage="percent(job)"
|
||||
:show-indicator="true"
|
||||
@@ -210,7 +311,7 @@ async function openDir(job: DownloadJob) {
|
||||
/>
|
||||
<div class="task-foot">
|
||||
<span class="sub">{{ job.message }}</span>
|
||||
<span class="sub">失败 {{ job.failed }}</span>
|
||||
<span class="sub">失败 {{ job.failed }} · {{ formatSize(job.fileBytes) }}</span>
|
||||
</div>
|
||||
<ul v-if="job.failures?.length" class="fail-list">
|
||||
<li v-for="item in job.failures.slice(0, 3)" :key="item.id">{{ item.id }}:{{ item.message }}</li>
|
||||
|
||||
Reference in New Issue
Block a user