fix: 区域表可以清除并重新选择同一文件

This commit is contained in:
2026-10-25 07:37:09 +08:00
parent 7af439d40d
commit 71f7e68079
@@ -26,6 +26,7 @@ const concurrency = ref(8);
const groups = ref<string[]>([]); const groups = ref<string[]>([]);
const outputDir = ref(""); const outputDir = ref("");
const file = ref<File | null>(null); const file = ref<File | null>(null);
const fileInput = ref<HTMLInputElement | null>(null);
const submitting = ref(false); const submitting = ref(false);
const gridSize = ref("GRID20"); const gridSize = ref("GRID20");
@@ -64,15 +65,20 @@ function syncGroups() {
function onFile(event: Event) { function onFile(event: Event) {
const input = event.target as HTMLInputElement; const input = event.target as HTMLInputElement;
const selected = input.files?.[0] ?? null; const selected = input.files?.[0] ?? null;
input.value = "";
if (selected && !selected.name.toLowerCase().endsWith(".csv")) { if (selected && !selected.name.toLowerCase().endsWith(".csv")) {
message.warning("区域表只支持 CSV"); message.warning("区域表只支持 CSV");
input.value = "";
file.value = null; file.value = null;
return; return;
} }
file.value = selected; file.value = selected;
} }
function clearFile() {
file.value = null;
if (fileInput.value) fileInput.value = "";
}
async function downloadSample() { async function downloadSample() {
const content = "\uFEFF20米栅格ID\r\n541927061\r\n544536471\r\n"; const content = "\uFEFF20米栅格ID\r\n541927061\r\n544536471\r\n";
if (!("__TAURI_INTERNALS__" in window)) { if (!("__TAURI_INTERNALS__" in window)) {
@@ -228,8 +234,9 @@ async function start() {
<div class="captcha-line"> <div class="captcha-line">
<n-button tag="label"> <n-button tag="label">
选择文件 选择文件
<input type="file" accept=".csv,text/csv" hidden @change="onFile" /> <input ref="fileInput" type="file" accept=".csv,text/csv" hidden @change="onFile" />
</n-button> </n-button>
<n-button v-if="file" quaternary @click="clearFile">清除</n-button>
<n-button quaternary @click="downloadSample">下载例程</n-button> <n-button quaternary @click="downloadSample">下载例程</n-button>
<span class="file-name">{{ file?.name || "不选则下载整个地市" }}</span> <span class="file-name">{{ file?.name || "不选则下载整个地市" }}</span>
</div> </div>