This commit is contained in:
孙佳艺
2026-06-26 17:25:11 +08:00
parent 3c3797a734
commit f2dbfbf62f
18 changed files with 1051 additions and 123 deletions
@@ -24,18 +24,30 @@ const NotificationPopup: React.FC = () => {
const [notifications, setNotifications] = useState<Notification[]>([]);
const [currentIndex, setCurrentIndex] = useState(0);
const refreshUser = useAuthStore((state) => state.refreshUser);
const setUserCredits = useAuthStore((state) => state.setUserCredits);
const fetchNotifications = useCallback(async () => {
try {
const result = await getNotifications(1, 20, false);
// 接口返回结构:{ credits: { balance: 4317.23 }, items: [...], total: N }
const data = result.items || [];
// 同步积分:result.credits.balance 与当前 user.credits 不一致时,直接替换
const newBalance = result?.credits?.balance;
if (typeof newBalance === 'number') {
const currentUser = useAuthStore.getState().user;
if (currentUser && currentUser.credits !== newBalance) {
setUserCredits(newBalance);
}
}
setNotifications(data);
if (data.length > 0 && !visible) {
setVisible(true);
setCurrentIndex(0);
}
} catch { /* ignore */ }
}, [visible]);
}, [visible, setUserCredits]);
useEffect(() => {
fetchNotifications();