update pay ui

This commit is contained in:
2025-12-02 17:55:01 +08:00
parent f60c6a8ae9
commit 2b3700369f

View File

@@ -74,9 +74,8 @@ export default function CenterDashboard() {
const navigate = useNavigate(); const navigate = useNavigate();
const toast = useToast(); const toast = useToast();
// ⚡ 提取 userId 为独立变量,避免 user 对象引用变化导致无限循环 // ⚡ 提取 userId 为独立变量
const userId = user?.id; const userId = user?.id;
const prevUserIdRef = React.useRef(userId);
// 🎯 初始化Dashboard埋点Hook // 🎯 初始化Dashboard埋点Hook
const dashboardEvents = useDashboardEvents({ const dashboardEvents = useDashboardEvents({
@@ -241,32 +240,16 @@ export default function CenterDashboard() {
return 'green'; return 'green';
}; };
// 🔧 使用 ref 跟踪是否已经加载过数据(首次加载标记)
const hasLoadedRef = React.useRef(false);
useEffect(() => { useEffect(() => {
console.log('[Center] 🔥 useEffect 触发', { const isOnCenterPage = location.pathname.includes('/home/center');
userId,
prevUserId: prevUserIdRef.current,
pathname: location.pathname,
hasUser: !!user,
time: new Date().toISOString()
});
const userIdChanged = prevUserIdRef.current !== userId; // 首次进入页面且有用户时加载数据
if (user && isOnCenterPage && !hasLoadedRef.current) {
if (userIdChanged) { console.log('[Center] 🚀 首次加载数据');
console.log('[Center] ⚠️ userId 发生变化:', prevUserIdRef.current, '->', userId); hasLoadedRef.current = true;
prevUserIdRef.current = userId;
}
// 只在 userId 真正变化或路径变化时加载数据
const shouldLoad = (userIdChanged || !prevUserIdRef.current) && user && location.pathname.includes('/home/center');
console.log('[Center] 🤔 是否应该加载数据:', shouldLoad, {
userIdChanged,
prevUserIdRef: prevUserIdRef.current,
hasUser: !!user,
pathMatch: location.pathname.includes('/home/center')
});
if (shouldLoad) {
loadData(); loadData();
} }
@@ -278,7 +261,14 @@ export default function CenterDashboard() {
}; };
document.addEventListener('visibilitychange', onVis); document.addEventListener('visibilitychange', onVis);
return () => document.removeEventListener('visibilitychange', onVis); return () => document.removeEventListener('visibilitychange', onVis);
}, [userId, location.pathname, loadData, user]); // ⚡ 使用 userId防重复通过 ref 判断 }, [userId, location.pathname, loadData, user]);
// 当用户登出再登入userId 变化)时,重置加载标记
useEffect(() => {
if (!user) {
hasLoadedRef.current = false;
}
}, [user]);
// 定时刷新实时行情(每分钟一次) // 定时刷新实时行情(每分钟一次)
useEffect(() => { useEffect(() => {