diff --git a/src/types/equipment.d.ts b/src/types/equipment.d.ts index 2e423b4..2e86b33 100644 --- a/src/types/equipment.d.ts +++ b/src/types/equipment.d.ts @@ -23,8 +23,8 @@ export interface EquipmentPageQuery { invoice?: string barcode?: string importer?: string - page?: number - pageSize?: number + page?: number // 当前页码 - 与后端参数保持一致 + pageSize?: number // 每页大小 orderBy?: string orderDirection?: string } diff --git a/src/views/system-resource/device-management/approval/index.vue b/src/views/system-resource/device-management/approval/index.vue index c665c07..9de6c40 100644 --- a/src/views/system-resource/device-management/approval/index.vue +++ b/src/views/system-resource/device-management/approval/index.vue @@ -249,6 +249,19 @@ const pagination = reactive({ showPageSize: true, showJumper: true, showTotal: (total: number) => `共 ${total} 条记录`, + pageSizeOptions: [10, 20, 50, 100], // 添加分页条数选项 + onChange: (page: number, pageSize: number) => { + console.log('分页变化 - 页码:', page, '每页条数:', pageSize) + pagination.current = page + pagination.pageSize = pageSize + loadData(currentSearchParams.value) + }, + onPageSizeChange: (pageSize: number) => { + console.log('每页条数变化:', pageSize) + pagination.pageSize = pageSize + pagination.current = 1 // 重置到第一页 + loadData(currentSearchParams.value) + } }) // 弹窗控制 @@ -460,8 +473,8 @@ const loadData = async (searchParams?: EquipmentApprovalListReq) => { try { // 构建完整的请求参数 - 参考设备采购功能的实现 const params: EquipmentApprovalListReq = { + pageNum: pagination.current, // 修改为 pageNum,与后端期望的参数名一致 pageSize: pagination.pageSize, - page: pagination.current, ...(searchParams || {}), } @@ -478,46 +491,52 @@ const loadData = async (searchParams?: EquipmentApprovalListReq) => { console.log('API响应:', res) - // 处理不同的响应格式 - let dataList: any[] = [] - let total = 0 + if (res.code === 200 || res.success || res.status === 200) { + let dataList: any[] = [] + let totalCount = 0 - if (res && res.data) { - if (Array.isArray(res.data)) { + // 检查不同的数据字段 - 后端返回的是 PageResult 格式 + if ((res as any).rows && Array.isArray((res as any).rows)) { + // 后端返回的是 PageResult 格式,数据在 rows 字段中 + dataList = (res as any).rows + totalCount = (res as any).total || 0 + console.log('从 rows 字段获取数据,总数:', totalCount) + } else if (Array.isArray(res.data)) { dataList = res.data - total = res.data.length + totalCount = (res as any).total || dataList.length || 0 + console.log('从 data 字段获取数据,总数:', totalCount) } else if (res.data && Array.isArray((res.data as any).records)) { dataList = (res.data as any).records - total = (res.data as any).total || 0 + totalCount = (res.data as any).total || dataList.length || 0 + console.log('从 records 字段获取数据,总数:', totalCount) } else if (res.data && Array.isArray((res.data as any).list)) { dataList = (res.data as any).list - total = (res.data as any).total || 0 - } else if (res.data && Array.isArray((res.data as any).rows)) { - dataList = (res.data as any).rows - total = (res.data as any).total || 0 - } else if (res.data && Array.isArray((res.data as any).data)) { - dataList = (res.data as any).data - total = (res.data as any).total || 0 + totalCount = (res.data as any).total || dataList.length || 0 + console.log('从 list 字段获取数据,总数:', totalCount) + } else { + console.warn('未找到有效的数据字段,响应结构:', res) + dataList = [] + totalCount = 0 } - } else if (Array.isArray(res)) { - dataList = res - total = res.length - } - console.log('处理后的数据列表:', dataList) - console.log('总数:', total) + if (dataList.length > 0) { + const transformedData = transformBackendData(dataList) + tableData.value = transformedData + console.log('数据转换完成,设置到表格:', transformedData.length, '条') + } else { + tableData.value = [] + console.log('没有数据,清空表格') + } - if (dataList.length > 0) { - const transformedData = transformBackendData(dataList) - console.log('转换后的数据:', transformedData) - tableData.value = transformedData + // 设置总数 - 优先使用后端返回的总数 + pagination.total = totalCount + console.log('设置分页总数:', totalCount) } else { - console.log('没有数据,设置空数组') + console.error('请求失败,响应:', res) + message.error(res.msg || (res as any).message || '加载数据失败') tableData.value = [] + pagination.total = 0 } - - pagination.total = total - console.log('设置分页总数:', pagination.total) } catch (error: any) { console.error('加载数据失败:', error) message.error(error?.message || '加载数据失败') @@ -525,7 +544,6 @@ const loadData = async (searchParams?: EquipmentApprovalListReq) => { pagination.total = 0 } finally { loading.value = false - console.log('📊 loadData - 加载完成') } } diff --git a/src/views/system-resource/device-management/index.vue b/src/views/system-resource/device-management/index.vue index f9575bb..dafb746 100644 --- a/src/views/system-resource/device-management/index.vue +++ b/src/views/system-resource/device-management/index.vue @@ -119,7 +119,11 @@ :loading="loading" :pagination="pagination" row-key="equipmentId" - @change="handleTableChange" + :scroll="{ x: 'max-content', y: 500 }" + :bordered="false" + :stripe="true" + size="medium" + table-layout="auto" >