首页
This commit is contained in:
@@ -413,14 +413,19 @@ const AppLayout: React.FC = () => {
|
||||
flexShrink: 0,
|
||||
background: 'linear-gradient(135deg, rgba(99, 102, 241, 0.06) 0%, rgba(139, 92, 246, 0.04) 100%)',
|
||||
}}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 14, cursor: 'pointer' }}
|
||||
onClick={() => {
|
||||
navigate('/home');
|
||||
}}>
|
||||
<div style={{
|
||||
width: 42, height: 42, borderRadius: 14, flexShrink: 0,
|
||||
background: 'linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
boxShadow: '0 4px 16px rgba(99, 102, 241, 0.35)',
|
||||
overflow: 'hidden',
|
||||
}}>
|
||||
}}
|
||||
|
||||
>
|
||||
{siteLogo ? (
|
||||
<img src={siteLogo} alt="logo" style={{ width: 28, height: 28, objectFit: 'contain' }} />
|
||||
) : (
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user