完善设备数据查询,优化get请求处理。

This commit is contained in:
ChenYi 2025-07-14 11:43:20 +08:00
parent 551323d5d1
commit a5781829e9
3 changed files with 69 additions and 12 deletions

View File

@ -2,7 +2,7 @@
import type { VbenFormProps } from '#/adapter/form'; import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table'; import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, nextTick, ref, watch } from 'vue'; import { computed, nextTick, ref, watch, onMounted } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
@ -46,7 +46,7 @@ const getDeviceInfoById = (deviceId: string) => {
}; };
const route = useRoute(); const route = useRoute();
const { DeviceType, DeviceId, FocusAddress } = route.query; const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query;
// //
const dynamicColumns = ref<any[]>([]); const dynamicColumns = ref<any[]>([]);
@ -89,6 +89,7 @@ const formOptions: VbenFormProps = {
FocusAddress: FocusAddress as string, FocusAddress: FocusAddress as string,
DeviceType: DeviceType ? Number(DeviceType) : undefined, DeviceType: DeviceType ? Number(DeviceType) : undefined,
DeviceId: DeviceId as string, DeviceId: DeviceId as string,
SystemName: SystemName as string,
}, },
// 使 // 使
submitOnChange: false, submitOnChange: false,
@ -170,24 +171,44 @@ const gridOptions: VxeGridProps<any> = {
console.log('=== API调用开始 ===2', ioTDataTypeValue); console.log('=== API调用开始 ===2', ioTDataTypeValue);
// DeviceId(10)使focusId // DeviceId(10)使focusId
let finalDeviceId = 0; let finalDeviceId = formValues.DeviceId || DeviceId;
const deviceInfo = getDeviceInfoById(formValues.DeviceId); if (formValues.DeviceId) {
finalDeviceId = const deviceInfo = getDeviceInfoById(formValues.DeviceId);
deviceTypeNumber === 10 && deviceInfo if (deviceInfo) {
? deviceInfo.focusId if (deviceTypeNumber === 10) {
: deviceInfo.meterId; // 使focusId
if (deviceInfo.focusId) {
finalDeviceId = deviceInfo.focusId;
console.log('设备类型为集中器使用focusId:', {
originalDeviceId: formValues.DeviceId,
focusId: deviceInfo.focusId,
deviceInfo: deviceInfo,
});
}
} else {
// 使meterId
if (deviceInfo.meterId) {
finalDeviceId = deviceInfo.meterId;
console.log('设备类型为非集中器使用meterId:', {
originalDeviceId: formValues.DeviceId,
meterId: deviceInfo.meterId,
deviceInfo: deviceInfo,
});
}
}
}
}
try { try {
const { data } = await postTreeModelDeviceDataInfoPage({ const { data } = await postTreeModelDeviceDataInfoPage({
body: { body: {
...formValues,
pageIndex: page.currentPage, pageIndex: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
// 使使 // 使使
DeviceType: deviceTypeNumber, DeviceType: deviceTypeNumber,
DeviceId: finalDeviceId.toString(), DeviceId: finalDeviceId,
FocusAddress: deviceInfo.focusAddress, FocusAddress: formValues.FocusAddress || FocusAddress,
// //
SystemName: formValues.SystemName, SystemName: formValues.SystemName || SystemName,
IoTDataType: ioTDataTypeValue, IoTDataType: ioTDataTypeValue,
}, },
}); });
@ -293,6 +314,40 @@ watch(
} }
}, },
); );
//
watch(
() => [DeviceType, DeviceId, FocusAddress, SystemName],
async (newValues, oldValues) => {
console.log('路由参数变化:', { newValues, oldValues });
//
if (newValues.some(val => val) && gridApi) {
//
await fetchDeviceOptions();
//
setTimeout(() => {
console.log('自动触发查询,路由参数:', { DeviceType, DeviceId, FocusAddress, SystemName });
gridApi.reload();
}, 100);
}
},
{ immediate: true }
);
//
onMounted(async () => {
console.log('页面挂载完成,检查路由参数:', { DeviceType, DeviceId, FocusAddress, SystemName });
//
if (DeviceType || DeviceId || FocusAddress || SystemName) {
//
await fetchDeviceOptions();
//
setTimeout(() => {
console.log('页面初始化时自动触发查询');
gridApi.reload();
}, 200);
}
});
</script> </script>
<template> <template>

View File

@ -176,6 +176,7 @@ const toStatusData = (row: Record<string, any>) => {
DeviceType: 10, DeviceType: 10,
DeviceId: row.focusId, DeviceId: row.focusId,
FocusAddress: row.focusAddress, FocusAddress: row.focusAddress,
SystemName: row.businessSystemName,
}, },
}); });
}; };

View File

@ -183,6 +183,7 @@ const toStatusData = (row: Record<string, any>) => {
DeviceType: row.meterType, DeviceType: row.meterType,
DeviceId: row.meterId, DeviceId: row.meterId,
FocusAddress: row.focusAddress, FocusAddress: row.focusAddress,
SystemName: row.businessSystemName,
}, },
}); });
}; };