'use client'; // 个人设置页 import { useState } from 'react'; import { API } from '@/lib/api'; import { useApp } from './AppProvider'; export default function SettingsPage() { const { currentUser, setCurrentUser } = useApp(); const [username, setUsername] = useState(currentUser?.username || ''); const [bio, setBio] = useState(currentUser?.bio || ''); const handleSave = async () => { if (!currentUser) { alert('请先登录'); return; } if (!username.trim()) { alert('用户名不能为空'); return; } try { const data = await API.updateProfile(currentUser.id, username.trim(), bio.trim()); if (data.error) throw new Error(data.error); setCurrentUser({ ...currentUser, username: username.trim(), bio: bio.trim() }); alert('保存成功!'); } catch (err) { alert('保存失败:' + err.message); } }; return (

设置

setUsername(e.target.value)} />