From 8631ead0b1ee53f8b1b236b01c73daf17df53279 Mon Sep 17 00:00:00 2001 From: "Mr.j" <2221464500@qq.com> Date: Tue, 12 Aug 2025 17:48:54 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2=E6=97=A0=E6=B3=95=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E5=92=8C=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96=E6=80=BB=E9=A1=B5?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/equipment.d.ts | 4 +- .../device-management/approval/index.vue | 78 ++++--- .../device-management/index.vue | 190 +++++++++++++++--- .../device-management/procurement/index.vue | 65 +++++- 4 files changed, 271 insertions(+), 66 deletions(-) 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" > + + +
+ +
@@ -262,33 +279,7 @@ const pagination = reactive({ // 确保分页器完全可见 hideOnSinglePage: false, // 分页器大小 - size: 'default', - // 分页器位置 - position: 'bottom', - // 分页事件处理 - onChange: (page: number, pageSize: number) => { - console.log('🔄 分页变化事件触发:', { page, pageSize }) - console.log('📊 变化前分页状态:', { - current: pagination.current, - pageSize: pagination.pageSize, - total: pagination.total - }) - - pagination.current = page - if (pageSize !== pagination.pageSize) { - pagination.pageSize = pageSize - pagination.current = 1 // 重置到第一页 - } - - console.log('📊 变化后分页状态:', { - current: pagination.current, - pageSize: pagination.pageSize, - total: pagination.total - }) - - console.log('🚀 开始重新加载数据...') - loadData(currentSearchParams.value) - } + size: 'default' }) // 弹窗控制 @@ -740,20 +731,20 @@ const handleTableChange = (pag: any) => { loadData(currentSearchParams.value) } -// 分页变化 - 已移至分页配置中处理 -// const handlePageChange = (page: number) => { -// console.log('页码变化:', page) -// pagination.current = page -// loadData(currentSearchParams.value) -// } +// 分页变化处理 +const handlePageChange = (page: number) => { + console.log('页码变化:', page) + pagination.current = page + loadData(currentSearchParams.value) +} -// 每页条数变化 - 已移至分页配置中处理 -// const handlePageSizeChange = (pageSize: number) => { -// console.log('每页条数变化:', pageSize) -// pagination.pageSize = pageSize -// pagination.current = 1 // 重置到第一页 -// loadData(currentSearchParams.value) -// } +// 每页条数变化处理 +const handlePageSizeChange = (pageSize: number) => { + console.log('每页条数变化:', pageSize) + pagination.pageSize = pageSize + pagination.current = 1 // 重置到第一页 + loadData(currentSearchParams.value) +} @@ -1132,28 +1123,39 @@ onMounted(() => { } } - // 分页样式优化 - .arco-pagination { - margin-top: 24px; - justify-content: center; - padding: 16px 0; + // 分页器容器样式 - 固定在表格下方 + .pagination-container { + position: sticky; + bottom: 0; + background: white; + padding: 16px 24px; + border-top: 1px solid var(--color-border); + display: flex; + justify-content: flex-end; + align-items: center; + z-index: 10; + box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06); - .arco-pagination-item { - border-radius: 6px; - margin: 0 4px; + .arco-pagination { + margin: 0; - &.arco-pagination-item-active { - background: var(--color-primary); - border-color: var(--color-primary); + .arco-pagination-item { + border-radius: 6px; + margin: 0 4px; + + &.arco-pagination-item-active { + background: var(--color-primary); + border-color: var(--color-primary); + } + } + + .arco-pagination-size-changer { + margin-left: 16px; + } + + .arco-pagination-jumper { + margin-left: 16px; } - } - - .arco-pagination-size-changer { - margin-left: 16px; - } - - .arco-pagination-jumper { - margin-left: 16px; } } diff --git a/src/views/system-resource/device-management/procurement/index.vue b/src/views/system-resource/device-management/procurement/index.vue index 2399f1e..b3f4431 100644 --- a/src/views/system-resource/device-management/procurement/index.vue +++ b/src/views/system-resource/device-management/procurement/index.vue @@ -116,9 +116,10 @@ :columns="columns" :data="tableData" :loading="loading" - :pagination="pagination" + :pagination="false" :row-selection="rowSelection" row-key="equipmentId" + :scroll="{ x: 'max-content', y: 400 }" @change="handleTableChange" > @@ -218,6 +219,23 @@ + + +
+ +
@@ -277,19 +295,7 @@ 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) - } + pageSizeOptions: [10, 20, 50, 100] }) // 弹窗控制 @@ -717,6 +723,21 @@ const handleTableChange = (pag: any) => { loadData(currentSearchParams.value) } +// 分页变化处理 +const handlePageChange = (page: number) => { + console.log('页码变化:', page) + pagination.current = page + loadData(currentSearchParams.value) +} + +// 每页条数变化处理 +const handlePageSizeChange = (pageSize: number) => { + console.log('每页条数变化:', pageSize) + pagination.pageSize = pageSize + pagination.current = 1 // 重置到第一页 + loadData(currentSearchParams.value) +} + // 新增 const handleAdd = () => { modalMode.value = 'add' @@ -1003,6 +1024,42 @@ onMounted(() => { color: var(--color-text-4); font-style: italic; } + + // 分页器容器样式 - 固定在表格下方 + .pagination-container { + position: sticky; + bottom: 0; + background: white; + padding: 16px 24px; + border-top: 1px solid var(--color-border); + display: flex; + justify-content: flex-end; + align-items: center; + z-index: 10; + box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06); + + .arco-pagination { + margin: 0; + + .arco-pagination-item { + border-radius: 6px; + margin: 0 4px; + + &.arco-pagination-item-active { + background: var(--color-primary); + border-color: var(--color-primary); + } + } + + .arco-pagination-size-changer { + margin-left: 16px; + } + + .arco-pagination-jumper { + margin-left: 16px; + } + } + } } // 响应式设计