From 72a0e1e65e1807f7ba5bfdf02def99c1eefe038e Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 25 Oct 2026 07:06:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=B0=E4=BD=8F=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E5=B9=B6=E6=8C=89=E7=99=BB=E5=BD=95=E5=9C=B0?= =?UTF-8?q?=E5=B8=82=E9=80=89=E6=8B=A9=E9=BB=98=E8=AE=A4=E5=9C=B0=E5=B8=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/download/GridDownloadView.vue | 56 ++++++++++++++++++- desktop/src/shell/Shell.vue | 2 +- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/desktop/src/features/download/GridDownloadView.vue b/desktop/src/features/download/GridDownloadView.vue index 539a98c..b48cb35 100644 --- a/desktop/src/features/download/GridDownloadView.vue +++ b/desktop/src/features/download/GridDownloadView.vue @@ -15,12 +15,14 @@ import { HelpCircleOutline } from "@vicons/ionicons5"; import { ApiError, chooseDirectory } from "../../shared/http"; import { createJob, loadMeta, type Meta } from "./api"; +const props = defineProps<{ cityName?: string }>(); const emit = defineEmits<{ started: [id: string] }>(); const message = useMessage(); +const FORM_KEY = "nqi.download.form"; const meta = ref(null); const network = ref("NR"); -const cityCode = ref("JM"); +const cityCode = ref(""); const month = ref(previousMonth()); const concurrency = ref(8); const groups = ref([]); @@ -39,6 +41,56 @@ const networkOptions = [ { label: "4G", value: "LTE" }, ]; +function readForm() { + try { + const raw = localStorage.getItem(FORM_KEY); + if (!raw) return null; + const data = JSON.parse(raw) as { + network?: unknown; + gridSize?: unknown; + concurrency?: unknown; + outputDir?: unknown; + }; + return data && typeof data === "object" ? data : null; + } catch { + return null; + } +} + +function applyForm() { + const saved = readForm(); + if (!saved) return; + if (saved.network === "NR" || saved.network === "LTE") network.value = saved.network; + if (saved.gridSize === "GRID20" || saved.gridSize === "GRID50") gridSize.value = saved.gridSize; + if (typeof saved.concurrency === "number" && saved.concurrency >= 1 && saved.concurrency <= 32) { + concurrency.value = Math.round(saved.concurrency); + } + if (typeof saved.outputDir === "string") outputDir.value = saved.outputDir; +} + +function rememberForm() { + localStorage.setItem( + FORM_KEY, + JSON.stringify({ + network: network.value, + gridSize: gridSize.value, + concurrency: concurrency.value, + outputDir: outputDir.value, + }), + ); +} + +function matchCity(cities: { name: string; code: string }[], cityName: string) { + const normalized = cityName.replace(/\s+/g, ""); + if (!cities.length) return ""; + if (!normalized) return cities[0].code; + const matches = cities.filter((city) => normalized === city.name || normalized === `${city.name}市` || normalized.includes(city.name)); + matches.sort((left, right) => right.name.length - left.name.length); + return matches[0]?.code ?? cities[0].code; +} + +applyForm(); + function previousMonth() { const date = new Date(); date.setDate(1); @@ -49,6 +101,7 @@ function previousMonth() { onMounted(async () => { try { meta.value = await loadMeta(); + cityCode.value = matchCity(meta.value.cities || [], props.cityName || ""); syncGroups(); } catch (error) { message.error(error instanceof ApiError ? error.message : "读取下载项目失败"); @@ -56,6 +109,7 @@ onMounted(async () => { }); watch(network, syncGroups); +watch([network, gridSize, concurrency, outputDir], rememberForm); function syncGroups() { const items = meta.value?.groups[network.value] || []; diff --git a/desktop/src/shell/Shell.vue b/desktop/src/shell/Shell.vue index 6ce4773..922d5c5 100644 --- a/desktop/src/shell/Shell.vue +++ b/desktop/src/shell/Shell.vue @@ -93,7 +93,7 @@ async function signOut() {
- +