Commit 57cfc0b6 by chenwq

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

2 parents a19d084f ff7a4012
Pipeline #322 for 57cfc0b6 failed in 0 seconds
# 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;
} }
/** /**
......
...@@ -121,6 +121,18 @@ http.interceptors.request.use((config: any) => { ...@@ -121,6 +121,18 @@ http.interceptors.request.use((config: any) => {
return config; return config;
}); });
// ---------- 令牌失效(401)的上层处理回调 ----------
// http 属于基础设施层,不应反向依赖 store / 路由。
// 采用回调注册:由 main.tsx 在启动时注入统一的登出入口。
// 未注册时退化为「仅清除令牌」,不会崩,但也无法触发跳转。
type UnauthorizedHandler = () => void;
let _unauthorizedHandler: UnauthorizedHandler | null = null;
/** 注册令牌失效的统一处理(应指向 store 的 logout) */
export function setUnauthorizedHandler(fn: UnauthorizedHandler) {
_unauthorizedHandler = fn;
}
// ---------- 响应拦截:服务端验签 + 统一错误 ---------- // ---------- 响应拦截:服务端验签 + 统一错误 ----------
// 生产置 VITE_STRICT_VERIFY=true:响应声明签名却无法校验时直接拒绝; // 生产置 VITE_STRICT_VERIFY=true:响应声明签名却无法校验时直接拒绝;
// 开发默认放行(仅告警),避免因公钥未加载/后端未对全部响应加签而阻断业务。 // 开发默认放行(仅告警),避免因公钥未加载/后端未对全部响应加签而阻断业务。
...@@ -171,8 +183,13 @@ http.interceptors.response.use( ...@@ -171,8 +183,13 @@ http.interceptors.response.use(
const body = raw ? JSON.parse(raw) : null; const body = raw ? JSON.parse(raw) : null;
if (body && typeof body === 'object' && 'code' in body && body.code !== 200) { if (body && typeof body === 'object' && 'code' in body && body.code !== 200) {
// 令牌失效/未登录:清除本地令牌,交由调用方引导重新登录 // 令牌失效/未登录:先自清除令牌,保证后续请求不再携带已失效凭据;
if (body.code === 401) clearToken(); // 再通知上层统一登出——必须同时清掉会话 session 并把 loggedIn 置 false,
// 否则会出现「能停在页面上但所有接口都 401」的半吊子状态。
if (body.code === 401) {
clearToken();
_unauthorizedHandler?.();
}
const err: any = new Error(body.message || '请求失败'); const err: any = new Error(body.message || '请求失败');
err.code = body.code; err.code = body.code;
err.data = 'data' in body ? body.data : undefined; err.data = 'data' in body ? body.data : undefined;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"menus": [ "menus": [
{ {
"group": "工作台", "group": "工作台",
"hideTitle": true,
"children": [ "children": [
{ {
"path": "/dashboard", "path": "/dashboard",
......
import { Layout, Menu, Avatar, Dropdown, Badge, Tooltip, Input, Button, Breadcrumb } from 'antd'; import { Layout, Menu, Avatar, Dropdown, Input, Button, Breadcrumb } from 'antd';
import { Suspense, useEffect, useState } from 'react'; import { Suspense, useEffect, useState } from 'react';
import { Outlet, useLocation, useNavigate } from 'react-router-dom'; import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import { import {
...@@ -11,10 +11,8 @@ import { ...@@ -11,10 +11,8 @@ import {
TeamOutlined, TeamOutlined,
AuditOutlined, AuditOutlined,
AppstoreOutlined, AppstoreOutlined,
BellOutlined,
MenuFoldOutlined, MenuFoldOutlined,
MenuUnfoldOutlined, MenuUnfoldOutlined,
QuestionCircleOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { useAccess, buildMenus, type MenuGroupDef } from '@/access'; import { useAccess, buildMenus, type MenuGroupDef } from '@/access';
import { useAppStore } from '@/store/useAppStore'; import { useAppStore } from '@/store/useAppStore';
...@@ -27,6 +25,9 @@ import type { MenuProps } from 'antd'; ...@@ -27,6 +25,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 仅作接口未就绪时的兜底 ---------- */
// 前端专属菜单:后端菜单树不下发「工作台」(它是所有角色的落地页,不该被权限挡), // 前端专属菜单:后端菜单树不下发「工作台」(它是所有角色的落地页,不该被权限挡),
...@@ -35,6 +36,8 @@ const { Header, Sider, Content } = Layout; ...@@ -35,6 +36,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' },
], ],
...@@ -55,9 +58,26 @@ const iconMap: Record<string, React.ReactNode> = { ...@@ -55,9 +58,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;
...@@ -98,17 +118,18 @@ export default function BasicLayout() { ...@@ -98,17 +118,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。
...@@ -206,13 +227,13 @@ export default function BasicLayout() { ...@@ -206,13 +227,13 @@ export default function BasicLayout() {
{/* 中:全局搜索 */} {/* 中:全局搜索 */}
<div className="uj-header-search"> <div className="uj-header-search">
<Input {/* <Input
prefix={<SearchOutlined style={{ color: '#8A94A6' }} />} prefix={<SearchOutlined style={{ color: '#8A94A6' }} />}
placeholder="搜索门店 / 任务…" placeholder="搜索门店 / 任务…"
variant="borderless" variant="borderless"
allowClear allowClear
/> />
<span className="uj-header-search-kbd">⌘K</span> <span className="uj-header-search-kbd">⌘K</span> */}
</div> </div>
{/* 右:通知 / 帮助 / 用户 */} {/* 右:通知 / 帮助 / 用户 */}
......
...@@ -6,12 +6,18 @@ import { ConfigProvider, App as AntApp } from 'antd'; ...@@ -6,12 +6,18 @@ import { ConfigProvider, App as AntApp } from 'antd';
import zhCN from 'antd/locale/zh_CN'; import zhCN from 'antd/locale/zh_CN';
import { router } from '@/router'; import { router } from '@/router';
import { queryClient } from '@/queryClient'; import { queryClient } from '@/queryClient';
import { useAppStore } from '@/store/useAppStore';
import { themeConfig } from '@/theme/themeConfig'; import { themeConfig } from '@/theme/themeConfig';
import { AccessProvider } from '@/access'; import { AccessProvider } from '@/access';
import { initSign } from '@/api'; import { initSign, setUnauthorizedHandler } from '@/api';
import './index.css'; import './index.css';
import './theme/design.css'; import './theme/design.css';
// 令牌失效(401)的统一处理出口。必须在任何请求发出(含下面的 initSign)之前注册。
// logout 会双清 uj_token 与 session 并把 loggedIn 置 false;
// RequireAuth 订阅了 loggedIn,状态翻转即自动重定向到 /login,无需手动跳转。
setUnauthorizedHandler(() => useAppStore.getState().logout());
// 拉取服务端公钥用于响应验签(本环境公钥接口需签名鉴权);失败仅告警, // 拉取服务端公钥用于响应验签(本环境公钥接口需签名鉴权);失败仅告警,
// 真正的阻断逻辑在各调用方(如登录)通过 ensureSignReady 自行判断。 // 真正的阻断逻辑在各调用方(如登录)通过 ensureSignReady 自行判断。
void initSign().catch(() => {}); void initSign().catch(() => {});
......
...@@ -10,11 +10,9 @@ import { ...@@ -10,11 +10,9 @@ import {
UserOutlined, UserOutlined,
ArrowRightOutlined, ArrowRightOutlined,
SafetyOutlined, SafetyOutlined,
RiseOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
import { UCard, UButton, UText } from '@uj/ui'; import { UCard, UButton, UText } from '@uj/ui';
import { brandGradient } from '@/theme/themeConfig';
import { useAppStore } from '@/store/useAppStore'; import { useAppStore } from '@/store/useAppStore';
import { useAccess, roleLabels, type ResourceKey } from '@/access'; import { useAccess, roleLabels, type ResourceKey } from '@/access';
...@@ -91,39 +89,26 @@ export default function Dashboard() { ...@@ -91,39 +89,26 @@ export default function Dashboard() {
return ( return (
<div className="uj-dash"> <div className="uj-dash">
{/* 品牌欢迎条 */} {/* 品牌欢迎条:浅色卡片 + 品牌色点睛(不再大面积铺深色,避免压抑) */}
<div className="uj-dash-hero" style={{ background: brandGradient }}> <div className="uj-dash-hero">
<div> <div className="uj-dash-hero-id">
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}> <div className="uj-dash-hero-brand">
<RiseOutlined style={{ color: '#5B8DEF', fontSize: 18 }} /> <span className="uj-dash-hero-mark" />
<span style={{ color: 'rgba(255,255,255,.55)', fontSize: 13, letterSpacing: 1 }}> STORE LAUNCH PLATFORM
STORE LAUNCH PLATFORM
</span>
</div> </div>
<h1 style={{ color: '#fff', fontSize: 26, fontWeight: 700, margin: '10px 0 6px' }}> <h1 className="uj-dash-hero-title">
{greeting()},{currentUser.name || '欢迎回来'} {greeting()},{currentUser.name || '欢迎回来'}
</h1> </h1>
<p style={{ color: 'rgba(255,255,255,.62)', fontSize: 13, margin: 0 }}> <p className="uj-dash-hero-sub">{dateText} · 欢迎回到优加门店上架系统</p>
{dateText} · 欢迎回到优加门店上架系统
</p>
</div> </div>
<div className="uj-dash-hero-actions"> <div className="uj-dash-hero-meta">
<div <div className="uj-dash-meta-item">
style={{ <span className="uj-dash-meta-label">账号</span>
textAlign: 'right', <span className="uj-dash-meta-value">{currentUser.account || '-'}</span>
color: 'rgba(255,255,255,.88)', </div>
fontSize: 13, <div className="uj-dash-meta-item">
lineHeight: 1.9, <span className="uj-dash-meta-label">角色</span>
}} <span className="uj-dash-meta-value">{roleText}</span>
>
<div>
<span style={{ opacity: 0.6 }}>账号 </span>
<span style={{ fontWeight: 600 }}>{currentUser.account || '-'}</span>
</div>
<div>
<span style={{ opacity: 0.6 }}>角色 </span>
<span style={{ fontWeight: 600 }}>{roleText}</span>
</div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -11,7 +11,7 @@ import { useNavigate } from 'react-router-dom'; ...@@ -11,7 +11,7 @@ import { useNavigate } from 'react-router-dom';
import { App } from 'antd'; import { App } from 'antd';
import { LockOutlined, UserOutlined } from '@ant-design/icons'; import { LockOutlined, UserOutlined } from '@ant-design/icons';
import { useAppStore } from '@/store/useAppStore'; import { useAppStore } from '@/store/useAppStore';
import { useAccess } from '@/access'; import { useAccess, saveLoginSession } from '@/access';
import { auth, menu as menuApi, ensureSignReady } from '@/api'; import { auth, menu as menuApi, ensureSignReady } from '@/api';
import { setToken } from '@/api/core/token'; import { setToken } from '@/api/core/token';
import { UButton, UForm, UFormItem, UInput, UTitle, UText } from '@uj/ui'; import { UButton, UForm, UFormItem, UInput, UTitle, UText } from '@uj/ui';
...@@ -34,8 +34,25 @@ export function LoginForm() { ...@@ -34,8 +34,25 @@ export function LoginForm() {
return; return;
} }
const res = await auth.login({ account, password }); const res = await auth.login({ account, password });
// 1) 持久化令牌(后续请求由 http 拦截器自动注入 Authorization) // 1) 持久化令牌(后续请求由 http 拦截器从 uj_token 读取并注入 Authorization)
setToken(res.token); setToken(res.token);
// 2) 持久化完整会话(localStorage 的 session)。
// 这是「刷新 / 重进」恢复登录态的唯一依据:useAppStore 的 loggedIn 初值由
// getLoginSession() 推导,RequireAuth 据此决定是否放行;路由守卫不看 uj_token。
// 缺这一步 → 刷新后 loggedIn=false,被直接踢回登录页。
// 同时承载 name/account/roleCodes/dataScope,供 StoreApprove、StoreListing 等页面刷新后仍可读。
saveLoginSession({
token: res.token,
tokenType: res.tokenType || 'Bearer',
expireAt: res.expireAt,
userId: res.userId,
account: res.account,
name: res.name,
orgId: res.orgId,
dataScope: res.dataScope,
roleCodes: res.roleCodes ?? [],
permCodes: res.permCodes ?? [],
});
// 菜单树与用户信息都按角色/账号下发:登录即视为账号切换点,旧缓存必须作废 // 菜单树与用户信息都按角色/账号下发:登录即视为账号切换点,旧缓存必须作废
menuApi.clearCache(); menuApi.clearCache();
auth.clearCache(); auth.clearCache();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
import { create } from 'zustand'; import { create } from 'zustand';
import { clearLoginSession, getLoginSession } from '@/access/session'; import { clearLoginSession, getLoginSession } from '@/access/session';
import { clearToken } from '@/api/core/token';
import { queryClient } from '@/queryClient'; import { queryClient } from '@/queryClient';
const savedSession = getLoginSession(); const savedSession = getLoginSession();
...@@ -39,6 +40,10 @@ export const useAppStore = create<AppState>((set) => ({ ...@@ -39,6 +40,10 @@ export const useAppStore = create<AppState>((set) => ({
set({ loggedIn: true, currentUser: u }); set({ loggedIn: true, currentUser: u });
}, },
logout: () => { logout: () => {
// 令牌(uj_token,http 拦截器读取)与会话(session,路由守卫读取)必须同时清:
// 只清一边会留下半吊子状态——令牌还在则刷新后仍能拉到用户信息,
// 会话还在则刷新后 loggedIn 仍为 true(尽管所有接口 401)。
clearToken();
clearLoginSession(); clearLoginSession();
queryClient.clear(); queryClient.clear();
set({ loggedIn: false }); set({ loggedIn: false });
......
...@@ -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 {
...@@ -477,29 +416,94 @@ ...@@ -477,29 +416,94 @@
gap: 18px; gap: 18px;
} }
/* 品牌欢迎条 */ /* 品牌欢迎条:浅色卡片 + 品牌色点睛。
旧版用 brandGradient(#0B1437→#16245A) 整条铺底,明度过低显得压抑;
现改为高明度底色,品牌感交给「小面积渐变方块 + 右上角柔光」承载。 */
.uj-dash-hero { .uj-dash-hero {
border-radius: 18px; position: relative;
overflow: hidden;
border-radius: 16px;
padding: 26px 30px; padding: 26px 30px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
gap: 20px; gap: 20px;
box-shadow: 0 18px 40px -22px rgba(11, 20, 55, 0.7); background: linear-gradient(120deg, #ffffff 0%, #f5f7ff 100%);
border: 1px solid rgba(43, 92, 230, 0.1);
box-shadow: 0 2px 10px rgba(16, 24, 64, 0.04);
}
/* 右上角品牌柔光:给浅底加层次,不占大面积 */
.uj-dash-hero::after {
content: '';
position: absolute;
right: -60px;
top: -80px;
width: 260px;
height: 260px;
border-radius: 50%;
background: radial-gradient(circle, rgba(43, 92, 230, 0.1) 0%, rgba(43, 92, 230, 0) 70%);
pointer-events: none;
}
.uj-dash-hero-id {
position: relative;
z-index: 1;
min-width: 0;
} }
.uj-dash-hero-actions { .uj-dash-hero-brand {
display: flex; display: flex;
gap: 12px; align-items: center;
gap: 8px;
font-size: 12px;
letter-spacing: 1.4px;
font-weight: 500;
color: #2b5ce6;
}
.uj-dash-hero-mark {
width: 16px;
height: 16px;
border-radius: 5px;
flex: none; flex: none;
background: linear-gradient(135deg, #2b5ce6, #5b8def);
box-shadow: 0 4px 10px rgba(43, 92, 230, 0.3);
} }
.uj-dash-hero-actions .ant-btn-ghost { .uj-dash-hero-title {
color: #fff; font-size: 24px;
border-color: rgba(255, 255, 255, 0.4); font-weight: 700;
color: #1d2533;
line-height: 1.25;
margin: 12px 0 6px;
}
.uj-dash-hero-sub {
font-size: 13px;
color: #6b7688;
margin: 0;
}
.uj-dash-hero-meta {
position: relative;
z-index: 1;
display: flex;
gap: 10px;
flex: none;
} }
.uj-dash-hero-actions .ant-btn-ghost:hover { .uj-dash-meta-item {
color: #fff !important; display: flex;
border-color: #fff !important; flex-direction: column;
background: rgba(255, 255, 255, 0.12) !important; gap: 3px;
min-width: 132px;
padding: 10px 14px;
border-radius: 10px;
background: rgba(43, 92, 230, 0.05);
border: 1px solid rgba(43, 92, 230, 0.08);
}
.uj-dash-meta-label {
font-size: 11px;
color: #8a94a6;
}
.uj-dash-meta-value {
font-size: 13px;
font-weight: 600;
color: #1d2533;
word-break: break-all;
} }
/* KPI 行 */ /* KPI 行 */
...@@ -795,6 +799,14 @@ ...@@ -795,6 +799,14 @@
.uj-dash-main { .uj-dash-main {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.uj-dash-hero {
flex-direction: column;
align-items: flex-start;
padding: 22px 20px;
}
.uj-dash-hero-meta {
width: 100%;
}
.uj-profile-grid { .uj-profile-grid {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
......
import type { ThemeConfig } from 'antd'; import type { ThemeConfig } from 'antd';
// 品牌色板(稳重内敛 · 企业级) // 品牌色板(稳重内敛 · 企业级)
export const brandDeep = '#0B1437'; // 墨蓝导航底(深色态) // 说明:brandDeep / brandGradient 原用于 Sider 与工作台欢迎条底;
export const brandGradient = 'linear-gradient(160deg, #0B1437 0%, #16245A 100%)'; // Sider / 登录品牌区 // 现将两处明度过低的深色底均已弃用(Sider 改由 design.css 的 .uj-sider 垂直 matte 深蓝承接,
// 工作台欢迎条改为浅色卡片 + 品牌色点睛)。这两个色值暂无代码引用,保留作品牌资产备查。
export const brandDeep = '#0B1437'; // 墨蓝导航底(深色态,暂未引用)
export const brandGradient = 'linear-gradient(160deg, #0B1437 0%, #16245A 100%)'; // 暂未引用
export const brandAccent = '#2B5CE6'; // 主操作蓝 export const brandAccent = '#2B5CE6'; // 主操作蓝
export const themeConfig: ThemeConfig = { export const themeConfig: ThemeConfig = {
...@@ -41,13 +44,28 @@ export const themeConfig: ThemeConfig = { ...@@ -41,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!