fix(admin): 修复履约渠道分页并统一列表分页状态
This commit is contained in:
@@ -29,7 +29,7 @@ import {
|
||||
message,
|
||||
} from 'antd'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
import PercentTable from '@/components/common/PercentTable'
|
||||
import FinanceSubNav from '@/components/admin/FinanceSubNav'
|
||||
@@ -48,11 +48,7 @@ import {
|
||||
} from '@/services/admin'
|
||||
import { formatRedeemAmount } from '@/utils/redeem'
|
||||
import { formatDateTime } from '@/utils/date-time'
|
||||
import {
|
||||
ADMIN_DEFAULT_PAGE_SIZE,
|
||||
buildAdminLocalTablePagination,
|
||||
buildAdminTablePagination,
|
||||
} from '@/utils/admin-pagination'
|
||||
import { ADMIN_DEFAULT_PAGE_SIZE, buildAdminTablePagination } from '@/utils/admin-pagination'
|
||||
|
||||
const CHANNEL_OPTIONS = [
|
||||
{ value: 'work_order', label: '接单平台' },
|
||||
@@ -251,12 +247,20 @@ function RulesPanel() {
|
||||
const queryClient = useQueryClient()
|
||||
const [open, setOpen] = useState(false)
|
||||
const [selectedRuleIds, setSelectedRuleIds] = useState<number[]>([])
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(ADMIN_DEFAULT_PAGE_SIZE)
|
||||
const [form] = Form.useForm()
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ['fulfillment-rules'],
|
||||
queryFn: () => fetchChannelRules(),
|
||||
queryKey: ['fulfillment-rules', page, pageSize],
|
||||
queryFn: () => fetchChannelRules({ page, pageSize }),
|
||||
})
|
||||
const ruleCount = query.data?.data?.total || 0
|
||||
|
||||
useEffect(() => {
|
||||
const maxPage = Math.max(1, Math.ceil(ruleCount / pageSize))
|
||||
if (page > maxPage) setPage(maxPage)
|
||||
}, [page, pageSize, ruleCount])
|
||||
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: (values: Record<string, unknown>) => saveChannelRule(values as never),
|
||||
@@ -339,7 +343,7 @@ function RulesPanel() {
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={`统一渠道配置(${query.data?.data?.length ?? 0})`}
|
||||
title={`统一渠道配置(${ruleCount})`}
|
||||
extra={
|
||||
<Space>
|
||||
<Button
|
||||
@@ -368,13 +372,21 @@ function RulesPanel() {
|
||||
rowKey="id"
|
||||
size="small"
|
||||
loading={query.isFetching}
|
||||
dataSource={query.data?.data || []}
|
||||
dataSource={query.data?.data?.items || []}
|
||||
columns={columns}
|
||||
rowSelection={{
|
||||
selectedRowKeys: selectedRuleIds,
|
||||
onChange: (keys) => setSelectedRuleIds(keys.map(Number)),
|
||||
}}
|
||||
pagination={buildAdminLocalTablePagination()}
|
||||
pagination={buildAdminTablePagination({
|
||||
current: query.data?.data?.page || page,
|
||||
pageSize: query.data?.data?.pageSize || pageSize,
|
||||
total: ruleCount,
|
||||
onChange: (nextPage, nextPageSize) => {
|
||||
setPage(nextPageSize !== pageSize ? 1 : nextPage)
|
||||
setPageSize(nextPageSize)
|
||||
},
|
||||
})}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
|
||||
Reference in New Issue
Block a user