From e4fcf728b864bb1492a9d7776ac5acc266812668 Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Fri, 11 Jul 2025 13:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=97=A5=E5=BF=97=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api-client/services.gen.ts | 2 +- apps/web-antd/src/api-client/types.gen.ts | 3 + .../src/views/dataManger/ctwingLog/schema.ts | 9 +- .../src/views/dataManger/deviceData/index.vue | 190 ++++++++++-------- 4 files changed, 115 insertions(+), 89 deletions(-) diff --git a/apps/web-antd/src/api-client/services.gen.ts b/apps/web-antd/src/api-client/services.gen.ts index e4d4b22..dbd6f38 100644 --- a/apps/web-antd/src/api-client/services.gen.ts +++ b/apps/web-antd/src/api-client/services.gen.ts @@ -3197,6 +3197,6 @@ export const postCTWingLogInfoPage = ( ThrowOnError >({ ...options, - url: '/TableModel/OneNETLogInfo', + url: '/TableModel/CTWingLogInfo', }); }; diff --git a/apps/web-antd/src/api-client/types.gen.ts b/apps/web-antd/src/api-client/types.gen.ts index 3343b3f..c0f0b39 100644 --- a/apps/web-antd/src/api-client/types.gen.ts +++ b/apps/web-antd/src/api-client/types.gen.ts @@ -5096,6 +5096,7 @@ export type IoTDBTreeModelDeviceDataDto = { export type IoTDBTreeModelDeviceDataPageListResultDto = { items?: Array | null; + totalCount?: number; }; export type IoTDBTreeModelDeviceDataPageAllResponse = @@ -5145,6 +5146,7 @@ export type IoTDBOneNETLogInfoPageListInput = { }; export type IoTDBOneNETLogInfoPageListResult = { items?: Array | null; + totalCount?: number; }; export type CTWingLogInfoDto = { @@ -5195,4 +5197,5 @@ export type IoTDBCTWingLogInfoDtoPageListInput = { }; export type IoTDBCTWingLogInfoDtoPageListResult = { items?: Array | null; + totalCount?: number; }; diff --git a/apps/web-antd/src/views/dataManger/ctwingLog/schema.ts b/apps/web-antd/src/views/dataManger/ctwingLog/schema.ts index 3c880d8..c8527fc 100644 --- a/apps/web-antd/src/views/dataManger/ctwingLog/schema.ts +++ b/apps/web-antd/src/views/dataManger/ctwingLog/schema.ts @@ -62,11 +62,6 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ title: $t('abp.IoTDBBase.DeviceId'), minWidth: 150, }, - { - field: 'devicePath', - title: $t('abp.IoTDBBase.DevicePath'), - minWidth: 200, - }, { field: 'platformTenantId', title: $t('abp.CTWingLog.PlatformTenantId'), @@ -90,7 +85,7 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ { field: 'messageType', title: $t('abp.CTWingLog.MessageType'), - minWidth: 120, + minWidth: 180, }, { field: 'protocol', @@ -111,13 +106,11 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ field: 'rawMessage', title: $t('abp.CTWingLog.RawMessage'), minWidth: 200, - showOverflow: false, }, { field: 'receivedPayload', title: $t('abp.CTWingLog.ReceivedPayload'), minWidth: 200, - showOverflow: false, }, { field: 'receivedTime', diff --git a/apps/web-antd/src/views/dataManger/deviceData/index.vue b/apps/web-antd/src/views/dataManger/deviceData/index.vue index b52a518..19a91ec 100644 --- a/apps/web-antd/src/views/dataManger/deviceData/index.vue +++ b/apps/web-antd/src/views/dataManger/deviceData/index.vue @@ -2,16 +2,16 @@ import type { VbenFormProps } from '#/adapter/form'; import type { VxeGridProps } from '#/adapter/vxe-table'; +import { computed, nextTick, ref, watch } from 'vue'; import { useRoute } from 'vue-router'; -import { nextTick, watch, ref, computed } from 'vue'; import { Page } from '@vben/common-ui'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { postTreeModelDeviceDataInfoPage } from '#/api-client'; -import { querySchema, tableSchema } from './schema'; import { generateDynamicColumns } from './dynamicColumns'; +import { querySchema } from './schema'; defineOptions({ name: 'DeviceData', @@ -29,19 +29,16 @@ const actualTotalCount = ref(0); // 固定列定义(始终显示)- 基于 IoTDBTreeModelDeviceDataDto 类型 const fixedColumns = [ { title: '序号', type: 'seq', width: 50 }, + { field: 'Timestamps', title: '时间戳', minWidth: 150 }, { field: 'SystemName', title: '系统名称', minWidth: 150 }, { field: 'ProjectId', title: '项目ID', minWidth: 150 }, { field: 'DeviceType', title: '设备类型', minWidth: 150 }, { field: 'IoTDataType', title: 'IoT数据类型', minWidth: 150 }, { field: 'DeviceId', title: '设备ID', minWidth: 150 }, - { field: 'Timestamps', title: '时间戳', minWidth: 150 }, ]; // 合并固定列和动态列 - 使用计算属性确保响应式 -const allColumns = computed(() => [ - ...fixedColumns, - ...dynamicColumns.value, -]); +const allColumns = computed(() => [...fixedColumns, ...dynamicColumns.value]); // 初始化默认列(防止表格空白) const initDefaultColumns = () => { @@ -67,7 +64,7 @@ const formOptions: VbenFormProps = { if (changedFields.includes('SystemName')) { console.log('SystemName changed, values:', values); console.log('Changed fields:', changedFields); - + // 使用 setTimeout 确保表单值已经完全更新 setTimeout(async () => { const latestValues = await gridApi.formApi.getValues(); @@ -103,7 +100,6 @@ const gridOptions: VxeGridProps = { }, toolbarConfig: { custom: true, - search: true, }, customConfig: { storage: true, @@ -115,8 +111,14 @@ const gridOptions: VxeGridProps = { ajax: { query: async ({ page }, formValues) => { console.log('=== API调用开始 ==='); - console.log('请求参数:', { page, formValues, DeviceType, DeviceId, FocusAddress }); - + console.log('请求参数:', { + page, + formValues, + DeviceType, + DeviceId, + FocusAddress, + }); + try { const { data } = await postTreeModelDeviceDataInfoPage({ body: { @@ -128,37 +130,46 @@ const gridOptions: VxeGridProps = { FocusAddress, }, }); - + console.log('API返回的原始数据:', data); console.log('数据类型:', typeof data); - console.log('data是否为null/undefined:', data === null || data === undefined); - + console.log( + 'data是否为null/undefined:', + data === null || data === undefined, + ); + if (data) { console.log('data.items存在:', !!data.items); - console.log('data.items类型:', Array.isArray(data.items) ? 'Array' : typeof data.items); + console.log( + 'data.items类型:', + Array.isArray(data.items) ? 'Array' : typeof data.items, + ); if (data.items) { console.log('data.items长度:', data.items.length); if (data.items.length > 0) { console.log('第一条数据:', data.items[0]); - console.log('第一条数据的所有字段:', Object.keys(data.items[0])); + console.log( + '第一条数据的所有字段:', + Object.keys(data.items[0]), + ); } } } - + // 简化处理逻辑,先确保基本功能正常 if (data?.items && data.items.length > 0) { console.log('原始items数据:', data.items); - + // 直接使用原始数据,不进行复杂处理 const items = data.items; - + // 动态生成列定义 const generatedColumns = generateDynamicColumns(items); console.log('生成的列定义:', generatedColumns); - + // 更新动态列 dynamicColumns.value = generatedColumns; - + // 使用setState更新整个gridOptions,确保列定义能够正确更新 await nextTick(); gridApi.setState({ @@ -167,54 +178,67 @@ const gridOptions: VxeGridProps = { columns: allColumns.value, }, }); - - // 由于API没有返回totalCount,我们需要特殊处理分页 - 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; + + // 由于API没有返回totalCount,我们需要特殊处理分页 + 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 { - // 第一页没满,说明总共就只有这么多数据 - estimatedTotalCount = currentItemsCount; + // 不是第一页,使用更准确的逻辑 + if (currentItemsCount === currentPageSize) { + // 当前页满了,说明可能还有更多数据 + estimatedTotalCount = + page.currentPage * currentPageSize + currentPageSize; + } else { + // 当前页没满,说明这是最后一页 + estimatedTotalCount = + (page.currentPage - 1) * currentPageSize + 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 = { + items: data.items || [], + totalCount: estimatedTotalCount, + }; + console.log('返回给表格的数据:', result); + console.log( + '估算总数:', + result.totalCount, + '当前页数据量:', + result.items.length, + ); + console.log('分页信息:', { + currentPage: page.currentPage, + pageSize: currentPageSize, + }); + return result; } - - // 确保总数至少等于当前页的数据量 - estimatedTotalCount = Math.max(estimatedTotalCount, currentItemsCount); - - // 如果当前页数据量小于页面大小,说明这是最后一页,更新缓存 - if (currentItemsCount < currentPageSize) { - actualTotalCount.value = estimatedTotalCount; - console.log('更新缓存的实际总数:', estimatedTotalCount); - } - - const result = { - items: data.items || [], - totalCount: estimatedTotalCount, - }; - console.log('返回给表格的数据:', result); - console.log('估算总数:', result.totalCount, '当前页数据量:', result.items.length); - console.log('分页信息:', { currentPage: page.currentPage, pageSize: currentPageSize }); - return result; - } - + console.log('没有数据或数据为空'); return { items: [], @@ -232,23 +256,29 @@ const gridOptions: VxeGridProps = { const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions }); // 监听分页器状态变化 -watch(() => gridApi?.pagerApi?.currentPage, (newPage, oldPage) => { - console.log('当前页变化:', { newPage, oldPage }); -}); +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; +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; } - // 重置到第一页 - gridApi.pagerApi.currentPage = 1; - } -}); + }, +);