feat: 完善登录保持、栅格下载和任务调度
This commit is contained in:
+6
-4
@@ -10,10 +10,12 @@ const user = ref<UserInfo | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-config-provider :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides">
|
||||
<n-message-provider>
|
||||
<LoginView v-if="!user" @success="user = $event" />
|
||||
<Shell v-else :user="user" @logout="user = null" />
|
||||
<n-config-provider class="app-root" :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides">
|
||||
<n-message-provider class="app-root">
|
||||
<div class="app-root">
|
||||
<LoginView v-if="!user" @success="user = $event" />
|
||||
<Shell v-else :user="user" @logout="user = null" />
|
||||
</div>
|
||||
</n-message-provider>
|
||||
</n-config-provider>
|
||||
</template>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NInput, NSpin, NTooltip } from "naive-ui";
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NInput, NModal, NSelect, NSpin, NTooltip } from "naive-ui";
|
||||
import { HelpCircleOutline, MoonOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { ApiError } from "../../shared/http";
|
||||
import { loadCaptcha, login, refreshCaptcha, sendSms, type UserInfo } from "./api";
|
||||
import { loadCaptcha, loadSaved, login, refreshCaptcha, resumeSaved, sendSms, type UserInfo } from "./api";
|
||||
import { isDark, toggleTheme } from "../../shared/theme";
|
||||
|
||||
const emit = defineEmits<{ success: [user: UserInfo] }>();
|
||||
@@ -21,13 +21,30 @@ const sending = ref(false);
|
||||
const submitting = ref(false);
|
||||
const errorText = ref("");
|
||||
const smsHint = ref("");
|
||||
const saved = ref<UserInfo[]>([]);
|
||||
const savedId = ref<string | null>(null);
|
||||
const resuming = ref(false);
|
||||
const countdown = ref(0);
|
||||
let timer = 0;
|
||||
|
||||
onMounted(() => {
|
||||
void connect();
|
||||
void refreshSaved();
|
||||
});
|
||||
|
||||
async function refreshSaved() {
|
||||
try {
|
||||
const result = await loadSaved();
|
||||
saved.value = result.accounts;
|
||||
if (!result.accounts.some((item) => item.loginId === savedId.value)) {
|
||||
savedId.value = result.accounts[0]?.loginId ?? null;
|
||||
}
|
||||
} catch {
|
||||
saved.value = [];
|
||||
savedId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function connect() {
|
||||
offline.value = "";
|
||||
ready.value = false;
|
||||
@@ -50,8 +67,8 @@ async function connect() {
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadCaptcha() {
|
||||
errorText.value = "";
|
||||
async function reloadCaptcha(keepError = false) {
|
||||
if (!keepError) errorText.value = "";
|
||||
try {
|
||||
if (!sessionId.value) {
|
||||
await connect();
|
||||
@@ -66,26 +83,59 @@ async function reloadCaptcha() {
|
||||
}
|
||||
}
|
||||
|
||||
function stopCountdown() {
|
||||
window.clearInterval(timer);
|
||||
countdown.value = 0;
|
||||
}
|
||||
|
||||
function startCountdown() {
|
||||
stopCountdown();
|
||||
countdown.value = 60;
|
||||
timer = window.setInterval(() => {
|
||||
countdown.value -= 1;
|
||||
if (countdown.value <= 0) stopCountdown();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function savedLabel(item: UserInfo) {
|
||||
const name = item.userName || item.loginId;
|
||||
return item.cityName ? `${name} · ${item.cityName}` : name;
|
||||
}
|
||||
|
||||
async function useSaved() {
|
||||
if (!savedId.value) return;
|
||||
resuming.value = true;
|
||||
errorText.value = "";
|
||||
try {
|
||||
const result = await resumeSaved(savedId.value);
|
||||
if (result.user) emit("success", result.user);
|
||||
} catch (error) {
|
||||
errorText.value = error instanceof ApiError ? error.message : "登录失败";
|
||||
await refreshSaved();
|
||||
} finally {
|
||||
resuming.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function requestSms() {
|
||||
if (!sessionId.value || countdown.value > 0) return;
|
||||
if (!sessionId.value || countdown.value > 0 || sending.value) return;
|
||||
sending.value = true;
|
||||
errorText.value = "";
|
||||
smsHint.value = "";
|
||||
startCountdown();
|
||||
try {
|
||||
const result = await sendSms(sessionId.value);
|
||||
smsHint.value = result.message || "短信已发送";
|
||||
countdown.value = 60;
|
||||
timer = window.setInterval(() => {
|
||||
countdown.value -= 1;
|
||||
if (countdown.value <= 0) window.clearInterval(timer);
|
||||
}, 1000);
|
||||
smsHint.value = result.message || "短信发送已受理";
|
||||
} catch (error) {
|
||||
stopCountdown();
|
||||
errorText.value = error instanceof ApiError ? error.message : "短信发送失败";
|
||||
} finally {
|
||||
sending.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
async function submit(smsCodeText = "") {
|
||||
if (smsRequired.value && !smsCodeText) return;
|
||||
errorText.value = "";
|
||||
submitting.value = true;
|
||||
try {
|
||||
@@ -94,22 +144,28 @@ async function submit() {
|
||||
username: username.value.trim(),
|
||||
password: password.value,
|
||||
captcha: captcha.value.trim(),
|
||||
smsCode: smsCode.value.trim(),
|
||||
smsCode: smsCodeText,
|
||||
});
|
||||
if (result.status === "sms_required") {
|
||||
smsRequired.value = true;
|
||||
smsHint.value = result.message || "请获取并填写短信验证码";
|
||||
smsCode.value = "";
|
||||
smsHint.value = "";
|
||||
return;
|
||||
}
|
||||
if (result.user) emit("success", result.user);
|
||||
if (result.user) {
|
||||
smsRequired.value = false;
|
||||
stopCountdown();
|
||||
emit("success", result.user);
|
||||
}
|
||||
} catch (error) {
|
||||
errorText.value = error instanceof ApiError ? error.message : "登录失败";
|
||||
smsRequired.value = false;
|
||||
await reloadCaptcha();
|
||||
if (!smsRequired.value) await reloadCaptcha(true);
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onUnmounted(stopCountdown);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -133,8 +189,19 @@ async function submit() {
|
||||
<n-spin :show="!ready && !offline">
|
||||
<n-alert v-if="!ready" type="warning" style="margin-bottom: 12px">连接失败,正在重试。</n-alert>
|
||||
<n-alert v-else-if="offline" type="warning" style="margin-bottom: 12px">{{ offline }}</n-alert>
|
||||
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
|
||||
<form @submit.prevent="submit">
|
||||
<n-alert v-if="errorText && !smsRequired" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
|
||||
<form @submit.prevent="submit()">
|
||||
<div v-if="saved.length" class="form-row">
|
||||
<label for="saved">已登录</label>
|
||||
<div class="captcha-line">
|
||||
<n-select
|
||||
id="saved"
|
||||
v-model:value="savedId"
|
||||
:options="saved.map((item) => ({ label: savedLabel(item), value: item.loginId }))"
|
||||
/>
|
||||
<n-button type="primary" secondary :loading="resuming" :disabled="!savedId" @click="useSaved">进入</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="username">账号</label>
|
||||
<n-input id="username" v-model:value="username" placeholder="账号" autocomplete="username" />
|
||||
@@ -158,21 +225,22 @@ async function submit() {
|
||||
<img v-if="captchaUrl" :src="captchaUrl" alt="验证码" title="点击刷新" @click="reloadCaptcha" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="smsRequired" class="form-row">
|
||||
<label for="sms">短信</label>
|
||||
<div class="captcha-line">
|
||||
<n-input id="sms" v-model:value="smsCode" placeholder="短信验证码" />
|
||||
<n-button :disabled="sending || countdown > 0" @click="requestSms">
|
||||
{{ countdown > 0 ? `${countdown}s` : "获取短信" }}
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="smsHint" class="file-name" style="margin: 0 0 8px 96px">{{ smsHint }}</p>
|
||||
<div class="gate-actions">
|
||||
<n-button type="primary" attr-type="submit" :loading="submitting" :disabled="!ready">登录</n-button>
|
||||
<n-button type="primary" attr-type="submit" :loading="submitting && !smsRequired" :disabled="!ready">登录</n-button>
|
||||
</div>
|
||||
</form>
|
||||
</n-spin>
|
||||
</section>
|
||||
<n-modal v-model:show="smsRequired" :mask-closable="false" :closable="false" preset="card" title="短信认证" style="width: 420px">
|
||||
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
|
||||
<n-input v-model:value="smsCode" placeholder="输入短信验证码" @keyup.enter="submit(smsCode.trim())" />
|
||||
<p v-if="smsHint" class="file-name" style="margin: 8px 0 0">{{ smsHint }}</p>
|
||||
<div class="sms-actions">
|
||||
<n-button :disabled="sending || countdown > 0" @click="requestSms">
|
||||
{{ countdown > 0 ? `重新发送(${countdown})` : "发送验证码" }}
|
||||
</n-button>
|
||||
<n-button type="primary" :loading="submitting" :disabled="!smsCode.trim()" @click="submit(smsCode.trim())">提交</n-button>
|
||||
</div>
|
||||
</n-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -38,6 +38,17 @@ export function login(body: {
|
||||
});
|
||||
}
|
||||
|
||||
export function loadSaved() {
|
||||
return api<{ accounts: UserInfo[] }>("/api/auth/saved");
|
||||
}
|
||||
|
||||
export function resumeSaved(loginId: string) {
|
||||
return api<{ status: string; user?: UserInfo }>("/api/auth/resume", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ loginId }),
|
||||
});
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
return api<{ ok: boolean }>("/api/auth/logout", { method: "POST" });
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NButton, NEmpty, NIcon, NProgress, NTag, useMessage } from "naive-ui";
|
||||
import { FolderOpenOutline, PlayOutline, StopCircleOutline } from "@vicons/ionicons5";
|
||||
import { NButton, NEmpty, NIcon, NInputNumber, NProgress, NTag, NTooltip, useMessage } from "naive-ui";
|
||||
import { FolderOpenOutline, HelpCircleOutline, PauseOutline, PlayOutline, StopCircleOutline } from "@vicons/ionicons5";
|
||||
import { ApiError, openLocal } from "../../shared/http";
|
||||
import { cancelJob, loadJobs, resumeJob, type DownloadJob } from "./api";
|
||||
import { cancelJob, loadDownloadSettings, loadJobs, pauseJob, resumeJob, saveDownloadSettings, type DownloadJob } from "./api";
|
||||
|
||||
const props = defineProps<{ focusId: string }>();
|
||||
const message = useMessage();
|
||||
const jobs = ref<DownloadJob[]>([]);
|
||||
const maxJobs = ref(2);
|
||||
const tab = ref<"active" | "done">("active");
|
||||
let timer = 0;
|
||||
|
||||
@@ -18,6 +19,7 @@ const visible = computed(() => (tab.value === "active" ? activeJobs.value : done
|
||||
const statusText: Record<string, string> = {
|
||||
queued: "等待中",
|
||||
running: "下载中",
|
||||
paused: "已暂停",
|
||||
cancelled: "已停止",
|
||||
error: "出错",
|
||||
done_with_errors: "部分失败",
|
||||
@@ -26,6 +28,11 @@ const statusText: Record<string, string> = {
|
||||
|
||||
onMounted(() => {
|
||||
void refresh();
|
||||
void loadDownloadSettings()
|
||||
.then((result) => {
|
||||
maxJobs.value = result.maxConcurrentJobs;
|
||||
})
|
||||
.catch(() => undefined);
|
||||
timer = window.setInterval(() => void refresh(), 1000);
|
||||
});
|
||||
|
||||
@@ -40,11 +47,48 @@ async function refresh() {
|
||||
}
|
||||
}
|
||||
|
||||
function statusLabel(job: DownloadJob) {
|
||||
if (job.status === "cancelled" && (job.message === "已取消" || job.message === "已中断")) return job.message;
|
||||
return statusText[job.status] || job.status;
|
||||
}
|
||||
|
||||
function scanning(job: DownloadJob) {
|
||||
return Boolean(job.wholeCity) && job.listingDone === false;
|
||||
}
|
||||
|
||||
function percent(job: DownloadJob) {
|
||||
if (!job.total) return 0;
|
||||
if (scanning(job) || !job.total) return 0;
|
||||
return Math.min(100, Math.round((job.completed / job.total) * 100));
|
||||
}
|
||||
|
||||
function countText(job: DownloadJob) {
|
||||
const written = `已写入 ${job.writtenRows} 行`;
|
||||
const progress = scanning(job)
|
||||
? `已完成 ${job.completed} · 已读取 ${job.discovered || 0} 个栅格`
|
||||
: `${job.completed}/${job.total} 个栅格`;
|
||||
return `${job.id} · ${progress} · ${written}`;
|
||||
}
|
||||
|
||||
async function saveLimit(value: number | null) {
|
||||
if (!value) return;
|
||||
try {
|
||||
const result = await saveDownloadSettings(value);
|
||||
maxJobs.value = result.maxConcurrentJobs;
|
||||
await refresh();
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "同时任务数保存失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function pause(job: DownloadJob) {
|
||||
try {
|
||||
await pauseJob(job.id);
|
||||
await refresh();
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "暂停失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function stop(job: DownloadJob) {
|
||||
try {
|
||||
await cancelJob(job.id);
|
||||
@@ -81,12 +125,29 @@ async function openDir(job: DownloadJob) {
|
||||
<section class="page">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<h2>下载管理</h2>
|
||||
<h2>下载管理</h2>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<span class="limit-label">同时任务</span>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
同时进行的下载任务数。每个任务仍按自己的并发数下载。
|
||||
</n-tooltip>
|
||||
<n-input-number
|
||||
class="limit-control"
|
||||
:value="maxJobs"
|
||||
:min="1"
|
||||
:max="8"
|
||||
size="small"
|
||||
@update:value="saveLimit"
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ on: tab === 'active' }" type="button" @click="tab = 'active'">
|
||||
正在下载<em>{{ activeJobs.length }}</em>
|
||||
未完成<em>{{ activeJobs.length }}</em>
|
||||
</button>
|
||||
<button class="tab" :class="{ on: tab === 'done' }" type="button" @click="tab = 'done'">
|
||||
已完成<em>{{ doneJobs.length }}</em>
|
||||
@@ -102,15 +163,34 @@ async function openDir(job: DownloadJob) {
|
||||
<div class="task-top">
|
||||
<div>
|
||||
<h3>{{ job.name }}</h3>
|
||||
<div class="sub">{{ job.completed }}/{{ job.total }} 个栅格 · 已写入 {{ job.writtenRows }} 行</div>
|
||||
<div class="sub">{{ countText(job) }}</div>
|
||||
</div>
|
||||
<div class="task-actions">
|
||||
<n-tag size="small" :type="job.status === 'running' ? 'info' : job.status === 'done' ? 'success' : 'warning'">
|
||||
{{ statusText[job.status] || job.status }}
|
||||
<n-tag size="small" :type="job.status === 'running' ? 'info' : job.status === 'done' ? 'success' : job.status === 'paused' ? 'warning' : 'default'">
|
||||
{{ statusLabel(job) }}
|
||||
</n-tag>
|
||||
<n-button v-if="job.status === 'running' || job.status === 'queued'" size="small" @click="stop(job)">
|
||||
<template #icon><n-icon><StopCircleOutline /></n-icon></template>
|
||||
停止
|
||||
<template v-if="job.status === 'running'">
|
||||
<n-button v-if="job.message !== '正在停止'" 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>
|
||||
<n-button v-else-if="job.status !== 'done'" size="small" type="primary" secondary @click="resume(job)">
|
||||
<template #icon><n-icon><PlayOutline /></n-icon></template>
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
NButton,
|
||||
NCheckbox,
|
||||
NCheckboxGroup,
|
||||
NDatePicker,
|
||||
NIcon,
|
||||
NInput,
|
||||
NInputNumber,
|
||||
@@ -21,13 +22,18 @@ const message = useMessage();
|
||||
const meta = ref<Meta | null>(null);
|
||||
const network = ref("NR");
|
||||
const cityCode = ref("JM");
|
||||
const month = ref(previousMonth());
|
||||
const month = ref<string | null>(previousMonth());
|
||||
const concurrency = ref(8);
|
||||
const groups = ref<string[]>([]);
|
||||
const outputDir = ref("");
|
||||
const file = ref<File | null>(null);
|
||||
const submitting = ref(false);
|
||||
|
||||
const gridSize = ref("GRID20");
|
||||
const sizeOptions = [
|
||||
{ label: "20米", value: "GRID20" },
|
||||
{ label: "50米", value: "GRID50" },
|
||||
];
|
||||
const networkOptions = [
|
||||
{ label: "5G", value: "NR" },
|
||||
{ label: "4G", value: "LTE" },
|
||||
@@ -52,12 +58,46 @@ onMounted(async () => {
|
||||
watch(network, syncGroups);
|
||||
|
||||
function syncGroups() {
|
||||
groups.value = (meta.value?.groups[network.value] || []).map((item) => item.id);
|
||||
const items = meta.value?.groups[network.value] || [];
|
||||
groups.value = items.some((item) => item.id === "rsrp") ? ["rsrp"] : [];
|
||||
}
|
||||
|
||||
function onFile(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
file.value = input.files?.[0] ?? null;
|
||||
const selected = input.files?.[0] ?? null;
|
||||
if (selected && !selected.name.toLowerCase().endsWith(".csv")) {
|
||||
message.warning("区域表只支持 CSV");
|
||||
input.value = "";
|
||||
file.value = null;
|
||||
return;
|
||||
}
|
||||
file.value = selected;
|
||||
}
|
||||
|
||||
async function downloadSample() {
|
||||
const content = "\uFEFF20米栅格ID\r\n541927061\r\n544536471\r\n";
|
||||
if (!("__TAURI_INTERNALS__" in window)) {
|
||||
const blob = new Blob([content], { type: "text/csv;charset=utf-8" });
|
||||
const link = document.createElement("a");
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = "区域表示例.csv";
|
||||
link.click();
|
||||
URL.revokeObjectURL(link.href);
|
||||
return;
|
||||
}
|
||||
const { save } = await import("@tauri-apps/plugin-dialog");
|
||||
const selected = await save({
|
||||
defaultPath: "区域表示例.csv",
|
||||
filters: [{ name: "CSV", extensions: ["csv"] }],
|
||||
});
|
||||
if (!selected) return;
|
||||
try {
|
||||
const { invoke } = await import("@tauri-apps/api/core");
|
||||
await invoke("write_sample_csv", { path: selected });
|
||||
message.success("例程已保存");
|
||||
} catch {
|
||||
message.error("例程保存失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function pickDir() {
|
||||
@@ -66,16 +106,17 @@ async function pickDir() {
|
||||
}
|
||||
|
||||
async function start() {
|
||||
if (!file.value) {
|
||||
message.warning("请先选择栅格 ID 表");
|
||||
if (file.value && !file.value.name.toLowerCase().endsWith(".csv")) {
|
||||
message.warning("区域表只支持 CSV");
|
||||
return;
|
||||
}
|
||||
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(month.value)) {
|
||||
message.warning("月份格式应为 YYYY-MM");
|
||||
if (!month.value || !/^\d{4}-(0[1-9]|1[0-2])$/.test(month.value)) {
|
||||
message.warning("请选择月份");
|
||||
return;
|
||||
}
|
||||
const form = new FormData();
|
||||
form.append("file", file.value);
|
||||
form.append("grid_size", gridSize.value);
|
||||
if (file.value) form.append("file", file.value);
|
||||
form.append("network", network.value);
|
||||
form.append("city_code", cityCode.value);
|
||||
form.append("month", month.value);
|
||||
@@ -85,7 +126,10 @@ async function start() {
|
||||
submitting.value = true;
|
||||
try {
|
||||
const job = await createJob(form);
|
||||
message.success("已开始下载");
|
||||
const removed = job.duplicateCount || 0;
|
||||
if (job.status === "queued") message.success("已加入等待");
|
||||
else if (!file.value) message.success("已开始下载整个地市");
|
||||
else message.success(removed ? `已开始下载,去掉 ${removed} 个重复栅格` : "已开始下载");
|
||||
emit("started", job.id);
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "创建下载失败");
|
||||
@@ -97,16 +141,20 @@ async function start() {
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<div class="page-scroll">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<h2>栅格下载</h2>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<n-button type="primary" :loading="submitting" @click="start">开始下载</n-button>
|
||||
</div>
|
||||
</header>
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<h2>栅格下载</h2>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<n-button type="primary" :loading="submitting" @click="start">开始下载</n-button>
|
||||
</div>
|
||||
</header>
|
||||
<div class="page-body">
|
||||
<div class="panel">
|
||||
<div class="form-row">
|
||||
<label>栅格</label>
|
||||
<n-select v-model:value="gridSize" :options="sizeOptions" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>网络</label>
|
||||
<n-select v-model:value="network" :options="networkOptions" />
|
||||
@@ -125,10 +173,10 @@ async function start() {
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
例如 2026-09。
|
||||
选择要下载的月份。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<n-input v-model:value="month" placeholder="YYYY-MM" />
|
||||
<n-date-picker v-model:formatted-value="month" type="month" value-format="yyyy-MM" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>
|
||||
@@ -142,7 +190,7 @@ async function start() {
|
||||
</label>
|
||||
<n-input-number v-model:value="concurrency" :min="1" :max="32" />
|
||||
</div>
|
||||
<div class="form-row" style="align-items: start">
|
||||
<div class="form-row form-top">
|
||||
<label>
|
||||
项目
|
||||
<n-tooltip>
|
||||
@@ -152,8 +200,8 @@ async function start() {
|
||||
选择要导出的指标。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<n-checkbox-group v-model:value="groups">
|
||||
<div v-for="item in meta?.groups[network] || []" :key="item.id" style="margin-bottom: 6px">
|
||||
<n-checkbox-group v-model:value="groups" class="checks">
|
||||
<div v-for="item in meta?.groups[network] || []" :key="item.id" class="check-line">
|
||||
<n-checkbox :value="item.id">{{ item.label }}</n-checkbox>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
@@ -171,15 +219,16 @@ async function start() {
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
支持 CSV、TXT、XLSX。
|
||||
不选文件则边读取边下载该地市的全部栅格,同时下载的数量由并发决定。选择文件时只支持 CSV。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<div class="captcha-line">
|
||||
<label class="n-button n-button--default-type" style="padding: 0 12px; line-height: 32px; border: 1px solid #d5e0ea; border-radius: 6px; cursor: pointer">
|
||||
<n-button tag="label">
|
||||
选择文件
|
||||
<input type="file" accept=".csv,.txt,.xlsx" hidden @change="onFile" />
|
||||
</label>
|
||||
<span class="file-name">{{ file?.name || "尚未选择" }}</span>
|
||||
<input type="file" accept=".csv,text/csv" hidden @change="onFile" />
|
||||
</n-button>
|
||||
<n-button quaternary @click="downloadSample">下载例程</n-button>
|
||||
<span class="file-name">{{ file?.name || "不选则下载整个地市" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
|
||||
@@ -21,10 +21,14 @@ export interface DownloadJob {
|
||||
network: string;
|
||||
cityName: string;
|
||||
month: string;
|
||||
wholeCity?: boolean;
|
||||
listingDone?: boolean;
|
||||
discovered?: number;
|
||||
total: number;
|
||||
completed: number;
|
||||
failed: number;
|
||||
writtenRows: number;
|
||||
duplicateCount?: number;
|
||||
csvPath: string;
|
||||
failures: { id: string; message: string }[];
|
||||
createdAt: string;
|
||||
@@ -49,3 +53,18 @@ export function cancelJob(id: string) {
|
||||
export function resumeJob(id: string) {
|
||||
return api<DownloadJob>(`/api/download/jobs/${id}/resume`, { method: "POST" });
|
||||
}
|
||||
|
||||
export function pauseJob(id: string) {
|
||||
return api<DownloadJob>(`/api/download/jobs/${id}/pause`, { method: "POST" });
|
||||
}
|
||||
|
||||
export function loadDownloadSettings() {
|
||||
return api<{ maxConcurrentJobs: number }>("/api/download/settings");
|
||||
}
|
||||
|
||||
export function saveDownloadSettings(maxConcurrentJobs: number) {
|
||||
return api<{ maxConcurrentJobs: number }>("/api/download/settings", {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({ maxConcurrentJobs }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { NButton, NIcon, NLayoutSider, NMenu } from "naive-ui";
|
||||
import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { logout, type UserInfo } from "../features/auth/api";
|
||||
import { isDark, toggleTheme } from "../shared/theme";
|
||||
import { navGroups, type PageKey } from "./navigation";
|
||||
import { navOptions, type PageKey } from "./navigation";
|
||||
import GridDownloadView from "../features/download/GridDownloadView.vue";
|
||||
import DownloadManagerView from "../features/download/DownloadManagerView.vue";
|
||||
|
||||
@@ -12,6 +12,7 @@ const props = defineProps<{ user: UserInfo }>();
|
||||
const emit = defineEmits<{ logout: [] }>();
|
||||
|
||||
const page = ref<PageKey>("grid");
|
||||
const expanded = ref<string[]>([]);
|
||||
const focusId = ref("");
|
||||
|
||||
function onMenu(key: string) {
|
||||
@@ -36,8 +37,8 @@ async function signOut() {
|
||||
<div class="shell">
|
||||
<aside class="sider">
|
||||
<div class="sider-title">NqiTools</div>
|
||||
<n-layout-sider :native-scrollbar="false" :width="220" style="background: transparent; flex: 1">
|
||||
<n-menu :value="page" :options="navGroups" @update:value="onMenu" />
|
||||
<n-layout-sider :native-scrollbar="false" :width="220" style="background: transparent; flex: 1; min-height: 0">
|
||||
<n-menu v-model:expanded-keys="expanded" :value="page" :options="navOptions" @update:value="onMenu" />
|
||||
</n-layout-sider>
|
||||
<div class="sider-user">
|
||||
<n-icon :size="18"><PersonOutline /></n-icon>
|
||||
|
||||
@@ -9,14 +9,14 @@ function renderIcon(icon: Component) {
|
||||
|
||||
export type PageKey = "grid" | "tasks";
|
||||
|
||||
export const navGroups = [
|
||||
export const navOptions = [
|
||||
{
|
||||
type: "group" as const,
|
||||
label: "下载",
|
||||
key: "download",
|
||||
icon: renderIcon(CloudDownloadOutline),
|
||||
children: [
|
||||
{ label: "栅格下载", key: "grid" as const, icon: renderIcon(CloudDownloadOutline) },
|
||||
{ label: "下载管理", key: "tasks" as const, icon: renderIcon(ListOutline) },
|
||||
],
|
||||
},
|
||||
{ label: "下载管理", key: "tasks" as const, icon: renderIcon(ListOutline) },
|
||||
];
|
||||
|
||||
+71
-17
@@ -31,9 +31,11 @@
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
#app,
|
||||
.app-root {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
button,
|
||||
@@ -44,9 +46,12 @@ select {
|
||||
|
||||
.gate {
|
||||
position: relative;
|
||||
min-height: 100%;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 32px 16px;
|
||||
background: var(--bg);
|
||||
}
|
||||
@@ -106,6 +111,14 @@ select {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.form-top {
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.form-top label {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.brand p {
|
||||
margin: 2px 0 0;
|
||||
font-size: 13px;
|
||||
@@ -117,6 +130,11 @@ select {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.captcha-line .n-select {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.form-row label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -134,13 +152,18 @@ select {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.gate-actions {
|
||||
.gate-actions,
|
||||
.sms-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.sms-actions {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.shell {
|
||||
height: 100%;
|
||||
display: grid;
|
||||
@@ -210,9 +233,16 @@ select {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.page-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.page-head {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
flex: none;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -247,13 +277,31 @@ select {
|
||||
}
|
||||
|
||||
.panel {
|
||||
margin: 16px 20px 24px;
|
||||
margin: 16px 20px;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
border-radius: 10px;
|
||||
padding: 16px 16px 8px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
cursor: help;
|
||||
.form-row .n-select,
|
||||
.form-row .n-date-picker,
|
||||
.form-row .n-input-number {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.checks {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.check-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
@@ -329,7 +377,7 @@ select {
|
||||
}
|
||||
|
||||
.empty {
|
||||
margin: 48px auto;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -337,6 +385,17 @@ select {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
flex: none;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.limit-label {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.limit-control {
|
||||
width: 112px;
|
||||
}
|
||||
|
||||
.fail-list {
|
||||
@@ -350,8 +409,3 @@ select {
|
||||
margin-top: 2px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.empty {
|
||||
margin: 48px auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user