修复分页异常问题
This commit is contained in:
parent
8b24e4219e
commit
d699782bc9
@ -8,7 +8,7 @@ import { useRoute } from 'vue-router';
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { postMetersPage, postCTWingLogInfoPage } from '#/api-client';
|
||||
import { postCTWingLogInfoPage, postMetersPage } from '#/api-client';
|
||||
|
||||
import DeviceSelect from '../deviceData/DeviceSelect.vue';
|
||||
import { querySchema, tableSchema } from './schema';
|
||||
@ -52,7 +52,7 @@ const getDeviceInfoById = (deviceId: string) => {
|
||||
if (!deviceId || !deviceOptions.value || deviceOptions.value.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const device = deviceOptions.value.find((device) => device.id === deviceId);
|
||||
return device;
|
||||
};
|
||||
@ -86,38 +86,43 @@ const formOptions: VbenFormProps = {
|
||||
// 当 DeviceId 发生变化时,更新 selectedDeviceInfo
|
||||
if (changedFields.includes('DeviceId')) {
|
||||
const deviceId = values.DeviceId;
|
||||
|
||||
|
||||
if (deviceId) {
|
||||
// 先尝试从 deviceOptions 中查找(备用方案)
|
||||
let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
|
||||
|
||||
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');
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
device = deviceSelectRef.getSelectedDevice();
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (device) {
|
||||
selectedDeviceInfo.value = device;
|
||||
} else {
|
||||
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
||||
if (delayedDevice) {
|
||||
selectedDeviceInfo.value = delayedDevice;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
// 静默处理错误
|
||||
}
|
||||
}, 100);
|
||||
@ -126,15 +131,15 @@ const formOptions: VbenFormProps = {
|
||||
selectedDeviceInfo.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 当任何相关字段发生变化时,刷新表格数据
|
||||
const relevantFields = new Set([
|
||||
'DeviceId',
|
||||
'DeviceType',
|
||||
'IoTDataType',
|
||||
'SystemName',
|
||||
'StartCreationTime',
|
||||
'EndCreationTime',
|
||||
'IoTDataType',
|
||||
'StartCreationTime',
|
||||
'SystemName',
|
||||
]);
|
||||
const hasRelevantChange = changedFields.some((field) =>
|
||||
relevantFields.has(field),
|
||||
@ -173,19 +178,23 @@ const gridOptions: VxeGridProps<any> = {
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
// 获取当前表单值,如果formValues为空则从表单API获取
|
||||
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
|
||||
|
||||
// 总是从表单API获取最新的表单值,确保分页时参数完整
|
||||
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
|
||||
|
||||
// 获取选中的设备信息
|
||||
let deviceId = currentFormValues.DeviceId || '';
|
||||
let systemName = '';
|
||||
const deviceType = currentFormValues.DeviceType || '';
|
||||
|
||||
|
||||
// 优先使用选中的设备信息
|
||||
const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
|
||||
|
||||
const deviceInfo =
|
||||
selectedDeviceInfo.value ||
|
||||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
|
||||
? getDeviceInfoById(currentFormValues.DeviceId)
|
||||
: null);
|
||||
|
||||
if (deviceInfo) {
|
||||
systemName = deviceInfo.systemName || '';
|
||||
systemName = deviceInfo.businessSystemName || '';
|
||||
// 根据设备类型获取正确的 id
|
||||
if (Number(deviceType) === 10) {
|
||||
// 集中器类型使用 focusId
|
||||
@ -195,7 +204,6 @@ const gridOptions: VxeGridProps<any> = {
|
||||
deviceId = deviceInfo.meterId || deviceId;
|
||||
}
|
||||
}
|
||||
|
||||
// 构建查询参数
|
||||
const queryParams = {
|
||||
pageIndex: page.currentPage,
|
||||
@ -209,7 +217,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
EndCreationTime: formatDate(currentFormValues.EndCreationTime),
|
||||
FocusAddress: currentFormValues.FocusAddress || '',
|
||||
};
|
||||
|
||||
|
||||
if (DeviceType) queryParams.DeviceType = DeviceType;
|
||||
if (DeviceId) queryParams.DeviceId = DeviceId;
|
||||
const { data } = await postCTWingLogInfoPage({
|
||||
|
||||
@ -52,7 +52,7 @@ const getDeviceInfoById = (deviceId: string) => {
|
||||
if (!deviceId || !deviceOptions.value || deviceOptions.value.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const device = deviceOptions.value.find((device) => device.id === deviceId);
|
||||
return device;
|
||||
};
|
||||
@ -85,38 +85,43 @@ const formOptions: VbenFormProps = {
|
||||
// 当 DeviceId 发生变化时,更新 selectedDeviceInfo
|
||||
if (changedFields.includes('DeviceId')) {
|
||||
const deviceId = values.DeviceId;
|
||||
|
||||
|
||||
if (deviceId) {
|
||||
// 先尝试从 deviceOptions 中查找(备用方案)
|
||||
let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
|
||||
|
||||
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');
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
device = deviceSelectRef.getSelectedDevice();
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (device) {
|
||||
selectedDeviceInfo.value = device;
|
||||
} else {
|
||||
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
||||
if (delayedDevice) {
|
||||
selectedDeviceInfo.value = delayedDevice;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
// 静默处理错误
|
||||
}
|
||||
}, 100);
|
||||
@ -125,15 +130,15 @@ const formOptions: VbenFormProps = {
|
||||
selectedDeviceInfo.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 当任何相关字段发生变化时,刷新表格数据
|
||||
const relevantFields = new Set([
|
||||
'DeviceId',
|
||||
'DeviceType',
|
||||
'IoTDataType',
|
||||
'SystemName',
|
||||
'StartCreationTime',
|
||||
'EndCreationTime',
|
||||
'IoTDataType',
|
||||
'StartCreationTime',
|
||||
'SystemName',
|
||||
]);
|
||||
const hasRelevantChange = changedFields.some((field) =>
|
||||
relevantFields.has(field),
|
||||
@ -157,7 +162,6 @@ const gridOptions: VxeGridProps<any> = {
|
||||
columns: tableSchema.value,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
// 确保分页功能正常工作
|
||||
pager: true,
|
||||
pagerConfig: {
|
||||
currentPage: 1,
|
||||
@ -172,19 +176,23 @@ const gridOptions: VxeGridProps<any> = {
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
// 获取当前表单值,如果formValues为空则从表单API获取
|
||||
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
|
||||
|
||||
// 总是从表单API获取最新的表单值,确保分页时参数完整
|
||||
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
|
||||
|
||||
// 获取选中的设备信息
|
||||
let deviceId = currentFormValues.DeviceId || '';
|
||||
let systemName = '';
|
||||
const deviceType = currentFormValues.DeviceType || '';
|
||||
|
||||
|
||||
// 优先使用选中的设备信息
|
||||
const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
|
||||
|
||||
const deviceInfo =
|
||||
selectedDeviceInfo.value ||
|
||||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
|
||||
? getDeviceInfoById(currentFormValues.DeviceId)
|
||||
: null);
|
||||
|
||||
if (deviceInfo) {
|
||||
systemName = deviceInfo.systemName || '';
|
||||
systemName = deviceInfo.businessSystemName || '';
|
||||
// 根据设备类型获取正确的 id
|
||||
if (Number(deviceType) === 10) {
|
||||
// 集中器类型使用 focusId
|
||||
@ -194,7 +202,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
deviceId = deviceInfo.meterId || deviceId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 构建查询参数
|
||||
const queryParams = {
|
||||
pageIndex: page.currentPage,
|
||||
@ -207,7 +215,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
StartCreationTime: formatDate(currentFormValues.StartCreationTime),
|
||||
EndCreationTime: formatDate(currentFormValues.EndCreationTime),
|
||||
};
|
||||
|
||||
|
||||
if (DeviceType) queryParams.DeviceType = DeviceType;
|
||||
if (DeviceId) queryParams.DeviceId = DeviceId;
|
||||
const { data } = await postOneNETLogInfoPage({
|
||||
@ -251,7 +259,6 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
// 页面初始化时获取设备信息
|
||||
onMounted(async () => {
|
||||
await fetchDeviceOptions();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user