完善设备数据查询,优化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 { 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 { Page } from '@vben/common-ui';
@ -46,7 +46,7 @@ const getDeviceInfoById = (deviceId: string) => {
};
const route = useRoute();
const { DeviceType, DeviceId, FocusAddress } = route.query;
const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query;
//
const dynamicColumns = ref<any[]>([]);
@ -89,6 +89,7 @@ const formOptions: VbenFormProps = {
FocusAddress: FocusAddress as string,
DeviceType: DeviceType ? Number(DeviceType) : undefined,
DeviceId: DeviceId as string,
SystemName: SystemName as string,
},
// 使
submitOnChange: false,
@ -170,24 +171,44 @@ const gridOptions: VxeGridProps<any> = {
console.log('=== API调用开始 ===2', ioTDataTypeValue);
// DeviceId(10)使focusId
let finalDeviceId = 0;
const deviceInfo = getDeviceInfoById(formValues.DeviceId);
finalDeviceId =
deviceTypeNumber === 10 && deviceInfo
? deviceInfo.focusId
: deviceInfo.meterId;
let finalDeviceId = formValues.DeviceId || DeviceId;
if (formValues.DeviceId) {
const deviceInfo = getDeviceInfoById(formValues.DeviceId);
if (deviceInfo) {
if (deviceTypeNumber === 10) {
// 使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 {
const { data } = await postTreeModelDeviceDataInfoPage({
body: {
...formValues,
pageIndex: page.currentPage,
pageSize: page.pageSize,
// 使使
DeviceType: deviceTypeNumber,
DeviceId: finalDeviceId.toString(),
FocusAddress: deviceInfo.focusAddress,
DeviceId: finalDeviceId,
FocusAddress: formValues.FocusAddress || FocusAddress,
//
SystemName: formValues.SystemName,
SystemName: formValues.SystemName || SystemName,
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>
<template>

View File

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

View File

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