feat: 完成登录与栅格下载桌面端

This commit is contained in:
2026-10-25 02:09:12 +08:00
commit 5ca491834e
76 changed files with 10637 additions and 0 deletions
@@ -0,0 +1,197 @@
<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import {
NButton,
NCheckbox,
NCheckboxGroup,
NIcon,
NInput,
NInputNumber,
NSelect,
NTooltip,
useMessage,
} from "naive-ui";
import { FolderOpenOutline, HelpCircleOutline } from "@vicons/ionicons5";
import { ApiError, chooseDirectory } from "../../shared/http";
import { createJob, loadMeta, type Meta } from "./api";
const emit = defineEmits<{ started: [id: string] }>();
const message = useMessage();
const meta = ref<Meta | null>(null);
const network = ref("NR");
const cityCode = ref("JM");
const month = ref(previousMonth());
const concurrency = ref(8);
const groups = ref<string[]>([]);
const outputDir = ref("");
const file = ref<File | null>(null);
const submitting = ref(false);
const networkOptions = [
{ label: "5G", value: "NR" },
{ label: "4G", value: "LTE" },
];
function previousMonth() {
const date = new Date();
date.setDate(1);
date.setMonth(date.getMonth() - 1);
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
}
onMounted(async () => {
try {
meta.value = await loadMeta();
syncGroups();
} catch (error) {
message.error(error instanceof ApiError ? error.message : "读取下载项目失败");
}
});
watch(network, syncGroups);
function syncGroups() {
groups.value = (meta.value?.groups[network.value] || []).map((item) => item.id);
}
function onFile(event: Event) {
const input = event.target as HTMLInputElement;
file.value = input.files?.[0] ?? null;
}
async function pickDir() {
const selected = await chooseDirectory();
if (selected) outputDir.value = selected;
}
async function start() {
if (!file.value) {
message.warning("请先选择栅格 ID 表");
return;
}
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(month.value)) {
message.warning("月份格式应为 YYYY-MM");
return;
}
const form = new FormData();
form.append("file", file.value);
form.append("network", network.value);
form.append("city_code", cityCode.value);
form.append("month", month.value);
form.append("groups", JSON.stringify(groups.value));
form.append("concurrency", String(concurrency.value || 8));
form.append("output_dir", outputDir.value.trim());
submitting.value = true;
try {
const job = await createJob(form);
message.success("已开始下载");
emit("started", job.id);
} catch (error) {
message.error(error instanceof ApiError ? error.message : "创建下载失败");
} finally {
submitting.value = false;
}
}
</script>
<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>
<div class="panel">
<div class="form-row">
<label>网络</label>
<n-select v-model:value="network" :options="networkOptions" />
</div>
<div class="form-row">
<label>地市</label>
<n-select
v-model:value="cityCode"
:options="(meta?.cities || []).map((city) => ({ label: city.name, value: city.code }))"
/>
</div>
<div class="form-row">
<label>
月份
<n-tooltip>
<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" />
</div>
<div class="form-row">
<label>
并发
<n-tooltip>
<template #trigger>
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
</template>
同时下载的栅格数量。
</n-tooltip>
</label>
<n-input-number v-model:value="concurrency" :min="1" :max="32" />
</div>
<div class="form-row" style="align-items: start">
<label>
项目
<n-tooltip>
<template #trigger>
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
</template>
选择要导出的指标。
</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 :value="item.id">{{ item.label }}</n-checkbox>
<n-tooltip>
<template #trigger>
<n-icon class="hint" :size="14" style="margin-left: 4px"><HelpCircleOutline /></n-icon>
</template>
{{ item.columns.join("、") }}
</n-tooltip>
</div>
</n-checkbox-group>
</div>
<div class="form-row">
<label>
区域表
<n-tooltip>
<template #trigger>
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
</template>
支持 CSV、TXT、XLSX。
</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">
选择文件
<input type="file" accept=".csv,.txt,.xlsx" hidden @change="onFile" />
</label>
<span class="file-name">{{ file?.name || "尚未选择" }}</span>
</div>
</div>
<div class="form-row">
<label>保存到</label>
<div class="captcha-line">
<n-input v-model:value="outputDir" placeholder="默认目录" />
<n-button @click="pickDir">
<template #icon><n-icon><FolderOpenOutline /></n-icon></template>
</n-button>
</div>
</div>
</div>
</div>
</section>
</template>