onenet日志查询
This commit is contained in:
parent
17be5382bf
commit
113f24cc9d
@ -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) => {
|
||||
// 获取当前表单值,如果formValues为空则从表单API获取
|
||||
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({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user