onenet日志查询
This commit is contained in:
parent
17be5382bf
commit
113f24cc9d
@ -63,7 +63,8 @@ const getDeviceInfoById = (deviceId: string) => {
|
|||||||
meterId: device.meterId,
|
meterId: device.meterId,
|
||||||
focusId: device.focusId,
|
focusId: device.focusId,
|
||||||
systemName: device.systemName,
|
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);
|
const device = deviceOptions.value.find((device) => device.id === deviceId);
|
||||||
@ -99,7 +100,9 @@ const formOptions: VbenFormProps = {
|
|||||||
// 添加表单值变化的处理函数
|
// 添加表单值变化的处理函数
|
||||||
handleValuesChange: async (values, changedFields) => {
|
handleValuesChange: async (values, changedFields) => {
|
||||||
console.log('handleValuesChange 被触发:', { 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
|
// 当 DeviceId 发生变化时,更新 selectedDeviceInfo
|
||||||
if (changedFields.includes('DeviceId')) {
|
if (changedFields.includes('DeviceId')) {
|
||||||
@ -107,18 +110,41 @@ const formOptions: VbenFormProps = {
|
|||||||
console.log('DeviceId 变化:', deviceId);
|
console.log('DeviceId 变化:', deviceId);
|
||||||
|
|
||||||
if (deviceId) {
|
if (deviceId) {
|
||||||
// 尝试从 DeviceSelect 组件中获取
|
// 先尝试从 deviceOptions 中查找(备用方案)
|
||||||
if (
|
let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
|
||||||
deviceSelectRef.value &&
|
|
||||||
typeof deviceSelectRef.value.getSelectedDevice === 'function'
|
// 如果没找到,尝试从 DeviceSelect 组件中获取
|
||||||
) {
|
if (!device && gridApi?.formApi) {
|
||||||
const device = deviceSelectRef.value.getSelectedDevice();
|
try {
|
||||||
|
// 获取 DeviceSelect 组件的实例
|
||||||
|
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||||
|
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||||
|
device = deviceSelectRef.getSelectedDevice();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('获取组件实例失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (device) {
|
if (device) {
|
||||||
selectedDeviceInfo.value = device;
|
selectedDeviceInfo.value = device;
|
||||||
console.log('handleValuesChange 更新设备信息:', device);
|
console.log('handleValuesChange 更新设备信息:', device);
|
||||||
}
|
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
selectedDeviceInfo.value = null;
|
selectedDeviceInfo.value = null;
|
||||||
@ -129,10 +155,10 @@ const formOptions: VbenFormProps = {
|
|||||||
const relevantFields = new Set([
|
const relevantFields = new Set([
|
||||||
'DeviceId',
|
'DeviceId',
|
||||||
'DeviceType',
|
'DeviceType',
|
||||||
'EndCreationTime',
|
|
||||||
'IoTDataType',
|
'IoTDataType',
|
||||||
'StartCreationTime',
|
|
||||||
'SystemName',
|
'SystemName',
|
||||||
|
'StartCreationTime',
|
||||||
|
'EndCreationTime',
|
||||||
]);
|
]);
|
||||||
const hasRelevantChange = changedFields.some((field) =>
|
const hasRelevantChange = changedFields.some((field) =>
|
||||||
relevantFields.has(field),
|
relevantFields.has(field),
|
||||||
@ -141,9 +167,8 @@ const formOptions: VbenFormProps = {
|
|||||||
if (hasRelevantChange) {
|
if (hasRelevantChange) {
|
||||||
// 使用 setTimeout 确保表单值已经完全更新
|
// 使用 setTimeout 确保表单值已经完全更新
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
if (gridApi) {
|
const latestValues = await gridApi.formApi.getValues();
|
||||||
gridApi.reload();
|
gridApi.reload(latestValues);
|
||||||
}
|
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -179,24 +204,27 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
ajax: {
|
ajax: {
|
||||||
query: async ({ page }, formValues) => {
|
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 = '';
|
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 状态:', {
|
const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
|
||||||
hasDeviceOptions: !!deviceOptions.value,
|
|
||||||
deviceOptionsLength: deviceOptions.value?.length || 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (deviceId && deviceOptions.value && deviceOptions.value.length > 0) {
|
|
||||||
const deviceInfo = getDeviceInfoById(deviceId);
|
|
||||||
console.log('getDeviceInfoById 结果:', deviceInfo);
|
|
||||||
if (deviceInfo) {
|
if (deviceInfo) {
|
||||||
console.log('找到设备信息:', deviceInfo);
|
console.log('使用设备信息:', deviceInfo);
|
||||||
systemName = deviceInfo.systemName || '';
|
systemName = deviceInfo.systemName || '';
|
||||||
// 根据设备类型获取正确的 id
|
// 根据设备类型获取正确的 id
|
||||||
if (Number(deviceType) === 10) {
|
if (Number(deviceType) === 10) {
|
||||||
@ -207,26 +235,24 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
deviceId = deviceInfo.meterId || deviceId;
|
deviceId = deviceInfo.meterId || deviceId;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('未找到设备信息,使用原始 deviceId:', deviceId);
|
console.log('没有找到设备信息,使用原始 deviceId:', deviceId);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
'deviceOptions 未加载或为空,使用原始 deviceId:',
|
|
||||||
deviceId,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建查询参数
|
// 构建查询参数
|
||||||
const queryParams = {
|
const queryParams = {
|
||||||
pageIndex: page.currentPage,
|
pageIndex: page.currentPage,
|
||||||
pageSize: page.pageSize,
|
pageSize: page.pageSize,
|
||||||
SearchKeyword: formValues?.SearchKeyword || '',
|
SearchKeyword: currentFormValues.SearchKeyword || '',
|
||||||
DeviceType: deviceType,
|
DeviceType: deviceType,
|
||||||
IoTDataType: formValues?.IoTDataType || '',
|
IoTDataType: currentFormValues.IoTDataType || '',
|
||||||
DeviceId: deviceId,
|
DeviceId: deviceId,
|
||||||
SystemName: systemName || formValues?.SystemName || '',
|
SystemName: systemName || currentFormValues.SystemName || '',
|
||||||
StartCreationTime: formatDate(formValues?.StartCreationTime),
|
StartCreationTime: formatDate(currentFormValues.StartCreationTime),
|
||||||
EndCreationTime: formatDate(formValues?.EndCreationTime),
|
EndCreationTime: formatDate(currentFormValues.EndCreationTime),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('最终查询参数:', queryParams);
|
||||||
|
|
||||||
if (DeviceType) queryParams.DeviceType = DeviceType;
|
if (DeviceType) queryParams.DeviceType = DeviceType;
|
||||||
if (DeviceId) queryParams.DeviceId = DeviceId;
|
if (DeviceId) queryParams.DeviceId = DeviceId;
|
||||||
const { data } = await postOneNETLogInfoPage({
|
const { data } = await postOneNETLogInfoPage({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user