F1-2: 迁移 claude-design 原型壳层到 eip4-web
新增 src/shell/(AppShell/Topbar/SideMenu/TabBar/GlobalSearch/SettingsDrawer/theme.css) 和 src/components/ui/(Icon/Dialog/Drawer/Toast/Pagination), src/api/menu.ts 含 GET /api/menu + 404 降级; App.tsx 路由改为 AppShell <Outlet> 包裹,登录/待办/amis 渲染三页功能保持不变。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
65
src/components/ui/Dialog.tsx
Normal file
65
src/components/ui/Dialog.tsx
Normal file
@@ -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<HTMLDivElement>) => {
|
||||
if (e.target === e.currentTarget) onClose();
|
||||
};
|
||||
return (
|
||||
<div className="mask" onMouseDown={handleMask}>
|
||||
<div className="dlg" style={{ width }}>
|
||||
<div className="dlg-head">
|
||||
<h3>{title}</h3>
|
||||
<button className="x-btn" onClick={onClose}>
|
||||
<Icon name="x" size={14} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="dlg-body">{children}</div>
|
||||
{foot ? <div className="dlg-foot">{foot}</div> : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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<HTMLDivElement>) => {
|
||||
if (e.target === e.currentTarget) onClose();
|
||||
};
|
||||
return (
|
||||
<div
|
||||
className="mask"
|
||||
style={{ justifyContent: 'flex-end', alignItems: 'stretch' }}
|
||||
onMouseDown={handleMask}
|
||||
>
|
||||
<div className="drawer" style={{ width, position: 'relative' }}>
|
||||
<div className="dlg-head">
|
||||
<h3>{title}</h3>
|
||||
<button className="x-btn" onClick={onClose}>
|
||||
<Icon name="x" size={14} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="dlg-body" style={{ flex: 1 }}>
|
||||
{children}
|
||||
</div>
|
||||
{foot ? <div className="dlg-foot">{foot}</div> : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
69
src/components/ui/Icon.tsx
Normal file
69
src/components/ui/Icon.tsx
Normal file
@@ -0,0 +1,69 @@
|
||||
// EIP4 线性图标集(16px 基准,29 种图标)— 从原型 ui.jsx 迁移
|
||||
import type { CSSProperties } from 'react';
|
||||
|
||||
const ICON_PATHS: Record<string, string> = {
|
||||
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 (
|
||||
<svg
|
||||
className={className}
|
||||
style={style}
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={sw}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d={ICON_PATHS[name] ?? ICON_PATHS.list} />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
53
src/components/ui/Pagination.tsx
Normal file
53
src/components/ui/Pagination.tsx
Normal file
@@ -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 (
|
||||
<div className="pagination">
|
||||
<span>共 {total.toLocaleString()} 条</span>
|
||||
<button className="pg-btn" disabled={page <= 1} onClick={() => onPage(page - 1)}>
|
||||
‹
|
||||
</button>
|
||||
{nums.map((n, i) =>
|
||||
n === '…' ? (
|
||||
<span key={'e' + i} style={{ padding: '0 2px' }}>
|
||||
…
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
key={n}
|
||||
className={'pg-btn' + (n === page ? ' on' : '')}
|
||||
onClick={() => onPage(n)}
|
||||
>
|
||||
{n}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
<button className="pg-btn" disabled={page >= pages} onClick={() => onPage(page + 1)}>
|
||||
›
|
||||
</button>
|
||||
<span>{pageSize} 条/页</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
56
src/components/ui/Toast.tsx
Normal file
56
src/components/ui/Toast.tsx
Normal file
@@ -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<ToastItem[]>([]);
|
||||
|
||||
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 (
|
||||
<div className="toast-wrap">
|
||||
{items.map((t) => (
|
||||
<div className="toast" key={t.id}>
|
||||
<span
|
||||
style={{
|
||||
color:
|
||||
t.tone === 'err'
|
||||
? 'var(--err)'
|
||||
: t.tone === 'warn'
|
||||
? 'var(--warn)'
|
||||
: 'var(--ok)',
|
||||
display: 'flex',
|
||||
}}
|
||||
>
|
||||
<Icon name={t.tone === 'err' ? 'x' : 'check'} size={15} sw={2} />
|
||||
</span>
|
||||
{t.msg}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function toast(msg: string, tone?: Tone): void {
|
||||
if (_pushToast) _pushToast(msg, tone);
|
||||
}
|
||||
6
src/components/ui/index.ts
Normal file
6
src/components/ui/index.ts
Normal file
@@ -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';
|
||||
Reference in New Issue
Block a user