fix: 管理页对齐表单,操作用提示条和确认框

This commit is contained in:
2026-10-30 11:37:33 +08:00
parent 564968472d
commit 06549316f9
7 changed files with 173 additions and 65 deletions
+25 -12
View File
@@ -1,11 +1,12 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NInput, NModal, NSelect } from "naive-ui";
import { NAlert, NButton, NInput, NModal, NSelect, useMessage } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api, token } from "../../shared/http";
interface Task { id: number; status: string; format: string; cellKey: string; error: string }
const tasks = ref<Task[]>([]);
const message = useMessage();
const show = ref(false);
const format = ref("xlsx");
const cellKey = ref("");
@@ -34,6 +35,7 @@ async function submit() {
body: JSON.stringify({ format: format.value, cellKey: cellKey.value, start: start.value, end: end.value }),
});
show.value = false;
message.success("已提交");
await load();
} catch (error) {
errorText.value = error instanceof Error ? error.message : "提交失败";
@@ -41,14 +43,22 @@ async function submit() {
}
async function download(row: Task) {
const response = await fetch(`/api/tasks/${row.id}/file`, { headers: { Authorization: `Bearer ${token()}` } });
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `结果.${row.format}`;
link.click();
URL.revokeObjectURL(url);
try {
const response = await fetch(`/api/tasks/${row.id}/file`, { headers: { Authorization: `Bearer ${token()}` } });
if (!response.ok) {
message.error("结果还不能下载");
return;
}
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `结果.${row.format}`;
link.click();
URL.revokeObjectURL(url);
} catch {
message.error("下载失败");
}
}
onMounted(load);
@@ -75,8 +85,11 @@ onMounted(load);
<tr v-for="row in tasks" :key="row.id">
<td>{{ row.cellKey || "全部" }}</td>
<td>{{ row.format }}</td>
<td>{{ statusLabel(row.status) }}</td>
<td><n-button v-if="row.status === 'done'" size="small" quaternary @click="download(row)">下载</n-button></td>
<td :class="row.status === 'failed' ? 'late' : ''">{{ statusLabel(row.status) }}</td>
<td>
<n-button v-if="row.status === 'done'" size="small" quaternary @click="download(row)">下载</n-button>
<span v-else-if="row.error" class="late">{{ row.error }}</span>
</td>
</tr>
</tbody>
</table>
@@ -88,7 +101,7 @@ onMounted(load);
<div class="form-row"><label>小区</label><n-input v-model:value="cellKey" placeholder="留空则导出全部" /></div>
<div class="form-row"><label>开始</label><n-input v-model:value="start" placeholder="YYYY-MM-DD" /></div>
<div class="form-row"><label>结束</label><n-input v-model:value="end" placeholder="YYYY-MM-DD" /></div>
<p v-if="errorText" style="color: var(--danger)">{{ errorText }}</p>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
</n-modal>
</Shell>
</template>