修复 邀请码接口加速

This commit is contained in:
moux1024 2025-09-23 15:05:08 +08:00
parent 8daf561674
commit 5ff071f6c0

View File

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