forked from 77media/video-flow
修复 邀请码接口加速
This commit is contained in:
parent
8daf561674
commit
5ff071f6c0
@ -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<any>('/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<any>('/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;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user