feat: 添加批量导出录像诊断并优化导出体验

This commit is contained in:
yangsy
2026-01-28 14:31:37 +08:00
parent 36e839142a
commit aa4684273b
3 changed files with 66 additions and 6 deletions

View File

@@ -1,11 +1,12 @@
<script setup lang="ts">
import { getRecordCheckApi, type NdmNvrResultVO, type Station } from '@/apis';
import { batchExportRecordCheckApi, getRecordCheckApi, pageDefParameterApi, type NdmNvrResultVO, type Station } from '@/apis';
import { exportRecordDiagCsv, isNvrCluster, transformRecordChecks } from '@/helpers';
import { useDeviceStore } from '@/stores';
import { parseErrorFeedback } from '@/utils';
import { downloadByData, parseErrorFeedback } from '@/utils';
import { useMutation } from '@tanstack/vue-query';
import { isCancel } from 'axios';
import { NButton, NGrid, NGridItem, NModal, NScrollbar, NSpin } from 'naive-ui';
import dayjs from 'dayjs';
import { NButton, NFlex, NGrid, NGridItem, NModal, NScrollbar, NSpin } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { computed, ref, toRefs } from 'vue';
@@ -60,7 +61,10 @@ const { mutate: exportRecordDiags, isPending: exporting } = useMutation({
return checks;
},
onSuccess: (checks, { stationCode }) => {
if (!checks || checks.length === 0) return;
if (!checks || checks.length === 0) {
window.$message.info(`没有录像诊断数据`);
return;
}
const recordDiags = transformRecordChecks(checks);
exportRecordDiagCsv(recordDiags, nvrClusterRecord.value[stationCode]?.stationName ?? '');
},
@@ -72,7 +76,48 @@ const { mutate: exportRecordDiags, isPending: exporting } = useMutation({
},
});
const { mutate: batchExportRecordCheck, isPending: batchExporting } = useMutation({
mutationFn: async () => {
const { records = [] } = await pageDefParameterApi({
model: {
key: 'NVR_GAP_SECONDS',
},
extra: {},
current: 1,
size: 1,
sort: 'id',
order: 'descending',
});
const gapSeconds = parseInt(records.at(0)?.value ?? '5');
window.$message.info('导出耗时较长,请耐心等待...');
const data = await batchExportRecordCheckApi(
{
checkDuration: 90,
gapSeconds,
stationCode: stations.value.map((station) => station.code),
},
{
signal: abortController.value.signal,
},
);
return data;
},
onSuccess: (data) => {
const time = dayjs().format('YYYY-MM-DD_HH-mm-ss');
downloadByData(data, `录像缺失记录_${time}.xlsx`);
},
onError: (error) => {
if (isCancel(error)) return;
console.error(error);
const errorFeedback = parseErrorFeedback(error);
window.$message.error(errorFeedback);
},
});
const onAfterLeave = () => {
abortController.value.abort();
emit('afterLeave');
};
</script>
@@ -92,6 +137,11 @@ const onAfterLeave = () => {
</NSpin>
</NScrollbar>
</template>
<template #action>
<NFlex justify="flex-end" align="center">
<NButton secondary :loading="batchExporting" @click="() => batchExportRecordCheck()">导出全部</NButton>
</NFlex>
</template>
</NModal>
</template>