fix: 区域表可以清除并重新选择同一文件
This commit is contained in:
@@ -26,6 +26,7 @@ const concurrency = ref(8);
|
||||
const groups = ref<string[]>([]);
|
||||
const outputDir = ref("");
|
||||
const file = ref<File | null>(null);
|
||||
const fileInput = ref<HTMLInputElement | null>(null);
|
||||
const submitting = ref(false);
|
||||
|
||||
const gridSize = ref("GRID20");
|
||||
@@ -64,15 +65,20 @@ function syncGroups() {
|
||||
function onFile(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const selected = input.files?.[0] ?? null;
|
||||
input.value = "";
|
||||
if (selected && !selected.name.toLowerCase().endsWith(".csv")) {
|
||||
message.warning("区域表只支持 CSV");
|
||||
input.value = "";
|
||||
file.value = null;
|
||||
return;
|
||||
}
|
||||
file.value = selected;
|
||||
}
|
||||
|
||||
function clearFile() {
|
||||
file.value = null;
|
||||
if (fileInput.value) fileInput.value = "";
|
||||
}
|
||||
|
||||
async function downloadSample() {
|
||||
const content = "\uFEFF20米栅格ID\r\n541927061\r\n544536471\r\n";
|
||||
if (!("__TAURI_INTERNALS__" in window)) {
|
||||
@@ -228,8 +234,9 @@ async function start() {
|
||||
<div class="captcha-line">
|
||||
<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 v-if="file" quaternary @click="clearFile">清除</n-button>
|
||||
<n-button quaternary @click="downloadSample">下载例程</n-button>
|
||||
<span class="file-name">{{ file?.name || "不选则下载整个地市" }}</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user