mirror of
https://github.com/t8y2/dbx.git
synced 2026-11-02 00:29:30 +00:00
Merge pull request #702 from DengQingNian/optimize/export-pagination-orderby-batchsize
perf(ui): 优化数据导出的ui体验和性能
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import { reactive, computed } from "vue";
|
||||
import * as api from "@/lib/api";
|
||||
|
||||
export interface ExportTask {
|
||||
exportId: string;
|
||||
tableName: string;
|
||||
format: "csv" | "xlsx";
|
||||
filePath: string;
|
||||
rowsExported: number;
|
||||
totalRows: number | null;
|
||||
status: string;
|
||||
errorMessage: string | null;
|
||||
}
|
||||
|
||||
const taskMap = reactive<Map<string, ExportTask>>(new Map());
|
||||
|
||||
export function useExportTracker() {
|
||||
const tasks = computed(() => Array.from(taskMap.values()));
|
||||
|
||||
const activeCount = computed(
|
||||
() => tasks.value.filter((t) => t.status === "Running" || t.status === "Writing").length,
|
||||
);
|
||||
|
||||
const hasActive = computed(() => activeCount.value > 0);
|
||||
|
||||
function addTask(tableName: string, format: "csv" | "xlsx", filePath: string): ExportTask {
|
||||
const exportId = crypto.randomUUID();
|
||||
const task = reactive<ExportTask>({
|
||||
exportId,
|
||||
tableName,
|
||||
format,
|
||||
filePath,
|
||||
rowsExported: 0,
|
||||
totalRows: null,
|
||||
status: "Running",
|
||||
errorMessage: null,
|
||||
});
|
||||
taskMap.set(exportId, task);
|
||||
return task;
|
||||
}
|
||||
|
||||
function removeTask(exportId: string) {
|
||||
taskMap.delete(exportId);
|
||||
}
|
||||
|
||||
function clearFinished() {
|
||||
for (const [id, task] of taskMap) {
|
||||
if (task.status === "Done" || task.status === "Error" || task.status === "Cancelled") {
|
||||
taskMap.delete(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function cancelTask(exportId: string) {
|
||||
try {
|
||||
await api.cancelTableExport(exportId);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
tasks,
|
||||
activeCount,
|
||||
hasActive,
|
||||
addTask,
|
||||
removeTask,
|
||||
clearFinished,
|
||||
cancelTask,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user