diff --git a/src/App.tsx b/src/App.tsx index d7a17c2..56c82e3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,13 +1,13 @@ import { useEffect } from 'react'; import { BrowserRouter, Navigate, Route, Routes, useNavigate } from 'react-router-dom'; import { setUnauthorizedHandler } from './api/http'; -import { AppLayout } from './components/AppLayout'; +import { AppShell } from './shell/AppShell'; import { RequireAuth } from './components/RequireAuth'; import { LoginPage } from './pages/LoginPage'; import { PageRenderPage } from './pages/PageRenderPage'; import { TodoPage } from './pages/TodoPage'; -// 把 401 跳登录的 handler 注入 http 层(在路由上下文内,可用 navigate) +// 把 401 跳登录的 handler 注入 http 层(在路由上下文内,可用 navigate) function UnauthorizedBridge() { const navigate = useNavigate(); useEffect(() => { @@ -21,28 +21,24 @@ export default function App() { + {/* 登录页(无壳) */} } /> + + {/* 登录后页面统一由 AppShell 包裹(Outlet 渲染子路由) */} - - - + } - /> - - - - - - } - /> - } /> + > + } /> + } /> + {/* 根路径默认跳待办 */} + } /> + + + {/* 兜底 */} } /> diff --git a/src/api/menu.ts b/src/api/menu.ts new file mode 100644 index 0000000..3c33fd2 --- /dev/null +++ b/src/api/menu.ts @@ -0,0 +1,49 @@ +// src/api/menu.ts — 菜单树 API +// GET /api/menu 返回三级树,后端可能晚于前端就绪,404/失败时优雅降级。 +import { http } from './http'; + +// 后端契约(已定死) +export interface MenuItem { + id: string; + name: string; + seq: number; + templateId?: string | null; + children?: MenuItem[]; +} + +export interface MenuRoot { + id: string; + name: string; + seq: number; + children?: MenuItem[]; +} + +export interface MenuResponse { + roots: MenuRoot[]; +} + +// 收集所有叶子节点(templateId 非空),携带面包屑路径 +export interface MenuLeaf { + id: string; + name: string; + templateId: string; + path: string; // 面包屑:父节点名 / ... / 叶子名 +} + +export function collectLeaves(items: MenuItem[], breadcrumb: string[] = []): MenuLeaf[] { + let out: MenuLeaf[] = []; + for (const m of items) { + if (m.templateId) { + out.push({ id: m.id, name: m.name, templateId: m.templateId, path: [...breadcrumb, m.name].join(' / ') }); + } + if (m.children?.length) { + out = out.concat(collectLeaves(m.children, [...breadcrumb, m.name])); + } + } + return out; +} + +export async function fetchMenu(): Promise { + const resp = await http.get('/api/menu'); + return resp.data; +} diff --git a/src/components/ui/Dialog.tsx b/src/components/ui/Dialog.tsx new file mode 100644 index 0000000..1acd102 --- /dev/null +++ b/src/components/ui/Dialog.tsx @@ -0,0 +1,65 @@ +// EIP4 Dialog / Drawer 弹层组件 — 从原型 ui.jsx 迁移 +import type { MouseEvent, ReactNode } from 'react'; +import { Icon } from './Icon'; + +interface DialogProps { + title: string; + width?: number; + onClose: () => void; + children: ReactNode; + foot?: ReactNode; +} + +export function Dialog({ title, width = 560, onClose, children, foot }: DialogProps) { + const handleMask = (e: MouseEvent) => { + if (e.target === e.currentTarget) onClose(); + }; + return ( +
+
+
+

{title}

+ +
+
{children}
+ {foot ?
{foot}
: null} +
+
+ ); +} + +interface DrawerProps { + title: string; + width?: number; + onClose: () => void; + children: ReactNode; + foot?: ReactNode; +} + +export function Drawer({ title, width = 420, onClose, children, foot }: DrawerProps) { + const handleMask = (e: MouseEvent) => { + if (e.target === e.currentTarget) onClose(); + }; + return ( +
+
+
+

{title}

+ +
+
+ {children} +
+ {foot ?
{foot}
: null} +
+
+ ); +} diff --git a/src/components/ui/Icon.tsx b/src/components/ui/Icon.tsx new file mode 100644 index 0000000..be47a9c --- /dev/null +++ b/src/components/ui/Icon.tsx @@ -0,0 +1,69 @@ +// EIP4 线性图标集(16px 基准,29 种图标)— 从原型 ui.jsx 迁移 +import type { CSSProperties } from 'react'; + +const ICON_PATHS: Record = { + home: 'M3 9.5 10 3l7 6.5M5 8.5V17h10V8.5', + todo: 'M4 3h12v14H4zM7 8h6M7 12h4', + flow: 'M4 5h4v4H4zM12 11h4v4h-4zM8 7h6v0M14 7v4M6 9v6h6', + list: 'M4 5h12M4 10h12M4 15h8', + doc: 'M5 3h7l3 3v11H5zM12 3v3h3M8 10h4M8 13h4', + team: 'M7 9a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zM2.5 16c0-2.5 2-4 4.5-4s4.5 1.5 4.5 4M13 9a2.3 2.3 0 1 0-.01-4.6M14 12c2 .3 3.5 1.6 3.5 3.8', + chart: 'M3 17h14M5 13v-3M9 13V6M13 13V9M17 13V4', + cal: 'M4 5h12v12H4zM4 9h12M7 3v3M13 3v3', + search: 'M9 14a5 5 0 1 0 0-10 5 5 0 0 0 0 10zM13 13l4 4', + org: 'M8 3h4v4H8zM3 13h4v4H3zM13 13h4v4h-4zM10 7v3M10 10H5v3M10 10h5v3', + gear: 'M10 13a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM10 2.8l.9 1.9 2-.5 1 1.7 1.9.9-.5 2 1.4 1.5-1.4 1.5.5 2-1.9.9-1 1.7-2-.5-.9 1.9-.9-1.9-2 .5-1-1.7-1.9-.9.5-2L2.8 10l1.4-1.5-.5-2 1.9-.9 1-1.7 2 .5z', + db: 'M10 3c3.3 0 6 .9 6 2s-2.7 2-6 2-6-.9-6-2 2.7-2 6-2zM4 5v10c0 1.1 2.7 2 6 2s6-.9 6-2V5M4 10c0 1.1 2.7 2 6 2s6-.9 6-2', + monitor: 'M3 4h14v9H3zM7 17h6M10 13v4', + edit: 'M12.5 3.5l4 4L7 17H3v-4zM11 5l4 4', + crane: 'M4 17h12M6 17V5l8-1.5V17M14 6l3 1v3M10 8h.01M10 11h.01', + brush: 'M13 3l4 4-7.5 7.5-4-4zM5.5 10.5 4 16l5.5-1.5', + bell: 'M10 3a5 5 0 0 1 5 5v3l1.5 2.5h-13L5 11V8a5 5 0 0 1 5-5zM8.5 16a1.5 1.5 0 0 0 3 0', + phone: 'M6 2h8v16H6zM9 15.5h2', + chevR: 'M7 4l6 6-6 6', + chevD: 'M4 7l6 6 6-6', + plus: 'M10 4v12M4 10h12', + x: 'M5 5l10 10M15 5L5 15', + check: 'M3.5 10.5l4 4 9-9', + refresh: 'M4 10a6 6 0 0 1 10.5-4M16 10a6 6 0 0 1-10.5 4M14.5 3v3h-3M5.5 17v-3h3', + download: 'M10 3v9M6 8.5l4 4 4-4M4 16h12', + upload: 'M10 12V3M6 6.5l4-4 4 4M4 16h12', + print: 'M6 7V3h8v4M6 13H4V7h12v6h-2M6 11h8v6H6z', + trash: 'M4 6h12M8 6V4h4v2M6 6l.8 11h6.4L14 6M8.5 9v5M11.5 9v5', + filter: 'M3 4h14l-5.5 6.5V16l-3 1.5v-7L3 4z', + more: 'M10 5h.01M10 10h.01M10 15h.01', + fold: 'M12 4l-6 6 6 6', + zap: 'M11 2 4 11h5l-1 7 7-9h-5l1-7z', + pin: 'M10 3l2 4 4.5.6-3.2 3.2.7 4.4L10 13l-4 2.2.7-4.4L3.5 7.6 8 7z', + eye: 'M2.5 10S5.5 5 10 5s7.5 5 7.5 5-3 5-7.5 5-7.5-5-7.5-5zM10 12a2 2 0 1 0 0-4 2 2 0 0 0 0 4z', + copy: 'M7 7h9v9H7zM4 13V4h9', + drag: 'M7 5h.01M13 5h.01M7 10h.01M13 10h.01M7 15h.01M13 15h.01', +}; + +export interface IconProps { + name: string; + size?: number; + sw?: number; + style?: CSSProperties; + className?: string; +} + +export function Icon({ name, size = 16, sw = 1.5, style, className }: IconProps) { + return ( + + ); +} diff --git a/src/components/ui/Pagination.tsx b/src/components/ui/Pagination.tsx new file mode 100644 index 0000000..add252c --- /dev/null +++ b/src/components/ui/Pagination.tsx @@ -0,0 +1,53 @@ +// EIP4 分页组件 — 从原型 ui.jsx 迁移 +import { useMemo } from 'react'; + +interface PaginationProps { + total: number; + page: number; + pageSize?: number; + onPage: (page: number) => void; +} + +export function Pagination({ total, page, pageSize = 10, onPage }: PaginationProps) { + const pages = Math.max(1, Math.ceil(total / pageSize)); + + const nums = useMemo(() => { + const arr: (number | '…')[] = []; + for (let i = 1; i <= pages; i++) { + if (i <= 3 || i > pages - 2 || Math.abs(i - page) <= 1) { + arr.push(i); + } else if (arr[arr.length - 1] !== '…') { + arr.push('…'); + } + } + return arr; + }, [pages, page]); + + return ( +
+ 共 {total.toLocaleString()} 条 + + {nums.map((n, i) => + n === '…' ? ( + + … + + ) : ( + + ), + )} + + {pageSize} 条/页 +
+ ); +} diff --git a/src/components/ui/Toast.tsx b/src/components/ui/Toast.tsx new file mode 100644 index 0000000..93fff17 --- /dev/null +++ b/src/components/ui/Toast.tsx @@ -0,0 +1,56 @@ +// EIP4 Toast 提示组件 — 从原型 ui.jsx 迁移 +// 使用单例 _pushToast 实现命令式调用:toast('消息', 'ok'|'warn'|'err') +import { useEffect, useState } from 'react'; +import { Icon } from './Icon'; + +type Tone = 'ok' | 'warn' | 'err'; + +interface ToastItem { + id: number; + msg: string; + tone: Tone; +} + +let _pushToast: ((msg: string, tone?: Tone) => void) | null = null; + +export function ToastHost() { + const [items, setItems] = useState([]); + + useEffect(() => { + _pushToast = (msg, tone = 'ok') => { + const id = Date.now() + Math.random(); + setItems((s) => [...s, { id, msg, tone }]); + setTimeout(() => setItems((s) => s.filter((t) => t.id !== id)), 2600); + }; + return () => { + _pushToast = null; + }; + }, []); + + return ( +
+ {items.map((t) => ( +
+ + + + {t.msg} +
+ ))} +
+ ); +} + +export function toast(msg: string, tone?: Tone): void { + if (_pushToast) _pushToast(msg, tone); +} diff --git a/src/components/ui/index.ts b/src/components/ui/index.ts new file mode 100644 index 0000000..4904ae0 --- /dev/null +++ b/src/components/ui/index.ts @@ -0,0 +1,6 @@ +// src/components/ui 统一出口 +export { Icon } from './Icon'; +export type { IconProps } from './Icon'; +export { ToastHost, toast } from './Toast'; +export { Dialog, Drawer } from './Dialog'; +export { Pagination } from './Pagination'; diff --git a/src/main.tsx b/src/main.tsx index d9736ad..d7bf8f5 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,5 +1,6 @@ import { StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; +import './shell/theme.css'; import App from './App'; createRoot(document.getElementById('root')!).render( diff --git a/src/shell/AppShell.tsx b/src/shell/AppShell.tsx new file mode 100644 index 0000000..7093292 --- /dev/null +++ b/src/shell/AppShell.tsx @@ -0,0 +1,209 @@ +// AppShell — 登录后整体布局:左侧栏 + 顶栏 + Tab 条 + 内容区 +// 替代原 AppLayout.tsx;多 Tab 状态存 localStorage 恢复。 +// +// 【Tab 设计取舍说明】 +// 内容区直接由 react-router 渲染当前路由,切 Tab = navigate(), +// 不做 keep-alive(切 Tab 重新挂载组件)。 +// 原因:keep-alive 需要将所有 Tab 内容同时挂载在 DOM 中,对 amis 渲染宿主 +// 会产生大量隐藏实例,内存/副作用难以控制。当前阶段优先保证正确性, +// keep-alive 作为后续优化项。 +import { useCallback, useEffect, useState } from 'react'; +import { Outlet, useLocation, useNavigate } from 'react-router-dom'; +import { getProfile } from '../auth/token'; +import { collectLeaves, fetchMenu } from '../api/menu'; +import type { MenuLeaf } from '../api/menu'; +import { ToastHost } from '../components/ui/Toast'; +import { Topbar } from './Topbar'; +import { SideMenu } from './SideMenu'; +import { TabBar } from './TabBar'; +import type { Tab } from './TabBar'; +import { SettingsDrawer, initTheme } from './SettingsDrawer'; + +const TABS_KEY = 'eip4-tabs'; +const ACTIVE_KEY = 'eip4-active-tab'; + +// 初始 Tab:「待办」作为保底 Tab,不可关闭 +const TODO_TAB: Tab = { key: '/todo', title: '待办' }; + +function loadTabs(): Tab[] { + try { + const raw = localStorage.getItem(TABS_KEY); + if (raw) { + const parsed = JSON.parse(raw) as Tab[]; + if (Array.isArray(parsed) && parsed.length) return parsed; + } + } catch { + // 忽略 + } + return [TODO_TAB]; +} + +function loadActiveKey(tabs: Tab[]): string { + try { + const a = localStorage.getItem(ACTIVE_KEY); + if (a && tabs.some((t) => t.key === a)) return a; + } catch { + // 忽略 + } + return tabs[0].key; +} + +// 初始化主题(刷新后恢复 localStorage 中的设置) +initTheme(); + +export function AppShell() { + const navigate = useNavigate(); + const location = useLocation(); + + const [tabs, setTabs] = useState(loadTabs); + const [activeKey, setActiveKey] = useState(() => loadActiveKey(loadTabs())); + const [collapsed, setCollapsed] = useState(false); + const [showSettings, setShowSettings] = useState(false); + const [leaves, setLeaves] = useState([]); + + const profile = getProfile(); + + // 同步 activeKey 跟随浏览器地址(直接输入 URL / 后退前进) + useEffect(() => { + const path = location.pathname; + // 若当前路径不在 tab 列表中则不自动新增(由菜单点击触发) + if (tabs.some((t) => t.key === path)) { + setActiveKey(path); + } + }, [location.pathname, tabs]); + + // 持久化 tabs + useEffect(() => { + try { + localStorage.setItem(TABS_KEY, JSON.stringify(tabs)); + } catch { + // 忽略 + } + }, [tabs]); + + // 持久化 activeKey + useEffect(() => { + try { + localStorage.setItem(ACTIVE_KEY, activeKey); + } catch { + // 忽略 + } + }, [activeKey]); + + // 加载菜单叶子供全局搜索使用(404/失败时 leaves 为空,搜索框显示空结果) + useEffect(() => { + fetchMenu() + .then((data) => { + const all: MenuLeaf[] = []; + for (const root of data.roots ?? []) { + all.push(...collectLeaves(root.children ?? [], [root.name])); + } + setLeaves(all); + }) + .catch(() => { + // 忽略,搜索降级为空结果 + }); + }, []); + + // 打开/激活一个 Tab + const openTab = useCallback( + (key: string, title: string) => { + setTabs((prev) => { + if (prev.some((t) => t.key === key)) return prev; + return [...prev, { key, title }]; + }); + setActiveKey(key); + navigate(key); + }, + [navigate], + ); + + // 从菜单点击触发(templateId → /page/:templateId) + const handleMenuOpen = useCallback( + (templateId: string) => { + if (templateId === '__todo__') { + openTab('/todo', '待办'); + return; + } + openTab(`/page/${templateId}`, templateId); + }, + [openTab], + ); + + // 全局搜索点击(叶子 templateId) + const handleSearchOpen = useCallback( + (templateId: string) => { + // 用菜单 leaves 找到真实 title + const leaf = leaves.find((l) => l.templateId === templateId); + openTab(`/page/${templateId}`, leaf?.name ?? templateId); + }, + [openTab, leaves], + ); + + // 切换 Tab(只切换路由,不增删) + const handleActive = useCallback( + (key: string) => { + setActiveKey(key); + navigate(key); + }, + [navigate], + ); + + // 关闭 Tab + const handleClose = useCallback( + (key: string) => { + setTabs((prev) => { + const next = prev.filter((t) => t.key !== key); + // 至少保留「待办」tab + const safe = next.length ? next : [TODO_TAB]; + // 若关闭的是当前激活 tab,激活相邻 tab(优先右侧) + if (key === activeKey) { + const idx = prev.findIndex((t) => t.key === key); + const nextActive = safe[Math.min(idx, safe.length - 1)].key; + setActiveKey(nextActive); + navigate(nextActive); + } + return safe; + }); + }, + [activeKey, navigate], + ); + + return ( +
+ handleActive('/todo')} + onOpenTemplate={handleSearchOpen} + onOpenSettings={() => setShowSettings(true)} + /> + +
+ setCollapsed((c) => !c)} + /> + +
+ +
+ {/* react-router Outlet 渲染当前路由内容 */} + +
+
+
+ + + + {showSettings ? setShowSettings(false)} /> : null} +
+ ); +} diff --git a/src/shell/GlobalSearch.tsx b/src/shell/GlobalSearch.tsx new file mode 100644 index 0000000..7a18138 --- /dev/null +++ b/src/shell/GlobalSearch.tsx @@ -0,0 +1,72 @@ +// GlobalSearch — 对已加载菜单树叶子做模糊匹配,从原型 frame.jsx 迁移 +import { useEffect, useRef, useState } from 'react'; +import { Icon } from '../components/ui/Icon'; +import type { MenuLeaf } from '../api/menu'; + +interface GlobalSearchProps { + leaves: MenuLeaf[]; + onOpen: (templateId: string) => void; +} + +export function GlobalSearch({ leaves, onOpen }: GlobalSearchProps) { + const [kw, setKw] = useState(''); + const [focus, setFocus] = useState(false); + const ref = useRef(null); + + useEffect(() => { + const h = (e: MouseEvent) => { + if (ref.current && !ref.current.contains(e.target as Node)) setFocus(false); + }; + document.addEventListener('mousedown', h); + return () => document.removeEventListener('mousedown', h); + }, []); + + const hits = kw + ? leaves.filter((m) => m.name.includes(kw) || m.path.includes(kw)).slice(0, 8) + : []; + + return ( +
+ + setFocus(true)} + onChange={(e) => setKw(e.target.value)} + /> + {focus && kw ? ( +
+ {hits.length === 0 ? ( +
+ 未找到「{kw}」相关功能 +
+ ) : ( + hits.map((h) => ( +
{ + onOpen(h.templateId); + setKw(''); + setFocus(false); + }} + > + {h.name} + + {h.path} + +
+ )) + )} +
+ ) : null} +
+ ); +} diff --git a/src/shell/SettingsDrawer.tsx b/src/shell/SettingsDrawer.tsx new file mode 100644 index 0000000..fe6fcc2 --- /dev/null +++ b/src/shell/SettingsDrawer.tsx @@ -0,0 +1,135 @@ +// SettingsDrawer — 品牌色 / 深色模式 / 密度 / 侧栏风格切换,存 localStorage +// 主题设置实时写入 document.documentElement,供 theme.css 变量响应 +import { useEffect, useState } from 'react'; +import { Drawer } from '../components/ui/Dialog'; + +const STORAGE_KEY = 'eip4-theme-settings'; + +// 四选一品牌色 +const BRAND_OPTIONS = ['#2B5CE6', '#0E7A6E', '#C2552B', '#5B4FC9']; + +export interface ThemeSettings { + brand: string; + dark: boolean; + density: 'normal' | 'compact'; + sidebarStyle: 'dark' | 'light'; +} + +const DEFAULTS: ThemeSettings = { + brand: '#2B5CE6', + dark: false, + density: 'normal', + sidebarStyle: 'dark', +}; + +// 加载持久化设置 +function loadSettings(): ThemeSettings { + try { + const raw = localStorage.getItem(STORAGE_KEY); + if (raw) return { ...DEFAULTS, ...(JSON.parse(raw) as Partial) }; + } catch { + // localStorage 不可用时使用默认值 + } + return { ...DEFAULTS }; +} + +// 将设置应用到 data 属性和 CSS 变量 +function applySettings(s: ThemeSettings) { + const r = document.documentElement; + r.style.setProperty('--brand', s.brand); + r.setAttribute('data-dark', s.dark ? '1' : '0'); + r.setAttribute('data-density', s.density); + r.setAttribute('data-sidebar', s.sidebarStyle); +} + +// 导出初始化函数供入口调用(页面刷新后恢复主题) +export function initTheme(): ThemeSettings { + const s = loadSettings(); + applySettings(s); + return s; +} + +interface SettingsDrawerProps { + onClose: () => void; +} + +export function SettingsDrawer({ onClose }: SettingsDrawerProps) { + const [s, setS] = useState(loadSettings); + + // 每次设置变更立即应用并持久化 + useEffect(() => { + applySettings(s); + try { + localStorage.setItem(STORAGE_KEY, JSON.stringify(s)); + } catch { + // 忽略 + } + }, [s]); + + const set = (k: K, v: ThemeSettings[K]) => + setS((prev) => ({ ...prev, [k]: v })); + + return ( + +
+ {/* 品牌色 */} +
+ 品牌色 +
+ {BRAND_OPTIONS.map((c) => ( +
set('brand', c)} + title={c} + /> + ))} +
+
+ + {/* 深色模式 */} +
+ 深色模式 +
+ + {/* 信息密度 */} +
+ 信息密度 +
+ {(['normal', 'compact'] as const).map((v) => ( + + ))} +
+
+ + {/* 侧栏风格 */} +
+ 侧栏风格 +
+ {(['dark', 'light'] as const).map((v) => ( + + ))} +
+
+
+ + ); +} diff --git a/src/shell/SideMenu.tsx b/src/shell/SideMenu.tsx new file mode 100644 index 0000000..b4fa42c --- /dev/null +++ b/src/shell/SideMenu.tsx @@ -0,0 +1,247 @@ +// SideMenu — 三级可折叠侧栏 + 折叠态浮出菜单 +// 从原型 frame.jsx SideMenu 迁移,数据改为从 /api/menu 加载(含 404 降级) +import { useEffect, useRef, useState } from 'react'; +import { Icon } from '../components/ui/Icon'; +import { collectLeaves, fetchMenu } from '../api/menu'; +import type { MenuRoot, MenuItem } from '../api/menu'; + +interface SideMenuProps { + collapsed: boolean; + /** 当前激活的路由路径,如 /page/xxx 或 /todo */ + activePath: string; + /** 点击叶子菜单时回调,传 templateId(或 '__todo__' 代表待办) */ + onOpen: (templateId: string) => void; + onToggle: () => void; +} + +// 判断 menuItem 或其子孙是否在激活路径下 +function containsActive(m: MenuItem | MenuRoot, activePath: string): boolean { + if ('templateId' in m && m.templateId && activePath === `/page/${m.templateId}`) return true; + return (m.children ?? []).some((c) => containsActive(c, activePath)); +} + +// 递归渲染菜单项(展开态) +function RenderItem({ + m, + lv, + open, + activePath, + onOpen, + onToggle, +}: { + m: MenuItem | MenuRoot; + lv: number; + open: Set; + activePath: string; + onOpen: (templateId: string) => void; + onToggle: (id: string) => void; +}) { + const isLeaf = 'templateId' in m && !!m.templateId; + const isGroup = !!(m.children?.length); + const isOn = isLeaf && activePath === `/page/${(m as MenuItem).templateId}`; + const isOpen = open.has(m.id); + const inPath = containsActive(m, activePath); + + const handleClick = () => { + if (isLeaf) { + onOpen((m as MenuItem).templateId!); + } else { + onToggle(m.id); + } + }; + + return ( +
+
+ {lv === 0 ? ( + + ) : ( + + )} + {m.name} + {isGroup ? ( + + + + ) : null} +
+ {isGroup && isOpen + ? (m.children ?? []).map((c) => ( + + )) + : null} +
+ ); +} + +// 根节点取 icon 映射(后端不传 icon,按 id 前缀猜测) +function getMenuIcon(m: MenuRoot): string { + const id = m.id.toUpperCase(); + if (id.includes('MESSAGE') || id.includes('TODO') || id.includes('APPROVE')) return 'todo'; + if (id.includes('PROJ') || id.includes('EQUIP') || id.includes('CONTRACT')) return 'crane'; + if (id.includes('HR') || id.includes('PERSON') || id.includes('STAFF')) return 'team'; + if (id.includes('REPORT') || id.includes('QUERY') || id.includes('STAT')) return 'chart'; + if (id.includes('SYS') || id.includes('PERM') || id.includes('ROLE')) return 'gear'; + if (id.includes('PLATFORM') || id.includes('META') || id.includes('DESIGN')) return 'db'; + if (id.includes('ORG')) return 'org'; + return 'list'; +} + +export function SideMenu({ collapsed, activePath, onOpen, onToggle }: SideMenuProps) { + const [roots, setRoots] = useState([]); + const [loadError, setLoadError] = useState(false); + const [openSet, setOpenSet] = useState>(() => new Set()); + const [flyout, setFlyout] = useState(null); + const flyoutRef = useRef(null); + flyoutRef.current = flyout; + + // 加载菜单,404/失败时降级 + useEffect(() => { + let alive = true; + fetchMenu() + .then((data) => { + if (!alive) return; + setRoots(data.roots ?? []); + setLoadError(false); + // 默认展开第一个根节点 + if (data.roots?.length) { + setOpenSet(new Set([data.roots[0].id])); + } + }) + .catch(() => { + if (alive) setLoadError(true); + }); + return () => { + alive = false; + }; + }, []); + + const toggleGroup = (id: string) => + setOpenSet((s) => { + const x = new Set(s); + x.has(id) ? x.delete(id) : x.add(id); + return x; + }); + + // 折叠态:图标列 + 浮出菜单 + if (collapsed) { + return ( + + ); + } + + // 展开态 + return ( + + ); +} diff --git a/src/shell/TabBar.tsx b/src/shell/TabBar.tsx new file mode 100644 index 0000000..a7b6c7c --- /dev/null +++ b/src/shell/TabBar.tsx @@ -0,0 +1,48 @@ +// TabBar — 多 Tab 页签条,从原型 frame.jsx TabBar 迁移 +import { Icon } from '../components/ui/Icon'; + +export interface Tab { + key: string; // 路由路径,如 /todo 或 /page/xxx + title: string; +} + +interface TabBarProps { + tabs: Tab[]; + activeKey: string; + onActive: (key: string) => void; + onClose: (key: string) => void; +} + +// 「待办」tab 固定显示 todo 图标 +const TODO_PATH = '/todo'; + +export function TabBar({ tabs, activeKey, onActive, onClose }: TabBarProps) { + return ( +
+ {tabs.map((t) => ( +
onActive(t.key)} + > + {t.key === TODO_PATH ? : null} + {t.title} + {/* 待办 tab 不可关闭(保底 tab) */} + {t.key !== TODO_PATH ? ( + { + e.stopPropagation(); + onClose(t.key); + }} + > + + + ) : null} +
+ ))} +
+ ); +} diff --git a/src/shell/Topbar.tsx b/src/shell/Topbar.tsx new file mode 100644 index 0000000..7b05cb6 --- /dev/null +++ b/src/shell/Topbar.tsx @@ -0,0 +1,69 @@ +// Topbar — 顶栏:品牌 + 搜索 + 待办入口 + 用户信息 + 设置入口 +// 从原型 frame.jsx Topbar 迁移,待办 badge 数由父层传入(后续可接真实 API) +import { Icon } from '../components/ui/Icon'; +import { GlobalSearch } from './GlobalSearch'; +import type { MenuLeaf } from '../api/menu'; +import type { UserProfile } from '../auth/token'; + +interface TopbarProps { + leaves: MenuLeaf[]; + profile: UserProfile | null; + todoBadge?: number; + onOpenTodo: () => void; + onOpenTemplate: (templateId: string) => void; + onOpenSettings: () => void; +} + +export function Topbar({ + leaves, + profile, + todoBadge, + onOpenTodo, + onOpenTemplate, + onOpenSettings, +}: TopbarProps) { + // 用户名显示:取 name 首字作头像 + const avatarChar = profile?.name?.[0] ?? '?'; + + return ( +
+ {/* 品牌 */} +
+ E4 + + EIP4{' '} + + 企业管理平台 + + +
+ +
+ + {/* 全局搜索 */} + + + {/* 待办铃铛 */} + + + {/* 设置 */} + + + {/* 用户信息 */} +
+ {avatarChar} + + {profile?.name ?? '未登录'} + {profile?.account ?? ''} + +
+
+ ); +} diff --git a/src/shell/theme.css b/src/shell/theme.css new file mode 100644 index 0000000..92f5d13 --- /dev/null +++ b/src/shell/theme.css @@ -0,0 +1,420 @@ +/* ============================================================================ + EIP4 设计系统 CSS 变量 — 从原型 EIP4 平台原型.html 完整迁移 + 品牌色/文字/背景/线条/圆角/阴影/框架尺寸,支持深色/紧凑/浅色侧栏/思源字体 + ============================================================================ */ + +:root { + /* 品牌色(JS 可覆盖 --brand 实现四选一切换) */ + --brand: #2B5CE6; + --brand-strong: color-mix(in oklch, var(--brand), black 16%); + --brand-soft: color-mix(in srgb, var(--brand), transparent 90%); + --brand-softer: color-mix(in srgb, var(--brand), transparent 95%); + --on-brand: #ffffff; + + /* 功能色 */ + --ok: #1f9e62; + --ok-soft: #e2f5ec; + --warn: #d8860b; + --warn-soft: #faf0dc; + --err: #d1453b; + --err-soft: #fbe9e7; + --info-soft: var(--brand-soft); + + /* 中性色 */ + --bg: #eef0f3; + --surface: #ffffff; + --surface-2: #f6f7f9; + --line: #e2e5ea; + --line-strong: #cdd2d9; + --text: #1c2128; + --text-2: #555c66; + --text-3: #8b929c; + + /* 侧栏色(深色默认) */ + --sidebar-bg: #1b2330; + --sidebar-text: #aeb6c2; + --sidebar-text-active: #ffffff; + + /* 顶栏色 */ + --topbar-bg: var(--surface); + + /* 字体 */ + --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif; + --font-num: "SF Pro Text", -apple-system, var(--font); + + /* 字号 */ + --fs: 14px; + --fs-sm: 12.5px; + --fs-lg: 16px; + + /* 控件/行高 */ + --ctl-h: 34px; + --row-h: 42px; + + /* 间距 */ + --pad: 16px; + --pad-lg: 20px; + + /* 圆角 */ + --radius: 6px; + --radius-lg: 10px; + + /* 阴影 */ + --shadow-1: 0 1px 2px rgba(28,33,40,.05), 0 1px 6px rgba(28,33,40,.04); + --shadow-2: 0 4px 14px rgba(28,33,40,.10), 0 1px 4px rgba(28,33,40,.06); + --shadow-3: 0 12px 40px rgba(28,33,40,.18); + + /* 框架尺寸 */ + --topbar-h: 50px; + --tabbar-h: 38px; + --sidebar-w: 216px; + --sidebar-w-min: 56px; +} + +/* 紧凑密度 */ +[data-density="compact"] { + --fs: 13px; + --fs-sm: 12px; + --fs-lg: 15px; + --ctl-h: 28px; + --row-h: 34px; + --pad: 12px; + --pad-lg: 16px; + --tabbar-h: 34px; + --topbar-h: 46px; +} + +/* 浅色侧栏 */ +[data-sidebar="light"] { + --sidebar-bg: #ffffff; + --sidebar-text: #555c66; + --sidebar-text-active: var(--brand); +} + +/* 深色模式 */ +[data-dark="1"] { + --bg: #15181d; + --surface: #1e232b; + --surface-2: #262c36; + --line: #323945; + --line-strong: #424b59; + --text: #e8eaee; + --text-2: #a3aab5; + --text-3: #6d7480; + --sidebar-bg: #181d25; + --sidebar-text: #9099a6; + --sidebar-text-active: #ffffff; + --ok-soft: #18352a; + --warn-soft: #3a2e15; + --err-soft: #3c211f; + --shadow-1: 0 1px 2px rgba(0,0,0,.3); + --shadow-2: 0 4px 14px rgba(0,0,0,.4); + --shadow-3: 0 12px 40px rgba(0,0,0,.55); +} +[data-dark="1"][data-sidebar="light"] { + --sidebar-bg: #1e232b; + --sidebar-text: #a3aab5; + --sidebar-text-active: #fff; +} + +/* 思源字体 */ +[data-font="noto"] { + --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif; +} + +/* ============================================================================ + 基础重置 + ============================================================================ */ +*, *::before, *::after { box-sizing: border-box; } + +body { + font-family: var(--font); + font-size: var(--fs); + color: var(--text); + background: var(--bg); + overflow: hidden; + margin: 0; +} + +/* 滚动条 */ +::-webkit-scrollbar { width: 6px; height: 6px; } +::-webkit-scrollbar-track { background: transparent; } +::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; } + +/* ============================================================================ + 通用工具类(全局可用) + ============================================================================ */ + +/* 按钮 */ +.btn { + display: inline-flex; align-items: center; justify-content: center; gap: 5px; + height: var(--ctl-h); padding: 0 14px; border-radius: var(--radius); + border: 1px solid var(--line-strong); background: var(--surface); + color: var(--text); font-size: var(--fs); cursor: pointer; white-space: nowrap; + transition: all .12s; font-family: inherit; +} +.btn:hover { border-color: var(--brand); color: var(--brand); } +.btn:disabled { opacity: .5; cursor: not-allowed; } +.btn-pri { background: var(--brand); border-color: var(--brand); color: var(--on-brand); } +.btn-pri:hover { background: var(--brand-strong); border-color: var(--brand-strong); color: var(--on-brand); } +.btn-danger-ghost { color: var(--err); border-color: color-mix(in srgb, var(--err), transparent 55%); } +.btn-danger-ghost:hover { background: var(--err-soft); border-color: var(--err); color: var(--err); } +.btn-text { border-color: transparent; background: transparent; color: var(--brand); padding: 0 6px; height: auto; } +.btn-sm { height: calc(var(--ctl-h) - 8px); padding: 0 10px; font-size: var(--fs-sm); } + +/* 输入框 */ +.input, +.select-like { + height: var(--ctl-h); padding: 0 10px; border: 1px solid var(--line-strong); + border-radius: var(--radius); background: var(--surface); color: var(--text); + font-size: var(--fs); font-family: inherit; outline: none; min-width: 0; + transition: border-color .12s, box-shadow .12s; +} +.input:focus, +.select-like:focus-within { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); } +.input::placeholder { color: var(--text-3); } +.select-like { display: flex; align-items: center; justify-content: space-between; cursor: pointer; } +.select-like .ph { color: var(--text-3); } + +/* 标签 */ +.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 4px; font-size: var(--fs-sm); white-space: nowrap; } +.tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; } +.tag-ok { background: var(--ok-soft); color: var(--ok); } +.tag-warn { background: var(--warn-soft); color: var(--warn); } +.tag-err { background: var(--err-soft); color: var(--err); } +.tag-info { background: var(--brand-soft); color: var(--brand); } +.tag-gray { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); } + +/* 卡片 */ +.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); } + +/* 表格 */ +.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); } +table.tbl { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--fs); } +.tbl th, .tbl td { height: var(--row-h); padding: 0 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; } +.tbl th { background: var(--surface-2); color: var(--text-2); font-weight: 500; font-size: var(--fs-sm); position: sticky; top: 0; z-index: 2; user-select: none; } +.tbl tbody tr:hover td { background: var(--brand-softer); } +.tbl tbody tr.sel td { background: var(--brand-soft); } +.cb { width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; } + +/* 表单字段 */ +.field { display: flex; flex-direction: column; gap: 4px; } +.field > label { font-size: var(--fs-sm); color: var(--text-2); } +.field > label .req { color: var(--err); margin-right: 2px; } +.field .err-msg { font-size: var(--fs-sm); color: var(--err); } +.field.has-err .input { border-color: var(--err); } +.field.span2 { grid-column: span 2; } + +/* 弹层公共 */ +.mask { + position: fixed; inset: 0; background: rgba(0,0,0,.35); + display: flex; align-items: center; justify-content: center; z-index: 200; +} +.dlg { + background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); + display: flex; flex-direction: column; max-height: 86vh; + animation: popIn .18s cubic-bezier(.2,.9,.3,1.2); min-width: 420px; +} +@keyframes popIn { + from { opacity: 0; transform: scale(.92); } + to { opacity: 1; transform: scale(1); } +} +.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px var(--pad-lg); border-bottom: 1px solid var(--line); } +.dlg-head h3 { font-size: var(--fs-lg); font-weight: 600; margin: 0; } +.dlg-body { padding: var(--pad-lg); overflow: auto; } +.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px var(--pad-lg); border-top: 1px solid var(--line); } +.x-btn { width: 28px; height: 28px; border: none; background: transparent; border-radius: 6px; cursor: pointer; color: var(--text-3); display: flex; align-items: center; justify-content: center; } +.x-btn:hover { background: var(--surface-2); color: var(--text); } + +/* 抽屉 */ +.drawer { + background: var(--surface); box-shadow: var(--shadow-3); z-index: 200; + display: flex; flex-direction: column; + animation: slideIn .2s cubic-bezier(.2,.9,.3,1); +} +@keyframes slideIn { + from { transform: translateX(100%); } + to { transform: translateX(0); } +} + +/* Toast */ +.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; pointer-events: none; } +.toast { + display: flex; align-items: center; gap: 8px; + background: var(--surface); border: 1px solid var(--line); + box-shadow: var(--shadow-2); border-radius: 8px; padding: 9px 16px; + font-size: var(--fs); + animation: toastIn .25s cubic-bezier(.2,.9,.3,1.3); +} +@keyframes toastIn { + from { opacity: 0; transform: translateY(12px) scale(.95); } + to { opacity: 1; transform: translateY(0) scale(1); } +} + +/* 分页 */ +.pagination { display: flex; align-items: center; gap: 6px; justify-content: flex-end; font-size: var(--fs-sm); color: var(--text-2); } +.pg-btn { min-width: 26px; height: 26px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--surface); color: var(--text-2); cursor: pointer; font-size: var(--fs-sm); font-family: inherit; } +.pg-btn:hover { border-color: var(--brand); color: var(--brand); } +.pg-btn.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); } +.pg-btn:disabled { opacity: .4; cursor: not-allowed; } + +/* 树节点 */ +.tree-node { display: flex; align-items: center; gap: 6px; height: calc(var(--ctl-h) - 2px); padding: 0 8px; border-radius: var(--radius); cursor: pointer; color: var(--text-2); white-space: nowrap; } +.tree-node:hover { background: var(--surface-2); color: var(--text); } +.tree-node.on { background: var(--brand-soft); color: var(--brand); font-weight: 500; } +.tree-toggle { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; color: var(--text-3); flex: 0 0 auto; transition: transform .15s; } +.tree-toggle.open { transform: rotate(90deg); } + +/* 辅助 */ +.muted { color: var(--text-3); } +.sub-text { color: var(--text-2); font-size: var(--fs-sm); } +.link { color: var(--brand); cursor: pointer; } +.link:hover { text-decoration: underline; } +.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex: 0 0 auto; } +.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 0; color: var(--text-3); font-size: var(--fs-sm); } +.hr { border: none; border-top: 1px solid var(--line); margin: var(--pad) 0; } + +/* ============================================================================ + 壳层布局 + ============================================================================ */ + +/* 应用根 */ +.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; } + +/* 顶栏 */ +.topbar { + height: var(--topbar-h); background: var(--topbar-bg); + border-bottom: 1px solid var(--line); + display: flex; align-items: center; gap: 14px; + padding: 0 16px; flex: 0 0 auto; z-index: 60; +} +.brand { display: flex; align-items: center; gap: 9px; cursor: pointer; text-decoration: none; color: inherit; } +.brand-mark { + width: 28px; height: 28px; border-radius: 7px; + background: var(--brand); color: var(--on-brand); + display: flex; align-items: center; justify-content: center; + font-weight: 700; font-size: 13px; letter-spacing: -.5px; +} +.brand-name { font-weight: 600; font-size: var(--fs); white-space: nowrap; } +.tb-icon { + position: relative; width: 34px; height: 34px; border: none; + background: transparent; border-radius: 8px; color: var(--text-2); + cursor: pointer; display: flex; align-items: center; justify-content: center; +} +.tb-icon:hover { background: var(--surface-2); color: var(--text); } +.tb-badge { + position: absolute; top: 2px; right: 0; min-width: 16px; height: 16px; + padding: 0 4px; border-radius: 8px; background: var(--err); color: #fff; + font-size: 10px; font-weight: 600; display: flex; align-items: center; justify-content: center; +} +.tb-user { display: flex; align-items: center; gap: 8px; padding-left: 10px; border-left: 1px solid var(--line); white-space: nowrap; cursor: pointer; } +.tb-user-name { display: flex; flex-direction: column; line-height: 1.25; font-size: var(--fs-sm); } + +/* 全局搜索 */ +.gsearch { + position: relative; display: flex; align-items: center; gap: 7px; + width: 240px; height: 32px; padding: 0 10px; + background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; +} +.gsearch:focus-within { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 2px var(--brand-soft); } +.gsearch input { border: none; outline: none; background: transparent; flex: 1; min-width: 0; font-size: var(--fs-sm); color: var(--text); font-family: inherit; } +.gsearch-drop { + position: absolute; top: calc(100% + 6px); left: 0; width: 300px; + z-index: 80; padding: 4px; box-shadow: var(--shadow-2); + max-height: 320px; overflow: auto; +} + +/* 主区域(侧栏 + 工作区) */ +.app-main { display: flex; flex: 1 1 0; overflow: hidden; } + +/* 侧栏 */ +.sidebar { + width: var(--sidebar-w); background: var(--sidebar-bg); + display: flex; flex-direction: column; flex: 0 0 auto; + transition: width .18s; border-right: 1px solid var(--line); + overflow: hidden; +} +.sidebar.collapsed { width: var(--sidebar-w-min); } +.sm-list { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 6px 0; } +.sm-item { + display: flex; align-items: center; gap: 9px; height: 36px; + padding-right: 10px; border-radius: 7px; color: var(--sidebar-text); + cursor: pointer; font-size: var(--fs); white-space: nowrap; user-select: none; +} +.sm-item:hover { background: color-mix(in srgb, var(--sidebar-text), transparent 90%); color: var(--sidebar-text-active); } +.sm-item.on { background: var(--brand); color: #fff; font-weight: 500; } +[data-sidebar="light"] .sm-item.on { background: var(--brand-soft); color: var(--brand); } +.sm-item.in-path { color: var(--sidebar-text-active); } +.sm-item.icon-only { justify-content: center; padding: 0; height: 40px; width: 44px; } +.sm-name { flex: 1; overflow: hidden; text-overflow: ellipsis; } +.sm-badge { min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--err); color: #fff; font-size: 10.5px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; } +.sm-badge.mini { width: 7px; height: 7px; min-width: 0; padding: 0; border-radius: 50%; position: absolute; top: 4px; right: 4px; } +.sm-flyout { + position: absolute; left: calc(100% + 6px); top: 0; min-width: 180px; + z-index: 90; padding: 4px; box-shadow: var(--shadow-2); +} +.sm-flyout-title { padding: 7px 10px 5px; font-size: 11px; color: var(--text-3); } +.sm-collapse { + display: flex; align-items: center; justify-content: center; gap: 7px; + height: 40px; margin: 8px; border: none; border-radius: 7px; + background: transparent; color: var(--sidebar-text); cursor: pointer; font-size: var(--fs-sm); + font-family: inherit; +} +.sm-collapse:hover { background: color-mix(in srgb, var(--sidebar-text), transparent 90%); color: var(--sidebar-text-active); } + +/* 工作区(Tab条 + 内容) */ +.app-work { display: flex; flex-direction: column; flex: 1 1 0; overflow: hidden; } + +/* Tab 条 */ +.tabbar { + height: var(--tabbar-h); display: flex; align-items: flex-end; gap: 3px; + padding: 0 10px; background: var(--surface); border-bottom: 1px solid var(--line); + overflow-x: auto; flex: 0 0 auto; +} +.wtab { + display: flex; align-items: center; gap: 6px; + height: calc(var(--tabbar-h) - 6px); padding: 0 12px; + border-radius: 7px 7px 0 0; border: 1px solid transparent; border-bottom: none; + color: var(--text-2); font-size: var(--fs-sm); cursor: pointer; white-space: nowrap; + user-select: none; background: transparent; +} +.wtab:hover { background: var(--surface-2); color: var(--text); } +.wtab.on { + background: var(--bg); border-color: var(--line); color: var(--text); + font-weight: 500; position: relative; +} +.wtab.on::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--bg); } +.wtab.on::before { content: ''; position: absolute; left: 10px; right: 10px; top: 0; height: 2px; border-radius: 0 0 2px 2px; background: var(--brand); } +.wtab-x { display: flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 4px; color: var(--text-3); } +.wtab-x:hover { background: var(--line); color: var(--text); } + +/* 内容区 */ +.app-pages { flex: 1 1 0; overflow: auto; background: var(--bg); } + +/* SettingsDrawer 面板 */ +.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); } +.settings-row:last-child { border-bottom: none; } +.settings-label { font-size: var(--fs-sm); color: var(--text-2); } +.color-swatches { display: flex; gap: 6px; } +.color-swatch { + width: 22px; height: 22px; border-radius: 50%; cursor: pointer; + border: 2px solid transparent; transition: transform .1s; +} +.color-swatch.active { border-color: var(--text); transform: scale(1.15); } +.toggle-btn { + width: 40px; height: 22px; border-radius: 11px; border: none; cursor: pointer; + background: var(--line-strong); position: relative; transition: background .15s; +} +.toggle-btn.on { background: var(--brand); } +.toggle-btn::after { + content: ''; position: absolute; top: 3px; left: 3px; + width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; +} +.toggle-btn.on::after { transform: translateX(18px); } +.radio-group { display: flex; gap: 6px; } +.radio-option { + padding: 3px 10px; border-radius: 5px; border: 1px solid var(--line-strong); + background: var(--surface); color: var(--text-2); font-size: var(--fs-sm); + cursor: pointer; transition: all .12s; font-family: inherit; +} +.radio-option.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 500; }