新版界面:品牌主题(深绿、暖纸色、金色强调)与应用外壳(顶栏、左侧导航、手机抽屉)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4a00b8f3fc
commit
eeea870963
10 files changed
+1340
-357
No files matched your search
@@ -0,0 +1,168 @@
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import { App as AntApp, Button, Drawer, Tag } from 'antd';
|
||||
import { LogoutOutlined, MenuOutlined, RollbackOutlined } from '@ant-design/icons';
|
||||
import type { LedgerClient } from '../lib/api';
|
||||
import { logout, shopName } from '../lib/session';
|
||||
import { modeLabel } from '../lib/format';
|
||||
import { useClientSnapshot } from '../lib/useClient';
|
||||
import type { LedgerState, SessionInfo } from '../shared';
|
||||
import { BrandMark } from './BrandMark';
|
||||
|
||||
// 与旧界面左侧导航相同的分区与编号。旧界面没有可直接定位到某个分区的地址,其余分区统一打开旧版首页(/)。
|
||||
interface NavItem {
|
||||
key: string;
|
||||
no?: string;
|
||||
label: string;
|
||||
}
|
||||
function navItems(role: string): NavItem[] {
|
||||
const owner = role === 'owner';
|
||||
return [
|
||||
{ key: 'create', no: '01', label: '开单' },
|
||||
{ key: 'price-locks', no: '02', label: '待交付' },
|
||||
{ key: 'material-pools', no: '03', label: '每日购料' },
|
||||
{ key: 'recoveries', no: '04', label: '回收/置换' },
|
||||
{ key: 'orders', no: '05', label: '订单' },
|
||||
{ key: 'stock', no: '06', label: '库存' },
|
||||
{ key: 'report', no: '07', label: '每日对账' },
|
||||
...(owner
|
||||
? [
|
||||
{ key: 'team-funds', no: '08', label: '团队账目' },
|
||||
{ key: 'private-operations', no: '09', label: '私域运营概况' },
|
||||
]
|
||||
: [{ key: 'people-entry', label: '登记人数' }]),
|
||||
{ key: 'settings', no: '10', label: owner ? '店铺与打印设置' : '修改密码' },
|
||||
];
|
||||
}
|
||||
|
||||
function SideNav({ role, onNavigate }: { role: string; onNavigate?: () => void }) {
|
||||
return (
|
||||
<nav className="side-nav" aria-label="主要功能">
|
||||
<ul>
|
||||
{navItems(role).map(item =>
|
||||
item.key === 'create' ? (
|
||||
<li key={item.key}>
|
||||
<a className="nav-link active" href="/next/" aria-current="page" onClick={onNavigate}>
|
||||
<span className="nav-no">{item.no}</span>
|
||||
<span className="nav-label">{item.label}</span>
|
||||
</a>
|
||||
</li>
|
||||
) : (
|
||||
<li key={item.key}>
|
||||
<a className="nav-link" href="/" title={'在旧版界面打开「' + item.label + '」'}>
|
||||
<span className="nav-no">{item.no || '··'}</span>
|
||||
<span className="nav-label">{item.label}</span>
|
||||
<span className="nav-old">旧版</span>
|
||||
</a>
|
||||
</li>
|
||||
),
|
||||
)}
|
||||
</ul>
|
||||
<p className="nav-foot">
|
||||
新版界面目前只有开单;
|
||||
<br />
|
||||
其他分区在旧版界面中打开。
|
||||
</p>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
export function AppShell({
|
||||
client,
|
||||
state,
|
||||
session,
|
||||
onLoggedOut,
|
||||
children,
|
||||
}: {
|
||||
client: LedgerClient;
|
||||
state: LedgerState;
|
||||
session: SessionInfo;
|
||||
onLoggedOut: () => void;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const { message } = AntApp.useApp();
|
||||
const [leaving, setLeaving] = useState(false);
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
useClientSnapshot(client);
|
||||
const name = shopName(state, session);
|
||||
const who = state.user.label || state.user.name;
|
||||
async function leave() {
|
||||
setLeaving(true);
|
||||
try {
|
||||
await logout(client);
|
||||
onLoggedOut();
|
||||
} catch (err) {
|
||||
message.error((err as Error).message);
|
||||
} finally {
|
||||
setLeaving(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="shell">
|
||||
<header className="app-header">
|
||||
<div className="app-header-brand">
|
||||
<Button
|
||||
className="menu-button"
|
||||
type="text"
|
||||
icon={<MenuOutlined />}
|
||||
aria-label="打开导航"
|
||||
aria-expanded={menuOpen}
|
||||
onClick={() => setMenuOpen(true)}
|
||||
/>
|
||||
<BrandMark name={name} />
|
||||
<div className="brand-text">
|
||||
<strong data-testid="store-name">{name}</strong>
|
||||
<small>开单 · 库存 · 订单利润</small>
|
||||
</div>
|
||||
</div>
|
||||
<div className="app-header-right">
|
||||
<Tag className="mode-tag" bordered={false}>
|
||||
{modeLabel(state.mode)}
|
||||
</Tag>
|
||||
<a className="old-ui-link" href="/">
|
||||
<RollbackOutlined aria-hidden="true" /> 返回旧版界面
|
||||
</a>
|
||||
<span className="identity" data-testid="identity" title={'当前账号:' + who}>
|
||||
<span className="identity-avatar" aria-hidden="true">
|
||||
{Array.from(who)[0]}
|
||||
</span>
|
||||
<span className="identity-name">{who}</span>
|
||||
</span>
|
||||
<Button
|
||||
className="logout-button"
|
||||
icon={<LogoutOutlined />}
|
||||
loading={leaving}
|
||||
disabled={client.busy}
|
||||
onClick={() => void leave()}
|
||||
>
|
||||
退出
|
||||
</Button>
|
||||
</div>
|
||||
</header>
|
||||
<div className="app-body">
|
||||
<aside className="app-sider">
|
||||
<SideNav role={state.user.role} />
|
||||
</aside>
|
||||
<Drawer
|
||||
className="nav-drawer"
|
||||
placement="left"
|
||||
width={272}
|
||||
open={menuOpen}
|
||||
onClose={() => setMenuOpen(false)}
|
||||
title={
|
||||
<span className="drawer-title">
|
||||
<BrandMark name={name} />
|
||||
{name}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<SideNav role={state.user.role} onNavigate={() => setMenuOpen(false)} />
|
||||
<div className="drawer-meta">
|
||||
<Tag bordered={false}>{modeLabel(state.mode)}</Tag>
|
||||
<a href="/">返回旧版界面</a>
|
||||
</div>
|
||||
</Drawer>
|
||||
<main className="main">{children}</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// 店铺标志:深绿底、米金色衬线字,取店名首字(与旧界面 .brand-mark 一致)。
|
||||
export function BrandMark({ name, size = 'md' }: { name: string; size?: 'md' | 'lg' }) {
|
||||
return (
|
||||
<span className={'brand-mark brand-mark-' + size} aria-hidden="true">
|
||||
{Array.from(name)[0] || '店'}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
import { useState } from 'react';
|
||||
import { App as AntApp, Button, Tag } from 'antd';
|
||||
import type { LedgerClient } from '../lib/api';
|
||||
import { logout, shopName } from '../lib/session';
|
||||
import { modeLabel } from '../lib/format';
|
||||
import { useClientSnapshot } from '../lib/useClient';
|
||||
import type { LedgerState, SessionInfo } from '../shared';
|
||||
|
||||
export function TopBar({
|
||||
client,
|
||||
state,
|
||||
session,
|
||||
onLoggedOut,
|
||||
}: {
|
||||
client: LedgerClient;
|
||||
state: LedgerState;
|
||||
session: SessionInfo;
|
||||
onLoggedOut: () => void;
|
||||
}) {
|
||||
const { message } = AntApp.useApp();
|
||||
const [leaving, setLeaving] = useState(false);
|
||||
useClientSnapshot(client);
|
||||
const name = shopName(state, session);
|
||||
return (
|
||||
<header className="topbar">
|
||||
<div className="topbar-brand">
|
||||
<span className="brand-mark" aria-hidden="true">
|
||||
{Array.from(name)[0] || '店'}
|
||||
</span>
|
||||
<div>
|
||||
<strong data-testid="store-name">{name}</strong>
|
||||
<small>新版界面 · 开单</small>
|
||||
</div>
|
||||
</div>
|
||||
<div className="topbar-right">
|
||||
<Tag className="mode-tag">{modeLabel(state.mode)}</Tag>
|
||||
<span className="identity" data-testid="identity">
|
||||
{state.user.label || state.user.name}
|
||||
</span>
|
||||
<a className="old-ui-link" href="/">
|
||||
返回旧版界面
|
||||
</a>
|
||||
<Button
|
||||
size="small"
|
||||
loading={leaving}
|
||||
disabled={client.busy}
|
||||
onClick={async () => {
|
||||
setLeaving(true);
|
||||
try {
|
||||
await logout(client);
|
||||
onLoggedOut();
|
||||
} catch (err) {
|
||||
message.error((err as Error).message);
|
||||
} finally {
|
||||
setLeaving(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
退出
|
||||
</Button>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user