onenet日志查询

This commit is contained in:
ChenYi 2025-07-17 11:47:00 +08:00
parent 17be5382bf
commit 113f24cc9d

View File

@ -63,7 +63,8 @@ const getDeviceInfoById = (deviceId: string) => {
meterId: device.meterId,
focusId: device.focusId,
systemName: device.systemName,
keys: Object.keys(device)
keys: Object.keys(device),
fullDevice: JSON.parse(JSON.stringify(device)) //
})));
const device = deviceOptions.value.find((device) => device.id === deviceId);
@ -99,7 +100,9 @@ const formOptions: VbenFormProps = {
//
handleValuesChange: async (values, changedFields) => {
console.log('handleValuesChange 被触发:', { values, changedFields });
console.log('deviceSelectRef.value:', deviceSelectRef.value);
console.log('当前所有表单值:', values);
console.log('DeviceType:', values.DeviceType);
console.log('IoTDataType:', values.IoTDataType);
// DeviceId selectedDeviceInfo
if (changedFields.includes('DeviceId')) {
@ -107,18 +110,41 @@ const formOptions: VbenFormProps = {
console.log('DeviceId 变化:', deviceId);
if (deviceId) {
// DeviceSelect
if (
deviceSelectRef.value &&
typeof deviceSelectRef.value.getSelectedDevice === 'function'
) {
const device = deviceSelectRef.value.getSelectedDevice();
// deviceOptions
let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
// DeviceSelect
if (!device && gridApi?.formApi) {
try {
// DeviceSelect
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice();
}
} catch (error) {
console.log('获取组件实例失败:', error);
}
}
if (device) {
selectedDeviceInfo.value = device;
console.log('handleValuesChange 更新设备信息:', device);
}
} else {
console.log('deviceSelectRef 不可用或 getSelectedDevice 方法不存在');
//
setTimeout(() => {
try {
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
const delayedDevice = deviceSelectRef.getSelectedDevice();
if (delayedDevice) {
selectedDeviceInfo.value = delayedDevice;
console.log('延迟获取设备信息成功:', delayedDevice);
}
}
} catch (error) {
console.log('延迟获取组件实例失败:', error);
}
}, 100);
}
} else {
selectedDeviceInfo.value = null;
@ -129,10 +155,10 @@ const formOptions: VbenFormProps = {
const relevantFields = new Set([
'DeviceId',
'DeviceType',
'EndCreationTime',
'IoTDataType',
'StartCreationTime',
'SystemName',
'StartCreationTime',
'EndCreationTime',
]);
const hasRelevantChange = changedFields.some((field) =>
relevantFields.has(field),
@ -141,9 +167,8 @@ const formOptions: VbenFormProps = {
if (hasRelevantChange) {
// 使 setTimeout
setTimeout(async () => {
if (gridApi) {
gridApi.reload();
}
const latestValues = await gridApi.formApi.getValues();
gridApi.reload(latestValues);
}, 0);
}
},
@ -179,24 +204,27 @@ const gridOptions: VxeGridProps<any> = {
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
// formValuesAPI
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
console.log('查询时的 formValues:', formValues);
console.log('查询时的 currentFormValues:', currentFormValues);
//
let deviceId = formValues?.DeviceId || '';
let deviceId = currentFormValues.DeviceId || '';
let systemName = '';
const deviceType = formValues?.DeviceType || '';
const deviceType = currentFormValues.DeviceType || '';
console.log('查询参数:', { deviceId, deviceType, formValues });
console.log('查询参数:', { deviceId, deviceType, currentFormValues });
console.log('currentFormValues.DeviceId:', currentFormValues.DeviceId);
console.log('currentFormValues.DeviceType:', currentFormValues.DeviceType);
console.log('currentFormValues.IoTDataType:', currentFormValues.IoTDataType);
// id
console.log('deviceOptions 状态:', {
hasDeviceOptions: !!deviceOptions.value,
deviceOptionsLength: deviceOptions.value?.length || 0,
});
// 使
const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
if (deviceId && deviceOptions.value && deviceOptions.value.length > 0) {
const deviceInfo = getDeviceInfoById(deviceId);
console.log('getDeviceInfoById 结果:', deviceInfo);
if (deviceInfo) {
console.log('找到设备信息:', deviceInfo);
console.log('使用设备信息:', deviceInfo);
systemName = deviceInfo.systemName || '';
// id
if (Number(deviceType) === 10) {
@ -207,26 +235,24 @@ const gridOptions: VxeGridProps<any> = {
deviceId = deviceInfo.meterId || deviceId;
}
} else {
console.log('未找到设备信息,使用原始 deviceId:', deviceId);
}
} else {
console.log(
'deviceOptions 未加载或为空,使用原始 deviceId:',
deviceId,
);
console.log('没有找到设备信息,使用原始 deviceId:', deviceId);
}
//
const queryParams = {
pageIndex: page.currentPage,
pageSize: page.pageSize,
SearchKeyword: formValues?.SearchKeyword || '',
SearchKeyword: currentFormValues.SearchKeyword || '',
DeviceType: deviceType,
IoTDataType: formValues?.IoTDataType || '',
IoTDataType: currentFormValues.IoTDataType || '',
DeviceId: deviceId,
SystemName: systemName || formValues?.SystemName || '',
StartCreationTime: formatDate(formValues?.StartCreationTime),
EndCreationTime: formatDate(formValues?.EndCreationTime),
SystemName: systemName || currentFormValues.SystemName || '',
StartCreationTime: formatDate(currentFormValues.StartCreationTime),
EndCreationTime: formatDate(currentFormValues.EndCreationTime),
};
console.log('最终查询参数:', queryParams);
if (DeviceType) queryParams.DeviceType = DeviceType;
if (DeviceId) queryParams.DeviceId = DeviceId;
const { data } = await postOneNETLogInfoPage({