Files
qlib/frontend/web/components/app-shell.tsx
T
Simon 0ab9038570 feat(web): M6.5 股票筛选页(/selection)—— 评分/条件双模式 + 当前/历史选股
- app/selection/page.tsx:因子评分(多因子+权重+TopN)与条件模式(结构化条件行
  编辑:static.*/因子/close>ma60/ROE 等,AND 语义);as_of 留空=最近交易日;
  结果表(rank/symbol/score/因子值/入选理由)+ 最近选股记录点击回看
- lib/types.ts:SelectionQuery/Condition/Candidate/Result/Meta/Run DTO
- app-shell 导航加入「股票筛选」;rail 脚注与 Dashboard 文案 SQLite→MySQL(M-DB 收尾)
- 端到端验证:真实 MySQL 上 POST /api/selections 返回候选并落库可读回;
  /selection 页面 200;后端全量 pytest + 前端 tsc --noEmit 通过
2026-09-09 00:25:27 +08:00

148 lines
4.1 KiB
TypeScript

"use client";
/** 应用外壳:桌面左侧导航栏 + 窄屏顶栏与抽屉(usePathname 高亮当前页)。 */
import { useEffect, useState } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Icon, type IconName } from "@/components/icons";
interface NavItem {
href: string;
label: string;
icon: IconName;
}
const GROUPS: { title: string; items: NavItem[] }[] = [
{
title: "研究",
items: [
{ href: "/", label: "总览", icon: "grid" },
{ href: "/stocks", label: "股票池", icon: "candles" },
{ href: "/selection", label: "股票筛选", icon: "target" },
{ href: "/factors", label: "因子研究", icon: "flask" },
{ href: "/factors/compose", label: "因子组合", icon: "layers" },
{ href: "/backtest", label: "选股回测", icon: "gauge" },
],
},
{
title: "归档",
items: [{ href: "/experiments", label: "实验", icon: "archive" }],
},
];
function isActive(href: string, pathname: string): boolean {
if (href === "/") return pathname === "/";
if (href === "/factors") return pathname === "/factors";
if (pathname === href || pathname.startsWith(href + "/")) return true;
return false;
}
function Brand() {
return (
<Link href="/" className="brand" style={{ textDecoration: "none" }}>
<span className="logo">
<Icon name="logo" size={18} />
</span>
<span>
qlib-platform
<small>个人 A 股量化研究台</small>
</span>
</Link>
);
}
function NavLinks({ pathname, onNavigate }: { pathname: string; onNavigate?: () => void }) {
return (
<>
{GROUPS.map((g) => (
<div key={g.title}>
<div className="nav-label">{g.title}</div>
{g.items.map((item) => {
const active = isActive(item.href, pathname);
return (
<Link
key={item.href}
href={item.href}
className={active ? "nav-link active" : "nav-link"}
aria-current={active ? "page" : undefined}
onClick={onNavigate}
>
<span className="nav-ic">
<Icon name={item.icon} size={17} />
</span>
{item.label}
</Link>
);
})}
</div>
))}
</>
);
}
export function AppShell({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const [open, setOpen] = useState(false);
// 路由变化时收起抽屉
useEffect(() => {
setOpen(false);
}, [pathname]);
useEffect(() => {
if (!open) return;
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") setOpen(false);
};
window.addEventListener("keydown", onKey);
document.body.style.overflow = "hidden";
return () => {
window.removeEventListener("keydown", onKey);
document.body.style.overflow = "";
};
}, [open]);
return (
<div className="shell">
<aside className="rail nav" aria-label="主导航">
<Brand />
<NavLinks pathname={pathname} />
<div className="rail-foot">
数据源 Tushare 首选 · 新浪校验兜底
<br />
数据库 MySQL · 研究引擎 Qlib
</div>
</aside>
<div className="topbar">
<button
type="button"
className="icon-btn"
aria-label="打开导航菜单"
aria-expanded={open}
onClick={() => setOpen(true)}
style={{ width: 36, height: 36 }}
>
<Icon name="filter" size={18} />
</button>
<Brand />
</div>
{open ? (
<div className="scrim show" aria-hidden="true" onClick={() => setOpen(false)} />
) : null}
<aside
className={open ? "drawer nav open" : "drawer nav"}
aria-label="移动端导航"
aria-hidden={!open}
>
{open ? <NavLinks pathname={pathname} onNavigate={() => setOpen(false)} /> : null}
</aside>
<main className="content">
<div className="page">{children}</div>
</main>
</div>
);
}