Commit 385affde by liimin

无法生成提交信息:本次代码变更内容为空,且未提供之前的提交历史记录。请提供具体的 diff 内容和历史提交记录。

0 parents
---
name: uj-ui
description: 优加门店上架系统自定义组件库(基于 antd,前缀 U*)。当需要新建/修改页面 UI、选用按钮/输入框/表格/弹窗等组件时,应优先使用 @uj/ui 而非原生 antd。
---
# @uj/ui 组件库使用指南(面向 AI 协作)
本库是优加门店上架系统的**统一 UI 组件库**,基于 antd 6 封装,所有组件以 `U` 前缀命名(如 `UButton`、`UTable`)。
其存在目的是:统一项目视觉与交互约定、沉淀业务默认值、为后续独立发包(npm)或拆 monorepo 做准备。
## 核心原则(AI 必须遵守)
1. **优先使用 `@uj/ui`,不要直接 import antd 的等价组件。**
写新页面或改 UI 时,先想「有没有对应的 U 组件」;有则用 U 组件,没有再 fallback 到 antd,并提醒补齐库。
2. **只封装、不 fork。** 库内组件通过 `forwardRef` / 函数包裹 + 透传 props + 项目默认值实现,绝不复制 antd 源码。
3. **新增组件要走库,不要散落在业务页面。** 通用 UI 元素应加到 `packages/ui/src/components/`,并在 `src/index.ts` 导出。
4. **antd 主题由应用层 `ConfigProvider` 统一控制(见 `src/theme/themeConfig.ts`)**,库内不要写死颜色。
## 安装与解析
- 仓库已是 pnpm workspace:`pnpm-workspace.yaml` 含 `packages/*`,`@uj/ui` 以 `workspace:*` 链接到应用。
- 运行 `pnpm install` 后,`@uj/ui` 通过 `packages/ui/package.json` 的 `exports` 指向 `src/index.ts`(源码直引,无需先构建)。
- 应用侧引用:`import { UButton, UTable } from '@uj/ui';`
- `antd` / `react` / `react-dom` 是 **peerDependencies**,全项目共用同一份实例。
## 当前组件清单
| 组件 | 基于 | 项目约定默认值 |
|---|---|---|
| `UButton` | antd `Button` | `type="primary"`、`size="middle"`(可覆盖) |
| `UInput` | antd `Input` | `allowClear` 默认开 |
| `USelect` | antd `Select` | `allowClear` 默认开 |
| `UCard` | antd `Card` | 统一命名入口(后续加默认样式) |
| `UTag` | antd `Tag` | 统一命名入口 |
| `UAlert` | antd `Alert` | 统一命名入口 |
| `UModal` | antd `Modal` | 默认 `centered`、`destroyOnClose`、`okButtonProps.type="primary"` |
| `UTable` | antd `Table` | `size="middle"` 默认 |
| `UUpload` | antd `Upload` | 统一命名入口;`UUpload.Dragger` 可用 |
> 未列出的 antd 组件(如 `Row/Col/Typography/Menu/Layout/Result`)目前仍直接 import antd;如高频出现,应补对应 U 封装。
## 使用示例
```tsx
import { UButton, UTable, UCard, UTag } from '@uj/ui';
// 按钮:默认主色,无需每次写 type="primary"
<UButton onClick={save}>保存</UButton>
// 表格:泛型用法与原生一致
<UTable<StoreRow> rowKey="id" columns={cols} dataSource={data} />
// 卡片 / 标签
<UCard><Statistic title="待上架" value={12} /></UCard>
<UTag color="green">营业中</UTag>
```
## 如何新增一个 U 组件
1. 在 `packages/ui/src/components/` 新建 `UXxx.tsx`,用 `forwardRef`/函数包裹 antd 对应组件,注入项目默认值,透传其余 props。
2. 在 `packages/ui/src/index.ts` 导出组件及 Props 类型。
3. 保持 `antd` 为 peer,不要在库里新增运行时依赖(业务依赖应放应用侧)。
4. 需要深度改样式时,用 antd 6 的 **CSS 变量 / `classNames`+`styles` 语义化钩子**,不要 `:global` 硬改 `.ant-*` class 名。
## 后续演进(已为 monorepo / npm 预留)
- **独立发包**:`cd packages/ui && pnpm build`(产出 `dist` 并改写 `exports` 指向构建产物),再 `pnpm publish`。
- **扩大 monorepo**:当前为「应用(根)+ packages/ui」的 workspace;新增包只需在 `packages/` 下加目录并加入 `pnpm-workspace.yaml`。
- 库与应用**共享同一 antd 实例**(peer 依赖),不会出现样式/上下文双实例问题。
node_modules
dist
dist-ssr
.pnpm-store
install*.log
*.local
.DS_Store
.vscode/*
!.vscode/extensions.json
# pnpm 常规配置
# 自动安装 peer 依赖,且不对 peer 冲突做硬性失败(antd6 / react19 / react-router7 偶有 peer 告警)
auto-install-peers=true
strict-peer-dependencies=false
# 优加门店上架系统(Vite 工程)
基于《技术栈评审纪要》落盘的可运行前端工程。技术栈:React 19 + TypeScript + antd 6 + Vite + React Router 7 + TanStack Query + Zustand。
## 评审纪要中的开放项(已按决策落定)
| 开放项(原纪要第五部分) | 落定决策 |
|---|---|
| 构建/路由分叉(Vite vs Umi Max) | **Vite + React Router 7**(自建、轻量、可控;布局/权限自接) |
| Excel 库(SheetJS vs ExcelJS) | **不引前端 Excel 库**,前端仅上传文件,解析 + 模板版本校验由后端完成 |
| 权限库(CASL vs access.ts) | **自研 `src/access` 三态模型**(`ck.on`/`half`/`na`),零依赖、AI 易扩展 |
## 与纪要事实的偏差(已就地修正)
纪要称 `@ant-design/pro-components v3.1.0` 已 GA 且配对 antd 6。**经 npm 核实不实**:
- pro-components **稳定版最新为 `2.8.10`,peer 仅 `antd ^4 || ^5`,不支持 antd 6**;
- `v3.x` 仅有 `beta` / 预发标签(如 `3.1.15-3`),**无正式 GA 版**。
因你选的是 Vite 自建路线(纪要明确"ProLayout/access 需自接"),本工程**不引入 pro-components**,改用 antd 6 原生 `Layout + Menu` 搭壳,保留核心正确结论(React 19 + antd 6)。若后续 pro-components v3 正式发布,可平滑替换 `src/layouts/BasicLayout.tsx`。
## 主题对接原型 Design Token
- `--primary:#2B5CE6` → antd `colorPrimary`(见 `src/theme/themeConfig.ts`)
- `--brand-deep:#0F1B3D` 深蓝导航 → 无 antd 对应项,由 Layout 背景 + Menu 主题处理
- antd 6 默认 pure CSS var 模式,已显式 `cssVar: true`
## 升级 6 的真实理由(非"省事")
antd 5 已进 1 年维护期、约 2026-11 EOL;新项目直接落 React 19 + antd 6,避开上线即踩维护线;pure CSS var 默认 + 语义化 DOM 利于还原原型。
## 目录结构
本仓库为 pnpm workspace:应用(根) + `packages/ui` 组件库。
```
packages/
└── ui/ # @uj/ui 自定义组件库(基于 antd,前缀 U*)
├── package.json # name=@uj/ui,antd/react 为 peer,exports 指向 src
├── tsconfig.json
└── src/
├── index.ts # 桶文件,统一导出 U* 组件
└── components/ # UButton / UInput / USelect / UCard / UTag / UAlert / UModal / UTable / UUpload
src/
├── main.tsx # 入口:ConfigProvider → AntApp → QueryClient → AccessProvider → Router
├── router/index.tsx # React Router 7 数据路由
├── layouts/BasicLayout.tsx # antd Layout + Menu,按权限过滤菜单(角色切换用 USelect)
├── theme/themeConfig.ts # antd 6 主题 + 原型 token 对接
├── access/ # 三态权限模型(自研)
│ ├── index.ts
│ └── AccessProvider.tsx
├── store/useAppStore.ts # Zustand 全局 UI 状态
├── api/request.ts # 请求封装 + 模板上传
└── pages/ # 工作台 / 门店上架 / 模板导入 / 权限管理 / 404(均使用 @uj/ui)
```
## 组件库 @uj/ui
统一基于 antd 6 封装,前缀 `U*`,已接入全部页面。新建/修改 UI 时优先 `import { UButton, UTable } from '@uj/ui'`,而非直接引 antd。详细用法、组件清单与新增规范见 `.codebuddy/skills/uj-ui/SKILL.md`。
为后续独立发包(npm)或扩展 monorepo 预留:`@uj/ui` 以 `workspace:*` 链接,antd/react 设为 peer 依赖,全项目共用同一份 antd 实例。
## 首次运行
依赖通过 **pnpm** 管理(见 `package.json` 的 `packageManager` 与 `.npmrc`)。本机需先装好 [pnpm](https://pnpm.io/)(Node 18.18+)。
```bash
pnpm install # 安装依赖,生成 node_modules 与 pnpm-lock.yaml
pnpm dev # 启动开发服务器:http://localhost:5173
pnpm build # 类型检查(tsc --noEmit)+ 生产构建到 dist/
pnpm preview # 本地预览构建产物
```
> 若某包因镜像源偶发抽取失败(如 `@ant-design/icons` 在 npmmirror 上曾损坏),重试一次,或临时切换官方源:
> `pnpm install --registry=https://registry.npmjs.org/`
> 编辑器仍报“找不到模块 antd”等红线时,确认 `node_modules/antd` 已存在,并执行
> `TypeScript: Restart TS Server`(VS Code `Ctrl+Shift+P`)刷新类型缓存。
后端约定(需自行实现):`POST /api/store-import`(multipart,含 `file` 与 `templateVersion=V1.0.1`)。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>优加门店上架系统</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
{
"name": "uj-store",
"private": true,
"version": "0.1.0",
"type": "module",
"packageManager": "pnpm@10.8.1",
"engines": {
"node": ">=18.18.0"
},
"scripts": {
"dev": "vite",
"build": "tsc --noEmit && vite build",
"preview": "vite preview",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@ant-design/icons": "^6.3.4",
"@tanstack/react-query": "^5.62.0",
"@uj/ui": "workspace:^0.1.0",
"antd": "^6.6.5",
"react": "^19.3.0",
"react-dom": "^19.3.0",
"react-router-dom": "^7.18.4",
"zustand": "^5.0.0"
},
"devDependencies": {
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^4.3.4",
"typescript": "^5.6.3",
"vite": "^6.0.0"
}
}
{
"name": "@uj/ui",
"version": "0.1.0",
"type": "module",
"description": "优加门店上架系统自定义组件库(基于 antd,前缀 U*)",
"main": "src/index.ts",
"module": "src/index.ts",
"types": "src/index.ts",
"exports": {
".": {
"types": "./src/index.ts",
"import": "./src/index.ts"
}
},
"sideEffects": false,
"files": [
"src",
"dist"
],
"scripts": {
"build": "vite build",
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"antd": "^6.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^4.3.4",
"antd": "^6.6.5",
"react": "^19.3.0",
"react-dom": "^19.3.0",
"typescript": "^5.6.3",
"vite": "^6.0.0"
}
}
import { Alert } from 'antd';
/** 项目提示条。统一命名入口。 */
export const UAlert = Alert;
import { Button, type ButtonProps } from 'antd';
import { forwardRef } from 'react';
export type UButtonProps = ButtonProps;
/**
* 项目统一按钮。约定主操作默认 primary、统一尺寸 middle,
* 仍可通过 props 覆盖。后续可在此注入埋点/权限/loading 自动处理等横切逻辑。
*/
export const UButton = forwardRef<HTMLButtonElement, UButtonProps>(
({ type = 'primary', size = 'middle', ...rest }, ref) => (
<Button ref={ref} type={type} size={size} {...rest} />
),
);
UButton.displayName = 'UButton';
import { Card } from 'antd';
/** 项目卡片容器。当前直接复用 antd Card,作为统一命名入口,后续可注入项目默认样式。 */
export const UCard = Card;
import { useLayoutEffect, useRef, useState } from 'react';
import { Table, type TableProps } from 'antd';
/**
* 自动铺满父容器剩余高度的表格。
*
* 原理:用 ResizeObserver 测量外层容器高度,扣除表头与分页高度后,
* 作为 antd Table 的 scroll.y —— 表体精确填满、表头吸顶、表体内部纵向滚动。
* 与 antd 内部 DOM 结构解耦,版本无关。
*
* 用法:放在具有确定高度的 flex 容器内(如外层 .uj-table-fill 的父级)。
* 例:
* <div style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
* <FillTable columns={cols} dataSource={data} rowKey="id" />
* </div>
*/
export function FillTable<T extends object = Record<string, unknown>>(
props: TableProps<T>,
) {
const wrapRef = useRef<HTMLDivElement>(null);
const [bodyHeight, setBodyHeight] = useState<number | undefined>(undefined);
useLayoutEffect(() => {
const wrap = wrapRef.current;
if (!wrap) return;
const measure = () => {
const header = wrap.querySelector('.ant-table-thead');
const pagination = wrap.querySelector('.ant-table-pagination');
const headerH = header
? (header as HTMLElement).getBoundingClientRect().height
: 0;
const pagH = pagination
? (pagination as HTMLElement).offsetHeight
: 0;
const available = Math.max(0, wrap.clientHeight - headerH - pagH);
setBodyHeight((prev) => (prev === available ? prev : available));
};
const ro = new ResizeObserver(measure);
ro.observe(wrap);
measure();
return () => ro.disconnect();
}, []);
return (
<div ref={wrapRef} className="uj-table-fill">
<Table
{...props}
scroll={{ ...props.scroll, y: bodyHeight ?? props.scroll?.y }}
/>
</div>
);
}
import { Input, type InputProps, type InputRef } from 'antd';
import { forwardRef } from 'react';
export type UInputProps = InputProps;
/** 项目统一输入框,默认开启 allowClear。 */
export const UInput = forwardRef<InputRef, UInputProps>(
({ allowClear = true, ...rest }, ref) => (
<Input ref={ref} allowClear={allowClear} {...rest} />
),
);
UInput.displayName = 'UInput';
import { Modal, type ModalProps } from 'antd';
/**
* 项目统一弹窗。约定默认居中、关闭时销毁内容、确认按钮为主色。
* 若需 Modal.confirm 等静态方法,后续可在此封装 UModal.confirm 包装器。
*/
export function UModal(props: ModalProps) {
const { centered = true, destroyOnClose = true, okButtonProps, ...rest } = props;
return (
<Modal
centered={centered}
destroyOnClose={destroyOnClose}
okButtonProps={{ type: 'primary', ...okButtonProps }}
{...rest}
/>
);
}
import { Select, type SelectProps } from 'antd';
export type USelectProps = SelectProps;
/**
* 项目统一下拉选择,默认开启 allowClear。
* 当前不转发 ref 以规避各 antd 大版本 ref 类型差异;如需 ref 再按需补充。
*/
export function USelect(props: USelectProps) {
const { allowClear = true, ...rest } = props;
return <Select allowClear={allowClear} {...rest} />;
}
import { Table, type TableProps } from 'antd';
/**
* 项目统一表格。约定默认尺寸 middle,后续可在此注入统一分页/空态/列设置等。
*/
export function UTable<T>(props: TableProps<T>) {
const { size = 'middle', ...rest } = props;
return <Table<T> size={size} {...rest} />;
}
import { Tag } from 'antd';
/** 项目标签。统一命名入口。 */
export const UTag = Tag;
import { Upload } from 'antd';
/** 项目上传。统一命名入口,UUpload.Dragger 可直接使用。 */
export const UUpload = Upload;
// @uj/ui —— 优加门店上架系统自定义组件库(基于 antd,前缀 U*)
// 用法:import { UButton, UTable } from '@uj/ui';
export { UButton } from './components/Button';
export type { UButtonProps } from './components/Button';
export { UInput } from './components/Input';
export type { UInputProps } from './components/Input';
export { USelect } from './components/Select';
export type { USelectProps } from './components/Select';
export { UCard } from './components/Card';
export { UTag } from './components/Tag';
export { UAlert } from './components/Alert';
export { UModal } from './components/Modal';
export { UTable } from './components/Table';
export { FillTable } from './components/FillTable';
export { UUpload } from './components/Upload';
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"noEmit": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"types": ["react"]
},
"include": ["src"]
}
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { fileURLToPath, URL } from 'node:url';
// 库构建配置:产出 ESM 到 dist/,并将 react / react-dom / antd 标记为外部依赖,
// 由使用方提供同一份实例。开发态由应用侧直接引用 src(见 package.json exports)。
export default defineConfig({
plugins: [react()],
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
},
build: {
lib: {
entry: fileURLToPath(new URL('./src/index.ts', import.meta.url)),
formats: ['es'],
fileName: 'uj-ui',
},
rollupOptions: {
external: ['react', 'react-dom', 'antd'],
},
},
});
packages:
- 'packages/*'
No preview for this file type
import { createContext, useContext, useMemo, useState, type ReactNode } from 'react';
import {
checkAccess,
defaultMatrix,
type PermissionMatrix,
type ResourceKey,
type RoleKey,
} from './index';
interface AccessContextValue {
role: RoleKey;
setRole: (r: RoleKey) => void;
matrix: PermissionMatrix;
can: (resource: ResourceKey, required?: 'view' | 'full') => boolean;
}
const AccessContext = createContext<AccessContextValue | null>(null);
export function AccessProvider({ children }: { children: ReactNode }) {
const [role, setRole] = useState<RoleKey>('admin');
const [matrix] = useState<PermissionMatrix>(defaultMatrix);
const value = useMemo<AccessContextValue>(
() => ({
role,
setRole,
matrix,
can: (resource, required = 'view') =>
checkAccess(matrix, role, resource, required),
}),
[role, matrix],
);
return <AccessContext.Provider value={value}>{children}</AccessContext.Provider>;
}
export function useAccess(): AccessContextValue {
const ctx = useContext(AccessContext);
if (!ctx) throw new Error('useAccess 必须在 <AccessProvider> 内使用');
return ctx;
}
// 三态权限模型(自研,零依赖,AI 易扩展)
// ck.on -> 完全(可读可写)
// half -> 部分(仅查看)
// na -> 无
export type PermissionState = 'ck.on' | 'half' | 'na';
export type ResourceKey =
| 'dashboard'
| 'store.listing'
| 'store.import'
| 'store.approve'
| 'system.role'
| 'system.account'
| 'access.manage';
export type RoleKey = 'admin' | 'operator' | 'viewer';
export type PermissionMatrix = Record<ResourceKey, Record<RoleKey, PermissionState>>;
export const defaultMatrix: PermissionMatrix = {
dashboard: { admin: 'ck.on', operator: 'ck.on', viewer: 'half' },
'store.listing': { admin: 'ck.on', operator: 'ck.on', viewer: 'half' },
'store.import': { admin: 'ck.on', operator: 'ck.on', viewer: 'na' },
'store.approve': { admin: 'ck.on', operator: 'half', viewer: 'na' },
'system.role': { admin: 'ck.on', operator: 'na', viewer: 'na' },
'system.account': { admin: 'ck.on', operator: 'na', viewer: 'na' },
'access.manage': { admin: 'ck.on', operator: 'na', viewer: 'na' },
};
/**
* 判定权限。
* @param required 'view'(默认,half 即可)| 'full'(需 ck.on)
*/
export function checkAccess(
matrix: PermissionMatrix,
role: RoleKey,
resource: ResourceKey,
required: 'view' | 'full' = 'view',
): boolean {
const state = matrix[resource]?.[role] ?? 'na';
if (state === 'na') return false;
if (required === 'full') return state === 'ck.on';
return true;
}
const BASE = '/api';
export async function request<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(`${BASE}${path}`, {
headers: { 'Content-Type': 'application/json' },
...init,
});
if (!res.ok) throw new Error(`请求失败: ${res.status}`);
return res.json() as Promise<T>;
}
// 门店上架 Excel 导入:前端仅上传文件,
// 解析与《【优加】门店上架模版-V1.0.1.xlsx》模板版本一致性校验由后端完成。
export async function uploadStoreTemplate(file: File): Promise<{ taskId: string }> {
const form = new FormData();
form.append('file', file);
form.append('templateVersion', 'V1.0.1');
const res = await fetch(`${BASE}/store-import`, { method: 'POST', body: form });
if (!res.ok) throw new Error('导入失败,请检查文件与模板版本');
return res.json();
}
interface LogoProps {
size?: number;
}
/**
* 品牌标识:渐变圆角方 + UJ 字标。
* 深色背景(Sider / 登录区)与浅色卡片均可用,靠自身渐变保证对比度。
*/
export function Logo({ size = 36 }: LogoProps) {
return (
<div
style={{
width: size,
height: size,
borderRadius: size * 0.28,
background: 'linear-gradient(135deg, #2B5CE6 0%, #5B8DEF 100%)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: '#fff',
fontWeight: 800,
fontSize: size * 0.4,
letterSpacing: 1,
boxShadow: '0 6px 16px -6px rgba(43,92,230,.6)',
flexShrink: 0,
userSelect: 'none',
}}
>
UJ
</div>
);
}
import type { ReactNode } from 'react';
interface PagePlaceholderProps {
title: string;
description?: string;
extra?: ReactNode;
}
/** 极简占位页:框架阶段先用,后续逐个替换为真实页面 */
export default function PagePlaceholder({ title, description, extra }: PagePlaceholderProps) {
return (
<div
style={{
flex: 1,
minHeight: 0,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
background: '#fff',
borderRadius: 12,
border: '1px dashed #E2E7EF',
}}
>
<div
style={{
width: 56,
height: 56,
borderRadius: 16,
background: 'linear-gradient(135deg, rgba(43,92,230,.12), rgba(91,141,239,.18))',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 24,
fontWeight: 700,
color: '#2B5CE6',
marginBottom: 16,
}}
>
{title.slice(0, 1)}
</div>
<div style={{ fontSize: 18, fontWeight: 600, color: '#1D2533' }}>{title}</div>
{description && (
<div style={{ marginTop: 8, fontSize: 13, color: '#8A94A6' }}>{description}</div>
)}
{extra && <div style={{ marginTop: 24 }}>{extra}</div>}
</div>
);
}
{
"menus": [
{
"group": "门店上架",
"children": [
{ "path": "/store/import", "label": "导入门店信息", "icon": "UploadOutlined", "resource": "store.import" },
{ "path": "/store/approve", "label": "门店审批", "icon": "AuditOutlined", "resource": "store.approve" },
{ "path": "/store/listing", "label": "门店列表", "icon": "ShopOutlined", "resource": "store.listing" }
]
},
{
"group": "系统设置",
"children": [
{ "path": "/system/roles", "label": "角色管理", "icon": "TeamOutlined", "resource": "system.role" },
{ "path": "/system/accounts", "label": "账号管理", "icon": "UserOutlined", "resource": "system.account" },
{ "path": "/access-manage", "label": "权限矩阵", "icon": "SafetyOutlined", "resource": "access.manage" }
]
}
]
}
:root {
/* 原型 Design Token 对齐(:root CSS 变量保留,供自定义 CSS 复用) */
--uj-primary: #2b5ce6;
--uj-brand-deep: #0f1b3d;
}
/* 全站授权字体:PingFang(苹方),从服务器远程获取 */
@font-face {
font-family: 'PingFang';
src: url('https://img02.glsx.com.cn/weapp/resource/saas/scrm/fonts/PingFang-Regular.ttf')
format('truetype');
font-weight: 400;
font-style: normal;
font-display: swap;
}
* {
box-sizing: border-box;
}
html,
body,
#root {
height: 100%;
margin: 0;
}
body {
font-family: 'PingFang', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'PingFang SC', 'Microsoft YaHei', sans-serif;
}
/* 彻底关掉 antd Table 内层容器的横向滚动条(亚像素/列宽导致)。
必须用 !important 覆盖 antd 运行时(CSS-in-JS)注入的 overflow-x:auto。 */
.ant-table,
.ant-table-container,
.ant-table-content {
overflow-x: hidden !important;
}
/* 表体纵向滚动条只在内容超出时出现(覆盖 antd 默认的 overflow-y:scroll 常驻滚动条) */
.ant-table-body {
overflow-x: hidden !important;
overflow-y: auto !important;
}
/* Sider 锁定溢出,避免菜单 hover 背景/折叠 tooltip 产生横向滚动条 */
.ant-layout-sider {
overflow: hidden !important;
}
/* 列表铺满内容区剩余高度:仅作为 flex 子项撑满父容器。
表体具体高度由 FillTable 组件用 ResizeObserver 测量后交给 antd scroll.y。 */
.uj-table-fill {
flex: 1 1 auto;
min-height: 0;
display: flex;
flex-direction: column;
}
/* 页面级兜底:任何元素(含被 portal 到 body 的 antd 浮层/tooltip)造成的横向溢出都不显示滚动条 */
html,
body {
overflow-x: hidden;
}
import { Layout, Menu, Avatar, Dropdown, Badge, Tooltip, Input, Button } from 'antd';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import {
DashboardOutlined,
ShopOutlined,
UploadOutlined,
SafetyOutlined,
SearchOutlined,
LogoutOutlined,
UserOutlined,
TeamOutlined,
AuditOutlined,
BellOutlined,
MenuFoldOutlined,
MenuUnfoldOutlined,
QuestionCircleOutlined,
} from '@ant-design/icons';
import { useAccess } from '@/access/AccessProvider';
import { useAppStore } from '@/store/useAppStore';
import { brandGradient } from '@/theme/themeConfig';
import { Logo } from '@/components/Logo';
import menuJson from '@/config/menu.json';
import type { ResourceKey } from '@/access';
import type { MenuProps } from 'antd';
const { Header, Sider, Content } = Layout;
/* ---------- 菜单数据结构(与 src/config/menu.json 对应,后续由后台下发替换) ---------- */
interface MenuItemDef {
path: string;
label: string;
icon: string;
resource: ResourceKey;
}
interface MenuGroupDef {
group: string;
children: MenuItemDef[];
}
// 图标注册表:JSON 只存图标名,渲染时查表(新增图标在这里登记即可)
const iconMap: Record<string, React.ReactNode> = {
DashboardOutlined: <DashboardOutlined />,
ShopOutlined: <ShopOutlined />,
UploadOutlined: <UploadOutlined />,
SafetyOutlined: <SafetyOutlined />,
TeamOutlined: <TeamOutlined />,
AuditOutlined: <AuditOutlined />,
UserOutlined: <UserOutlined />,
};
const allGroups = menuJson.menus as MenuGroupDef[];
export default function BasicLayout() {
const navigate = useNavigate();
const location = useLocation();
const { can, role } = useAccess();
const { collapsed, toggleCollapsed, currentUser, logout } = useAppStore();
// JSON -> antd Menu items(按权限过滤)
const items: MenuProps['items'] = allGroups.map((g) => ({
type: 'group' as const,
label: g.group,
children: g.children
.filter((m) => can(m.resource))
.map((m) => ({
key: m.path,
icon: iconMap[m.icon],
label: m.label,
})),
}));
const flat = allGroups.flatMap((g) => g.children);
const selectedKey =
flat.find((m) => location.pathname.startsWith(m.path))?.path ?? '/store/listing';
const current = flat.find((m) => m.path === selectedKey);
const currentGroup = allGroups.find((g) => g.children.some((m) => m.path === selectedKey));
const onLogout = () => {
logout();
navigate('/login');
};
return (
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
<Sider
collapsed={collapsed}
trigger={null}
width={232}
collapsedWidth={68}
className="uj-sider"
style={{ background: brandGradient }}
>
{/* 品牌区 */}
<div className={`uj-sider-brand${collapsed ? ' is-collapsed' : ''}`}>
<Logo size={34} />
{!collapsed && (
<div className="uj-sider-brand-text">
<span className="t">优加门店上架</span>
<span className="s">Store Launch Platform</span>
</div>
)}
</div>
{/* 菜单区 */}
<div className="uj-sider-menu">
<Menu
theme="dark"
mode="inline"
className="uj-menu"
selectedKeys={[selectedKey]}
items={items}
onClick={({ key }) => navigate(key)}
/>
</div>
</Sider>
<Layout style={{ minWidth: 0 }}>
<Header className="uj-header">
{/* 左:折叠 + 面包屑式页题 */}
<div className="uj-header-left">
<Button
type="text"
aria-label="切换菜单"
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
onClick={toggleCollapsed}
className="uj-header-fold"
/>
<span style={{ fontSize: 16, fontWeight: 600, color: '#1D2533' }}>
{current?.label ?? '门店列表'}
</span>
{currentGroup && (
<>
<span className="uj-header-crumb-sep">/</span>
<span style={{ fontSize: 13, color: '#8A94A6' }}>{currentGroup.group}</span>
</>
)}
</div>
{/* 中:全局搜索 */}
<div className="uj-header-search">
<Input
prefix={<SearchOutlined style={{ color: '#8A94A6' }} />}
placeholder="搜索门店 / 任务…"
variant="borderless"
allowClear
/>
<span className="uj-header-search-kbd">⌘K</span>
</div>
{/* 右:通知 / 帮助 / 用户 */}
<div className="uj-header-right">
<Badge dot>
<button type="button" className="uj-header-icon-btn" aria-label="通知">
<BellOutlined />
</button>
</Badge>
<Tooltip title="帮助中心">
<button type="button" className="uj-header-icon-btn" aria-label="帮助">
<QuestionCircleOutlined />
</button>
</Tooltip>
<span className="uj-header-divider" />
<Dropdown
placement="bottomRight"
menu={{
items: [
{ key: 'profile', icon: <UserOutlined />, label: '个人资料' },
{ type: 'divider' },
{
key: 'logout',
icon: <LogoutOutlined />,
label: '退出登录',
onClick: onLogout,
},
],
}}
>
<button type="button" className="uj-header-user">
<Avatar
size={32}
style={{ background: 'linear-gradient(135deg,#2B5CE6,#5B8DEF)' }}
icon={<UserOutlined />}
/>
<div className="uj-header-user-text">
<span className="n">{currentUser.name}</span>
<span className="r">
{role === 'admin' ? '管理员' : role === 'operator' ? '运营' : '访客'}
</span>
</div>
</button>
</Dropdown>
</div>
</Header>
<Content
style={{
flex: 1,
minHeight: 0,
overflow: 'auto',
background: '#F4F6FA',
padding: 24,
display: 'flex',
flexDirection: 'column',
}}
>
<Outlet />
</Content>
</Layout>
</Layout>
);
}
import React from 'react';
import ReactDOM from 'react-dom/client';
import { RouterProvider } from 'react-router-dom';
import { QueryClientProvider } from '@tanstack/react-query';
import { ConfigProvider, App as AntApp } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import { router } from '@/router';
import { queryClient } from '@/queryClient';
import { themeConfig } from '@/theme/themeConfig';
import { AccessProvider } from '@/access/AccessProvider';
import './index.css';
import './theme/design.css';
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ConfigProvider locale={zhCN} theme={themeConfig}>
<AntApp>
<QueryClientProvider client={queryClient}>
<AccessProvider>
<RouterProvider router={router} />
</AccessProvider>
</QueryClientProvider>
</AntApp>
</ConfigProvider>
</React.StrictMode>,
);
import { useState } from 'react';
import { Tag, Typography } from 'antd';
import { useAccess } from '@/access/AccessProvider';
import type {
PermissionMatrix,
PermissionState,
ResourceKey,
RoleKey,
} from '@/access';
import { USelect, UTable, UTag, FillTable } from '@uj/ui';
const resourceLabels: Record<ResourceKey, string> = {
dashboard: '工作台',
'store.listing': '门店列表',
'store.import': '导入门店信息',
'store.approve': '门店审批',
'system.role': '角色管理',
'system.account': '账号管理',
'access.manage': '权限矩阵',
};
const roleLabels: Record<RoleKey, string> = {
admin: '管理员',
operator: '运营',
viewer: '访客',
};
const stateOptions = [
{ value: 'ck.on', label: '完全(ck.on)' },
{ value: 'half', label: '部分(half)' },
{ value: 'na', label: '无(na)' },
];
export default function AccessManage() {
const { matrix: initial, role } = useAccess();
const [matrix, setMatrix] = useState<PermissionMatrix>(initial);
const roles = Object.keys(roleLabels) as RoleKey[];
const resources = Object.keys(resourceLabels) as ResourceKey[];
const columns = [
{
title: '资源',
dataIndex: 'resource',
key: 'resource',
render: (_: unknown, res: ResourceKey) => resourceLabels[res],
},
...roles.map((rl) => ({
title: roleLabels[rl],
dataIndex: rl,
key: rl,
render: (_: unknown, res: ResourceKey) => (
<USelect
size="small"
style={{ width: 130 }}
value={matrix[res][rl]}
options={stateOptions}
onChange={(v: PermissionState) =>
setMatrix((m) => ({ ...m, [res]: { ...m[res], [rl]: v } }))
}
/>
),
})),
];
return (
<div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
<Typography.Paragraph type="secondary">
三态权限矩阵(ck.on 完全 / half 部分仅查看 / na 无)。当前登录角色:
<Tag color="blue" style={{ marginLeft: 8 }}>
{roleLabels[role]}
</Tag>
</Typography.Paragraph>
<FillTable<ResourceKey>
rowKey={(r) => r}
columns={columns as never}
dataSource={resources}
pagination={false}
/>
</div>
);
}
import PagePlaceholder from '@/components/PagePlaceholder';
export default function AccountManage() {
return <PagePlaceholder title="账号管理" description="账号开通、禁用与角色绑定(建设中)" />;
}
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { App, Button, Form, Input, Typography } from 'antd';
import { LockOutlined, UserOutlined, CheckCircleFilled } from '@ant-design/icons';
import { useAppStore } from '@/store/useAppStore';
import { useAccess } from '@/access/AccessProvider';
import { UInput } from '@uj/ui';
import { Logo } from '@/components/Logo';
import type { RoleKey } from '@/access';
const { Title, Text } = Typography;
export default function Login() {
const navigate = useNavigate();
const { message } = App.useApp();
const { login } = useAppStore();
const { setRole } = useAccess();
const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const doLogin = (name: string) => {
const r: RoleKey = 'admin';
setRole(r);
login({ name, role: r });
message.success(`欢迎回来,${name}`);
setTimeout(() => navigate('/'), 350);
};
const onFinish = (values: { account: string }) => {
setLoading(true);
setTimeout(() => {
setLoading(false);
doLogin(values.account || '用户');
}, 600);
};
return (
<div className="uj-login-wrap">
<aside className="uj-login-aside">
<div className="uj-login-brand">
<Logo size={44} />
<span>优加门店上架</span>
</div>
<div className="uj-login-hero">
<h1>
统一门店上架
<br />
让每一次开店更可控
</h1>
<p>模板治理 · 批量导入 · 三态权限,一站式管理全国门店上架全流程。</p>
</div>
<ul className="uj-login-feats">
<li>
<CheckCircleFilled style={{ color: '#5B8DEF' }} /> 标准化门店上架模板,版本一致性自动校验
</li>
<li>
<CheckCircleFilled style={{ color: '#5B8DEF' }} /> 批量导入与进度看板,过程透明可追溯
</li>
<li>
<CheckCircleFilled style={{ color: '#5B8DEF' }} /> ck.on / half / na 三态权限,精细到资源
</li>
</ul>
<div
style={{ position: 'absolute', width: 280, height: 280, right: -60, top: -40, background: '#2B5CE6', borderRadius: '50%', filter: 'blur(70px)', opacity: 0.45 }}
/>
<div
style={{ position: 'absolute', width: 220, height: 220, left: -40, bottom: -30, background: '#5B8DEF', borderRadius: '50%', filter: 'blur(70px)', opacity: 0.35 }}
/>
</aside>
<main className="uj-login-main">
<div className="uj-login-card">
<Title level={3} style={{ marginBottom: 4 }}>
欢迎登录
</Title>
<Text type="secondary">请输入账号信息以继续</Text>
<Form form={form} layout="vertical" onFinish={onFinish} style={{ marginTop: 24 }} requiredMark={false}>
<Form.Item name="account" label="账号" rules={[{ required: true, message: '请输入账号' }]}>
<UInput prefix={<UserOutlined />} placeholder="手机号 / 工号" size="large" />
</Form.Item>
<Form.Item name="password" label="密码" rules={[{ required: true, message: '请输入密码' }]}>
<Input.Password prefix={<LockOutlined />} placeholder="请输入密码" size="large" />
</Form.Item>
<Button type="primary" htmlType="submit" size="large" block loading={loading}>
登 录
</Button>
</Form>
</div>
<Text type="secondary" style={{ marginTop: 24, fontSize: 12 }}>
© 2026 优加门店上架系统 · 企业级门店治理平台
</Text>
</main>
</div>
);
}
import { Result } from 'antd';
import { useNavigate } from 'react-router-dom';
import { UButton } from '@uj/ui';
export default function NotFound() {
const nav = useNavigate();
return (
<Result
status="404"
title="404"
subTitle="页面不存在"
extra={
<UButton onClick={() => nav('/dashboard')}>返回工作台</UButton>
}
/>
);
}
import PagePlaceholder from '@/components/PagePlaceholder';
export default function RoleManage() {
return <PagePlaceholder title="角色管理" description="角色定义与权限分配(建设中)" />;
}
import PagePlaceholder from '@/components/PagePlaceholder';
export default function StoreApprove() {
return <PagePlaceholder title="门店审批" description="门店上架申请的审批与流转(建设中)" />;
}
import PagePlaceholder from '@/components/PagePlaceholder';
export default function StoreImport() {
return <PagePlaceholder title="导入门店信息" description="批量导入门店基础信息与上架资料(建设中)" />;
}
import type { ColumnsType } from 'antd/es/table';
import { useQuery } from '@tanstack/react-query';
import { request } from '@/api/request';
import { FillTable, UTag } from '@uj/ui';
interface StoreRow {
id: string;
name: string;
city: string;
status: 'on' | 'off' | 'pending';
owner: string;
}
async function fetchStores(): Promise<StoreRow[]> {
// 占位:真实接入后端 /api/stores
return [];
}
const statusMeta: Record<StoreRow['status'], { color: string; text: string }> = {
on: { color: 'green', text: '营业中' },
off: { color: 'default', text: '已下架' },
pending: { color: 'gold', text: '待上架' },
};
export default function StoreListing() {
const { data, isLoading } = useQuery({
queryKey: ['stores'],
queryFn: fetchStores,
});
const columns: ColumnsType<StoreRow> = [
{ title: '门店ID', dataIndex: 'id' },
{ title: '门店名称', dataIndex: 'name' },
{ title: '城市', dataIndex: 'city' },
{
title: '状态',
dataIndex: 'status',
render: (s: StoreRow['status']) => (
<UTag color={statusMeta[s].color}>{statusMeta[s].text}</UTag>
),
},
{ title: '负责人', dataIndex: 'owner' },
];
return (
<div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
<FillTable<StoreRow>
rowKey="id"
loading={isLoading}
columns={columns}
dataSource={data}
pagination={{ pageSize: 10 }}
/>
</div>
);
}
import { useState } from 'react';
import { App, Typography } from 'antd';
import { InboxOutlined } from '@ant-design/icons';
import type { UploadProps } from 'antd';
import { uploadStoreTemplate } from '@/api/request';
import { UAlert, UUpload } from '@uj/ui';
export default function TemplateImport() {
const { message } = App.useApp();
const [uploading, setUploading] = useState(false);
const props: UploadProps = {
name: 'file',
multiple: false,
accept: '.xlsx,.xls',
showUploadList: true,
beforeUpload: async (file) => {
setUploading(true);
try {
await uploadStoreTemplate(file as File);
message.success('模板已提交,后端解析中');
} catch (e) {
message.error((e as Error).message);
} finally {
setUploading(false);
}
// 返回 false 阻止 antd 自动上传,由我们手动走后端
return false;
},
};
return (
<div style={{ maxWidth: 640 }}>
<UAlert
type="info"
showIcon
style={{ marginBottom: 16 }}
message="Excel 由后端解析"
description="上传《【优加】门店上架模版-V1.0.1.xlsx》,前端仅做文件提交;模板版本一致性校验在后端完成。"
/>
<Typography.Paragraph type="secondary">
前端不引入 Excel 解析库,文件经 /api/store-import 提交,由后端完成解析与校验。
</Typography.Paragraph>
<UUpload.Dragger {...props} disabled={uploading}>
<p className="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p className="ant-upload-text">点击或拖拽门店上架模版到此处</p>
<p className="ant-upload-hint">支持 .xlsx / .xls,单文件</p>
</UUpload.Dragger>
</div>
);
}
import { QueryClient } from '@tanstack/react-query';
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 30_000,
retry: 1,
refetchOnWindowFocus: false,
},
},
});
import type { ReactNode } from 'react';
import { createBrowserRouter, Navigate } from 'react-router-dom';
import BasicLayout from '@/layouts/BasicLayout';
import Dashboard from '@/pages/Dashboard';
import StoreListing from '@/pages/StoreListing';
import StoreImport from '@/pages/StoreImport';
import StoreApprove from '@/pages/StoreApprove';
import AccessManage from '@/pages/AccessManage';
import RoleManage from '@/pages/RoleManage';
import AccountManage from '@/pages/AccountManage';
import NotFound from '@/pages/NotFound';
import Login from '@/pages/Login';
import { useAppStore } from '@/store/useAppStore';
function RequireAuth({ children }: { children: ReactNode }) {
const loggedIn = useAppStore((s) => s.loggedIn);
if (!loggedIn) return <Navigate to="/login" replace />;
return <>{children}</>;
}
// React Router 7 数据路由(SPA / 声明式)
// 路由与菜单(src/config/menu.json)保持对应;新页面 = 新路由 + 菜单项
export const router = createBrowserRouter([
{ path: '/login', element: <Login /> },
{
path: '/',
element: (
<RequireAuth>
<BasicLayout />
</RequireAuth>
),
children: [
{ index: true, element: <Navigate to="/store/listing" replace /> },
{ path: 'dashboard', element: <Dashboard /> },
{ path: 'store/import', element: <StoreImport /> },
{ path: 'store/approve', element: <StoreApprove /> },
{ path: 'store/listing', element: <StoreListing /> },
{ path: 'system/roles', element: <RoleManage /> },
{ path: 'system/accounts', element: <AccountManage /> },
{ path: 'access-manage', element: <AccessManage /> },
],
},
{ path: '*', element: <NotFound /> },
]);
import { create } from 'zustand';
interface AppState {
collapsed: boolean;
toggleCollapsed: () => void;
currentUser: { name: string; role: string };
setCurrentUser: (u: { name: string; role: string }) => void;
loggedIn: boolean;
login: (u: { name: string; role: string }) => void;
logout: () => void;
}
export const useAppStore = create<AppState>((set) => ({
collapsed: false,
toggleCollapsed: () => set((s) => ({ collapsed: !s.collapsed })),
currentUser: { name: '管理员', role: 'admin' },
setCurrentUser: (u) => set({ currentUser: u }),
loggedIn: false,
login: (u) => set({ loggedIn: true, currentUser: u }),
logout: () => set({ loggedIn: false }),
}));
import type { ThemeConfig } from 'antd';
// 品牌色板(稳重内敛 · 企业级)
export const brandDeep = '#0B1437'; // 墨蓝导航底(深色态)
export const brandGradient = 'linear-gradient(160deg, #0B1437 0%, #16245A 100%)'; // Sider / 登录品牌区
export const brandAccent = '#2B5CE6'; // 主操作蓝
export const themeConfig: ThemeConfig = {
cssVar: true,
token: {
colorPrimary: brandAccent,
colorLink: brandAccent,
colorLinkHover: '#4B75EA',
colorSuccess: '#16A34A',
colorWarning: '#D97706',
colorError: '#E5484D',
colorInfo: brandAccent,
colorBgLayout: '#F4F6FA',
colorBgContainer: '#FFFFFF',
colorBorderSecondary: '#E8ECF3',
colorBorder: '#E2E7EF',
colorText: '#1D2533',
colorTextHeading: '#1D2533',
colorTextDescription: '#4A5568',
colorTextSecondary: '#4A5568',
borderRadius: 8,
borderRadiusLG: 12,
controlHeight: 36,
fontSize: 14,
fontFamily:
"'PingFang', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif",
boxShadowSecondary: '0 6px 20px -8px rgba(16,24,40,.12)',
wireframe: false,
},
components: {
Layout: {
headerBg: '#FFFFFF',
headerHeight: 60,
headerPadding: '0 20px',
siderBg: 'transparent',
bodyBg: '#F4F6FA',
},
Menu: {
darkItemBg: 'transparent',
darkSubMenuItemBg: 'transparent',
darkItemSelectedBg: 'rgba(43,92,230,.22)',
darkItemSelectedColor: '#FFFFFF',
itemHeight: 44,
itemMarginInline: 8,
iconSize: 16,
},
Card: {
borderRadiusLG: 12,
},
Button: {
controlHeight: 36,
borderRadius: 8,
primaryShadow: '0 6px 16px -6px rgba(43,92,230,.5)',
},
},
};
/// <reference types="vite/client" />
{
"compilerOptions": {
"target": "ES2022",
"useDefineForClassFields": true,
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"paths": {
"@/*": ["./src/*"],
"@uj/ui": ["./packages/ui/src/index.ts"]
}
},
"include": ["src"]
}
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { fileURLToPath, URL } from 'node:url';
// Vite 自建 + React Router 7(SPA / 声明式路由)
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
// 组件库源码直引:即使 workspace 软链未就绪(如 install 被中断),dev/构建也能解析
'@uj/ui': fileURLToPath(new URL('./packages/ui/src/index.ts', import.meta.url)),
},
},
server: {
port: 5173,
// 前端只负责上传文件,Excel 解析与模板版本校验走后端
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
},
},
},
});
# 优加门店上架系统 · 工程化技术栈评审纪要
> 评审对象:基于《优加门店上架系统 · 高保真原型 V1.4.0》(纯静态 HTML/CSS 单页,5 个 section 靠 `data-page` 切视图,Design Token 全在 `:root` 的 CSS 变量里)提出的技术栈升级推荐
> 评审结论:方向正确(React 19 + antd 6 是当前正解),但推荐语中两条"理由"不成立,栈本身漏一个架构分叉点,Excel/权限库需显式落定
---
## 一、查证的版本事实(截至 2026-09)
| 项 | 状态 | 证据 |
|---|---|---|
| antd 6 | 已 GA 且成熟 | 6.0.0 于 2025-11-21 发 Stable;稳定线已到 6.2.x(2026 持续发版)。v5 转入 `v5.x-stable` 1 年维护期,不再加功能 |
| antd 6 最低 React | React 18,官方推荐 19 | 升级公告:minimum React 18,仍建议用最新 React 19 |
| React 19 兼容垫片 | antd 6 默认不需要 | 公告:`Modal.confirm` 等静态方法可直接删掉 `@ant-design/v5-patch-for-react-19` |
| CSS 变量主题 | antd 6 默认 pure CSS var 模式 | 公告:彻底移除 IE 后,@ant-design/cssinjs 默认 pure CSS Variables,支持实时换肤 |
| @ant-design/pro-components v3 | 真实存在且配对 antd 6 | 3.1.0(2025-12-25):「Upgrade to Ant Design v6: Full support」;3.x 要求 antd≥6.0、React≥18;由原多包合并为单包 |
| React Router 7 | 稳定,兼容 React 19 | 2024 末发布,SPA/声明式模式正常 |
**组合自洽性**:`React 19 + antd 6 + pro-components v3` 当前正确,非拍脑袋。
---
## 二、推荐中"对"的点
1. antd 6 + React 19 是当前正解(见上表)。
2. 去掉 `@ant-design/v5-patch-for-react-19` 垫片真实——antd 6 默认零垫片。
3. pro-components 选 v3 而非 v2 正确:v2 是 antd 5 线,v3 才是 antd 6 线,二者**不可同包混用**(迁移指南明确警告混用会触发样式/运行时错误)。
---
## 三、需要修订的点(带证据)
### 修订 1:"少了那层 React 19 兼容垫片"——真,但非 antd 6 独一份
antd **5.21+** 起已能在 React 19 上跑、无需 patch。若当前基线是 antd 5,光为去垫片可只升 antd 5 最新,不必升 6。此条不能作"升 6 的理由"。
### 修订 2:"主题切到 CSS 变量,跟 Design Token 对接更自然"——过度美化,且 antd 5 就有
- antd **5.13+** 的 `ConfigProvider` 已支持 `cssVar: true`。CSS 变量主题**不是 antd 6 新能力**,v6 仅设为默认。
- 原型 token 与 antd token 非 1:1:
- `--primary:#2B5CE6` → antd `colorPrimary`,v5/v6 均用 `theme={{ token: { colorPrimary:'#2B5CE6' }}}`,两边一样自然。
- `--brand-deep:#0F1B3D`(导航深蓝底)是**自定义 token,antd 无对应项**,靠 ProLayout `token` + 自定义 CSS 处理,v5/v6 同样手写。
- 真实 antd 6 主题收益:**pure CSS var 默认 + 开放样式算法 + 语义化 DOM(ConfigProvider 的 classNames/styles 统一改组件内部结构)**。后者对还原原型里 nav/step/chain/上传区更顺手——这条才该写进理由。
### 修订 3:漏一个架构分叉——Vite 自建 vs Umi Max
"React 19 默认 Vite"不严谨:Vite 是构建器,不绑定 React 19。antd 生态**官方一等栈是 Ant Design Pro v6 = React 19 + antd 6 + ProComponents v3 + Umi Max 4 + utoopack(Turbopack)**,自带 layout/access/route/AI 助手,生产构建快约 42%。
- 走 **Umi Max**:白拿 ProLayout + 权限路由。
- 走 **Vite + React Router 7 自建**:更轻,但 ProLayout/access 需自接。
此为架构级选择,不能一句话"默认 Vite"带过,须先定走哪条。
### 修订 4:"权限/Excel/反过度设计:同前"——核不到,但原型有硬需求
原型明确含:① Excel 导入(《【优加】门店上架模版-V1.0.1.xlsx》,须校验模板版本一致性);② 角色/账号管理权限矩阵(ck.on/half/na 三态)。两项必须进栈且写明库:Excel 用 SheetJS 还是 ExcelJS?权限用 CASL 还是自研 access.ts?"同前"指向未贴出的前稿,无法验证其覆盖。建议显式写出。
### 修订 5:补强"为什么是现在升 6"——真理由
非"更省事",是 **antd 5 已进 1 年维护期、约 2026-11 EOL**。2026 年底新项目落 antd 5 等于上线即踩维护线。升 6 硬理由:避开 EOL + pure CSS var 默认 + 语义化 DOM 利于还原 + React Compiler 产物。
---
## 四、技术栈定稿建议
| 层 | 选型 | 备注 |
|---|---|---|
| 框架 | React 19 + TypeScript | antd 6 官方推荐搭配 |
| UI | antd 6 + @ant-design/pro-components v3 | v3 是 antd 6 线,禁与 v2 混用 |
| 构建/路由 | **二选一写明**:Umi Max 4(官方栈,自带 ProLayout+access+route) 或 Vite + React Router 7(自建、更轻) | 先定分叉 |
| 数据/状态 | TanStack Query + Zustand | 不变 |
| Excel | SheetJS / ExcelJS(显式指定,含模板版本校验) | 覆盖原型导入需求 |
| 权限 | CASL / access.ts(显式指定,覆盖三态权限矩阵) | 覆盖原型角色/账号页 |
| 反过度设计 | 同前 | — |
| 主题 | `colorPrimary:#2B5CE6` 对接主色;`--brand-deep:#0F1B3D` 深蓝导航用 ProLayout token + 自定义 CSS | antd 6 pure CSS var 默认 |
**一句话定稿**:antd 5 已进 1 年维护期、约 2026-11 EOL,新项目直接落 React 19 + antd 6,避开上线即踩维护线;主题用 `colorPrimary` 对接原型主色,深蓝导航区用 ProLayout token + 自定义 CSS 处理。
---
## 五、给对方的两条硬性修改要求
1. 理由从"省事 / 对接自然"改为"避开 EOL + 语义化 DOM 利于还原"。
2. 把 Vite/Umi 分叉、Excel 库、权限库三项显式定下,删掉"同前"留白。
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!