修复分页异常问题
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 { Page } from '@vben/common-ui';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
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 DeviceSelect from '../deviceData/DeviceSelect.vue';
|
||||||
import { querySchema, tableSchema } from './schema';
|
import { querySchema, tableSchema } from './schema';
|
||||||
@ -89,17 +89,21 @@ const formOptions: VbenFormProps = {
|
|||||||
|
|
||||||
if (deviceId) {
|
if (deviceId) {
|
||||||
// 先尝试从 deviceOptions 中查找(备用方案)
|
// 先尝试从 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 组件中获取
|
// 如果没找到,尝试从 DeviceSelect 组件中获取
|
||||||
if (!device && gridApi?.formApi) {
|
if (!device && gridApi?.formApi) {
|
||||||
try {
|
try {
|
||||||
// 获取 DeviceSelect 组件的实例
|
// 获取 DeviceSelect 组件的实例
|
||||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
const deviceSelectRef =
|
||||||
|
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||||
device = deviceSelectRef.getSelectedDevice();
|
device = deviceSelectRef.getSelectedDevice();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch {
|
||||||
// 静默处理错误
|
// 静默处理错误
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,14 +114,15 @@ const formOptions: VbenFormProps = {
|
|||||||
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
try {
|
try {
|
||||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
const deviceSelectRef =
|
||||||
|
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||||
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
||||||
if (delayedDevice) {
|
if (delayedDevice) {
|
||||||
selectedDeviceInfo.value = delayedDevice;
|
selectedDeviceInfo.value = delayedDevice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch {
|
||||||
// 静默处理错误
|
// 静默处理错误
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
@ -131,10 +136,10 @@ const formOptions: VbenFormProps = {
|
|||||||
const relevantFields = new Set([
|
const relevantFields = new Set([
|
||||||
'DeviceId',
|
'DeviceId',
|
||||||
'DeviceType',
|
'DeviceType',
|
||||||
'IoTDataType',
|
|
||||||
'SystemName',
|
|
||||||
'StartCreationTime',
|
|
||||||
'EndCreationTime',
|
'EndCreationTime',
|
||||||
|
'IoTDataType',
|
||||||
|
'StartCreationTime',
|
||||||
|
'SystemName',
|
||||||
]);
|
]);
|
||||||
const hasRelevantChange = changedFields.some((field) =>
|
const hasRelevantChange = changedFields.some((field) =>
|
||||||
relevantFields.has(field),
|
relevantFields.has(field),
|
||||||
@ -173,8 +178,8 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
ajax: {
|
ajax: {
|
||||||
query: async ({ page }, formValues) => {
|
query: async ({ page }, formValues) => {
|
||||||
// 获取当前表单值,如果formValues为空则从表单API获取
|
// 总是从表单API获取最新的表单值,确保分页时参数完整
|
||||||
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
|
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
|
||||||
|
|
||||||
// 获取选中的设备信息
|
// 获取选中的设备信息
|
||||||
let deviceId = currentFormValues.DeviceId || '';
|
let deviceId = currentFormValues.DeviceId || '';
|
||||||
@ -182,10 +187,14 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
const deviceType = currentFormValues.DeviceType || '';
|
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) {
|
if (deviceInfo) {
|
||||||
systemName = deviceInfo.systemName || '';
|
systemName = deviceInfo.businessSystemName || '';
|
||||||
// 根据设备类型获取正确的 id
|
// 根据设备类型获取正确的 id
|
||||||
if (Number(deviceType) === 10) {
|
if (Number(deviceType) === 10) {
|
||||||
// 集中器类型使用 focusId
|
// 集中器类型使用 focusId
|
||||||
@ -195,7 +204,6 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
deviceId = deviceInfo.meterId || deviceId;
|
deviceId = deviceInfo.meterId || deviceId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建查询参数
|
// 构建查询参数
|
||||||
const queryParams = {
|
const queryParams = {
|
||||||
pageIndex: page.currentPage,
|
pageIndex: page.currentPage,
|
||||||
|
|||||||
@ -88,17 +88,21 @@ const formOptions: VbenFormProps = {
|
|||||||
|
|
||||||
if (deviceId) {
|
if (deviceId) {
|
||||||
// 先尝试从 deviceOptions 中查找(备用方案)
|
// 先尝试从 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 组件中获取
|
// 如果没找到,尝试从 DeviceSelect 组件中获取
|
||||||
if (!device && gridApi?.formApi) {
|
if (!device && gridApi?.formApi) {
|
||||||
try {
|
try {
|
||||||
// 获取 DeviceSelect 组件的实例
|
// 获取 DeviceSelect 组件的实例
|
||||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
const deviceSelectRef =
|
||||||
|
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||||
device = deviceSelectRef.getSelectedDevice();
|
device = deviceSelectRef.getSelectedDevice();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch {
|
||||||
// 静默处理错误
|
// 静默处理错误
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,14 +113,15 @@ const formOptions: VbenFormProps = {
|
|||||||
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
try {
|
try {
|
||||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
const deviceSelectRef =
|
||||||
|
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||||
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
||||||
if (delayedDevice) {
|
if (delayedDevice) {
|
||||||
selectedDeviceInfo.value = delayedDevice;
|
selectedDeviceInfo.value = delayedDevice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch {
|
||||||
// 静默处理错误
|
// 静默处理错误
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
@ -130,10 +135,10 @@ const formOptions: VbenFormProps = {
|
|||||||
const relevantFields = new Set([
|
const relevantFields = new Set([
|
||||||
'DeviceId',
|
'DeviceId',
|
||||||
'DeviceType',
|
'DeviceType',
|
||||||
'IoTDataType',
|
|
||||||
'SystemName',
|
|
||||||
'StartCreationTime',
|
|
||||||
'EndCreationTime',
|
'EndCreationTime',
|
||||||
|
'IoTDataType',
|
||||||
|
'StartCreationTime',
|
||||||
|
'SystemName',
|
||||||
]);
|
]);
|
||||||
const hasRelevantChange = changedFields.some((field) =>
|
const hasRelevantChange = changedFields.some((field) =>
|
||||||
relevantFields.has(field),
|
relevantFields.has(field),
|
||||||
@ -157,7 +162,6 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
columns: tableSchema.value,
|
columns: tableSchema.value,
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
keepSource: true,
|
keepSource: true,
|
||||||
// 确保分页功能正常工作
|
|
||||||
pager: true,
|
pager: true,
|
||||||
pagerConfig: {
|
pagerConfig: {
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
@ -172,8 +176,8 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
ajax: {
|
ajax: {
|
||||||
query: async ({ page }, formValues) => {
|
query: async ({ page }, formValues) => {
|
||||||
// 获取当前表单值,如果formValues为空则从表单API获取
|
// 总是从表单API获取最新的表单值,确保分页时参数完整
|
||||||
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
|
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
|
||||||
|
|
||||||
// 获取选中的设备信息
|
// 获取选中的设备信息
|
||||||
let deviceId = currentFormValues.DeviceId || '';
|
let deviceId = currentFormValues.DeviceId || '';
|
||||||
@ -181,10 +185,14 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
const deviceType = currentFormValues.DeviceType || '';
|
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) {
|
if (deviceInfo) {
|
||||||
systemName = deviceInfo.systemName || '';
|
systemName = deviceInfo.businessSystemName || '';
|
||||||
// 根据设备类型获取正确的 id
|
// 根据设备类型获取正确的 id
|
||||||
if (Number(deviceType) === 10) {
|
if (Number(deviceType) === 10) {
|
||||||
// 集中器类型使用 focusId
|
// 集中器类型使用 focusId
|
||||||
@ -251,7 +259,6 @@ watch(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// 页面初始化时获取设备信息
|
// 页面初始化时获取设备信息
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await fetchDeviceOptions();
|
await fetchDeviceOptions();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user