diff --git a/furniture-3d-system/src/app/api/operation-logs/route.ts b/furniture-3d-system/src/app/api/operation-logs/route.ts index 02aecfc4..03337939 100644 --- a/furniture-3d-system/src/app/api/operation-logs/route.ts +++ b/furniture-3d-system/src/app/api/operation-logs/route.ts @@ -34,7 +34,7 @@ export async function GET(request: NextRequest) { const params = request.nextUrl.searchParams const page = Math.max(1, Number.parseInt(params.get('page') ?? '1', 10) || 1) const pageSize = Math.min( - 100, + 200, Math.max(1, Number.parseInt(params.get('pageSize') ?? '50', 10) || 50), ) const result = await operationLogService.list({ diff --git a/furniture-3d-system/src/app/intake/operation-logs/ProductDevelopmentOperationLogClient.tsx b/furniture-3d-system/src/app/intake/operation-logs/ProductDevelopmentOperationLogClient.tsx index 668833bc..c6399ea2 100644 --- a/furniture-3d-system/src/app/intake/operation-logs/ProductDevelopmentOperationLogClient.tsx +++ b/furniture-3d-system/src/app/intake/operation-logs/ProductDevelopmentOperationLogClient.tsx @@ -92,7 +92,7 @@ export default function ProductDevelopmentOperationLogClient() { aria-labelledby="operations-tab" hidden={activeTab !== 'operations'} > - +
{ expect(screen.getAllByText('JUSHUITAN_VIRTUAL_INVENTORY_FAILED').length).toBeGreaterThan(0) expect(screen.getByText(/rate limited/)).toBeInTheDocument() + expect(screen.getByRole('navigation', { name: '操作日志分页' })).toBeInTheDocument() + expect(screen.getByRole('textbox', { name: '跳转页码' })).toHaveValue('1') + }) + + it('supports changing pages and page size from the floating pagination', async () => { + fetchMock.mockResolvedValue({ + ok: true, + json: async () => ({ + success: true, + data: [], + meta: { pagination: { page: 1, total: 101, totalPages: 3, hasMore: true } }, + }), + }) + + const actor = userEvent.setup() + render() + + await waitFor(() => expect(screen.getByText('共 101 条')).toBeInTheDocument()) + await actor.click(screen.getByRole('button', { name: '下一页' })) + await waitFor(() => expect(fetchMock).toHaveBeenLastCalledWith( + expect.stringContaining('page=2'), + expect.any(Object), + )) + + await actor.selectOptions(screen.getByRole('combobox', { name: '每页条数' }), '200') + await waitFor(() => expect(fetchMock).toHaveBeenLastCalledWith( + expect.stringContaining('pageSize=200'), + expect.any(Object), + )) }) }) diff --git a/furniture-3d-system/src/app/operation-logs/OperationLogClient.tsx b/furniture-3d-system/src/app/operation-logs/OperationLogClient.tsx index 6aacd71c..6d7197aa 100644 --- a/furniture-3d-system/src/app/operation-logs/OperationLogClient.tsx +++ b/furniture-3d-system/src/app/operation-logs/OperationLogClient.tsx @@ -3,14 +3,11 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import Link from 'next/link' import { - ChevronLeft, - ChevronRight, ExternalLink, FileWarning, RefreshCw, Search, ShieldAlert, - X, } from 'lucide-react' import { actionLabels, @@ -22,13 +19,23 @@ import { type OperationLog, type OperationStatus, } from './operationLogPresentation' +import { OperationLogPagination } from './OperationLogPagination' +import { OperationLogDetailDrawer } from './OperationLogDetailDrawer' -export default function OperationLogClient({ showHeader = true }: { showHeader?: boolean }) { +export default function OperationLogClient({ + showHeader = true, + embedded = false, +}: { + showHeader?: boolean + embedded?: boolean +}) { const [logs, setLogs] = useState([]) const [selectedLog, setSelectedLog] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [page, setPage] = useState(1) + const [pageInput, setPageInput] = useState('1') + const [pageSize, setPageSize] = useState(50) const [total, setTotal] = useState(0) const [totalPages, setTotalPages] = useState(1) const [problemOnly, setProblemOnly] = useState(true) @@ -39,7 +46,7 @@ export default function OperationLogClient({ showHeader = true }: { showHeader?: const [endDate, setEndDate] = useState('') const query = useMemo(() => { - const params = new URLSearchParams({ page: String(page), pageSize: '50' }) + const params = new URLSearchParams({ page: String(page), pageSize: String(pageSize) }) if (problemOnly) params.set('problemOnly', 'true') if (action) params.set('action', action) if (status && !problemOnly) params.set('status', status) @@ -47,7 +54,7 @@ export default function OperationLogClient({ showHeader = true }: { showHeader?: if (startDate) params.set('startDate', startDate) if (endDate) params.set('endDate', endDate) return params.toString() - }, [action, endDate, keyword, page, problemOnly, startDate, status]) + }, [action, endDate, keyword, page, pageSize, problemOnly, startDate, status]) const loadLogs = useCallback(async () => { setLoading(true) @@ -82,8 +89,16 @@ export default function OperationLogClient({ showHeader = true }: { showHeader?: callback() } + const commitPageInput = () => { + const nextPage = Math.min(Math.max(1, totalPages), Math.max(1, Number(pageInput) || 1)) + setPage(nextPage) + setPageInput(String(nextPage)) + } + + useEffect(() => setPageInput(String(page)), [page]) + return ( -
+
{showHeader ? (
@@ -105,8 +120,8 @@ export default function OperationLogClient({ showHeader = true }: { showHeader?:
) : null} -
-
+
+
) : ( -
+
- + @@ -227,85 +242,23 @@ export default function OperationLogClient({ showHeader = true }: { showHeader?: )} -
- 共 {total} 条 -
- - {page} / {Math.max(1, totalPages)} - -
-
- {selectedLog ? ( -
setSelectedLog(null)}> - -
- ) : null} + { setPageSize(value); setPage(1) }} + /> + + {selectedLog ? setSelectedLog(null)} /> : null} ) } diff --git a/furniture-3d-system/src/app/operation-logs/OperationLogDetailDrawer.tsx b/furniture-3d-system/src/app/operation-logs/OperationLogDetailDrawer.tsx new file mode 100644 index 00000000..a89f9bb0 --- /dev/null +++ b/furniture-3d-system/src/app/operation-logs/OperationLogDetailDrawer.tsx @@ -0,0 +1,67 @@ +import { X } from 'lucide-react' +import { + actionLabels, + formatTime, + OperationStatusBadge, + type OperationLog, +} from './operationLogPresentation' + +type Props = { + log: OperationLog + onClose: () => void +} + +export function OperationLogDetailDrawer({ log, onClose }: Props) { + return ( +
+ +
+ ) +} diff --git a/furniture-3d-system/src/app/operation-logs/OperationLogPagination.tsx b/furniture-3d-system/src/app/operation-logs/OperationLogPagination.tsx new file mode 100644 index 00000000..9b610038 --- /dev/null +++ b/furniture-3d-system/src/app/operation-logs/OperationLogPagination.tsx @@ -0,0 +1,76 @@ +import { ArrowLeft, ArrowRight } from 'lucide-react' + +type Props = { + page: number + pageInput: string + pageSize: number + total: number + totalPages: number + loading: boolean + onPageChange: (page: number) => void + onPageInputChange: (value: string) => void + onCommitPageInput: () => void + onPageSizeChange: (pageSize: number) => void +} + +export function OperationLogPagination(props: Props) { + const totalPageCount = Math.max(1, props.totalPages) + + return ( + + ) +} diff --git a/furniture-3d-system/src/server/services/operation-log.service.ts b/furniture-3d-system/src/server/services/operation-log.service.ts index dca1d4c8..67760867 100644 --- a/furniture-3d-system/src/server/services/operation-log.service.ts +++ b/furniture-3d-system/src/server/services/operation-log.service.ts @@ -48,7 +48,7 @@ class OperationLogService { async list(options: OperationLogListOptions = {}) { const page = Math.max(1, options.page ?? 1) - const pageSize = Math.min(100, Math.max(1, options.pageSize ?? 50)) + const pageSize = Math.min(200, Math.max(1, options.pageSize ?? 50)) const { items, total } = await operationLogRepository.findMany({ page, pageSize,
时间 结果