'use client'; // 个人设置页:侧边栏布局 + 上下滑动平滑切换 // - 三个面板纵向排列在滚动容器里,scroll-snap 每次滑动对齐一个面板 // - 点侧边栏导航 → 平滑滚动到对应面板;滚动结束 → 自动更新导航高亮 import { useState, useRef, useCallback } from 'react'; import { Icon } from './Icons'; import SettingsProfile from './SettingsProfile'; import AccountSecurity from './AccountSecurity'; import RecoveryCodes from './RecoveryCodes'; const NAV = [ { key: 'profile', label: '个人资料', icon: 'user' }, { key: 'security', label: '安全设置', icon: 'shieldAlert' }, { key: 'recovery', label: '恢复码', icon: 'lock' }, ]; export default function SettingsPage() { const [tab, setTab] = useState('profile'); const scrollRef = useRef(null); const scrollTicking = useRef(false); // 滚动结束(或对齐后)更新高亮 const handleScroll = useCallback(() => { const el = scrollRef.current; if (!el || scrollTicking.current) return; scrollTicking.current = true; requestAnimationFrame(() => { scrollTicking.current = false; const idx = Math.round(el.scrollTop / el.clientHeight); const key = NAV[Math.min(Math.max(idx, 0), NAV.length - 1)]?.key; if (key) setTab(key); }); }, []); // 点击导航 → 平滑滚动到对应面板 const goTo = (key, e) => { if (e) e.preventDefault(); setTab(key); const el = scrollRef.current; if (!el) return; const idx = NAV.findIndex((n) => n.key === key); el.scrollTo({ top: idx * el.clientHeight, behavior: 'smooth' }); }; return (

设置

); }