From 990626b3ff757ce18ab229727ae6079546052dfd Mon Sep 17 00:00:00 2001 From: yangsy Date: Thu, 6 Nov 2025 14:27:54 +0800 Subject: [PATCH] feat(dashboard): export devices --- .../requests/device/export/ndm-icmp-export.ts | 17 ++++ .../dashboard-page/device-statistic.vue | 85 +++++++++++++++++++ src/pages/dashboard-page.vue | 39 ++++++++- 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/apis/requests/device/export/ndm-icmp-export.ts create mode 100644 src/components/dashboard-page/device-statistic.vue diff --git a/src/apis/requests/device/export/ndm-icmp-export.ts b/src/apis/requests/device/export/ndm-icmp-export.ts new file mode 100644 index 0000000..24abf2a --- /dev/null +++ b/src/apis/requests/device/export/ndm-icmp-export.ts @@ -0,0 +1,17 @@ +import { ndmClient } from '@/apis/client'; + +export const ndmExportDevices = async (status?: string) => { + const endpoint = '/api/ndm/ndmIcmpExport/exportByTemplate'; + const body = new URLSearchParams(); + body.append('status', status ?? ''); + const resp = await ndmClient.post(endpoint, body, { + responseType: 'blob', + retRaw: true, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + }); + const [err, data] = resp; + if (err || !data) { + throw err; + } + return data; +}; diff --git a/src/components/dashboard-page/device-statistic.vue b/src/components/dashboard-page/device-statistic.vue new file mode 100644 index 0000000..0a05b1c --- /dev/null +++ b/src/components/dashboard-page/device-statistic.vue @@ -0,0 +1,85 @@ + + + + + diff --git a/src/pages/dashboard-page.vue b/src/pages/dashboard-page.vue index 44479f3..40b0185 100644 --- a/src/pages/dashboard-page.vue +++ b/src/pages/dashboard-page.vue @@ -9,9 +9,15 @@ import { useStationStore } from '@/stores/station'; import { useLineDevicesStore } from '@/stores/line-devices'; import { NGrid, NGi } from 'naive-ui'; import { storeToRefs } from 'pinia'; -import { ref, watch } from 'vue'; +import { computed, ref, watch } from 'vue'; import { useLineAlarmCountsStore } from '@/stores/line-alarm-counts'; import { useLayoutStore } from '@/stores/layout'; +import { DeviceType } from '@/enums/device-type'; +import DeviceStatistic from '@/components/dashboard-page/device-statistic.vue'; +import { useMutation } from '@tanstack/vue-query'; +import { ndmExportDevices } from '@/apis/requests'; +import { downloadByData } from '@/utils/download'; +import dayjs from 'dayjs'; const stationStore = useStationStore(); const { stationList } = storeToRefs(stationStore); @@ -49,6 +55,28 @@ watch([lineDevicesQueryError, lineAlarmCountsQueryError], ([newLineDevicesQueryE } }); +const { mutate: exportDevices, isPending: exporting } = useMutation({ + mutationFn: async (params: { status: string }) => { + const data = await ndmExportDevices(params.status); + return data; + }, + onSuccess: (data, variables) => { + const { status } = variables; + let fileName = '全部设备列表'; + if (status === '10') { + fileName = '在线设备列表'; + } else if (status === '20') { + fileName = '离线设备列表'; + } + const time = dayjs().format('YYYY-MM-DD_HH-mm-ss'); + downloadByData(data, `${fileName}_${time}.xlsx`); + }, + onError: (error) => { + console.error(error); + window.$message.error(error.message); + }, +}); + const selectedStation = ref(); const offlineDeviceTreeModalShow = ref(false); const deviceAlarmTreeModalShow = ref(false); @@ -68,6 +96,15 @@ const openDeviceParamsConfigModal = (station: Station) => {