refactor&perf

- proxy config
- query export
- optimize station card request
This commit is contained in:
yangsy
2025-08-25 15:49:21 +08:00
parent dea621a7a2
commit d0658580a0
23 changed files with 263 additions and 109 deletions

View File

@@ -3,7 +3,7 @@
import type { Station } from '@/apis/domains';
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
import { ndmDeviceAlarmLogDefaultExportByTemplate } from '@/apis/requests';
import type { StationAlarms } from '@/composables/query/use-line-alarms-query';
import type { StationAlarms } from '@/composables/query/alarm/use-line-alarms-query';
import { JAVA_INTEGER_MAX_VALUE } from '@/constants';
import { DeviceType, DeviceTypeName, type DeviceTypeCode } from '@/enums/device-type';
import { useQueryControlStore } from '@/stores/query-control';
@@ -15,7 +15,7 @@ import { computed, h, reactive, toRefs, watch } from 'vue';
interface Props {
station: Station;
stationAlarms: StationAlarms;
stationAlarms?: StationAlarms;
}
const props = defineProps<Props>();
@@ -35,7 +35,7 @@ watch(show, (newValue) => {
const alarmCount = computed(() => {
return Object.values(DeviceType).reduce((count, deviceType) => {
return count + stationAlarms.value[deviceType].length;
return count + (stationAlarms.value?.[deviceType].length ?? 0);
}, 0);
});
@@ -43,7 +43,7 @@ const classifiedCounts = computed(() => {
return Object.values(DeviceType).map<{ label: string; count: number }>((deviceType) => {
return {
label: DeviceTypeName[deviceType],
count: stationAlarms.value[deviceType].length,
count: stationAlarms.value?.[deviceType].length ?? 0,
};
});
});
@@ -132,7 +132,7 @@ const tablePagination = reactive<PaginationProps>({
},
});
const tableData = computed<DataTableRowData[]>(() => stationAlarms.value.unclassified);
const tableData = computed<DataTableRowData[]>(() => stationAlarms.value?.unclassified ?? []);
const { mutate: downloadTableData, isPending: isDownloading } = useMutation({
mutationFn: async () => {

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Station } from '@/apis/domains';
import type { NdmDeviceVO } from '@/apis/models';
import type { StationDevices } from '@/composables/query/use-line-devices-query';
import type { StationDevices } from '@/composables/query';
import { DeviceType, DeviceTypeName } from '@/enums/device-type';
import { useQueryControlStore } from '@/stores/query-control';
import { NButton, NCol, NInput, NModal, NRow, NStatistic, NTree } from 'naive-ui';
@@ -11,7 +11,7 @@ import { useRoute, useRouter } from 'vue-router';
interface Props {
station: Station;
stationDevices: StationDevices;
stationDevices?: StationDevices;
}
const props = defineProps<Props>();
@@ -42,7 +42,7 @@ const searchFilter: (pattern: string, node: TreeOption) => boolean = (pattern, n
const offlineDeviceCount = computed(() => {
let count = 0;
Object.values(DeviceType).forEach((deviceType) => {
const offlineDeviceList = stationDevices.value[deviceType].filter((device) => device.deviceStatus === '20');
const offlineDeviceList = stationDevices.value?.[deviceType].filter((device) => device.deviceStatus === '20') ?? [];
count += offlineDeviceList.length;
});
return count;
@@ -52,15 +52,15 @@ const classifiedCounts = computed(() => {
return Object.values(DeviceType).map((deviceType) => {
return {
label: DeviceTypeName[deviceType],
offlineCount: stationDevices.value[deviceType].filter((device) => device.deviceStatus === '20').length,
total: stationDevices.value[deviceType].length,
offlineCount: stationDevices.value?.[deviceType].filter((device) => device.deviceStatus === '20').length ?? 0,
total: stationDevices.value?.[deviceType].length ?? 0,
};
});
});
const treeData = computed<TreeOption[]>(() => {
return Object.values(DeviceType).map<TreeOption>((deviceType) => {
const offlineDeviceList = stationDevices.value[deviceType].filter((device) => device.deviceStatus === '20');
const offlineDeviceList = stationDevices.value?.[deviceType].filter((device) => device.deviceStatus === '20') ?? [];
return {
label: `${DeviceTypeName[deviceType]} (${offlineDeviceList.length}台)`,
key: deviceType,

View File

@@ -4,30 +4,31 @@ import DeviceParamsConfigModal from './device-params-config-modal.vue';
import OfflineDeviceDetailModal from './offline-device-detail-modal.vue';
import type { Station } from '@/apis/domains';
import { DeviceType } from '@/enums/device-type';
import type { StationAlarms } from '@/composables/query/use-line-alarms-query';
import type { StationDevices } from '@/composables/query/use-line-devices-query';
import { useStationDevicesQuery } from '@/composables/query/device/use-station-devices-query';
import { ControlOutlined } from '@vicons/antd';
import { Video as VideoIcon } from '@vicons/carbon';
import axios from 'axios';
import { NCard, NStatistic, NTag, NGrid, NGi, NButton, NIcon, useThemeVars, NSpace, NTooltip } from 'naive-ui';
import { toRefs, computed, ref } from 'vue';
import { useStationAlarmsQuery } from '@/composables/query/alarm/use-station-alarms-query';
interface Props {
station: Station;
stationDevices: StationDevices;
stationAlarms: StationAlarms;
}
const props = defineProps<Props>();
const { station, stationDevices, stationAlarms } = toRefs(props);
const { station } = toRefs(props);
const { code, name, online } = toRefs(station.value);
const { data: stationDevices } = useStationDevicesQuery(code.value);
const { data: stationAlarms } = useStationAlarmsQuery(station.value.code);
// 计算总离线设备数量
const offlineDeviceCount = computed(() => {
let count = 0;
Object.values(DeviceType).forEach((deviceType) => {
const offlineDeviceList = stationDevices.value[deviceType].filter((device) => device.deviceStatus === '20');
const offlineDeviceList = stationDevices.value?.[deviceType].filter((device) => device.deviceStatus === '20') ?? [];
count += offlineDeviceList.length;
});
return count;
@@ -35,14 +36,14 @@ const offlineDeviceCount = computed(() => {
const deviceCount = computed(() => {
let count = 0;
Object.values(DeviceType).forEach((deviceType) => {
count += stationDevices.value[deviceType].length;
count += stationDevices.value?.[deviceType].length ?? 0;
});
return count;
});
const devicAlarmCount = computed(() => {
let count = 0;
Object.values(DeviceType).forEach((deviceType) => {
count += stationAlarms.value[deviceType].length;
count += stationAlarms.value?.[deviceType].length ?? 0;
});
return count;
});