完善设备数据查询,优化get请求处理。
This commit is contained in:
parent
551323d5d1
commit
a5781829e9
@ -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>
|
||||||
|
|||||||
@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user