This commit is contained in:
何德超 2025-08-12 17:59:35 +08:00
commit 9d6086726d
4 changed files with 271 additions and 66 deletions

View File

@ -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
}

View File

@ -249,6 +249,19 @@ const pagination = reactive<any>({
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 - 加载完成')
}
}

View File

@ -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"
>
<template #equipmentType="{ record }">
<a-tag :color="getEquipmentTypeColor(record.equipmentType)">
@ -247,13 +251,44 @@ const tableData = ref<EquipmentResp[]>([])
const loading = ref(false)
//
const pagination = reactive<any>({
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showPageSize: true,
showTotal: true,
showJumper: true,
showTotal: (total: number) => `${total} 条记录`,
showPageSize: true,
pageSizeOptions: [10, 20, 50, 100],
//
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)
}
})
//
@ -568,46 +603,101 @@ const transformBackendData = (data: any[]) => {
const loadData = async (searchParams?: EquipmentPageQuery) => {
loading.value = true
try {
//
const params = {
pageSize: pagination.pageSize,
page: pagination.current,
pageNum: pagination.current, // - 使pageNum
pageSize: pagination.pageSize, //
...(searchParams || {}), //
}
console.log('🚀 发送分页请求参数:', params)
console.log('📊 当前分页状态:', {
current: pagination.current,
pageSize: pagination.pageSize,
total: pagination.total
})
const res = await EquipmentAPI.pageEquipment(params)
console.log('📡 后端响应数据:', res)
//
if (res.success || res.status === 200 || res.code === 200) {
if (res.code === 200 || res.success || res.status === 200) {
//
let dataList: any[] = []
let totalCount = 0
//
if (Array.isArray(res.data)) {
dataList = res.data
} else if (res.data && Array.isArray((res.data as any).records)) {
dataList = (res.data as any).records
} else if (res.data && Array.isArray((res.data as any).list)) {
dataList = (res.data as any).list
} else if (res.data && Array.isArray((res.data as any).rows)) {
dataList = (res.data as any).rows
console.log('🔍 开始解析响应数据,响应结构:', res)
// - 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, '当前页数据:', dataList.length)
} else if ((res as any).data && Array.isArray((res as any).data)) {
dataList = (res as any).data
totalCount = (res as any).total || dataList.length || 0
console.log('✅ 从 data 字段获取数据,总数:', totalCount, '当前页数据:', dataList.length)
} else if ((res as any).data && (res as any).data.rows && Array.isArray((res as any).data.rows)) {
// res.data.rows res.data.total
dataList = (res as any).data.rows
totalCount = (res as any).data.total || 0
console.log('✅ 从嵌套 data.rows 字段获取数据,总数:', totalCount, '当前页数据:', dataList.length)
} else if ((res as any).data && Array.isArray(((res as any).data as any).records)) {
dataList = ((res as any).data as any).records
totalCount = (((res as any).data as any).total) || dataList.length || 0
console.log('✅ 从 records 字段获取数据,总数:', totalCount, '当前页数据:', dataList.length)
} else if ((res as any).data && Array.isArray(((res as any).data as any).list)) {
dataList = ((res as any).data as any).list
totalCount = (((res as any).data as any).total) || dataList.length || 0
console.log('✅ 从 list 字段获取数据,总数:', totalCount, '当前页数据:', dataList.length)
} else {
console.warn('⚠️ 未找到有效的数据字段,响应结构:', res)
dataList = []
totalCount = 0
}
// total使
if (dataList.length > 0 && totalCount === 0) {
totalCount = dataList.length
console.log('⚠️ 后端未返回total使用当前页数据长度作为总数:', totalCount)
}
// total0
if (dataList.length > 0 && totalCount === 0) {
console.warn('🚨 后端分页逻辑问题返回了数据但total为0使用当前页数据长度作为总数')
totalCount = dataList.length
}
if (dataList.length > 0) {
const transformedData = transformBackendData(dataList)
tableData.value = transformedData
console.log('✅ 数据转换完成,设置到表格:', transformedData.length, '条')
} else {
tableData.value = []
console.log(' 没有数据,清空表格')
}
//
pagination.total = (res.data as any)?.total || (res as any).total || dataList.length || 0
// - 使
pagination.total = totalCount
console.log('📊 设置分页总数:', totalCount)
console.log('📊 分页组件状态:', {
current: pagination.current,
pageSize: pagination.pageSize,
total: pagination.total
})
} else {
message.error(res.msg || '加载数据失败')
console.error('❌ 请求失败,响应:', res)
message.error((res as any).msg || (res as any).message || '加载数据失败')
tableData.value = []
pagination.total = 0
}
} catch (error: any) {
console.error('加载数据失败:', error)
console.error('加载数据失败:', error)
message.error(error?.message || '加载数据失败')
tableData.value = []
pagination.total = 0
} finally {
loading.value = false
}
@ -631,11 +721,42 @@ const handleReset = () => {
//
const handleTableChange = (pag: any) => {
pagination.current = pag.current || 1
pagination.pageSize = pag.pageSize || 10
console.log('表格变化,分页参数:', pag) //
//
if (pag.current !== undefined) {
pagination.current = pag.current
}
if (pag.pageSize !== undefined) {
pagination.pageSize = pag.pageSize
}
console.log('更新分页配置:', {
current: pagination.current,
pageSize: pagination.pageSize
})
//
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'
@ -920,7 +1041,8 @@ onMounted(() => {
.table-card {
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
overflow: hidden;
overflow: visible; // visible
min-height: 600px; //
.card-title {
display: flex;
@ -943,6 +1065,11 @@ onMounted(() => {
}
.arco-table {
//
.arco-table-container {
overflow: visible;
}
.arco-table-th {
background: var(--color-fill-2);
font-weight: 600;
@ -956,6 +1083,12 @@ onMounted(() => {
.arco-table-tr:hover {
background: var(--color-fill-1);
}
//
.arco-table-body {
overflow-y: auto;
max-height: 500px; //
}
}
}
@ -1003,6 +1136,7 @@ onMounted(() => {
.arco-pagination {
margin-top: 24px;
justify-content: center;
padding: 16px 0;
.arco-pagination-item {
border-radius: 6px;
@ -1013,6 +1147,14 @@ onMounted(() => {
border-color: var(--color-primary);
}
}
.arco-pagination-size-changer {
margin-left: 16px;
}
.arco-pagination-jumper {
margin-left: 16px;
}
}
//

View File

@ -277,6 +277,19 @@ const pagination = reactive<any>({
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)
}
})
//
@ -592,31 +605,52 @@ const loadData = async (searchParams?: EquipmentListReq) => {
loading.value = true
try {
//
const params: EquipmentListReq = {
pageSize: pagination.pageSize,
page: pagination.current,
pageNum: pagination.current, //
pageSize: pagination.pageSize, //
minPrice: undefined,
maxPrice: undefined,
...(searchParams || {}),
}
console.log('📊 loadData - 构建的完整请求参数:', params)
console.log('📊 当前分页状态:', {
current: pagination.current,
pageSize: pagination.pageSize,
total: pagination.total
})
const res = await equipmentProcurementApi.page(params)
console.log('API响应:', res)
if (res.success || res.status === 200 || res.code === 200) {
if (res.code === 200 || res.success || res.status === 200) {
let dataList: any[] = []
let totalCount = 0
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, '当前页数据:', dataList.length)
} else if (Array.isArray(res.data)) {
dataList = res.data
totalCount = (res as any).total || dataList.length || 0
console.log('✅ 从 data 字段获取数据,总数:', totalCount, '当前页数据:', dataList.length)
} else if (res.data && Array.isArray((res.data as any).records)) {
dataList = (res.data as any).records
totalCount = (res.data as any).total || dataList.length || 0
console.log('✅ 从 records 字段获取数据,总数:', totalCount, '当前页数据:', dataList.length)
} else if (res.data && Array.isArray((res.data as any).list)) {
dataList = (res.data as any).list
} else if (res.data && Array.isArray((res.data as any).rows)) {
dataList = (res.data as any).rows
totalCount = (res.data as any).total || dataList.length || 0
console.log('✅ 从 list 字段获取数据,总数:', totalCount, '当前页数据:', dataList.length)
} else {
console.warn('⚠️ 未找到有效的数据字段,响应结构:', res)
dataList = []
totalCount = 0
}
console.log('处理后的数据列表:', dataList)
@ -633,14 +667,25 @@ const loadData = async (searchParams?: EquipmentListReq) => {
tableData.value = []
}
pagination.total = (res.data as any)?.total || (res as any).total || dataList.length || 0
console.log('总数:', pagination.total)
// - 使
pagination.total = totalCount
console.log('📊 总数:', totalCount)
console.log('📊 分页组件状态:', {
current: pagination.current,
pageSize: pagination.pageSize,
total: pagination.total
})
} else {
message.error(res.msg || '加载数据失败')
console.error('❌ 请求失败,响应:', res)
message.error(res.msg || (res as any).message || '加载数据失败')
tableData.value = []
pagination.total = 0
}
} catch (error: any) {
console.error('加载数据失败:', error)
console.error('加载数据失败:', error)
message.error(error?.message || '加载数据失败')
tableData.value = []
pagination.total = 0
} finally {
loading.value = false
}