[阶段10] 前端以 Framework7 重建,采用 iOS 原生形态
按要求废弃手写外壳,改用 Framework7 React(theme=ios)。参照 PeakWatch 的信息架构与卡片语言。 保留(这些是资产,不该重来): - 数据层 services/api.ts、聚合 lib/aggregate.ts、参考区间 lib/ranges.ts - 图表组件 Chart / Ring / Sparkline / BandBar / MetricCard / MetricStrip - 经校验的配色令牌(色盲安全 + 对比度,浅深两档) 替换: - 路由与外壳交给 F7:五个 Tab 各自独立导航栈,推入详情页不影响其他 Tab - 页面转场、橡皮筋滚动、大标题折叠、半透明栏 —— 这些正是换框架的理由, 手写做不像 - 底部标签栏改用 F7 Toolbar,触控目标与安全区由框架处理 配色接入: - 新增 f7theme.css 把我们的令牌映射到 F7 的 CSS 变量,让它的导航栏/ 列表/面板与我们的图表同属一套设计,而不是两种视觉打架 - F7 的深色靠 .dark 类,我们的靠 data-theme,两者在 App 里同步切换 fix: 图标显示为原始名称(squ/hea/cale…) - iconIos/iconMd 引用的是 framework7-icons 字体,没装就只会渲染出名字 其他: - tsconfig moduleResolution 改为 bundler —— F7 用 exports 映射, node 解析方式找不到它的类型 - 登录页不套 Tab 外壳,未登录时不该出现导航 桌面与手机都要好看:内容在宽屏收进 1100px 居中列并加密卡片列数, 窄屏走底部标签栏;两档都已实机核对。 bundle 190KB -> 399KB,是换取原生手感的代价。 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
49
client/.attic/App.old.tsx
Normal file
49
client/.attic/App.old.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
||||
import Layout from './components/Layout';
|
||||
import ProtectedRoute from './components/ProtectedRoute';
|
||||
import Login from './pages/Login';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
import DataSync from './pages/DataSync';
|
||||
import Trends from './pages/Trends';
|
||||
import Recommendations from './pages/Recommendations';
|
||||
import Settings from './pages/Settings';
|
||||
import Sleep from './pages/Sleep';
|
||||
import Achievements from './pages/Achievements';
|
||||
import Daily from './pages/Daily';
|
||||
import Health from './pages/Health';
|
||||
import { FEATURES } from './features';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Router>
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Layout>
|
||||
<Routes>
|
||||
<Route path="/" element={<Dashboard />} />
|
||||
<Route path="/sync" element={<DataSync />} />
|
||||
<Route path="/health" element={<Health />} />
|
||||
<Route path="/daily" element={<Daily />} />
|
||||
<Route path="/trends" element={<Trends />} />
|
||||
<Route path="/sleep" element={<Sleep />} />
|
||||
<Route path="/achievements" element={<Achievements />} />
|
||||
{FEATURES.ai && (
|
||||
<Route path="/recommendations" element={<Recommendations />} />
|
||||
)}
|
||||
<Route path="/settings" element={<Settings />} />
|
||||
</Routes>
|
||||
</Layout>
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
181
client/.attic/Layout.css
Normal file
181
client/.attic/Layout.css
Normal file
@@ -0,0 +1,181 @@
|
||||
.layout {
|
||||
min-height: 100vh;
|
||||
background: var(--surface-0);
|
||||
}
|
||||
|
||||
.header {
|
||||
background: color-mix(in srgb, var(--surface-0) 82%, transparent);
|
||||
backdrop-filter: saturate(160%) blur(14px);
|
||||
-webkit-backdrop-filter: saturate(160%) blur(14px);
|
||||
border-bottom: 1px solid var(--border);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.header-inner {
|
||||
max-width: 1180px;
|
||||
margin: 0 auto;
|
||||
padding: 0 1.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.25rem;
|
||||
height: 54px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 0.92rem;
|
||||
font-weight: 680;
|
||||
color: var(--text-primary);
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.nav {
|
||||
display: flex;
|
||||
gap: 0.15rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
padding: 0.38rem 0.7rem;
|
||||
border-radius: 8px;
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
font-size: 0.86rem;
|
||||
white-space: nowrap;
|
||||
transition: background 0.15s var(--ease), color 0.15s var(--ease);
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
background: var(--surface-1);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.nav-link.active {
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
/* Icon shortcuts only appear once the text nav collapses. */
|
||||
.header-secondary {
|
||||
display: none;
|
||||
gap: 0.1rem;
|
||||
}
|
||||
|
||||
.icon-link {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 9px;
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
font-size: 1rem;
|
||||
transition: background 0.15s var(--ease), color 0.15s var(--ease);
|
||||
}
|
||||
|
||||
.icon-link:hover,
|
||||
.icon-link.active {
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
background: none;
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-secondary);
|
||||
border-radius: 8px;
|
||||
padding: 0.3rem 0.6rem;
|
||||
font-size: 0.74rem;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
white-space: nowrap;
|
||||
transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
border-color: var(--border-strong);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.content {
|
||||
max-width: 1180px;
|
||||
margin: 0 auto;
|
||||
padding: 1.5rem 1.5rem 4rem;
|
||||
}
|
||||
|
||||
/* Bottom tab bar ----------------------------------------------------------- */
|
||||
.tabbar {
|
||||
display: none;
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
/* Clears the iOS home indicator rather than sitting under it. */
|
||||
bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
|
||||
z-index: 30;
|
||||
gap: 0.15rem;
|
||||
padding: 0.3rem;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--surface-2) 88%, transparent);
|
||||
backdrop-filter: saturate(180%) blur(20px);
|
||||
-webkit-backdrop-filter: saturate(180%) blur(20px);
|
||||
border: 1px solid var(--border);
|
||||
box-shadow: 0 6px 28px rgba(0, 0, 0, 0.28);
|
||||
}
|
||||
|
||||
.tab {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.1rem;
|
||||
/* Comfortably past the 44px touch-target minimum. */
|
||||
min-width: 60px;
|
||||
padding: 0.42rem 0.5rem;
|
||||
border-radius: 999px;
|
||||
text-decoration: none;
|
||||
color: var(--text-muted);
|
||||
transition: color 0.18s var(--ease), background 0.18s var(--ease);
|
||||
}
|
||||
|
||||
.tab-icon {
|
||||
font-size: 1.05rem;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.tab-label {
|
||||
font-size: 0.66rem;
|
||||
font-weight: 550;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.tab:active {
|
||||
transform: scale(0.94);
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.nav { display: none; }
|
||||
.header-secondary { display: flex; }
|
||||
.tabbar { display: flex; }
|
||||
.header-inner { padding: 0 0.9rem; gap: 0.5rem; }
|
||||
.logo { font-size: 0.85rem; }
|
||||
/* Room for the floating bar so the last card is never trapped under it. */
|
||||
.content { padding: 1.1rem 0.9rem calc(5.5rem + env(safe-area-inset-bottom, 0px)); }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.nav-link, .icon-link, .tab, .theme-toggle { transition: none; }
|
||||
.tab:active { transform: none; }
|
||||
}
|
||||
131
client/.attic/Layout.tsx
Normal file
131
client/.attic/Layout.tsx
Normal file
@@ -0,0 +1,131 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { FEATURES } from '../features';
|
||||
import './Layout.css';
|
||||
|
||||
interface LayoutProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
interface NavItem {
|
||||
path: string;
|
||||
label: string;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
/** The five thumb-reachable destinations in the bottom bar. */
|
||||
const NAV: NavItem[] = [
|
||||
{ path: '/', label: '今日', icon: '◱' },
|
||||
{ path: '/health', label: '健康', icon: '♡' },
|
||||
{ path: '/daily', label: '每日', icon: '◉' },
|
||||
{ path: '/trends', label: '趋势', icon: '◈' },
|
||||
{ path: '/achievements', label: '成就', icon: '▽' },
|
||||
];
|
||||
|
||||
/** Secondary destinations: the bottom bar only holds five. */
|
||||
const SECONDARY: NavItem[] = [
|
||||
{ path: '/sleep', label: '睡眠', icon: '☾' },
|
||||
...(FEATURES.ai ? [{ path: '/recommendations', label: '建议', icon: '✦' }] : []),
|
||||
{ path: '/sync', label: '同步', icon: '⟳' },
|
||||
{ path: '/settings', label: '设置', icon: '⚙' },
|
||||
];
|
||||
|
||||
type Theme = 'light' | 'dark' | 'system';
|
||||
|
||||
/* Dark mode is a deliberate, validated palette rather than an inverted one, so
|
||||
the choice is stamped on <html> and the tokens swap in one place. */
|
||||
function useTheme(): [Theme, (t: Theme) => void] {
|
||||
const [theme, setTheme] = useState<Theme>(
|
||||
() => (localStorage.getItem('ghl_theme') as Theme) || 'system'
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
if (theme === 'system') root.removeAttribute('data-theme');
|
||||
else root.setAttribute('data-theme', theme);
|
||||
localStorage.setItem('ghl_theme', theme);
|
||||
}, [theme]);
|
||||
|
||||
return [theme, setTheme];
|
||||
}
|
||||
|
||||
const isActive = (pathname: string, path: string) =>
|
||||
path === '/' ? pathname === '/' : pathname.startsWith(path);
|
||||
|
||||
function Layout({ children }: LayoutProps) {
|
||||
const location = useLocation();
|
||||
const [theme, setTheme] = useTheme();
|
||||
|
||||
const cycle = () =>
|
||||
setTheme(theme === 'system' ? 'light' : theme === 'light' ? 'dark' : 'system');
|
||||
const themeLabel = { system: '自动', light: '浅色', dark: '深色' }[theme];
|
||||
|
||||
return (
|
||||
<div className="layout">
|
||||
<header className="header">
|
||||
<div className="header-inner">
|
||||
<Link to="/" className="logo">Garmin Health Lab</Link>
|
||||
|
||||
{/* Wide screens show every destination in one row; narrow screens use
|
||||
the bottom bar instead, where the thumb already is. */}
|
||||
<nav className="nav" aria-label="主导航">
|
||||
{[...NAV, ...SECONDARY].map((item) => (
|
||||
<Link
|
||||
key={item.path}
|
||||
to={item.path}
|
||||
className={`nav-link ${isActive(location.pathname, item.path) ? 'active' : ''}`}
|
||||
aria-current={isActive(location.pathname, item.path) ? 'page' : undefined}
|
||||
>
|
||||
{item.label}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<div className="header-actions">
|
||||
<nav className="header-secondary" aria-label="次级导航">
|
||||
{SECONDARY.map((item) => (
|
||||
<Link
|
||||
key={item.path}
|
||||
to={item.path}
|
||||
className={`icon-link ${isActive(location.pathname, item.path) ? 'active' : ''}`}
|
||||
title={item.label}
|
||||
aria-label={item.label}
|
||||
>
|
||||
<span aria-hidden="true">{item.icon}</span>
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
<button
|
||||
className="theme-toggle"
|
||||
onClick={cycle}
|
||||
aria-label={`切换主题,当前${themeLabel}`}
|
||||
>
|
||||
{themeLabel}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main className="content">{children}</main>
|
||||
|
||||
<nav className="tabbar" aria-label="主导航">
|
||||
{NAV.map((item) => {
|
||||
const active = isActive(location.pathname, item.path);
|
||||
return (
|
||||
<Link
|
||||
key={item.path}
|
||||
to={item.path}
|
||||
className={`tab ${active ? 'active' : ''}`}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
>
|
||||
<span className="tab-icon" aria-hidden="true">{item.icon}</span>
|
||||
<span className="tab-label">{item.label}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Layout;
|
||||
18
client/.attic/ProtectedRoute.tsx
Normal file
18
client/.attic/ProtectedRoute.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
|
||||
interface ProtectedRouteProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
function ProtectedRoute({ children }: ProtectedRouteProps) {
|
||||
const token = localStorage.getItem('ghl_token');
|
||||
|
||||
if (!token) {
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
export default ProtectedRoute;
|
||||
Reference in New Issue
Block a user