完善设备数据查询,优化get请求处理。
This commit is contained in:
parent
551323d5d1
commit
a5781829e9
@ -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;
|
||||
let finalDeviceId = formValues.DeviceId || DeviceId;
|
||||
if (formValues.DeviceId) {
|
||||
const deviceInfo = getDeviceInfoById(formValues.DeviceId);
|
||||
finalDeviceId =
|
||||
deviceTypeNumber === 10 && deviceInfo
|
||||
? deviceInfo.focusId
|
||||
: deviceInfo.meterId;
|
||||
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>
|
||||
|
||||
@ -176,6 +176,7 @@ const toStatusData = (row: Record<string, any>) => {
|
||||
DeviceType: 10,
|
||||
DeviceId: row.focusId,
|
||||
FocusAddress: row.focusAddress,
|
||||
SystemName: row.businessSystemName,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -183,6 +183,7 @@ const toStatusData = (row: Record<string, any>) => {
|
||||
DeviceType: row.meterType,
|
||||
DeviceId: row.meterId,
|
||||
FocusAddress: row.focusAddress,
|
||||
SystemName: row.businessSystemName,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user