feat: 提示统一为可关闭的 toast
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NInput, NModal, NSelect, useMessage } from "naive-ui";
|
||||
import { NButton, NInput, NModal, NSelect } from "naive-ui";
|
||||
import Shell from "../../shell/Shell.vue";
|
||||
import { api, token } from "../../shared/http";
|
||||
import { useToast } from "../../shared/toast";
|
||||
|
||||
interface Task { id: number; status: string; format: string; cellKey: string; error: string }
|
||||
const tasks = ref<Task[]>([]);
|
||||
const message = useMessage();
|
||||
const toast = useToast();
|
||||
const show = ref(false);
|
||||
const format = ref("xlsx");
|
||||
const cellKey = ref("");
|
||||
const start = ref("");
|
||||
const end = ref("");
|
||||
const errorText = ref("");
|
||||
const formats = [{ label: "xlsx", value: "xlsx" }, { label: "xls", value: "xls" }, { label: "csv", value: "csv" }];
|
||||
|
||||
function statusLabel(status: string) {
|
||||
@@ -28,17 +28,16 @@ async function load() {
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
errorText.value = "";
|
||||
try {
|
||||
await api("/api/tasks", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ format: format.value, cellKey: cellKey.value, start: start.value, end: end.value }),
|
||||
});
|
||||
show.value = false;
|
||||
message.success("已提交");
|
||||
toast.success("已提交");
|
||||
await load();
|
||||
} catch (error) {
|
||||
errorText.value = error instanceof Error ? error.message : "提交失败";
|
||||
toast.error(error instanceof Error ? error.message : "提交失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +45,7 @@ async function download(row: Task) {
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${row.id}/file`, { headers: { Authorization: `Bearer ${token()}` } });
|
||||
if (!response.ok) {
|
||||
message.error("结果还不能下载");
|
||||
toast.error("结果还不能下载");
|
||||
return;
|
||||
}
|
||||
const blob = await response.blob();
|
||||
@@ -57,7 +56,7 @@ async function download(row: Task) {
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
} catch {
|
||||
message.error("下载失败");
|
||||
toast.error("下载失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +100,6 @@ 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>
|
||||
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
|
||||
</n-modal>
|
||||
</Shell>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user