fix: 记住下载选项并按登录地市选择默认地市

This commit is contained in:
2026-10-25 07:37:09 +08:00
parent 81a5fbe46e
commit 72a0e1e65e
2 changed files with 56 additions and 2 deletions
@@ -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<Meta | null>(null);
const network = ref("NR");
const cityCode = ref("JM");
const cityCode = ref("");
const month = ref<string | null>(previousMonth());
const concurrency = ref(8);
const groups = ref<string[]>([]);
@@ -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] || [];
+1 -1
View File
@@ -93,7 +93,7 @@ async function signOut() {
</div>
</aside>
<main class="content">
<GridDownloadView v-if="page === 'grid'" @started="onStarted" />
<GridDownloadView v-if="page === 'grid'" :city-name="props.user.cityName" @started="onStarted" />
<DownloadManagerView v-else :focus-id="focusId" />
</main>
</div>