Commit ec5c2281 by 张立顺

Merge branch 'v1.0.0' of http://192.168.3.233:8090/ujia/uj-store into v1.0.0

2 parents acb9f81c a8e8b0d6
Pipeline #326 for ec5c2281 failed in 0 seconds
...@@ -93,3 +93,51 @@ ...@@ -93,3 +93,51 @@
3. `http.ts`:401 分支原只 `clearToken()` → 会话残留会造成「能停在内页但所有接口 401」的半吊子状态。改为依赖倒置:新增 `setUnauthorizedHandler(fn)` 注册回调(http 属基础设施层,不反向依赖 store/router),401 时 `clearToken()` + 回调;由 `main.tsx` 注册指向 `useAppStore.getState().logout()`(双清 + loggedIn=false → RequireAuth 自动重定向,无需手动 navigate)。注册必须在 `initSign()` 之前。 3. `http.ts`:401 分支原只 `clearToken()` → 会话残留会造成「能停在内页但所有接口 401」的半吊子状态。改为依赖倒置:新增 `setUnauthorizedHandler(fn)` 注册回调(http 属基础设施层,不反向依赖 store/router),401 时 `clearToken()` + 回调;由 `main.tsx` 注册指向 `useAppStore.getState().logout()`(双清 + loggedIn=false → RequireAuth 自动重定向,无需手动 navigate)。注册必须在 `initSign()` 之前。
- **注意**:`saveLoginSession` 的过期判定在 `session.ts:30` —— `new Date(expireAt).getTime() <= Date.now()`。若后端返回秒级时间戳会被判为 1970 年立即过期。自查方法:登录后控制台看 `JSON.parse(localStorage.session).expireAt` 与 `Date.now()` 对比。 - **注意**:`saveLoginSession` 的过期判定在 `session.ts:30` —— `new Date(expireAt).getTime() <= Date.now()`。若后端返回秒级时间戳会被判为 1970 年立即过期。自查方法:登录后控制台看 `JSON.parse(localStorage.session).expireAt` 与 `Date.now()` 对比。
- 类型检查 `tsc --noEmit` EXIT=0。 - 类型检查 `tsc --noEmit` EXIT=0。
## 菜单分组支持隐藏标题(hideTitle),工作台不再显示 group title
- 需求:左侧菜单「工作台」分组不想显示 `ant-menu-item-group-title`。
- **做法,不用 CSS 隐藏**:CSS 隐藏会留下 `.ant-menu-item-group-title` 的一行空白占位(它有 `padding-block: 12px 6px`)。改为在生成 items 时让该分组**不生成 `type:'group'` 节点**,children 直接平铺到当前层级,DOM 里真没有标题节点。
- 改动:
- `adapter.ts` `MenuGroupDef` 新增可选字段 `hideTitle?: boolean`(通用能力,非工作台专用硬编码)。后端树不下发该字段,仅前端固定组与兜底 menu.json 标注。
- `BasicLayout.tsx`:`FRONTEND_ONLY_GROUPS` 工作台加 `hideTitle: true`;items 由 `groups.map` 改为 `groups.flatMap<MenuItemType>`(泛型必须显式,否则 TS 把返回值推成 `(A[]|B[])[]`,不兼容 `flatMap` 期望的 `U | readonly U[]`,报 TS2345)。
- 新增类型别名 `type MenuItemType = NonNullable<MenuProps['items']>[number]`。
- `design.css`:平铺项加 `.uj-menu-item-flat`(`margin-block:4px`;`:first-child` 再 `margin-top:10px`),补回失去的标题占位,避免紧贴滚动区顶部/与下方分组挤在一起。
- `menu.json` 兜底组「工作台」同步加 `hideTitle: true`,保证接口失败回落时视觉一致。
- **踩坑(自己的错)**:Edit 时 old_string 锚点写错,误删了 `import type { MenuProps } from 'antd'` 与 `const { Header, Sider, Content } = Layout`,已读回恢复。**教训:改 import 区时 old_string 必须带上足够上下文,且先 Read 确认再改。**
- **遗留 4 条 TS6133(非本次改动引入,是超人在对话之间改代码留下的孤儿)**:`BasicLayout` 的 `Input`、`SearchOutlined`(header 搜索框 JSX 被删后残留);`StoreApprove:251 dataScope`、`StoreListing:157 scopeLabel`(算出来没渲染)。清理 `dataScope/scopeLabel` 会连锁让 `scope` 及 `getLoginSession/getUserInfo/getDataScopeLabel` 导入也变未使用,需迭代清理。已告知超人,待其决定是否清。
## 【架构约定】antd 组件定制只走 ConfigProvider token,禁止 CSS 覆盖组件内部盒模型
- 超人拍板:**antd Menu 除主题色外,所有布局相关样式(宽高/内外边距/定位/显示模式)一律沿用组件自身,不用自定义 CSS 覆盖**。
- **技术根因(antd 6.6.5 源码实证)**:
- `node_modules/antd/es/menu/style/vertical.js` 给 item 设了 `height/lineHeight/paddingInline/marginInline/marginBlock/width`(width 来自 `itemWidth` token)。
- 折叠态 `&-inline-collapsed` 用直接子代选择器覆盖 `> .ant-menu-item` 与 `> .ant-menu-item-group > .ant-menu-item-group-list > .ant-menu-item`,设 `display:flex; justifyContent:flex-start; paddingInline: calc(50% - collapsedIconSize/2 - itemMarginInline)`。
- 结论:**布局几何必须由 token 给**。我们此前写的 `width:auto !important` + `padding-inline:18px !important` + `justify-content:center` 正好把这三条原生计算全部覆盖掉,折叠态图标居中失衡就是这么来的(一个偏窄的盒子里做 center → 视觉偏左)。
- **token 清单(`components.Menu`,全部经 tsc 校验可用)**:`darkItemBg/darkSubMenuItemBg/darkItemColor/darkItemHoverBg/darkItemHoverColor/darkItemSelectedBg/darkItemSelectedColor/darkGroupTitleColor/darkPopupBg/itemHeight/itemMarginInline/itemPaddingInline/itemMarginBlock/itemBorderRadius/collapsedWidth/collapsedIconSize/iconSize/iconMarginInlineEnd/groupTitleFontSize/groupTitleLineHeight/groupTitleColor/subMenuItemBorderRadius/horizontalItemBorderRadius`。
- **本次落地**:
- `design.css` 菜单区块从 ~110 行压到 ~28 行,**只保留**:根 `background:transparent`、分组标题三项无 token 的字形(font-weight/letter-spacing/text-transform)、选中态 `inset` 阴影指示条、折叠态隐藏分组标题(唯一非颜色覆盖,已注明可删)。
- 删除的几何覆盖:`.ant-menu-item-group-list{display:flex}`、`.ant-menu-item{position/width/padding-inline/color/transition}`、`.ant-menu-item-icon{font-size}`、整套 `::before` 伪元素画胶囊机制与 `overflow:visible !important`、`.uj-menu-item-flat` 全部平移/折叠校准规则、`.ant-menu-inline-collapsed{width:100%}`。
- 删除 `.uj-sider` 上失效的 `--uj-menu-inset` / `--uj-menu-radius` 自定义变量。
- `themeConfig.ts` Menu token 补齐上述颜色与几何;`collapsedWidth: 68` **必须与 `<Sider collapsedWidth={68}>` 一致**(Menu 折叠态有自己的 collapsedWidth,默认 80,不等会溢出或留缝)。
- `BasicLayout.tsx` 移除已无 CSS 消费的 `className: 'uj-menu-item-flat'`。
- **踩坑备忘**:`.ant-menu-item` 有 antd 原生 `overflow:hidden`。做左侧指示条用 `inset box-shadow`(不占盒模型、不变宽高),不要用 `border-inline-start`(会改宽度从而破坏折叠居中计算)。
- 类型检查:本次改动零错;仓库仍剩上述 4 条历史 TS6133(非本次引入)。
## 菜单图标:后端 icon 字段取值约定 + 未知图标名告警
- **机制**:后端 `/system/menu/tree/current` 的 `icon` 是 **antd 图标名的字符串**(PascalCase,如 `ShopOutlined`),前端在 `BasicLayout.tsx` 的 `iconMap` 查表换成 React 节点;查不到或为 `null` 时回落 `DEFAULT_MENU_ICON = <AppstoreOutlined />`。这就是「所有菜单都是同一个默认图标」的原因(后端 icon 全为 null)。
- **当前 iconMap 只登记 6 个**:`DashboardOutlined`(仅前端固定工作台用)/`ShopOutlined`/`UploadOutlined`/`AuditOutlined`/`TeamOutlined`/`UserOutlined`。
- **后端应下发的值(照抄 menu.json 兜底菜单即可)**:
| route | 菜单 | icon |
| --------------- | ------------ | ---------------- |
| /store/import | 导入门店信息 | `UploadOutlined` |
| /store/approval | 门店审批 | `AuditOutlined` |
| /store/listing | 门店列表 | `ShopOutlined` |
| /system/role | 角色管理 | `TeamOutlined` |
| /system/user | 账号管理 | `UserOutlined` |
- 分组节点(nodeType=1)不渲染图标,`icon` 返回 null 即可;按钮点(nodeType=3)不进菜单,无需配。
- /dashboard 由前端 `FRONTEND_ONLY_GROUPS` 固定,后端不需要下发。
- **本次改动**:`BasicLayout.tsx` 新增 `resolveIcon(name)`,未知图标名在**开发环境告警一次**(用 `warnedIcons: Set<string>` 去重,避免每项刷屏),取代原先 `(m.icon && iconMap[m.icon]) || DEFAULT_MENU_ICON` 的静默回落;`import.meta.env.DEV` 可用(`src/vite-env.d.ts` 已 reference `vite/client`)。
- 注意 `tsconfig.json` 开了 `noUnusedLocals` / `noUnusedParameters` —— 未使用的局部变量与参数会直接报 TS6133。
- 类型检查:本次改动零错;仓库仍剩上述 4 条历史 TS6133。
# uj-store 长期项目约定
## UI 定制原则:antd 组件只用 ConfigProvider token,不用 CSS 覆盖组件内部盒模型
超人 2026-10-10 拍板,适用于全项目所有 antd 组件(先在 Menu 上执行):
- **允许**:主题色、透明度、字号/字重/字距/大小写这类**不影响布局**的属性,可写在 `src/theme/design.css`。
- **禁止**:覆盖组件内部节点的 `width / height / padding / margin / display / position / justify-content` 等几何属性。
- **正解**:几何一律从 `src/theme/themeConfig.ts` 的 `components.<Comp>` token 下发。token 是 antd 官方认可的定制入口,组件内部的宽度与居中计算会跟着 token 重算,不会互相打架。
**为什么这条不是洁癖而是硬约束**(antd 6.6.5 源码实证):
- `antd/es/menu/style/vertical.js` 给 item 设了完整的 `height / lineHeight / paddingInline / marginInline / marginBlock / width`(均来自 token)。
- 折叠态 `&-inline-collapsed` 用直接子代选择器重写 `> .ant-menu-item` 及 `> .ant-menu-item-group > .ant-menu-item-group-list > .ant-menu-item`,设 `paddingInline: calc(50% - collapsedIconSize/2 - itemMarginInline)`、`justifyContent: flex-start`。
- 一旦用 CSS 把 `width` / `padding-inline` 改成自己的值,这条 calc 就失准,表现为折叠态图标不居中(视觉偏左)。历史上为此连续迭代 4 版 CSS 方案均未解决,改回 token 后一次到位。
**配套注意**:
- `Menu.collapsedWidth` 必须与 `<Sider collapsedWidth>` 保持一致(Menu 折叠态有自己的 collapsedWidth,默认 80)。
- 做选中态左侧指示条用 `inset box-shadow`(不占盒模型),不要用 `border-inline-start`(会改宽度,破坏上面的居中计算)。antd item 原生是 `overflow: hidden`。
- antd 折叠态**不隐藏** `ant-menu-item-group-title`(只做 text-overflow 省略)。若要隐藏,这是目前唯一保留的非颜色 CSS 覆盖,已在 design.css 注释里标注可删。
## 技术栈与环境
- React + Vite + TypeScript + antd 6 + zustand + React Router 7(数据路由)。
- 自定义组件库 `@uj/ui`(前缀 `U*`,workspace package),多数是 antd 薄封装,通常**没有**自己的 Props 类型导出(如无 `UTableProps`,用 antd 的 `TableProps`)。
- tsc 校验命令(沙箱内 shell 缺 `sed/dirname/uname`,npm/pnpm CLI 起不来,必须这样跑):
`C:\Users\Limin\.workbuddy\binaries\node\versions\22.22.2-3\node.exe ./node_modules/typescript/bin/tsc --noEmit > d:/work/uj-store/_tsc.log 2>&1`
临时日志统一用托管 node 的 `fs.unlinkSync` 删(`rm` 会被 shell shim 挡住)。
## 权限模型
- 后端真源:`/system/menu/tree/current` 下发按角色装配的菜单树(含 `route` / `icon`);`auth.info()` 下发 `permCodes`(冒号格式)。
- 前端**不做任何权限码映射**:`toFrontendPoint` 是 identity。所有 `ResourceKey`(`store:list` / `store:import` / `store:approve` / `system:role` / `system:user`)、`P.*` 常量、`menu.json` resource 均为后端冒号格式。
- 权限按钮 JSX 一律按 `P.*` 常量名引用,改值即生效,组件层不用动。
- 判定两条路径:页面级 `can(resource)` 有三段兜底(`points.has(resource)` → `:manage` → `startsWith(resource + ':')`);按钮级 `canPoint(point)` 严格 `points.has()`,**无兜底**,必须与后端码逐字符一致。
## 登录态持久化(两套存储,必须同时维护)
- `uj_token`(localStorage):http 拦截器取 Authorization 的来源。
- `session`:路由守卫 `RequireAuth` 读 `useAppStore.loggedIn` 的依据,同时承载 name/account/dataScope/roleCodes/permCodes。
- 写入方在 `LoginForm.doLogin`:必须**同时** `setToken()` 和 `saveLoginSession()`。登出必须**同时** `clearToken()` 和 `clearLoginSession()`。
- 401 通过 `setUnauthorizedHandler()` 回调统一登出,http 层不反向依赖 store。
## 未决事项
- `P.STORE_APPROVE_AUDIT` / `P.STORE_LISTING_DELETE` 挂了后端不存在的动作码(后端审批只有 `pass`/`reject`,列表只有 `export`),按钮当前隐藏,等超人指定挂哪个权限点。
- `store.test.ts:191` 断言 `templateVersion === 'V1.0.1'`,但 `store.ts` 的 `uploadImport` 不 append 该字段 —— 断言必失败,等超人决定改实现还是删断言。
- 4 条历史 TS6133 孤儿(`BasicLayout` 的 `Input`/`SearchOutlined`,`StoreApprove` 的 `dataScope`,`StoreListing` 的 `scopeLabel`),超人未决定是否清理。
- `themeConfig.ts` 的 `brandDeep` / `brandGradient` 已无引用,保留作品牌资产备查。
...@@ -32,6 +32,12 @@ export interface MenuItemDef { ...@@ -32,6 +32,12 @@ export interface MenuItemDef {
export interface MenuGroupDef { export interface MenuGroupDef {
group: string; group: string;
children: MenuItemDef[]; children: MenuItemDef[];
/**
* true:不渲染分组标题,children 直接平铺为该层级的菜单项。
* 用于「工作台」这类只有一个入口的分组——挂一个独占一行的标题纯属噪音。
* 后端菜单树不会下发该字段,仅由前端固定组与兜底 menu.json 标注意图。
*/
hideTitle?: boolean;
} }
/** /**
......
...@@ -25,13 +25,26 @@ export const P = { ...@@ -25,13 +25,26 @@ export const P = {
STORE_LISTING_DELETE: 'store:list:delete', STORE_LISTING_DELETE: 'store:list:delete',
/** 角色管理 /** 角色管理
* system:role:view - 查看角色详情 * system:role:view - 查看角色详情
* system:role:save - 新增/编辑/删除角色 * system:role:save - 新增角色
* system:role:update - 编辑角色
* system:role:delete - 删除角色
*/ */
SYSTEM_ROLE_VIEW: 'system:role:view', SYSTEM_ROLE_VIEW: 'system:role:view',
SYSTEM_ROLE_SAVE: 'system:role:save', SYSTEM_ROLE_SAVE: 'system:role:save',
/** 账号管理 */ SYSTEM_ROLE_UPDATE: 'system:role:update',
SYSTEM_ROLE_DELETE: 'system:role:delete',
/** 账号管理
* system:user:view - 查看账号详情
* system:user:save - 新增账号
* system:user:update - 编辑账号
* system:user:status - 启用/停用账号
* system:user:reset - 重置密码
*/
SYSTEM_USER_VIEW: 'system:user:view', SYSTEM_USER_VIEW: 'system:user:view',
SYSTEM_USER_SAVE: 'system:user:save', SYSTEM_USER_SAVE: 'system:user:save',
SYSTEM_USER_UPDATE: 'system:user:update',
SYSTEM_USER_STATUS: 'system:user:status',
SYSTEM_USER_RESET: 'system:user:reset',
// 复用片段 // 复用片段
VIEW: ':view', VIEW: ':view',
MANAGE: ':manage', MANAGE: ':manage',
......
...@@ -56,6 +56,11 @@ class Menu extends ApiClient { ...@@ -56,6 +56,11 @@ class Menu extends ApiClient {
return this.treePromise; return this.treePromise;
} }
/** 角色详情使用的全量菜单树,不受当前登录用户菜单范围限制。 */
allTree(): Promise<MenuNode[]> {
return this.get<MenuNode[]>('/system/menu/tree');
}
/** 退出登录 / 切换账号时必须调用:菜单树随角色变化,缓存需失效 */ /** 退出登录 / 切换账号时必须调用:菜单树随角色变化,缓存需失效 */
clearCache() { clearCache() {
this.treePromise = null; this.treePromise = null;
......
...@@ -30,6 +30,22 @@ export interface RolePageItem { ...@@ -30,6 +30,22 @@ export interface RolePageItem {
sort?: number; sort?: number;
} }
export interface RoleDetail {
roleId: number;
roleCode: string;
roleName: string;
description?: string;
isBuiltin: number;
defaultDataScope: number;
defaultDataScopeLabel?: string;
userCount: number;
sort: number;
status: number;
permEditable: boolean;
menuIds: number[];
timestamp: number;
}
export interface RoleCreatePayload { export interface RoleCreatePayload {
roleCode: string; roleCode: string;
roleName: string; roleName: string;
...@@ -70,12 +86,18 @@ class Role extends ApiClient { ...@@ -70,12 +86,18 @@ class Role extends ApiClient {
page(payload: RolePageParams) { page(payload: RolePageParams) {
return this.post<RolePageResult>('/system/role/page', payload as Record<string, unknown>); return this.post<RolePageResult>('/system/role/page', payload as Record<string, unknown>);
} }
detail(roleId: number) {
return this.get<RoleDetail>(`/system/role/${roleId}`);
}
createSystem(payload: RoleCreatePayload) { createSystem(payload: RoleCreatePayload) {
return this.post<null>('/system/role/create', payload); return this.post<null>('/system/role/create', payload);
} }
updateSystem(payload: RoleUpdatePayload) { updateSystem(payload: RoleUpdatePayload) {
return this.post<null>('/system/role/update', payload); return this.post<null>('/system/role/update', payload);
} }
deleteSystem(roleId: number) {
return this.post<null>(`/system/role/${roleId}/delete`);
}
list(params: Record<string, unknown> = {}) { list(params: Record<string, unknown> = {}) {
return this.get<PageResult<RoleItem>>('/store/role/list', params); return this.get<PageResult<RoleItem>>('/store/role/list', params);
} }
......
...@@ -35,7 +35,6 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -35,7 +35,6 @@ export function SearchForm<T extends Record<string, unknown>>({
const common = { const common = {
disabled: typeof field.disabled === 'boolean' ? field.disabled : false, disabled: typeof field.disabled === 'boolean' ? field.disabled : false,
placeholder: field.placeholder, placeholder: field.placeholder,
size: 'small' as const,
}; };
const width = field.width ?? '100%'; const width = field.width ?? '100%';
if (field.type === 'select' || field.type === 'selectMultiple') if (field.type === 'select' || field.type === 'selectMultiple')
...@@ -52,9 +51,7 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -52,9 +51,7 @@ export function SearchForm<T extends Record<string, unknown>>({
return <UCascader {...common} style={{ width }} options={field.options} allowClear={false} />; return <UCascader {...common} style={{ width }} options={field.options} allowClear={false} />;
if (field.type === 'date') return <UDatePicker {...common} style={{ width }} />; if (field.type === 'date') return <UDatePicker {...common} style={{ width }} />;
if (field.type === 'dateRange') if (field.type === 'dateRange')
return ( return <UDatePicker.RangePicker disabled={common.disabled} style={{ width }} />;
<UDatePicker.RangePicker disabled={common.disabled} size={common.size} style={{ width }} />
);
if (field.type === 'radio') return <URadio.Group {...common} options={field.options} />; if (field.type === 'radio') return <URadio.Group {...common} options={field.options} />;
return field.type === 'textarea' ? ( return field.type === 'textarea' ? (
<UInput.TextArea {...common} style={{ width }} /> <UInput.TextArea {...common} style={{ width }} />
...@@ -84,7 +81,6 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -84,7 +81,6 @@ export function SearchForm<T extends Record<string, unknown>>({
<UFormItem style={searchActionsStyle}> <UFormItem style={searchActionsStyle}>
<UButton <UButton
type="default" type="default"
size="small"
onClick={() => { onClick={() => {
const resetValues = fields.reduce<Record<string, unknown>>((values, field) => { const resetValues = fields.reduce<Record<string, unknown>>((values, field) => {
const initialValue = initialValues?.[field.name]; const initialValue = initialValues?.[field.name];
...@@ -99,7 +95,7 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -99,7 +95,7 @@ export function SearchForm<T extends Record<string, unknown>>({
> >
重置 重置
</UButton> </UButton>
<UButton htmlType="submit" size="small" style={{ marginLeft: 8 }}> <UButton htmlType="submit" style={{ marginLeft: 8 }}>
查询 查询
</UButton> </UButton>
</UFormItem> </UFormItem>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"menus": [ "menus": [
{ {
"group": "工作台", "group": "工作台",
"hideTitle": true,
"children": [ "children": [
{ {
"path": "/dashboard", "path": "/dashboard",
......
...@@ -24,6 +24,9 @@ import type { MenuProps } from 'antd'; ...@@ -24,6 +24,9 @@ import type { MenuProps } from 'antd';
const { Header, Sider, Content } = Layout; const { Header, Sider, Content } = Layout;
/** antd Menu 的单条目类型:MenuProps['items'] 联合里的成员(普通项 / 分组 / 分割线…) */
type MenuItemType = NonNullable<MenuProps['items']>[number];
/* ---------- 菜单数据:以后端 /system/menu/tree/current 为准,menu.json 仅作接口未就绪时的兜底 ---------- */ /* ---------- 菜单数据:以后端 /system/menu/tree/current 为准,menu.json 仅作接口未就绪时的兜底 ---------- */
// 前端专属菜单:后端菜单树不下发「工作台」(它是所有角色的落地页,不该被权限挡), // 前端专属菜单:后端菜单树不下发「工作台」(它是所有角色的落地页,不该被权限挡),
...@@ -32,6 +35,8 @@ const { Header, Sider, Content } = Layout; ...@@ -32,6 +35,8 @@ const { Header, Sider, Content } = Layout;
const FRONTEND_ONLY_GROUPS: MenuGroupDef[] = [ const FRONTEND_ONLY_GROUPS: MenuGroupDef[] = [
{ {
group: '工作台', group: '工作台',
// 无标题组:菜单项平铺到顶层,不挂「工作台」标题
hideTitle: true,
children: [ children: [
{ path: '/dashboard', label: '工作台', icon: 'DashboardOutlined', resource: 'dashboard' }, { path: '/dashboard', label: '工作台', icon: 'DashboardOutlined', resource: 'dashboard' },
], ],
...@@ -52,9 +57,26 @@ const iconMap: Record<string, React.ReactNode> = { ...@@ -52,9 +57,26 @@ const iconMap: Record<string, React.ReactNode> = {
AuditOutlined: <AuditOutlined />, AuditOutlined: <AuditOutlined />,
UserOutlined: <UserOutlined />, UserOutlined: <UserOutlined />,
}; };
/** 后端未下发图标(icon 为 null)时的兜底图标 */ /** 后端未下发图标(icon 为 null)或图标名未登记时的兜底图标 */
const DEFAULT_MENU_ICON: React.ReactNode = <AppstoreOutlined />; const DEFAULT_MENU_ICON: React.ReactNode = <AppstoreOutlined />;
// 后端下发的 icon 是「antd 图标名字符串」,这里查表换成 React 节点。
// 未登记的图标名会静默回落默认图标 —— 这正是之前「菜单全是同一个图标」排查起来很痛苦的原因,
// 故开发环境对未知图标名告警一次(同名只报一次,避免菜单每项刷屏)。
const warnedIcons = new Set<string>();
function resolveIcon(name: string | null | undefined): React.ReactNode {
const hit = name ? iconMap[name] : undefined;
if (hit) return hit;
if (name && import.meta.env.DEV && !warnedIcons.has(name)) {
warnedIcons.add(name);
console.warn(
`[menu] 图标「${name}」未在 src/layouts/BasicLayout.tsx 的 iconMap 中登记,已回落默认图标。` +
`请在 iconMap 补一行,或让后端改发已支持的值。`,
);
}
return DEFAULT_MENU_ICON;
}
// 兜底菜单:接口失败/尚未返回时使用(与 src/config/menu.json 对应) // 兜底菜单:接口失败/尚未返回时使用(与 src/config/menu.json 对应)
const fallbackGroups: MenuGroupDef[] = (() => { const fallbackGroups: MenuGroupDef[] = (() => {
const raw = (menuJson as { menus?: unknown }).menus; const raw = (menuJson as { menus?: unknown }).menus;
...@@ -95,17 +117,18 @@ export default function BasicLayout() { ...@@ -95,17 +117,18 @@ export default function BasicLayout() {
: fallbackGroups; : fallbackGroups;
// -> antd Menu items(后端树已在 buildMenus 内与 permCodes 取过交集;兜底菜单按权限过滤) // -> antd Menu items(后端树已在 buildMenus 内与 permCodes 取过交集;兜底菜单按权限过滤)
const items: MenuProps['items'] = groups.map((g) => ({ // hideTitle 的分组不生成 type:'group',改由 children 平铺到当前层级——
type: 'group' as const, // 这样是真没有标题节点,而不是用 CSS 把标题藏起来(藏起来会留下一行空白占位)。
label: g.group, const items: MenuItemType[] = groups.flatMap<MenuItemType>((g) => {
children: g.children const children = g.children
.filter((m) => !m.resource || can(m.resource)) .filter((m) => !m.resource || can(m.resource))
.map((m) => ({ .map((m) => ({
key: m.path, key: m.path,
icon: (m.icon && iconMap[m.icon]) || DEFAULT_MENU_ICON, icon: resolveIcon(m.icon),
label: m.label, label: m.label,
})),
})); }));
return g.hideTitle ? children : [{ type: 'group' as const, label: g.group, children }];
});
const flat = groups.flatMap((g) => g.children); const flat = groups.flatMap((g) => g.children);
// 非菜单页面(如 /profile)不匹配任何菜单项:菜单不高亮,页题走 EXTRA_TITLES。 // 非菜单页面(如 /profile)不匹配任何菜单项:菜单不高亮,页题走 EXTRA_TITLES。
......
...@@ -155,7 +155,7 @@ export default function AccountManage() { ...@@ -155,7 +155,7 @@ export default function AccountManage() {
const rowActions: RowActionSchema<AccountRow>[] = [ const rowActions: RowActionSchema<AccountRow>[] = [
{ {
label: '编辑', label: '编辑',
permission: P.SYSTEM_USER_SAVE, permission: P.SYSTEM_USER_UPDATE,
onClick: (row) => { onClick: (row) => {
setEditingAccount(row.source); setEditingAccount(row.source);
setAccountModalOpen(true); setAccountModalOpen(true);
...@@ -163,12 +163,12 @@ export default function AccountManage() { ...@@ -163,12 +163,12 @@ export default function AccountManage() {
}, },
{ {
label: '重置密码', label: '重置密码',
permission: P.SYSTEM_USER_SAVE, permission: P.SYSTEM_USER_RESET,
onClick: (row) => setResettingAccount(row.source), onClick: (row) => setResettingAccount(row.source),
}, },
{ {
label: (row) => (row.status === 1 ? '停用' : '启用'), label: (row) => (row.status === 1 ? '停用' : '启用'),
permission: P.SYSTEM_USER_SAVE, permission: P.SYSTEM_USER_STATUS,
danger: (row) => row.status === 1, danger: (row) => row.status === 1,
onClick: (row) => setChangingStatusAccount(row.source), onClick: (row) => setChangingStatusAccount(row.source),
}, },
......
import { App, ConfigProvider } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import type { ButtonHTMLAttributes } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import RoleManage from './index';
const api = vi.hoisted(() => ({
page: vi.fn(),
detail: vi.fn(),
allTree: vi.fn(),
deleteSystem: vi.fn(),
}));
vi.mock('@/api', () => ({ role: api, menu: { allTree: api.allTree } }));
vi.mock('@/access', () => ({
P: { SYSTEM_ROLE_VIEW: 'system:role:view', SYSTEM_ROLE_SAVE: 'system:role:save' },
PermButton: ({
children,
permission: _permission,
danger: _danger,
...props
}: ButtonHTMLAttributes<HTMLButtonElement> & { permission?: string; danger?: boolean }) => (
<button {...props}>{children}</button>
),
}));
function renderPage() {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(
<ConfigProvider locale={zhCN}>
<App>
<QueryClientProvider client={client}>
<RoleManage />
</QueryClientProvider>
</App>
</ConfigProvider>,
);
}
describe('角色管理', () => {
beforeEach(() => {
vi.clearAllMocks();
api.page.mockResolvedValue({
records: [
{
roleId: 1,
roleName: '超级管理员',
roleCode: 'SYS_ADMIN',
defaultDataScope: 1,
userCount: 2,
isBuiltin: 1,
status: 1,
},
],
total: 1,
current: 1,
size: 10,
pages: 1,
});
api.detail.mockResolvedValue({
roleId: 1,
roleName: '超级管理员',
roleCode: 'SYS_ADMIN',
description: '拥有全部系统权限',
isBuiltin: 1,
defaultDataScope: 1,
defaultDataScopeLabel: '全部数据',
userCount: 2,
sort: 10,
status: 1,
permEditable: false,
menuIds: [10, 11],
timestamp: 0,
});
api.allTree.mockResolvedValue([
{
id: 10,
parentId: 0,
label: '系统设置',
permCode: null,
nodeType: 1,
sort: 1,
status: 1,
children: [
{
id: 11,
parentId: 10,
label: '角色管理',
permCode: 'system:role:view',
nodeType: 2,
sort: 1,
status: 1,
children: [
{
id: 12,
parentId: 11,
label: '编辑角色',
permCode: 'system:role:save',
nodeType: 3,
sort: 1,
status: 1,
children: [],
},
],
},
],
},
]);
api.deleteSystem.mockResolvedValue(null);
});
it('点击查看详情后从左侧打开只读角色详情抽屉', async () => {
renderPage();
fireEvent.click(await screen.findByRole('button', { name: '查看详情' }));
expect(await screen.findByText('角色详情 · 超级管理员')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: '保存并生效' })).not.toBeInTheDocument();
expect(screen.getAllByRole('button', { name: /退\s*出|关\s*闭/ }).length).toBeGreaterThan(0);
expect(screen.getByRole('tree')).toHaveTextContent('系统设置');
expect(screen.getByRole('tree')).toHaveTextContent('角色管理');
expect(screen.getByRole('tree')).toHaveTextContent('编辑角色');
expect(screen.getAllByLabelText('部分授权').length).toBeGreaterThan(1);
fireEvent.click(screen.getByRole('button', { name: '收起系统设置' }));
expect(screen.getByRole('tree')).not.toHaveTextContent('角色管理');
fireEvent.click(screen.getByRole('button', { name: '展开系统设置' }));
expect(screen.getByRole('tree')).toHaveTextContent('角色管理');
expect(api.detail).toHaveBeenCalledWith(1);
expect(api.allTree).toHaveBeenCalledTimes(1);
});
it('确认后删除角色并刷新列表', async () => {
renderPage();
fireEvent.click(await screen.findByRole('button', { name: '删除' }));
expect(await screen.findByText('是否删除角色“超级管理员”')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /确\s*定/ }));
await waitFor(() => expect(api.deleteSystem).toHaveBeenCalledWith(1));
});
});
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import { useQuery } from '@tanstack/react-query'; import { message } from 'antd';
import { useMutation, useQuery } from '@tanstack/react-query';
import type { ColumnsType } from 'antd/es/table'; import type { ColumnsType } from 'antd/es/table';
import { UCard, UTag, UText, UTitle } from '@uj/ui'; import { UCard, UTag, UText, UTitle } from '@uj/ui';
import { import {
DataTable, DataTable,
DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE,
ConfirmModal,
SearchForm, SearchForm,
type FieldSchema, type FieldSchema,
type RowActionSchema, type RowActionSchema,
...@@ -14,6 +16,7 @@ import { P, PermButton } from '@/access'; ...@@ -14,6 +16,7 @@ import { P, PermButton } from '@/access';
import { role, type RolePageItem, type RolePageParams } from '@/api'; import { role, type RolePageItem, type RolePageParams } from '@/api';
import { getDataScopeLabel } from '@/constants/dataScope'; import { getDataScopeLabel } from '@/constants/dataScope';
import { RoleModal } from './components/RoleModal'; import { RoleModal } from './components/RoleModal';
import { RoleDetailDrawer } from './components/RoleDetailDrawer';
import { getBaseList } from './tools/constants'; import { getBaseList } from './tools/constants';
interface Row { interface Row {
...@@ -54,6 +57,17 @@ export default function RoleManage() { ...@@ -54,6 +57,17 @@ export default function RoleManage() {
const [queryVersion, setQueryVersion] = useState(0); const [queryVersion, setQueryVersion] = useState(0);
const [roleModalOpen, setRoleModalOpen] = useState(false); const [roleModalOpen, setRoleModalOpen] = useState(false);
const [editingRole, setEditingRole] = useState<RolePageItem>(); const [editingRole, setEditingRole] = useState<RolePageItem>();
const [detailRole, setDetailRole] = useState<RolePageItem>();
const [deletingRole, setDeletingRole] = useState<RolePageItem>();
const deleteMutation = useMutation({
mutationFn: (roleItem: RolePageItem) => role.deleteSystem(roleItem.roleId),
onSuccess: () => {
void message.success('角色已删除');
setDeletingRole(undefined);
setQueryVersion((version) => version + 1);
},
onError: (error: Error) => void message.error(error.message || '删除失败,请稍后重试'),
});
const { const {
data: result, data: result,
isLoading, isLoading,
...@@ -123,10 +137,14 @@ export default function RoleManage() { ...@@ -123,10 +137,14 @@ export default function RoleManage() {
}, },
]; ];
const rowActions: RowActionSchema<Row>[] = [ const rowActions: RowActionSchema<Row>[] = [
{ label: '查看详情', permission: P.SYSTEM_ROLE_VIEW, onClick: () => undefined }, {
label: '查看详情',
permission: P.SYSTEM_ROLE_VIEW,
onClick: (row) => setDetailRole(row.source),
},
{ {
label: '编辑', label: '编辑',
permission: P.SYSTEM_ROLE_SAVE, permission: P.SYSTEM_ROLE_UPDATE,
onClick: (row) => { onClick: (row) => {
setEditingRole(row.source); setEditingRole(row.source);
setRoleModalOpen(true); setRoleModalOpen(true);
...@@ -134,9 +152,9 @@ export default function RoleManage() { ...@@ -134,9 +152,9 @@ export default function RoleManage() {
}, },
{ {
label: '删除', label: '删除',
permission: P.SYSTEM_ROLE_SAVE, permission: P.SYSTEM_ROLE_DELETE,
danger: true, danger: true,
onClick: () => undefined, onClick: (row) => setDeletingRole(row.source),
}, },
]; ];
return ( return (
...@@ -203,6 +221,20 @@ export default function RoleManage() { ...@@ -203,6 +221,20 @@ export default function RoleManage() {
setQueryVersion((version) => version + 1); setQueryVersion((version) => version + 1);
}} }}
/> />
<RoleDetailDrawer
open={Boolean(detailRole)}
roleId={detailRole?.roleId}
onClose={() => setDetailRole(undefined)}
/>
<ConfirmModal
open={Boolean(deletingRole)}
content={`是否删除角色${deletingRole ? `“${deletingRole.roleName}”` : ''}`}
confirmLoading={deleteMutation.isPending}
onCancel={() => setDeletingRole(undefined)}
onConfirm={() => {
if (deletingRole) deleteMutation.mutate(deletingRole);
}}
/>
</div> </div>
); );
} }
...@@ -45,7 +45,7 @@ function NodeIcon({ status, index }: NodeIconProps) { ...@@ -45,7 +45,7 @@ function NodeIcon({ status, index }: NodeIconProps) {
width: 32, width: 32,
height: 32, height: 32,
borderRadius: '50%', borderRadius: '50%',
background: '#4F46E5', background: '#2B5CE6',
display: 'inline-flex', display: 'inline-flex',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
...@@ -149,7 +149,7 @@ export function ApprovalChainPreview({ ...@@ -149,7 +149,7 @@ export function ApprovalChainPreview({
style={{ marginBottom: 20, border: '1px solid #E5E7EB', borderRadius: 10 }} style={{ marginBottom: 20, border: '1px solid #E5E7EB', borderRadius: 10 }}
title={ title={
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}> <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<InfoCircleFilled style={{ color: '#4F46E5', fontSize: 14 }} /> <InfoCircleFilled style={{ color: '#2B5CE6', fontSize: 14 }} />
<span style={{ fontSize: 15, fontWeight: 600 }}>审批链预览</span> <span style={{ fontSize: 15, fontWeight: 600 }}>审批链预览</span>
</div> </div>
} }
...@@ -172,7 +172,7 @@ export function ApprovalChainPreview({ ...@@ -172,7 +172,7 @@ export function ApprovalChainPreview({
fontSize: 14, fontSize: 14,
fontWeight: 600, fontWeight: 600,
color: color:
n.status === 'active' ? '#4F46E5' : n.status === 'done' ? '#16A34A' : '#6B7280', n.status === 'active' ? '#2B5CE6' : n.status === 'done' ? '#16A34A' : '#6B7280',
textAlign: 'center', textAlign: 'center',
}} }}
> >
......
...@@ -99,7 +99,7 @@ export function ImportInfoCard({ values, checkResult, onChange }: ImportInfoCard ...@@ -99,7 +99,7 @@ export function ImportInfoCard({ values, checkResult, onChange }: ImportInfoCard
style={{ marginBottom: 20, border: '1px solid #E5E7EB' }} style={{ marginBottom: 20, border: '1px solid #E5E7EB' }}
title={ title={
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}> <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<InfoCircleFilled style={{ color: '#4F46E5', fontSize: 14 }} /> <InfoCircleFilled style={{ color: '#2B5CE6', fontSize: 14 }} />
<span style={{ fontSize: 15, fontWeight: 600 }}>导入信息</span> <span style={{ fontSize: 15, fontWeight: 600 }}>导入信息</span>
</div> </div>
} }
......
...@@ -36,7 +36,7 @@ export function NoticeSection() { ...@@ -36,7 +36,7 @@ export function NoticeSection() {
gap: 6, gap: 6,
padding: '2px 10px', padding: '2px 10px',
borderRadius: 10, borderRadius: 10,
background: '#4F46E5', background: '#2B5CE6',
color: '#fff', color: '#fff',
fontSize: 12, fontSize: 12,
fontWeight: 500, fontWeight: 500,
...@@ -45,7 +45,7 @@ export function NoticeSection() { ...@@ -45,7 +45,7 @@ export function NoticeSection() {
<BulbFilled style={{ fontSize: 12 }} /> <BulbFilled style={{ fontSize: 12 }} />
上架联动规则 上架联动规则
</span> </span>
<span style={{ fontSize: 14, fontWeight: 600, color: '#3730A3' }}> <span style={{ fontSize: 14, fontWeight: 600, color: '#2B5CE6' }}>
主服务商切换与外部系统联动要点 主服务商切换与外部系统联动要点
</span> </span>
</div> </div>
...@@ -69,7 +69,7 @@ export function NoticeSection() { ...@@ -69,7 +69,7 @@ export function NoticeSection() {
height: 18, height: 18,
borderRadius: '50%', borderRadius: '50%',
background: '#E0E7FF', background: '#E0E7FF',
color: '#4338CA', color: '#2B5CE6',
fontSize: 11, fontSize: 11,
fontWeight: 600, fontWeight: 600,
display: 'inline-flex', display: 'inline-flex',
......
...@@ -31,15 +31,6 @@ export function PageHeader() { ...@@ -31,15 +31,6 @@ export function PageHeader() {
loading: downloading, loading: downloading,
onClick: handleDownload, onClick: handleDownload,
}, },
{
key: 'spec',
label: '查看导入规范',
icon: null as React.ReactNode,
loading: false,
onClick: () => {
console.log('查看导入规范');
},
},
]; ];
return ( return (
......
...@@ -38,7 +38,7 @@ export function PolicyConfirmHeader({ ...@@ -38,7 +38,7 @@ export function PolicyConfirmHeader({
}} }}
> >
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}> <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<InfoCircleFilled style={{ color: '#4F46E5', fontSize: 14 }} /> <InfoCircleFilled style={{ color: '#2B5CE6', fontSize: 14 }} />
<span style={{ fontSize: 15, fontWeight: 600, color: '#1A202C' }}> <span style={{ fontSize: 15, fontWeight: 600, color: '#1A202C' }}>
商务政策确认 · {storeName} / 共 {displayRows} 行 商务政策确认 · {storeName} / 共 {displayRows} 行
</span> </span>
......
...@@ -119,7 +119,7 @@ export function SubmitConfirmCard({ ...@@ -119,7 +119,7 @@ export function SubmitConfirmCard({
}, },
{ {
label: '运营成本合计', label: '运营成本合计',
value: <span style={{ color: '#4F46E5', fontWeight: 600 }}>{finalInfo.operatingCost}</span>, value: <span style={{ color: '#2B5CE6', fontWeight: 600 }}>{finalInfo.operatingCost}</span>,
desc: finalInfo.operatingCostDetail, desc: finalInfo.operatingCostDetail,
}, },
{ {
...@@ -144,7 +144,7 @@ export function SubmitConfirmCard({ ...@@ -144,7 +144,7 @@ export function SubmitConfirmCard({
style={{ marginBottom: 20, border: '1px solid #E5E7EB', borderRadius: 10 }} style={{ marginBottom: 20, border: '1px solid #E5E7EB', borderRadius: 10 }}
title={ title={
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}> <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<InfoCircleFilled style={{ color: '#4F46E5', fontSize: 14 }} /> <InfoCircleFilled style={{ color: '#2B5CE6', fontSize: 14 }} />
<span style={{ fontSize: 15, fontWeight: 600 }}>提交确认</span> <span style={{ fontSize: 15, fontWeight: 600 }}>提交确认</span>
</div> </div>
} }
......
...@@ -197,7 +197,7 @@ export function UploadCard({ ...@@ -197,7 +197,7 @@ export function UploadCard({
style={{ border: '1px solid #E5E7EB', marginBottom: 20 }} style={{ border: '1px solid #E5E7EB', marginBottom: 20 }}
title={ title={
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}> <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<InfoCircleFilled style={{ color: '#4F46E5', fontSize: 14 }} /> <InfoCircleFilled style={{ color: '#2B5CE6', fontSize: 14 }} />
<span style={{ fontSize: 15, fontWeight: 600 }}>上传门店上架表</span> <span style={{ fontSize: 15, fontWeight: 600 }}>上传门店上架表</span>
</div> </div>
} }
...@@ -224,9 +224,9 @@ export function UploadCard({ ...@@ -224,9 +224,9 @@ export function UploadCard({
}} }}
> >
{uploading ? ( {uploading ? (
<LoadingOutlined style={{ fontSize: 22, color: '#4F46E5' }} /> <LoadingOutlined style={{ fontSize: 22, color: '#2B5CE6' }} />
) : ( ) : (
<UploadOutlined style={{ fontSize: 22, color: '#4F46E5' }} /> <UploadOutlined style={{ fontSize: 22, color: '#2B5CE6' }} />
)} )}
</div> </div>
<p <p
......
...@@ -15,7 +15,7 @@ interface StatCardProps { ...@@ -15,7 +15,7 @@ interface StatCardProps {
const toneMap: Record<StatItem['tone'], { border: string; accent: string }> = { const toneMap: Record<StatItem['tone'], { border: string; accent: string }> = {
primary: { primary: {
border: '1px solid #C7D2FE', border: '1px solid #C7D2FE',
accent: '#4F46E5', accent: '#2B5CE6',
}, },
success: { success: {
border: '1px solid #86EFAC', border: '1px solid #86EFAC',
......
...@@ -179,10 +179,8 @@ ...@@ -179,10 +179,8 @@
/* 垂直、低饱和、matte 深蓝:比原 160° 对角渐变更稳重、更有层次但不「动」。 */ /* 垂直、低饱和、matte 深蓝:比原 160° 对角渐变更稳重、更有层次但不「动」。 */
background: linear-gradient(180deg, #0e1736 0%, #111b3d 55%, #0e1631 100%); background: linear-gradient(180deg, #0e1736 0%, #111b3d 55%, #0e1631 100%);
box-shadow: 4px 0 24px -12px rgba(6, 12, 38, 0.55); box-shadow: 4px 0 24px -12px rgba(6, 12, 38, 0.55);
/* 侧边菜单的水平几何只由这一个旋钮决定: /* 侧边菜单不再有 CSS 旋钮:高度 / 左右留白 / 圆角 / 图标尺寸 / 折叠宽度
--uj-menu-inset 胶囊左右留白;--uj-menu-radius 胶囊圆角。改这两处,展开态同步生效。 */ 全部写在 themeConfig.ts 的 components.Menu token 里,由组件自身参与计算。 */
--uj-menu-inset: 10px;
--uj-menu-radius: 10px;
} }
.uj-sider > .ant-layout-sider-children { .uj-sider > .ant-layout-sider-children {
display: flex; display: flex;
...@@ -224,9 +222,9 @@ ...@@ -224,9 +222,9 @@
text-transform: uppercase; text-transform: uppercase;
} }
/* 菜单区:接管滚动,隐藏滚动条。 /* 菜单滚动区:只负责接管滚动与隐藏滚动条。
横向安全区不再由容器 padding 承担 —— 由菜单项自身的对称 margin 承担(见下方 --uj-menu-inset)。 横向留白不再由这里承担 —— 由 Menu 的 itemMarginInline token 承担(见 themeConfig.ts)。
另外加 scrollbar-gutter: stable both-edges:即使滚动条真的占了宽度, 加 scrollbar-gutter: stable both-edges:即使滚动条真的占了宽度,
浏览器也会在**两侧同时**预留相同空间,左右不会因此失对称。 */ 浏览器也会在**两侧同时**预留相同空间,左右不会因此失对称。 */
.uj-sider-menu { .uj-sider-menu {
flex: 1; flex: 1;
...@@ -242,93 +240,34 @@ ...@@ -242,93 +240,34 @@
height: 0; height: 0;
} }
/* 菜单质感:分组标题 / 圆角选中态 / 悬浮 */ /* 菜单:本文件**只做主题着色**。
所有几何量(高度、左右留白、内间距、圆角、图标尺寸、折叠宽度)都不在此覆盖,
改由 ConfigProvider 的 Menu token 下发(见 src/theme/themeConfig.ts 的 components.Menu)——
那是 antd 官方认可的定制入口,组件内部的宽度/居中计算会跟着 token 一起重算,不会互相打架。
折叠态的图标居中尤其依赖这一点:antd 原生用 marginInline + paddingInline:calc(50% - 图标宽/2 - margin),
任何对 width / padding-inline 的 CSS 覆盖都会把它算歪。 */
.uj-menu.ant-menu-dark { .uj-menu.ant-menu-dark {
background: transparent; background: transparent;
} }
/* 分组标题:只有字重/字距/大小写没有对应 token,故保留这三项;
字号与颜色已移到 themeConfig 的 groupTitleFontSize / darkGroupTitleColor。
间距一律不写——antd 自身会让标题与菜单项对齐,手动设 padding 反而容易错位。 */
.uj-menu.ant-menu-dark .ant-menu-item-group-title { .uj-menu.ant-menu-dark .ant-menu-item-group-title {
color: rgba(255, 255, 255, 0.32);
font-size: 10.5px;
font-weight: 600; font-weight: 600;
letter-spacing: 2px; letter-spacing: 2px;
text-transform: uppercase; text-transform: uppercase;
padding-block: 12px 6px;
/* 与菜单项文字左对齐:item 的外边距 10 + 内边距 18 = 28 */
padding-inline: 28px;
} }
/* 分组列表改为 flex 列容器:子项在交叉轴上 stretch, /* 选中态左侧指示条:用 inset 阴影画,不占盒模型空间,
此时 width:auto 必然撑满 content box,不依赖百分比对其包含块的解算结果。 */ 因此不会改变组件的宽高,也不会干扰折叠态的居中计算。 */
.uj-menu.ant-menu-dark .ant-menu-item-group-list {
display: flex;
flex-direction: column;
}
.uj-menu.ant-menu-dark .ant-menu-item {
position: relative;
border-radius: var(--uj-menu-radius);
/* 宽度由 flex 容器的交叉轴拉伸得到(宽度永远是「容器内容宽 - 两侧 margin」),
不需要与任何数值配对;左右留白只由这一条 margin 决定,天然对称。 */
width: auto !important;
/* margin-inline: var(--uj-menu-inset) !important; */
/* antd 给「分组内」item 的是非对称 padding:paddingInline: 28px 16px
(见 antd/es/menu/style/index.js 的 -item-group-list 规则),必须抹平为对称值。 */
padding-inline: 18px !important;
color: rgba(255, 255, 255, 0.62);
transition: all 0.25s ease;
}
.uj-menu.ant-menu-dark .ant-menu-item .ant-menu-item-icon {
font-size: 15px;
}
/* 胶囊统一用具名 ::before 画:inset 四边归零 + 圆角继承宿主,
不使用 left/right 分写,避免出现某一边被后续规则覆盖而失衡。 */
.uj-menu.ant-menu-dark .ant-menu-item::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
opacity: 0;
transition: opacity 0.25s ease;
pointer-events: none;
}
/* 悬浮态 */
.uj-menu.ant-menu-dark .ant-menu-item:not(.ant-menu-item-selected):hover {
color: #fff;
background: transparent !important;
}
.uj-menu.ant-menu-dark .ant-menu-item:not(.ant-menu-item-selected):hover::before {
opacity: 1;
background: rgba(255, 255, 255, 0.06);
}
/* 选中态:克制品牌色淡填充 + 左侧细指示条(无发光,企业级稳重感)。
淡填充让人看清「当前位置」,但不过分跳;细条在收起态仍保留,指向更明确。 */
.uj-menu.ant-menu-dark .ant-menu-item-selected { .uj-menu.ant-menu-dark .ant-menu-item-selected {
background: transparent !important; box-shadow: inset 3px 0 0 0 #5b8def;
color: #fff !important;
overflow: visible !important;
}
.uj-menu.ant-menu-dark .ant-menu-item-selected::before {
opacity: 1;
background: rgba(43, 92, 230, 0.22) !important;
box-shadow: inset 3px 0 0 0 #5b8def !important;
}
.uj-menu.ant-menu-dark .ant-menu-item-selected > * {
position: relative;
z-index: 1;
}
/* 收缩态:隐藏分组标题;图标居中改用 flex(antd 原用 paddingInline 计算,被上面的对称 padding 覆盖掉了) */
.uj-menu.ant-menu-inline-collapsed {
width: 100%;
} }
/* 收起态隐藏分组标题 —— 这是本区块唯一一处非颜色覆盖:
antd 折叠时并不隐藏分组标题,只做 text-overflow 省略(会留下比如「门…」这样的小字),
企业后台通常选择直接隐藏。若你想要组件原生行为,删掉这三条即可。 */
.uj-menu.ant-menu-inline-collapsed .ant-menu-item-group-title { .uj-menu.ant-menu-inline-collapsed .ant-menu-item-group-title {
display: none; display: none;
} }
.uj-menu.ant-menu-inline-collapsed .ant-menu-item {
/* 外边距与宽度无需为收起态另写一套:沿用上面的对称 margin + 拉伸宽度,
收起态自动同样居中(68 - 10×2 = 48)。仅把内边距归零,让图标在窄胶囊里居中
(antd 原本用 paddingInline 的 calc 值居中,被上面的对称 padding 覆盖掉了)。 */
padding-inline: 0 !important;
justify-content: center;
border-radius: var(--uj-menu-radius);
}
/* ============ 应用骨架:Header ============ */ /* ============ 应用骨架:Header ============ */
.uj-header { .uj-header {
......
...@@ -44,13 +44,28 @@ export const themeConfig: ThemeConfig = { ...@@ -44,13 +44,28 @@ export const themeConfig: ThemeConfig = {
bodyBg: '#F4F6FA', bodyBg: '#F4F6FA',
}, },
Menu: { Menu: {
// —— 颜色(暗色模式)——
darkItemBg: 'transparent', darkItemBg: 'transparent',
darkSubMenuItemBg: 'transparent', darkSubMenuItemBg: 'transparent',
darkItemColor: 'rgba(255,255,255,.62)',
darkItemHoverBg: 'rgba(255,255,255,.06)',
darkItemHoverColor: '#FFFFFF',
darkItemSelectedBg: 'rgba(43,92,230,.22)', darkItemSelectedBg: 'rgba(43,92,230,.22)',
darkItemSelectedColor: '#FFFFFF', darkItemSelectedColor: '#FFFFFF',
darkGroupTitleColor: 'rgba(255,255,255,.32)',
// 折叠态弹出的子菜单底:与 .uj-sider 中段色一致,避免弹出层露出 antd 默认的深蓝黑
darkPopupBg: '#111B3D',
// —— 几何:全部走 token,不在 design.css 里用 CSS 覆盖组件内部盒模型 ——
// antd 会用 itemMarginInline 参与折叠态居中计算(paddingInline: calc(50% - 图标宽/2 - itemMarginInline)),
// 所以「胶囊左右留白」必须由这个 token 给,不能用 CSS margin 顶替。
itemMarginInline: 10,
itemBorderRadius: 10,
itemHeight: 44, itemHeight: 44,
itemMarginInline: 8, iconSize: 15,
iconSize: 16, groupTitleFontSize: 10.5,
// 必须与 <Sider collapsedWidth={68}> 保持一致:Menu 折叠态有自己的 collapsedWidth,
// 两者不等会让菜单比侧栏宽(溢出)或窄(留缝)。
collapsedWidth: 68,
}, },
Card: { Card: {
borderRadiusLG: 12, borderRadiusLG: 12,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!