修改架构,移动端优先。

save
This commit is contained in:
cheney
2026-08-03 18:05:50 +08:00
committed by Cheney
parent 1c07b417ce
commit 08b3655a38
71 changed files with 2524 additions and 290 deletions
+40
View File
@@ -0,0 +1,40 @@
import { Routes, Route, Navigate, useLocation } from 'react-router-dom'
import MobileShell from './layouts/MobileShell.jsx'
import LoginPage from './pages/LoginPage.jsx'
import HomePage from './pages/HomePage.jsx'
import MacroPage from './pages/MacroPage.jsx'
import MonitorPage from './pages/MonitorPage.jsx'
import MePage from './pages/MePage.jsx'
import { useAuth } from './auth/AuthContext.jsx'
// 已登录访问 /login 自动回首页
function RedirectIfAuthed({ children }) {
const { user, loading } = useAuth()
if (loading) return null
if (user) return <Navigate to="/" replace />
return children
}
// 未登录访问受保护页面 → 跳 /login
function RequireAuth({ children }) {
const { user, loading } = useAuth()
const location = useLocation()
if (loading) return <div className="page-loading">加载中...</div>
if (!user) return <Navigate to="/login" state={{ from: location }} replace />
return children
}
export default function App() {
return (
<Routes>
<Route path="/login" element={<RedirectIfAuthed><LoginPage /></RedirectIfAuthed>} />
<Route element={<RequireAuth><MobileShell /></RequireAuth>}>
<Route path="/" element={<HomePage />} />
<Route path="/macro/*" element={<MacroPage />} />
<Route path="/monitor" element={<MonitorPage />} />
<Route path="/me" element={<MePage />} />
</Route>
<Route path="*" element={<Navigate to="/" replace />} />
</Routes>
)
}
+43
View File
@@ -0,0 +1,43 @@
// API 调用封装: 自动带 JWT、401 自动清 token、抛统一错误
const TOKEN_KEY = 'iboard_token'
const REMEMBER_KEY = 'iboard_remember'
export function getToken() {
return localStorage.getItem(TOKEN_KEY) || ''
}
export function setToken(token) {
if (token) localStorage.setItem(TOKEN_KEY, token)
else localStorage.removeItem(TOKEN_KEY)
}
export function getRememberFlag() {
return localStorage.getItem(REMEMBER_KEY) === '1'
}
export function setRememberFlag(v) {
if (v) localStorage.setItem(REMEMBER_KEY, '1')
else localStorage.removeItem(REMEMBER_KEY)
}
export async function api(path, { method = 'GET', body, headers = {} } = {}) {
const token = getToken()
const res = await fetch('/api' + path, {
method,
headers: {
'Content-Type': 'application/json',
...(token ? { Authorization: 'Bearer ' + token } : {}),
...headers,
},
body: body ? JSON.stringify(body) : undefined,
})
if (res.status === 401) {
setToken('')
const data = await res.json().catch(() => ({}))
if (!path.startsWith('/auth/')) window.location.assign('/login')
throw new Error(data.error || '未登录')
}
const data = await res.json().catch(() => ({}))
if (!res.ok) throw new Error(data.error || '请求失败 (' + res.status + ')')
return data
}
+60
View File
@@ -0,0 +1,60 @@
import { createContext, useContext, useEffect, useState } from 'react'
import { api, getToken, setToken, setRememberFlag } from '../api/client.js'
const AuthContext = createContext(null)
export function AuthProvider({ children }) {
const [user, setUser] = useState(null)
const [loading, setLoading] = useState(true)
// 启动时: 有 token 就尝试拉 /me, 失败则清空
useEffect(() => {
let cancelled = false
async function bootstrap() {
if (!getToken()) {
setLoading(false)
return
}
try {
const data = await api('/auth/me')
if (!cancelled) setUser(data.user)
} catch {
if (!cancelled) {
setToken('')
setUser(null)
}
} finally {
if (!cancelled) setLoading(false)
}
}
bootstrap()
return () => { cancelled = true }
}, [])
async function login(email, password, remember) {
const data = await api('/auth/login', { method: 'POST', body: { email, password, remember: !!remember } })
setToken(data.token)
setRememberFlag(!!remember)
setUser(data.user)
return data.user
}
async function logout() {
try { await api('/auth/logout', { method: 'POST' }) } catch { /* ignore */ }
setToken('')
setRememberFlag(false)
setUser(null)
}
return (
<AuthContext.Provider value={{ user, loading, login, logout }}>
{children}
</AuthContext.Provider>
)
}
export function useAuth() {
const ctx = useContext(AuthContext)
if (!ctx) throw new Error('useAuth must be used inside AuthProvider')
return ctx
}
+26
View File
@@ -0,0 +1,26 @@
import { NavLink } from 'react-router-dom'
const TABS = [
{ to: '/', label: '首页', icon: '⌂' },
{ to: '/macro', label: '宏观', icon: '◫' },
{ to: '/monitor', label: '监控', icon: '◉' },
{ to: '/me', label: '我', icon: '☺' },
]
export default function BottomNav() {
return (
<nav className="bottom-nav" aria-label="主导航">
{TABS.map((t) => (
<NavLink
key={t.to}
to={t.to}
end={t.to === '/'}
className={({ isActive }) => 'bottom-nav-item' + (isActive ? ' active' : '')}
>
<span className="icon" aria-hidden="true">{t.icon}</span>
<span>{t.label}</span>
</NavLink>
))}
</nav>
)
}
+86
View File
@@ -0,0 +1,86 @@
import { useRef, useState, useEffect } from 'react'
// 滑屏容器 + 顶栏 tabs
// props:
// tabs: [{ key, label, render }]
// active: 当前激活 key
// onChange(key): 切换回调 (用户滑动或点击 tab)
export default function SwipeTabs({ tabs, active, onChange }) {
const idx = Math.max(0, tabs.findIndex((t) => t.key === active))
const [dragging, setDragging] = useState(false)
const [offsetPx, setOffsetPx] = useState(0)
const [animOff, setAnimOff] = useState(false)
const startX = useRef(0)
const containerRef = useRef(null)
// idx 变化时关闭拖动动画 (避免快速切换时滑动残影)
useEffect(() => { setOffsetPx(0); setAnimOff(false) }, [idx])
function onTouchStart(e) {
startX.current = e.touches[0].clientX
setDragging(true)
setAnimOff(true)
}
function onTouchMove(e) {
if (!dragging) return
const dx = e.touches[0].clientX - startX.current
const w = containerRef.current?.offsetWidth || window.innerWidth
// 限制左右溢出 (超过边界阻力增大)
const limited = Math.max(Math.min(dx, w * 0.4), -w * 0.4)
setOffsetPx(limited)
}
function onTouchEnd() {
if (!dragging) return
setDragging(false)
setAnimOff(false)
const w = containerRef.current?.offsetWidth || window.innerWidth
const dx = offsetPx
let next = idx
if (dx < -w * 0.18 && idx < tabs.length - 1) next = idx + 1
else if (dx > w * 0.18 && idx > 0) next = idx - 1
setOffsetPx(0)
if (next !== idx) onChange(tabs[next].key)
}
// 用 -33.33% × idx 作为基础位移, 再叠加拖动偏移
const basePct = idx * 33.3333
const dragPct = containerRef.current
? (offsetPx / containerRef.current.offsetWidth) * 100
: 0
const translate = `calc(-${basePct}% + ${dragPct}%)`
return (
<>
<div className="top-tabs" role="tablist">
{tabs.map((t) => (
<button
key={t.key}
role="tab"
aria-selected={t.key === active}
className={'top-tabs-item' + (t.key === active ? ' active' : '')}
onClick={() => onChange(t.key)}
>
{t.label}
</button>
))}
</div>
<div
ref={containerRef}
className="swipe-container"
onTouchStart={onTouchStart}
onTouchMove={onTouchMove}
onTouchEnd={onTouchEnd}
onTouchCancel={onTouchEnd}
>
<div
className={'swipe-track' + (animOff || dragging ? ' no-anim' : '')}
style={{ '--swipe-offset': translate, transform: `translateX(${translate})` }}
>
{tabs.map((t) => (
<div key={t.key} className="swipe-pane">{t.render()}</div>
))}
</div>
</div>
</>
)
}
+14
View File
@@ -0,0 +1,14 @@
import { Outlet } from 'react-router-dom'
import BottomNav from '../components/BottomNav.jsx'
// 移动端应用外壳: 底栏 + 滚动主区
export default function MobileShell() {
return (
<div className="app-root">
<main className="app-main">
<Outlet />
</main>
<BottomNav />
</div>
)
}
+16
View File
@@ -0,0 +1,16 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { BrowserRouter } from 'react-router-dom'
import App from './App.jsx'
import { AuthProvider } from './auth/AuthContext.jsx'
import './styles/globals.css'
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<BrowserRouter>
<AuthProvider>
<App />
</AuthProvider>
</BrowserRouter>
</React.StrictMode>,
)
+10
View File
@@ -0,0 +1,10 @@
// 首页: 暂留占位, 后续接入监控告警 / 个性化推荐
export default function HomePage() {
return (
<div className="placeholder-page">
<div className="icon">⌂</div>
<div>首页</div>
<div style={{ fontSize: 12, opacity: .7 }}>后续接入: 监控告警 / 个性化推荐 / 收藏的指标</div>
</div>
)
}
+61
View File
@@ -0,0 +1,61 @@
import { useState } from 'react'
import { useNavigate, useLocation, Navigate } from 'react-router-dom'
import { useAuth } from '../auth/AuthContext.jsx'
export default function LoginPage() {
const { user, login } = useAuth()
const navigate = useNavigate()
const location = useLocation()
const from = location.state?.from?.pathname || '/'
const [email, setEmail] = useState('admin@iboard.local')
const [password, setPassword] = useState('admin123')
const [remember, setRemember] = useState(true)
const [busy, setBusy] = useState(false)
const [err, setErr] = useState('')
if (user) return <Navigate to={from} replace />
async function onSubmit(e) {
e.preventDefault()
setErr('')
setBusy(true)
try {
await login(email.trim(), password, remember)
navigate(from, { replace: true })
} catch (e) {
setErr(e.message)
} finally {
setBusy(false)
}
}
return (
<div className="login-page">
<form className="login-card" onSubmit={onSubmit}>
<div className="login-title">iBoard</div>
<div className="login-subtitle">登录后继续</div>
{err && <div className="login-error">{err}</div>}
<div className="login-field">
<label htmlFor="email">邮箱</label>
<input id="email" type="email" autoComplete="username" required value={email} onChange={(e) => setEmail(e.target.value)} />
</div>
<div className="login-field">
<label htmlFor="password">密码</label>
<input id="password" type="password" autoComplete="current-password" required value={password} onChange={(e) => setPassword(e.target.value)} />
</div>
<label className="login-options">
<input type="checkbox" checked={remember} onChange={(e) => setRemember(e.target.checked)} />
<span>记住登录 (7 天免登录)</span>
</label>
<button className="login-btn" type="submit" disabled={busy}>
{busy ? '登录中...' : '登录'}
</button>
<div className="login-hint">
默认账号: admin@iboard.local<br />
首次登录后请尽快修改密码
</div>
</form>
</div>
)
}
+62
View File
@@ -0,0 +1,62 @@
import { useState } from 'react'
import { useNavigate, useLocation, Routes, Route, Navigate } from 'react-router-dom'
import SwipeTabs from '../components/SwipeTabs.jsx'
import DataView from './macro/DataView.jsx'
import StrategyView from './macro/StrategyView.jsx'
import ArticlesView from './macro/ArticlesView.jsx'
import ArticleDetail from './macro/ArticleDetail.jsx'
// 宏观: 顶栏 3 tab (经济文章 / 经济数据 / 策略研究), 默认 经济数据
// /macro → 重定向到 /macro/data
// /macro/data → 经济数据 (默认)
// /macro/strategy→ 策略研究
// /macro/articles→ 经济文章
// /macro/articles/:slug → 文章详情
const TABS = [
{ key: 'data', label: '经济数据', path: '/macro/data' },
{ key: 'strategy', label: '策略研究', path: '/macro/strategy' },
{ key: 'articles', label: '经济文章', path: '/macro/articles' },
]
function activeFromPath(pathname) {
if (pathname.startsWith('/macro/articles')) return 'articles'
if (pathname.startsWith('/macro/strategy')) return 'strategy'
return 'data'
}
export default function MacroPage() {
const location = useLocation()
const navigate = useNavigate()
const active = activeFromPath(location.pathname)
const tabs = TABS.map((t) => ({
key: t.key,
label: t.label,
render: () => {
if (t.key === 'data') return <DataView />
if (t.key === 'strategy') return <StrategyView />
if (t.key === 'articles') return <ArticlesView />
return null
},
}))
function onChange(key) {
const next = TABS.find((t) => t.key === key)
if (next) navigate(next.path)
}
// 详情页 /macro/articles/:slug 单独走 React Router 渲染, 不参与滑屏
if (location.pathname.match(/^\/macro\/articles\/[^/]+$/)) {
return (
<Routes>
<Route path="articles/:slug" element={<ArticleDetail />} />
</Routes>
)
}
return (
<div>
<SwipeTabs tabs={tabs} active={active} onChange={onChange} />
</div>
)
}
+36
View File
@@ -0,0 +1,36 @@
import { useNavigate } from 'react-router-dom'
import { useAuth } from '../auth/AuthContext.jsx'
export default function MePage() {
const { user, logout } = useAuth()
const navigate = useNavigate()
async function onLogout() {
if (!confirm('确定退出登录?')) return
await logout()
navigate('/login', { replace: true })
}
return (
<div>
<div className="me-header">
<div className="me-name">{user?.name || '用户'}</div>
<div className="me-email">{user?.email}</div>
</div>
<div className="me-list">
<div className="list-item">
<span className="label">用户 ID</span>
<span className="value">#{user?.id}</span>
</div>
<div className="list-item">
<span className="label">注册时间</span>
<span className="value">{user?.createdAt ? new Date(user.createdAt).toLocaleDateString() : '-'}</span>
</div>
<div className="list-item" onClick={onLogout} role="button" style={{ cursor: 'pointer' }}>
<span className="label danger">退出登录</span>
<span className="value">›</span>
</div>
</div>
</div>
)
}
+10
View File
@@ -0,0 +1,10 @@
// 监控: 暂留占位
export default function MonitorPage() {
return (
<div className="placeholder-page">
<div className="icon">◉</div>
<div>监控</div>
<div style={{ fontSize: 12, opacity: .7 }}>后续接入: 指标阈值告警 / 时序趋势</div>
</div>
)
}
+35
View File
@@ -0,0 +1,35 @@
import { useEffect, useState } from 'react'
import { useParams, useNavigate, Link } from 'react-router-dom'
import { api } from '../../api/client.js'
// 文章详情: /macro/articles/:slug
export default function ArticleDetail() {
const { slug } = useParams()
const navigate = useNavigate()
const [article, setArticle] = useState(null)
const [err, setErr] = useState('')
const [loading, setLoading] = useState(true)
useEffect(() => {
let cancelled = false
setLoading(true)
api('/articles/' + encodeURIComponent(slug))
.then((data) => { if (!cancelled) setArticle(data.article) })
.catch((e) => !cancelled && setErr(e.message))
.finally(() => !cancelled && setLoading(false))
return () => { cancelled = true }
}, [slug])
if (loading) return <div className="loading">加载中...</div>
if (err) return <div className="error-banner">{err}</div>
if (!article) return <div className="empty">文章不存在</div>
return (
<div className="article-detail">
<div className="article-back" onClick={() => navigate(-1)} role="button">‹ 返回</div>
<h1>{article.title}</h1>
<div className="meta">{article.date}</div>
<div className="article-content" dangerouslySetInnerHTML={{ __html: article.contentHtml }} />
</div>
)
}
+39
View File
@@ -0,0 +1,39 @@
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import { api } from '../../api/client.js'
// 经济文章: 列表, 点进 /macro/articles/:slug
export default function ArticlesView() {
const [articles, setArticles] = useState([])
const [err, setErr] = useState('')
const [loading, setLoading] = useState(true)
useEffect(() => {
let cancelled = false
setLoading(true)
api('/articles')
.then((data) => { if (!cancelled) setArticles(data.articles || []) })
.catch((e) => !cancelled && setErr(e.message))
.finally(() => !cancelled && setLoading(false))
return () => { cancelled = true }
}, [])
if (loading) return <div className="loading">加载中...</div>
if (err) return <div className="error-banner">{err}</div>
if (!articles.length) return <div className="empty">暂无文章</div>
return (
<div>
<div className="page-title">经济文章</div>
<div className="list">
{articles.map((a) => (
<Link key={a.id} to={`/macro/articles/${encodeURIComponent(a.slug)}`} className="list-item">
<div className="list-item-title">{a.title}</div>
<div className="list-item-meta">{a.date}</div>
<div className="list-item-excerpt">{a.excerpt}</div>
</Link>
))}
</div>
</div>
)
}
+109
View File
@@ -0,0 +1,109 @@
import { useEffect, useState } from 'react'
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'
import { api } from '../../api/client.js'
// 经济数据: 从 /api/indicators 拉所有指标, 顶上一个 chip 行切换, 下面渲染图表+表格
export default function DataView() {
const [indicators, setIndicators] = useState([])
const [selected, setSelected] = useState(null)
const [err, setErr] = useState('')
const [loading, setLoading] = useState(true)
useEffect(() => {
let cancelled = false
setLoading(true)
api('/indicators')
.then((data) => {
if (cancelled) return
setIndicators(data.indicators || [])
if (data.indicators && data.indicators[0]) setSelected(data.indicators[0].name)
})
.catch((e) => !cancelled && setErr(e.message))
.finally(() => !cancelled && setLoading(false))
return () => { cancelled = true }
}, [])
if (loading) return <div className="loading">加载中...</div>
if (err) return <div className="error-banner">{err}</div>
if (!indicators.length) return <div className="empty">暂无指标数据, 请先执行 npm run db:seed</div>
// 按 groupName 分组, chip 行按组排列
const groups = groupBy(indicators, 'groupName')
const cur = indicators.find((i) => i.name === selected)
const chartData = cur ? buildMonthlySeries(cur.data) : []
return (
<div>
<div className="page-title">经济数据</div>
{Object.entries(groups).map(([groupName, list]) => (
<div key={groupName}>
<div className="section-title">{groupName}</div>
<div className="chip-row">
{list.map((i) => (
<button
key={i.name}
className={'chip' + (selected === i.name ? ' active' : '')}
onClick={() => setSelected(i.name)}
>
{shortTitle(i)}
</button>
))}
</div>
</div>
))}
{cur && (
<div style={{ padding: '0 12px 12px' }}>
<div className="card">
<div style={{ fontWeight: 600, marginBottom: 4 }}>{cur.data.title || cur.name}</div>
<div style={{ fontSize: 12, color: 'var(--color-muted)', marginBottom: 8 }}>
单位 {cur.data.unit || '-'} · 来源 {cur.data.source || 'seed'}
</div>
<div className="chart-wrap">
<ResponsiveContainer width="100%" height={260}>
<LineChart data={chartData} margin={{ top: 10, right: 16, left: 0, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="month" tick={{ fontSize: 11 }} />
<YAxis tick={{ fontSize: 11 }} />
<Tooltip />
<Legend />
<Line type="monotone" dataKey="value" name={cur.data.unit || '值'} stroke="#2563eb" strokeWidth={2} dot={{ r: 3 }} />
</LineChart>
</ResponsiveContainer>
</div>
<div style={{ maxHeight: 240, overflow: 'auto' }}>
<table className="data-table">
<thead>
<tr><th>月份</th><th style={{ textAlign: 'right' }}>数值</th></tr>
</thead>
<tbody>
{chartData.map((r) => (
<tr key={r.month}><td>{r.month}</td><td style={{ textAlign: 'right' }}>{r.value}</td></tr>
))}
</tbody>
</table>
</div>
</div>
</div>
)}
</div>
)
}
function groupBy(arr, key) {
return arr.reduce((acc, x) => {
const k = x[key] || '其它'
;(acc[k] = acc[k] || []).push(x)
return acc
}, {})
}
function shortTitle(i) {
if (i.data && i.data.title) return i.data.title
return i.name
}
// 把 data.rows: [{month, value}, ...] 直接返回, 服务端已经按月排好
function buildMonthlySeries(data) {
return (data && data.rows) || []
}
+108
View File
@@ -0,0 +1,108 @@
import { useEffect, useState } from 'react'
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'
import { api } from '../../api/client.js'
// 策略研究: 顶部 chip 行选策略, 下面显示 4 张图 (debt / gdp / debtToGdp / interestToGdp) + 表格
const SERIES = [
{ key: 'debt', label: '政府债务 (万亿美元)', color: '#8884d8' },
{ key: 'gdp', label: 'GDP (万亿美元)', color: '#3cb44b' },
{ key: 'debtToGdp', label: '债务/GDP (%)', color: '#4363d8' },
{ key: 'interestToGdp', label: '债务利息/GDP (%)', color: '#f58231' },
]
export default function StrategyView() {
const [strategies, setStrategies] = useState([])
const [selected, setSelected] = useState(null)
const [err, setErr] = useState('')
const [loading, setLoading] = useState(true)
useEffect(() => {
let cancelled = false
setLoading(true)
api('/strategies')
.then((data) => {
if (cancelled) return
setStrategies(data.strategies || [])
if (data.strategies && data.strategies[0]) setSelected(data.strategies[0].name)
})
.catch((e) => !cancelled && setErr(e.message))
.finally(() => !cancelled && setLoading(false))
return () => { cancelled = true }
}, [])
if (loading) return <div className="loading">加载中...</div>
if (err) return <div className="error-banner">{err}</div>
if (!strategies.length) return <div className="empty">暂无策略数据</div>
const cur = strategies.find((s) => s.name === selected)
const rows = cur ? cur.data.rows : []
return (
<div>
<div className="page-title">策略研究</div>
<div className="chip-row" style={{ paddingLeft: 12 }}>
{strategies.map((s) => (
<button
key={s.name}
className={'chip' + (selected === s.name ? ' active' : '')}
onClick={() => setSelected(s.name)}
>
{s.description || s.name}
</button>
))}
</div>
{cur && (
<div style={{ padding: '0 12px 12px' }}>
<div className="card">
<div style={{ fontWeight: 600, marginBottom: 4 }}>{cur.description || cur.name}</div>
<div style={{ fontSize: 12, color: 'var(--color-muted)', marginBottom: 8 }}>
数据 {rows.length} 条 · 来源 {cur.data.source || 'seed'}
</div>
{SERIES.map((s) => (
<div key={s.key} style={{ marginBottom: 12 }}>
<div style={{ fontSize: 13, fontWeight: 500, marginBottom: 4 }}>{s.label}</div>
<div className="chart-wrap">
<ResponsiveContainer width="100%" height={220}>
<LineChart data={rows} margin={{ top: 8, right: 12, left: 0, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="year" tick={{ fontSize: 11 }} />
<YAxis tick={{ fontSize: 11 }} />
<Tooltip />
<Legend />
<Line type="monotone" dataKey={s.key} name={s.label} stroke={s.color} strokeWidth={2} dot={{ r: 3 }} />
</LineChart>
</ResponsiveContainer>
</div>
</div>
))}
<div style={{ maxHeight: 220, overflow: 'auto', marginTop: 8 }}>
<table className="data-table">
<thead>
<tr>
<th>年份</th>
<th style={{ textAlign: 'right' }}>债务</th>
<th style={{ textAlign: 'right' }}>GDP</th>
<th style={{ textAlign: 'right' }}>债务/GDP</th>
<th style={{ textAlign: 'right' }}>利息/GDP</th>
</tr>
</thead>
<tbody>
{rows.map((r) => (
<tr key={r.year}>
<td>{r.year}</td>
<td style={{ textAlign: 'right' }}>{r.debt}</td>
<td style={{ textAlign: 'right' }}>{r.gdp}</td>
<td style={{ textAlign: 'right' }}>{r.debtToGdp}</td>
<td style={{ textAlign: 'right' }}>{r.interestToGdp}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
)}
</div>
)
}
+717
View File
@@ -0,0 +1,717 @@
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: #f5f5f5;
color: #333;
}
.container {
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* Navbar */
.navbar {
background-color: #333;
color: white;
padding: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.5rem;
font-weight: bold;
}
.logo a {
color: white;
text-decoration: none;
}
.nav-links {
display: flex;
gap: 1rem;
}
.nav-links a {
color: white;
text-decoration: none;
padding: 0.5rem;
border-radius: 4px;
}
.nav-links a:hover {
background-color: #555;
}
/* Global link styles */
a {
text-decoration: none;
cursor: pointer;
}
/* Main content */
main {
flex: 1;
padding: 2rem;
max-width: 1200px;
margin: 0 auto;
width: 100%;
}
.title {
font-size: 2.5rem;
margin-bottom: 1rem;
color: #333;
}
.description {
font-size: 1.2rem;
margin-bottom: 2rem;
color: #666;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 1.5rem;
}
.card {
background-color: white;
padding: 1.5rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: transform 0.2s ease;
}
.card:hover {
transform: translateY(-5px);
}
.card h2 {
margin-bottom: 0.5rem;
color: #333;
}
.card p {
color: #666;
}
/* Footer */
.footer {
background-color: #333;
color: white;
padding: 1rem;
text-align: center;
margin-top: auto;
}
.footer-content {
max-width: 1200px;
margin: 0 auto;
}
/* Data page layout */
.data-layout {
display: flex;
gap: 2rem;
margin-top: 2rem;
}
.data-sidebar {
width: 250px;
flex-shrink: 0;
}
.data-content {
flex: 1;
min-width: 0;
}
.indicator-group {
margin-bottom: 1.5rem;
}
.group-title {
font-size: 1.1rem;
font-weight: 600;
color: #333;
margin-bottom: 0.75rem;
padding-bottom: 0.5rem;
border-bottom: 2px solid #ddd;
}
.indicator-list {
list-style: none;
padding: 0;
margin: 0;
}
.indicator-item {
padding: 0.75rem 1rem;
margin-bottom: 0.5rem;
background-color: white;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s ease;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.indicator-item:hover {
background-color: #f0f0f0;
transform: translateX(4px);
}
.indicator-item.active {
background-color: #333;
color: white;
}
.indicator-detail {
background-color: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.indicator-title {
font-size: 1.8rem;
color: #333;
margin-bottom: 0.5rem;
}
.indicator-description {
color: #666;
margin-bottom: 2rem;
}
.chart-container {
margin-bottom: 3rem;
padding: 1rem;
background-color: #fafafa;
border-radius: 8px;
}
.data-table-container {
margin-top: 2rem;
}
.table-title {
font-size: 1.3rem;
color: #333;
margin-bottom: 1rem;
}
.data-table {
width: 100%;
border-collapse: collapse;
font-size: 0.95rem;
}
.data-table th,
.data-table td {
padding: 0.75rem 1rem;
text-align: left;
border-bottom: 1px solid #eee;
}
.data-table th {
background-color: #f5f5f5;
font-weight: 600;
color: #333;
}
.data-table tbody tr:hover {
background-color: #f9f9f9;
}
/* Articles section */
.articles-section {
margin-top: 4rem;
margin-bottom: 2rem;
}
.section-title {
font-size: 2rem;
color: #333;
margin-bottom: 1.5rem;
padding-bottom: 0.5rem;
border-bottom: 2px solid #ddd;
}
.articles-grid {
display: flex;
flex-direction: column;
gap: 1rem;
margin-bottom: 2rem;
}
.article-card {
background-color: white;
padding: 1.5rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: all 0.2s ease;
cursor: pointer;
}
.article-card:hover {
background-color: #f9f9f9;
transform: translateX(5px);
}
.article-date {
font-size: 0.9rem;
color: #666;
margin-bottom: 0.75rem;
}
.article-title {
font-size: 1.2rem;
font-weight: 600;
color: #333;
margin-bottom: 0.75rem;
line-height: 1.4;
}
.article-excerpt {
color: #666;
line-height: 1.5;
font-size: 0.95rem;
}
/* Pagination */
.pagination {
display: flex;
justify-content: flex-end;
gap: 0.5rem;
margin-top: 2rem;
}
.page-link {
padding: 0.5rem 1rem;
background-color: white;
border: 1px solid #ddd;
border-radius: 4px;
color: #333;
text-decoration: none;
transition: all 0.2s ease;
}
.page-link:hover {
background-color: #f0f0f0;
}
.page-link.active {
background-color: #333;
color: white;
border-color: #333;
}
/* Article detail page */
.article-detail {
max-width: 800px;
margin: 0 auto;
background-color: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.article-detail-title {
font-size: 2.5rem;
color: #333;
margin-bottom: 1rem;
line-height: 1.2;
}
.article-detail-date {
font-size: 1rem;
color: #666;
margin-bottom: 2rem;
padding-bottom: 1rem;
border-bottom: 1px solid #eee;
}
.article-detail-content {
color: #333;
line-height: 1.6;
}
.article-detail-content h1,
.article-detail-content h2,
.article-detail-content h3,
.article-detail-content h4,
.article-detail-content h5,
.article-detail-content h6 {
margin-top: 2rem;
margin-bottom: 1rem;
color: #333;
}
.article-detail-content p {
margin-bottom: 1.5rem;
}
.article-detail-content ul,
.article-detail-content ol {
margin-bottom: 1.5rem;
padding-left: 2rem;
}
.article-detail-content li {
margin-bottom: 0.5rem;
}
.article-detail-content img {
max-width: 100%;
height: auto;
margin: 2rem 0;
border-radius: 8px;
}
@media (max-width: 900px) {
.data-layout {
flex-direction: column;
}
.data-sidebar {
width: 100%;
}
.pagination {
justify-content: center;
}
.article-detail {
padding: 1.5rem;
}
.article-detail-title {
font-size: 2rem;
}
.strategy-layout {
flex-direction: column;
}
.strategy-sidebar {
width: 100%;
}
}
/* Strategy page layout */
.strategy-layout {
display: flex;
gap: 2rem;
margin-top: 2rem;
}
.strategy-sidebar {
width: 250px;
flex-shrink: 0;
}
.strategy-content {
flex: 1;
min-width: 0;
}
.sidebar-title {
font-size: 1.1rem;
font-weight: 600;
color: #333;
margin-bottom: 0.75rem;
padding-bottom: 0.5rem;
border-bottom: 2px solid #ddd;
}
.strategy-list {
list-style: none;
padding: 0;
margin: 0;
}
.strategy-item {
padding: 0.75rem 1rem;
margin-bottom: 0.5rem;
background-color: white;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s ease;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.strategy-item:hover {
background-color: #f0f0f0;
transform: translateX(4px);
}
.strategy-item.active {
background-color: #333;
color: white;
}
.strategy-detail {
background-color: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.strategy-title {
font-size: 1.8rem;
color: #333;
margin-bottom: 0.5rem;
}
.strategy-description {
color: #666;
margin-bottom: 2rem;
}
.chart-section {
margin-bottom: 3rem;
}
.chart-title {
font-size: 1.3rem;
color: #333;
margin-bottom: 1rem;
}
/* ================== 移动端优先布局 (mobile-first) ================== */
:root {
--color-bg: #f5f5f5;
--color-card: #ffffff;
--color-text: #333333;
--color-muted: #666666;
--color-border: #e5e7eb;
--color-primary: #1f2937;
--color-accent: #2563eb;
--color-danger: #dc2626;
--bottom-nav-h: 56px;
--top-tabs-h: 44px;
--safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #root {
height: 100%;
background: var(--color-bg);
color: var(--color-text);
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: transparent;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
'Hiragino Sans GB', 'Microsoft YaHei', Roboto, sans-serif;
font-size: 14px;
overscroll-behavior-y: contain;
}
a { color: inherit; text-decoration: none; cursor: pointer; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font: inherit; }
/* 应用主框架 */
.app-root {
display: flex;
flex-direction: column;
min-height: 100vh;
min-height: 100dvh;
max-width: 768px;
margin: 0 auto;
background: var(--color-bg);
position: relative;
}
.app-main {
flex: 1 1 auto;
padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px);
overflow-y: auto;
}
.app-main.has-top-tabs {
padding-top: var(--top-tabs-h);
}
/* 顶栏 tabs (宏观页用) */
.top-tabs {
position: sticky;
top: 0;
z-index: 10;
height: var(--top-tabs-h);
display: flex;
background: #fff;
border-bottom: 1px solid var(--color-border);
align-items: stretch;
}
.top-tabs-item {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
color: var(--color-muted);
position: relative;
user-select: none;
}
.top-tabs-item.active {
color: var(--color-primary);
font-weight: 600;
}
.top-tabs-item.active::after {
content: '';
position: absolute;
left: 30%;
right: 30%;
bottom: 6px;
height: 2px;
background: var(--color-primary);
border-radius: 2px;
}
/* 滑屏容器 */
.swipe-container {
position: relative;
overflow: hidden;
touch-action: pan-y;
}
.swipe-track {
display: flex;
width: 300%;
transform: translateX(var(--swipe-offset, 0%));
transition: transform 0.25s ease;
will-change: transform;
}
.swipe-track.no-anim { transition: none; }
.swipe-pane {
width: 33.3333%;
flex-shrink: 0;
overflow-y: auto;
}
/* 底部 tab */
.bottom-nav {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 20;
height: calc(var(--bottom-nav-h) + var(--safe-bottom));
padding-bottom: var(--safe-bottom);
display: flex;
background: #fff;
border-top: 1px solid var(--color-border);
max-width: 768px;
margin: 0 auto;
}
.bottom-nav-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 2px;
font-size: 11px;
color: var(--color-muted);
user-select: none;
}
.bottom-nav-item .icon { font-size: 20px; line-height: 1; }
.bottom-nav-item.active { color: var(--color-primary); font-weight: 600; }
/* 通用卡片 */
.card { background: #fff; border-radius: 10px; padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card + .card { margin-top: 10px; }
.page-title { font-size: 20px; font-weight: 700; padding: 14px 16px 4px; }
.page-desc { font-size: 13px; color: var(--color-muted); padding: 0 16px 12px; }
.section-title { font-size: 16px; font-weight: 600; padding: 14px 16px 8px; }
/* 列表 */
.list { padding: 0 12px; }
.list-item { background: #fff; padding: 14px; border-radius: 10px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.04); display: block; }
.list-item-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; line-height: 1.4; }
.list-item-meta { font-size: 12px; color: var(--color-muted); margin-bottom: 6px; }
.list-item-excerpt { font-size: 13px; color: var(--color-muted); line-height: 1.5; }
/* 图表 */
.chart-wrap { background: #fafafa; border-radius: 8px; padding: 8px; margin: 8px 0 16px; }
/* 表格 */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--color-border); }
.data-table th { background: #f8f8f8; font-weight: 600; }
/* 登录 */
.login-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(180deg, #1f2937 0%, #1f2937 35%, #f5f5f5 35%); }
.login-card { background: #fff; width: 100%; max-width: 380px; border-radius: 14px; padding: 24px; box-shadow: 0 4px 24px rgba(0,0,0,.1); }
.login-title { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.login-subtitle { text-align: center; color: var(--color-muted); margin-bottom: 20px; font-size: 13px; }
.login-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.login-field label { font-size: 12px; color: var(--color-muted); }
.login-field input { padding: 12px; border: 1px solid var(--color-border); border-radius: 8px; outline: none; }
.login-field input:focus { border-color: var(--color-primary); }
.login-options { display: flex; align-items: center; gap: 6px; margin-bottom: 18px; font-size: 13px; color: var(--color-muted); }
.login-btn { width: 100%; padding: 13px; background: var(--color-primary); color: #fff; border-radius: 8px; font-weight: 600; }
.login-btn:disabled { opacity: 0.6; }
.login-hint { text-align: center; font-size: 12px; color: var(--color-muted); margin-top: 14px; line-height: 1.6; }
.login-error { background: #fef2f2; color: var(--color-danger); padding: 10px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
/* 我 */
.me-header { background: var(--color-primary); color: #fff; padding: 30px 16px 24px; }
.me-name { font-size: 18px; font-weight: 600; }
.me-email { font-size: 13px; opacity: .8; margin-top: 2px; }
.me-list { padding: 12px; }
.me-list .list-item { display: flex; align-items: center; justify-content: space-between; }
.me-list .list-item .label { font-size: 14px; }
.me-list .list-item .value { font-size: 13px; color: var(--color-muted); }
.me-list .danger { color: var(--color-danger); }
.loading, .page-loading { padding: 40px; text-align: center; color: var(--color-muted); }
.empty { padding: 40px; text-align: center; color: var(--color-muted); font-size: 13px; }
.error-banner { background: #fef2f2; color: var(--color-danger); padding: 10px 14px; font-size: 13px; border-radius: 6px; margin: 12px; }
/* 占位页 */
.placeholder-page { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; padding: 24px; text-align: center; color: var(--color-muted); gap: 12px; }
.placeholder-page .icon { font-size: 48px; opacity: .6; }
/* 文章详情 */
.article-detail { background: #fff; padding: 18px 16px 24px; }
.article-detail h1 { font-size: 20px; line-height: 1.35; margin-bottom: 8px; }
.article-detail .meta { font-size: 12px; color: var(--color-muted); margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--color-border); }
.article-content { font-size: 15px; line-height: 1.75; color: #333; }
.article-content h1, .article-content h2, .article-content h3 { margin: 1.2em 0 0.6em; line-height: 1.3; }
.article-content p { margin-bottom: 0.9em; }
.article-content ul, .article-content ol { margin: 0 0 1em 1.4em; }
.article-content img { max-width: 100%; border-radius: 6px; margin: 0.6em 0; }
.article-back { display: inline-flex; align-items: center; gap: 4px; padding: 8px 0; color: var(--color-accent); font-size: 13px; }
/* 侧边栏式选择器 (移动端改为顶部 chip 行) */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; }
.chip-row::-webkit-scrollbar { display: none; }
.chip { padding: 7px 12px; background: #fff; border: 1px solid var(--color-border); border-radius: 999px; font-size: 13px; white-space: nowrap; }
.chip.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }