feat: migrate to Next.js 14 (App Router + Route Handlers)
- Replace Express server with Next.js Route Handlers (16 API routes) - Rewrite index.html SPA as React components (feed, post, admin, modals) - Move style.css to app/globals.css with dark/light themes intact - Add lib/db.js, lib/auth.js (JWT), lib/api.js (client API wrapper) - Server binds 0.0.0.0 by default; host/port configurable via config.js - Uploads served via /api/uploads route (rewrite keeps /uploads/ URLs) - Multi-stage dockerfile using standalone output
This commit is contained in:
1 parent
ef1318da66
commit
281460fb03
52 files changed
+2833
-3372
No files matched your search
@@ -0,0 +1,50 @@
|
||||
'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 (
|
||||
<div className="page-slide active">
|
||||
<div className="page-header" style={{ maxWidth: 400, margin: '0 auto', width: '100%' }}>
|
||||
<h2>设置</h2>
|
||||
</div>
|
||||
<div style={{ maxWidth: 400, margin: '0 auto', width: '100%' }}>
|
||||
<label style={{ fontWeight: 600, fontSize: 14 }}>用户名</label>
|
||||
<input
|
||||
type="text"
|
||||
style={{ width: '100%', padding: '8px 12px', border: '1px solid #e2e8f0', borderRadius: 4, margin: '6px 0 12px' }}
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
/>
|
||||
<label style={{ fontWeight: 600, fontSize: 14 }}>个人简介</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
style={{ width: '100%', padding: '8px 12px', border: '1px solid #e2e8f0', borderRadius: 4, margin: '6px 0 12px' }}
|
||||
value={bio}
|
||||
onChange={(e) => setBio(e.target.value)}
|
||||
/>
|
||||
<button className="btn-primary" onClick={handleSave}>保存设置</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user