完善表格展示布局
This commit is contained in:
parent
fb44ace832
commit
f967080ccd
@ -23,6 +23,9 @@ const { DeviceType, DeviceId, FocusAddress } = route.query;
|
|||||||
// 动态列定义
|
// 动态列定义
|
||||||
const dynamicColumns = ref<any[]>([]);
|
const dynamicColumns = ref<any[]>([]);
|
||||||
|
|
||||||
|
// 缓存实际的数据总量
|
||||||
|
const actualTotalCount = ref<number>(0);
|
||||||
|
|
||||||
// 固定列定义(始终显示)- 基于 IoTDBTreeModelDeviceDataDto 类型
|
// 固定列定义(始终显示)- 基于 IoTDBTreeModelDeviceDataDto 类型
|
||||||
const fixedColumns = [
|
const fixedColumns = [
|
||||||
{ title: '序号', type: 'seq', width: 50 },
|
{ title: '序号', type: 'seq', width: 50 },
|
||||||
@ -86,6 +89,17 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
pagerConfig: {
|
pagerConfig: {
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
pageSize: 20,
|
pageSize: 20,
|
||||||
|
// 添加分页事件处理
|
||||||
|
onChange: (currentPage: number, pageSize: number) => {
|
||||||
|
console.log('分页变化:', { currentPage, pageSize });
|
||||||
|
// 当pageSize变化时,重置到第一页
|
||||||
|
if (pageSize !== gridOptions.pagerConfig.pageSize) {
|
||||||
|
console.log('页面大小变化,重置到第一页');
|
||||||
|
// 更新配置中的pageSize
|
||||||
|
gridOptions.pagerConfig.pageSize = pageSize;
|
||||||
|
gridOptions.pagerConfig.currentPage = 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
custom: true,
|
custom: true,
|
||||||
@ -154,13 +168,50 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 确保返回的数据包含totalCount字段
|
// 由于API没有返回totalCount,我们需要特殊处理分页
|
||||||
// 由于API响应中没有totalCount,我们使用items的长度作为总数
|
const currentPageSize = page.pageSize;
|
||||||
|
const currentItemsCount = data.items ? data.items.length : 0;
|
||||||
|
|
||||||
|
// 简化的总数估算逻辑
|
||||||
|
let estimatedTotalCount = 0;
|
||||||
|
|
||||||
|
// 如果是第一页,使用保守的估算
|
||||||
|
if (page.currentPage === 1) {
|
||||||
|
if (currentItemsCount === currentPageSize) {
|
||||||
|
// 第一页满了,说明可能还有更多数据
|
||||||
|
// 使用一个保守的估算:假设至少还有一页数据
|
||||||
|
estimatedTotalCount = currentPageSize * 2;
|
||||||
|
} else {
|
||||||
|
// 第一页没满,说明总共就只有这么多数据
|
||||||
|
estimatedTotalCount = currentItemsCount;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 不是第一页,使用更准确的逻辑
|
||||||
|
if (currentItemsCount === currentPageSize) {
|
||||||
|
// 当前页满了,说明可能还有更多数据
|
||||||
|
estimatedTotalCount = page.currentPage * currentPageSize + currentPageSize;
|
||||||
|
} else {
|
||||||
|
// 当前页没满,说明这是最后一页
|
||||||
|
estimatedTotalCount = (page.currentPage - 1) * currentPageSize + currentItemsCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保总数至少等于当前页的数据量
|
||||||
|
estimatedTotalCount = Math.max(estimatedTotalCount, currentItemsCount);
|
||||||
|
|
||||||
|
// 如果当前页数据量小于页面大小,说明这是最后一页,更新缓存
|
||||||
|
if (currentItemsCount < currentPageSize) {
|
||||||
|
actualTotalCount.value = estimatedTotalCount;
|
||||||
|
console.log('更新缓存的实际总数:', estimatedTotalCount);
|
||||||
|
}
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
items: data.items || [],
|
items: data.items || [],
|
||||||
totalCount: data.items ? data.items.length : 0,
|
totalCount: estimatedTotalCount,
|
||||||
};
|
};
|
||||||
console.log('返回给表格的数据:', result);
|
console.log('返回给表格的数据:', result);
|
||||||
|
console.log('估算总数:', result.totalCount, '当前页数据量:', result.items.length);
|
||||||
|
console.log('分页信息:', { currentPage: page.currentPage, pageSize: currentPageSize });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +230,25 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
||||||
|
|
||||||
|
// 监听分页器状态变化
|
||||||
|
watch(() => gridApi?.pagerApi?.currentPage, (newPage, oldPage) => {
|
||||||
|
console.log('当前页变化:', { newPage, oldPage });
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(() => gridApi?.pagerApi?.pageSize, (newSize, oldSize) => {
|
||||||
|
console.log('页面大小变化:', { newSize, oldSize });
|
||||||
|
if (newSize !== oldSize && oldSize) {
|
||||||
|
console.log('页面大小从', oldSize, '变为', newSize, ',重置到第一页');
|
||||||
|
// 如果新的页面大小大于缓存的总数,清除缓存
|
||||||
|
if (actualTotalCount.value > 0 && newSize > actualTotalCount.value) {
|
||||||
|
console.log('新页面大小大于缓存总数,清除缓存');
|
||||||
|
actualTotalCount.value = 0;
|
||||||
|
}
|
||||||
|
// 重置到第一页
|
||||||
|
gridApi.pagerApi.currentPage = 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user