This commit is contained in:
2026-11-19 10:09:33 +08:00
parent d31f5a701c
commit d2013c2a07
181 changed files with 47968 additions and 4 deletions
@@ -0,0 +1,69 @@
import { createContext, useContext, useRef, type ReactNode } from 'react';
import { Pause, Play } from 'lucide-react';
import { useTheme } from '../../context/ThemeContext';
import { useAutoScroll } from '../../hooks/useAutoScroll';
/**
* 左右工作区列表的自动滚动开关。
* 用 context 下发而不是逐层传 prop:一份弧板里挂着好几个页签
* (左:销售订单 / 客户资料;右:采购单 / 生产工单 / 供应商资料),
* 开关属于「这块面板」而不是某个列表,页签组件本身不该关心它。
*/
const AutoScrollCtx = createContext(false);
export const AutoScrollProvider = AutoScrollCtx.Provider;
/** 当前面板是否开启自动滚动;ScrollList 用它决定是否挂滚动循环 */
export const useAutoScrollEnabled = () => useContext(AutoScrollCtx);
interface ToggleProps {
on: boolean;
onToggle: () => void;
/** 收起态宽度只够一个图标,文字标签在展开态才出现 */
expanded?: boolean;
}
/** 面板标题栏的自动滚动开关按钮:开=可点击关闭,关=可点击开启 */
export function AutoScrollToggle({ on, onToggle, expanded = true }: ToggleProps) {
const { tokens } = useTheme();
const c = on ? tokens.accent : tokens.textMuted;
return (
<button
onClick={onToggle}
aria-pressed={on}
title={on ? '列表自动滚动中,点击关闭' : '自动滚动已关闭,点击开启'}
className="ghost-btn"
style={{
display: 'flex', alignItems: 'center', gap: 4, flexShrink: 0,
height: 22, padding: expanded ? '0 7px 0 5px' : '0 5px', borderRadius: 6, cursor: 'pointer',
fontSize: 11, fontWeight: 600, whiteSpace: 'nowrap',
color: c, background: on ? tokens.accentBg : 'transparent',
border: `1px solid ${on ? tokens.borderAccent : tokens.border}`,
}}
>
{on ? <Pause size={12} /> : <Play size={12} />}
{expanded && <span>{on ? '自动滚动' : '已暂停'}</span>}
</button>
);
}
/**
* 面板内带自动滚动的列表容器:样式同 PanelBody,差别是它挂了滚动循环。
* 开关默认跟随所在面板的 AutoScrollProvider,也可以显式传 autoScroll 覆盖。
*/
export function ScrollList({ children, autoScroll }: { children: ReactNode; autoScroll?: boolean }) {
const ctx = useAutoScrollEnabled();
const enabled = autoScroll ?? ctx;
const ref = useRef<HTMLDivElement>(null);
useAutoScroll(ref, enabled);
return (
<div
ref={ref}
className="space-scroll"
data-autoscroll={enabled ? 'on' : 'off'}
style={{ flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden', padding: '0 0 10px 0' }}
>
{children}
</div>
);
}
@@ -0,0 +1,104 @@
import type { ReactNode } from 'react';
import {
Activity, AlertTriangle, BarChart3, BookOpen, Boxes, ClipboardList, Database, FileDown, FileText,
FlaskConical, GanttChart, Gauge, ListChecks, ListOrdered, Network, PieChart, Plug, Settings2, Sparkles, Workflow,
} from 'lucide-react';
import { useTheme } from '../../context/ThemeContext';
import { useText } from '../../i18n/useText';
export type TabKey = 'detail' | 'trend' | 'structure' | 'region' | 'risk' | 'cockpit' | 'priority' | 'entry' | 'task' | 'master' | 'caliber' | 'integration' | 'disclosure' | 'forecast' | 'linemap' | 'report';
export type StageKey = 'know' | 'feat' | 'ont' | 'data';
const GROUPS: { title: string; tabs: TabKey[] }[] = [
{ title: '运营监控', tabs: ['cockpit', 'linemap', 'detail', 'trend'] },
{ title: '分析诊断', tabs: ['structure', 'region', 'risk', 'forecast'] },
{ title: '改善闭环', tabs: ['priority', 'entry', 'task'] },
{ title: '运维配置', tabs: ['master', 'caliber', 'integration', 'report', 'disclosure'] },
];
const TAB_ICON: Record<TabKey, typeof Gauge> = {
cockpit: Gauge, linemap: Workflow, detail: GanttChart, trend: Activity,
structure: PieChart, region: BarChart3, risk: AlertTriangle, forecast: Sparkles,
priority: ListOrdered, entry: ClipboardList, task: ListChecks,
master: Database, caliber: Settings2, integration: Plug, report: FileDown, disclosure: FileText,
};
const STAGES: { key: StageKey; label: string; icon: typeof Gauge; tip: string }[] = [
{ key: 'know', label: '知识库', icon: BookOpen, tip: '查看 PE/IE/QE/ME 角色标准文件及其向量化 / 图谱化结果' },
{ key: 'feat', label: '工艺建模', icon: FlaskConical, tip: '查看 OEE 本体特征范围:设备/事件/状态段/损失四类对象的实例、关系与规则' },
{ key: 'ont', label: '业务本体', icon: Boxes, tip: '查看业务对象、关系、规则与动作(实时统计)' },
{ key: 'data', label: '数据集总览', icon: Network, tip: '四层 27 张表 · 本机 PostgreSQL 实况' },
];
interface Props {
tab: TabKey;
stage: StageKey | null;
onTab: (k: TabKey) => void;
onStage: (k: StageKey) => void;
}
export default function LeftNav({ tab, stage, onTab, onStage }: Props) {
const { tokens } = useTheme();
const { t } = useText();
const item = (key: string, label: string, Icon: typeof Gauge, on: boolean, onClick: () => void, tip?: string): ReactNode => (
<button
key={key}
onClick={onClick}
title={tip}
data-role={`nav-${key}`}
aria-current={on ? 'page' : undefined}
className="ghost-btn"
style={{
position: 'relative', display: 'flex', alignItems: 'center', gap: 9, width: '100%',
padding: '6px 10px 6px 12px', borderRadius: 9, cursor: 'pointer', textAlign: 'left',
fontSize: 13, fontWeight: on ? 700 : 500, whiteSpace: 'nowrap',
color: on ? tokens.accent : tokens.textSub,
background: on ? tokens.accentBg : 'transparent',
border: `1px solid ${on ? tokens.borderAccent : 'transparent'}`,
transition: 'background .18s ease, color .18s ease',
}}
>
{on && <span style={{ position: 'absolute', left: 0, top: 7, bottom: 7, width: 3, borderRadius: 2, background: tokens.accent }} />}
<Icon size={15} style={{ flexShrink: 0 }} />
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{label}</span>
</button>
);
const heading = (title: string, first = false) => (
<>
{!first && <div style={{ height: 1, background: tokens.border, margin: '8px 6px 0' }} />}
<div style={{
display: 'flex', alignItems: 'center', gap: 7,
fontSize: 13, fontWeight: 800, color: tokens.text, letterSpacing: '0.08em',
padding: first ? '8px 10px 5px' : '10px 10px 5px',
}}>
<span style={{ width: 3, height: 13, borderRadius: 2, background: tokens.accent, flexShrink: 0 }} />
{title}
</div>
</>
);
return (
<nav
data-role="left-nav"
className="space-scroll round-scroll"
style={{
flex: '0 0 208px', minHeight: 0, overflowY: 'auto', padding: '6px 8px 10px',
borderRadius: 16, border: `1px solid ${tokens.borderAccent}`,
background: tokens.centerBg, boxShadow: tokens.centerShadow,
backdropFilter: 'blur(10px) saturate(1.3)',
display: 'flex', flexDirection: 'column', gap: 1,
}}
>
{GROUPS.map((g, gi) => (
<div key={g.title} style={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
{heading(g.title, gi === 0)}
{g.tabs.map(k => item(k, t.tab[k], TAB_ICON[k], stage === null && tab === k, () => onTab(k)))}
</div>
))}
{heading('建模配置')}
{STAGES.map(s => item(`stage-${s.key}`, s.label, s.icon, stage === s.key, () => onStage(s.key), s.tip))}
</nav>
);
}
@@ -0,0 +1,141 @@
import { forwardRef, type ReactNode } from 'react';
import { ChevronsLeft, ChevronsRight } from 'lucide-react';
import { useTheme } from '../../context/ThemeContext';
/** 侧板外凸弧线的水平位移(与参考实现一致的"太空舱"侧板语法) */
const BULGE = 28;
interface PanelShellProps {
side: 'left' | 'right';
expanded: boolean;
onToggle: () => void;
widthCollapsed?: number;
widthExpanded?: number;
icon?: ReactNode;
title: string;
badge?: ReactNode;
extra?: ReactNode;
/** 独占一行的分段切换,避免与标题争抢标题行宽度 */
tabs?: ReactNode;
hint?: string;
children: ReactNode;
animClass?: string;
}
export default function PanelShell({
side, expanded, onToggle, widthCollapsed = 268, widthExpanded = 452,
icon, title, badge, extra, tabs, hint, children, animClass,
}: PanelShellProps) {
const { tokens } = useTheme();
const W = expanded ? widthExpanded : widthCollapsed;
const totalW = W + BULGE;
const gid = `mec-pnl-${side}`;
const left = side === 'left';
const path = left
? `M 0,0 L ${W - 70},0 Q ${W},0 ${W},80 C ${W + BULGE},2000 ${W + BULGE},8000 ${W},9920 L 0,10000 Z`
: `M ${totalW},0 L ${BULGE + 70},0 Q ${BULGE},0 ${BULGE},80 C 0,2000 0,8000 ${BULGE},9920 L ${totalW},10000 Z`;
return (
<div
className={`panel-shell ${animClass ?? ''}`}
style={{
position: 'relative', width: totalW, height: '100%', flex: '0 0 auto',
transition: 'width 0.3s cubic-bezier(0.4,0,0.2,1)',
}}
>
<svg
viewBox={`0 0 ${totalW} 10000`}
preserveAspectRatio="none"
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', overflow: 'visible' }}
>
<defs>
<linearGradient id={gid} x1={left ? '0' : '1'} y1="0" x2={left ? '1' : '0'} y2="1">
<stop offset="0%" stopColor={tokens.svgPanelFrom} />
<stop offset="100%" stopColor={tokens.svgPanelTo} />
</linearGradient>
</defs>
<path d={path} fill={`url(#${gid})`} />
<path d={path} fill="none" stroke={tokens.svgStroke} strokeWidth={6} opacity={0.18} />
<path d={path} fill="none" stroke={tokens.svgStroke} strokeWidth={1} />
<circle cx={left ? W : BULGE} cy={80} r={3.5} fill={tokens.svgDot} />
<circle cx={left ? W : BULGE} cy={9920} r={3.5} fill={tokens.svgDot} />
</svg>
{/* 内容层压在弧板之上,宽度不超过直边区域 */}
<div
style={{
position: 'absolute', top: 0, bottom: 0,
[left ? 'left' : 'right']: 0,
width: W,
display: 'flex', flexDirection: 'column', minHeight: 0,
padding: left ? '10px 24px 8px 14px' : '10px 14px 8px 24px',
backdropFilter: 'blur(14px)', WebkitBackdropFilter: 'blur(14px)',
} as React.CSSProperties}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, height: 30, flex: '0 0 auto' }}>
<span style={{ width: 3, height: 16, borderRadius: 2, background: tokens.accent, flex: '0 0 auto' }} />
{icon && <span style={{ display: 'flex', color: tokens.accent }}>{icon}</span>}
<span style={{
fontSize: 15, fontWeight: 700, color: tokens.text, letterSpacing: '0.02em',
whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
flex: '0 1 auto', minWidth: 0,
}}>{title}</span>
{badge}
<span style={{ flex: 1 }} />
{extra}
<button
onClick={onToggle}
className="ghost-btn"
style={{
display: 'flex', alignItems: 'center', justifyContent: 'center',
width: 22, height: 22, borderRadius: 5, cursor: 'pointer', flexShrink: 0,
color: tokens.textMuted, border: `1px solid ${tokens.border}`,
}}
>
{expanded
? (left ? <ChevronsLeft size={13} /> : <ChevronsRight size={13} />)
: (left ? <ChevronsRight size={13} /> : <ChevronsLeft size={13} />)}
</button>
</div>
{tabs && (
<div style={{ display: 'flex', gap: 4, flex: '0 0 auto', marginBottom: 8 }}>{tabs}</div>
)}
{hint && (
<div style={{ fontSize: 12.5, color: tokens.textMuted, marginBottom: 7, lineHeight: 1.45 }}>
{hint}
</div>
)}
<div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
{children}
</div>
</div>
</div>
);
}
/** 面板内统一的滚动容器;ref 外放,供调用方实现自动滚动等滚动控制 */
export const PanelBody = forwardRef<HTMLDivElement, { children: ReactNode; pad?: string }>(
function PanelBody({ children, pad = '0 0 10px 0' }, ref) {
return (
<div ref={ref} className="space-scroll" style={{ flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden', padding: pad }}>
{children}
</div>
);
},
);
/** 标题栏数量徽标 */
export function CountBadge({ n, color }: { n: number | string; color?: string }) {
const { tokens } = useTheme();
return (
<span style={{
fontSize: 12, fontWeight: 700, padding: '1px 8px', borderRadius: 10,
background: `${color ?? tokens.accent}22`, color: color ?? tokens.accent,
border: `1px solid ${color ?? tokens.accent}33`, lineHeight: '16px',
}}>{n}</span>
);
}