diff --git a/app/share/page.tsx b/app/share/page.tsx index 37e2b83..d7a454f 100644 --- a/app/share/page.tsx +++ b/app/share/page.tsx @@ -97,39 +97,61 @@ export default function SharePage(): JSX.Element { React.useEffect(() => { let mounted = true; - (async () => { + + // 并行发起所有请求,每个请求完成后立即处理 + const fetchRecords = async () => { try { const response = await fetchInviteRecords(); - if (mounted && response.successful) { + if (!mounted) return; // 早期返回检查 + if (response.successful) { setRecords(response.data.record_list); setPagination(response.data.pagination); } - } catch { - // 保持静默失败,页面仍可用 + } catch (error) { + if (mounted) { + console.warn('Failed to fetch invite records:', error); + } } - // 获取邀请统计信息 + }; + + const fetchStats = async () => { try { const res = await get('/api/user_fission/my_invite_stats'); + if (!mounted) return; // 早期返回检查 const stats = res?.data ?? {}; - if (mounted) { - if (typeof stats.total_invited === 'number') { - setInvitedCount(stats.total_invited); - } - if (typeof stats.total_invite_credits === 'number') { - setTotalInviteCredits(stats.total_invite_credits); - } + if (typeof stats.total_invited === 'number') { + setInvitedCount(stats.total_invited); + } + if (typeof stats.total_invite_credits === 'number') { + setTotalInviteCredits(stats.total_invite_credits); + } + } catch (error) { + if (mounted) { + console.warn('Failed to fetch invite stats:', error); } - } catch { - // 保持静默失败 } + }; + + const fetchInviteCode = async () => { try { const res = await get('/api/user_fission/my_invite_code'); + if (!mounted) return; // 早期返回检查 const code = res?.data?.invite_code ?? res?.data?.inviteCode ?? ''; - if (mounted && typeof code === 'string') setInviteCode(code); - } catch { - // 保持静默失败 + if (typeof code === 'string') { + setInviteCode(code); + } + } catch (error) { + if (mounted) { + console.warn('Failed to fetch invite code:', error); + } } - })(); + }; + + // 并行发起所有请求,每个请求完成后立即处理响应 + fetchRecords(); + fetchStats(); + fetchInviteCode(); + return () => { mounted = false; };