diff --git a/frontend/src/pages/approval/list.tsx b/frontend/src/pages/approval/list.tsx index 651b05d..61f5f6c 100644 --- a/frontend/src/pages/approval/list.tsx +++ b/frontend/src/pages/approval/list.tsx @@ -52,40 +52,25 @@ export default function ApprovalList() { const [hasMore, setHasMore] = useState(true) const [page, setPage] = useState(1) - // 加载数据 - const loadData = async (pageNum: number = 1, isRefresh: boolean = false) => { + // 加载数据 - 接收 tab 参数避免使用旧的 activeTab + const loadData = async (pageNum: number = 1, isRefresh: boolean = false, tab?: string) => { if (loading) return - console.log('🔍 Loading approval list:', { activeTab, pageNum, isRefresh }) + // 使用传入的 tab 参数,如果没有则使用当前 activeTab + const currentTab = tab || activeTab + console.log('🔍 Loading approval list:', { currentTab, activeTab, tab, pageNum, isRefresh }) setLoading(true) try { const result = await approvalApi.getList({ - type: activeTab, + type: currentTab, page: pageNum, page_size: 20, }) - console.log('📦 API response:', { type: activeTab, result }) + console.log('📦 API response:', { type: currentTab, count: result?.list?.length, result }) - const newList = result.list || [] - - if (isRefresh || pageNum === 1) { - setList(newList) - } else { - setList([...list, ...newList]) - } - - setHasMore(newList.length >= 20) - setPage(pageNum) - } catch (error: any) { - console.error('Failed to load approvals:', error) - } finally { - setLoading(false) - } - } - - const newList = result.list || [] + const newList = result?.list || [] if (isRefresh || pageNum === 1) { setList(newList) @@ -104,11 +89,13 @@ export default function ApprovalList() { // 切换标签 const handleTabChange = (key: string) => { + console.log('🔄 Tab changing from', activeTab, 'to', key) setActiveTab(key as 'my' | 'pending' | 'approved') setList([]) setHasMore(true) setPage(1) - loadData(1, true) + // 直接传入新的 tab 值,避免使用旧的 activeTab + loadData(1, true, key) } // 刷新