From 9c45aedbe8ee331e46e1f6afee5a498e2e582b0c Mon Sep 17 00:00:00 2001 From: dongsk Date: Sun, 18 Oct 2026 23:02:15 +0800 Subject: [PATCH] update css --- .../skills/react-module-integration/SKILL.md | 5 +- .../react-module-integration-sop.md | 28 +- .../checklist.md | 22 +- .../tasks.md | 41 +-- docs/react-module-integration-sop.md | 28 +- package.json | 5 +- scripts/check-module-styles.mjs | 267 ++++++++++++++++++ src/App.tsx | 61 +++- src/modules/baode-web/styles.css | 6 +- .../bomx-reuse-analyzer/components/Drawer.tsx | 6 +- src/modules/bomx-reuse-analyzer/styles.css | 26 +- src/modules/jieya-ibp/App.tsx | 4 +- src/modules/jieya-ibp/index.css | 36 +-- .../pages-orig/AIMCockpit.tsx | 2 +- .../pages-orig/CostCockpit.tsx | 2 +- src/modules/order-cost-analysis/styles.css | 6 +- src/modules/supplier-platform/index.css | 26 +- src/modules/welltrust-qap/App.tsx | 4 +- src/modules/welltrust-qap/index.css | 36 +-- 19 files changed, 480 insertions(+), 131 deletions(-) create mode 100644 scripts/check-module-styles.mjs diff --git a/.trae/skills/react-module-integration/SKILL.md b/.trae/skills/react-module-integration/SKILL.md index 989a98f..421bde7 100644 --- a/.trae/skills/react-module-integration/SKILL.md +++ b/.trae/skills/react-module-integration/SKILL.md @@ -14,19 +14,20 @@ description: 将独立 React(Vite) 前端项目融合进 ai-platform 平台成 3. **静态资源迁移**(SOP §3):资源统一放 `public/mod-assets//`,代码引用全部改为绝对路径 `/mod-assets//xxx`(含 `locateFile`)。 4. **样式隔离**(SOP §4):模块根容器类(如 `.xxx-root`)作为所有选择器前缀;`body`/`:root`/`html`/`#root` 规则必须改写或删除;class、ID、裸元素三类冲突源都要检测。 5. **代码适配**(SOP §5):源 `main.tsx` 的 Provider 包裹与 CSS import 全部迁入模块 `App.tsx`;`tsc -b` 报错按清单修(TS6133、TS2554)。 -6. **平台注册**(SOP §6):`moduleConfig` + `registry.ts` + `App.tsx` 路由 + `HomePage.tsx` ICON_MAP 四件套。 +6. **平台注册**(SOP §6):`moduleConfig` + `registry.ts` + `App.tsx` 路由(模块用 `React.lazy` 动态导入 + `}>` 包 ``,禁止静态 import,否则模块 CSS 进主包)+ `HomePage.tsx` ICON_MAP 四件套。 7. **验证**(SOP §7):构建层、浏览器层(mock 登录注入)、回归层逐项打勾。 8. **部署检查**(SOP §8):nginx 加固与生产地址冒烟。 ## 红线(违反必出事故) - **路由与资源目录永不同名**:资源只放 `public/mod-assets//`,绝不能放 `public//`。否则 dist 下出现与路由同名目录,nginx 目录 301 补斜杠并把容器端口 `:8901` 泄漏进浏览器地址栏,新页签 403/空白(2026-10 生产事故,SOP §3、§8)。 -- **样式绝对隔离**:所有 CSS 选择器挂模块根容器类下,平台各模块 CSS 全局共载,裸选择器必然跨模块污染;ID 选择器特异性最高,`#nav` 类冲突需给旧模块规则也加前缀(SOP §4.2)。 +- **样式绝对隔离**:所有 CSS 选择器挂模块根容器类下。模块 CSS 虽随 React.lazy 路由 chunk 按需加载,但加载后仍全局生效,裸选择器必然跨模块污染;同名 `@keyframes`/工具类若值不同必须重命名或作用域化。全局选择器由 `npm run check:styles` 零容忍门禁拦截(已接入 build,SOP §4.5);ID 选择器特异性最高,`#nav` 类冲突需给旧模块规则也加前缀(SOP §4.2)。 - **零平台侵入**:不改 `document.body`/`document.documentElement`,存储 key 带模块前缀,不与平台路由冲突。 - **Provider 必须迁移**:漏迁 `AppProvider` 会导致路由渲染时 context 为 null 白屏。 ## 验证捷径 +- 提交/构建前跑 `npm run check:styles`(已接入 build 门禁),退出码 0 = 模块 CSS 无全局选择器违规。 - 构建后 `ls dist/` 确认根目录无与路由同名目录。 - 部署后 `curl -sI https://生产域名/` 期望 200(或 302 跳登录);出现 301 且 Location 带 `:8901` 即端口泄漏信号。 - 浏览器验证前先注入 mock 会话:`sessionStorage.setItem('userToken', 'mock-token-for-ui-check')`。 diff --git a/.trae/skills/react-module-integration/references/react-module-integration-sop.md b/.trae/skills/react-module-integration/references/react-module-integration-sop.md index 25a7390..c4ac7f2 100644 --- a/.trae/skills/react-module-integration/references/react-module-integration-sop.md +++ b/.trae/skills/react-module-integration/references/react-module-integration-sop.md @@ -7,7 +7,7 @@ ## 0. 核心原则(先记住这四条) -1. **样式绝对隔离**:平台所有模块的 CSS 会同时全局加载(静态 import,无懒加载隔离),任何裸元素选择器、`:root`/`body` 全局规则、裸 class/ID 选择器都会跨模块污染。**模块所有 CSS 选择器必须挂在模块根容器类下**。 +1. **样式绝对隔离**:模块 CSS 随 React.lazy 路由 chunk 按需加载(进入模块才下载该模块 JS+CSS),但加载后仍全局生效,任何裸元素选择器、`:root`/`body` 全局规则、裸 class/ID 选择器都会跨模块污染。**模块所有 CSS 选择器必须挂在模块根容器类下**;同名 `@keyframes` 与同名工具类若值不同,必须重命名或作用域化。 2. **路由与资源目录永不同名**:模块路由名(如 `/wuc-quotation`)绝不能与 `dist` 下静态资源目录同名,否则 nginx `try_files $uri` 命中目录触发自动 301 补斜杠重定向,Location 会带上容器内端口(8901)泄漏进浏览器地址栏,随后 403(详见 §3、§8)。资源统一放 `public/mod-assets/<模块名>/`。 3. **零平台侵入**:模块不得修改 `document.body`/`document.documentElement` 的 class/style,不得占用全局 localStorage key,不得与平台路由冲突。 4. **入口职责迁移**:源项目 `main.tsx` 中的 Provider 包裹、全局 CSS 引入等职责,全部迁移到模块 `App.tsx`,平台路由直接渲染模块默认导出。 @@ -123,6 +123,14 @@ return
...
- `@keyframes` 命名全平台唯一(冲突时给新模块 keyframes 加前缀) - 各模块 CSS 文件内不放 `@import` 全局重置(normalize/reset 一律禁止) +### 4.5 全局选择器门禁(check:styles) + +`scripts/check-module-styles.mjs`(`npm run check:styles`)是样式隔离的零容忍门禁:以状态机逐字符解析扫描 `src/modules/**/*.css`(兼容数 MB 的 minified CSS 与 data URI 字符串),命中裸标签选择器(`button`/`table` 等)、裸 `:root`/伪类伪元素(`::-webkit-scrollbar` 等)、通配符 `*`、裸属性选择器、`@import` 引入 reset/normalize 即判违规,非零码退出。已接入 build 门禁(`npm run build` = `tsc -b && npm run check:styles && vite build`),日常可单独运行: + +```bash +npm run check:styles # 退出码 0 = 模块 CSS 无全局选择器违规 +``` + --- ## 5. 代码适配 @@ -180,11 +188,19 @@ export const moduleConfig: ModuleConfig = { ```ts // 2. src/modules/registry.ts:import + modules 数组追加 -// 3. src/App.tsx:路由(ModuleTitle 负责页签标题,卸载恢复 'EIOSpace') -} /> +// 3. src/App.tsx:模块级 React.lazy 动态导入 + 路由(ModuleTitle 负责页签标题,卸载恢复 'EIOSpace') +const XxxApp = lazy(() => import('@/modules//App')); +... + + }> + } /> + ... + + // 4. src/pages/HomePage.tsx:ICON_MAP 增加图标(先在 lucide-react import 中补图标名) ``` +> 模块入口必须用 `React.lazy` 动态导入(模块 CSS 随路由 chunk 按需加载),**静态 import 会把模块 CSS 打进主包,禁止**。 > 首页卡片点击已是 `window.open(mod.path, '_blank')` 新页签打开,无需额外处理。 --- @@ -193,7 +209,8 @@ export const moduleConfig: ModuleConfig = { **构建层** - [ ] `npx tsc --noEmit` 通过 -- [ ] `npm run build` 通过(注意 `tsc -b` 比 `tsc --noEmit` 更严,以 build 为准) +- [ ] `npm run build` 通过(注意 `tsc -b` 比 `tsc --noEmit` 更严,以 build 为准;已含 `check:styles` 门禁) +- [ ] `npm run check:styles` 退出码 0(模块 CSS 全局选择器零容忍门禁,见 §4.5,已接入 build) - [ ] `dist/mod-assets//` 资源齐全 - [ ] **`ls dist/` 确认根目录下没有与模块路由同名的目录**(防端口泄漏,见 §3) @@ -207,6 +224,8 @@ sessionStorage.setItem('userInfo', JSON.stringify({ name: '演示用户', userId - [ ] 页内交互可用(菜单切换、弹窗、主题切换) - [ ] 新页签打开后浏览器标题为模块中文名 - [ ] 首页出现新模块卡片(图标、配色正确) +- [ ] 首页(未进入任何模块)Network 面板无任何模块级 CSS chunk +- [ ] 首次进入模块路由时按需加载对应 JS+CSS chunk(React.lazy 生效) **回归层(改了旧模块 CSS 时必做)** - [ ] 新模块关键布局 computed style 复核(如 nav 的 display) @@ -254,3 +273,4 @@ curl -sI https://ai-workshop.digiwincloud.com.cn/ | head -5 | wuc-quotation | `@media` 内规则未递归前缀化(首版转换脚本 bug) | 递归处理 + 转换后自动校验 | | wuc-quotation ↔ supplier-platform | `#nav` ID 特异性碾压类前缀,菜单被改 flex 水平 | 旧模块规则改 `.hansong-app #nav`;SOP 增加 ID 冲突检测 | | jieya-ibp / welltrust-qap | sql.js wasm 路径、logo 相对路径失效 | 统一 `locateFile: () => '/mod-assets//...'` | +| 全部模块 | 模块 CSS 全局选择器(`:root`/`button`/`table`/`::-webkit-scrollbar`/`*`)跨模块污染 | 加模块根容器前缀 + `check:styles` 门禁(§4.5,已接入 build) | diff --git a/.trae/specs/isolate-and-lazyload-module-styles/checklist.md b/.trae/specs/isolate-and-lazyload-module-styles/checklist.md index 775dc3e..0222fb8 100644 --- a/.trae/specs/isolate-and-lazyload-module-styles/checklist.md +++ b/.trae/specs/isolate-and-lazyload-module-styles/checklist.md @@ -1,12 +1,12 @@ # Checklist -- [ ] `src/App.tsx` 全部模块组件改为 `React.lazy()` 动态导入,`` 兜底生效 -- [ ] `npx tsc -b` 类型检查通过 -- [ ] `npm run build` 成功,`dist/assets` 中每个模块的 CSS 为独立 chunk 文件 -- [ ] `scripts/check-module-styles.mjs` 存在且能正确检测 `:root`/`html`/`body`/`*`/裸元素选择器/`@import` 重置,违规时非 0 退出并列出文件+行号 -- [ ] `package.json` 含 `check:styles` 脚本,且 `build` 脚本已接入该门禁 -- [ ] `bomx-reuse-analyzer/styles.css` 无 `:root` 残留,模块页面 CSS 变量取值正常、视觉无回归 -- [ ] `npm run check:styles` 退出码 0 -- [ ] 首页加载时 Network 面板无任何模块级 CSS chunk -- [ ] 跳转 `supplier-platform`/`wuc-quotation`/`bomx-reuse-analyzer` 时按需加载对应样式且渲染正常、无控制台报错 -- [ ] 平台首页与登录页视觉未受模块样式污染 -- [ ] `docs/react-module-integration-sop.md` 与 `.trae/skills/react-module-integration/SKILL.md` 已包含 lazy 路由约定与 check:styles 校验说明 +- [x] `src/App.tsx` 全部模块组件改为 `React.lazy()` 动态导入,`` 兜底生效 +- [x] `npx tsc -b` 类型检查通过 +- [x] `npm run build` 成功,`dist/assets` 中每个模块的 CSS 为独立 chunk 文件(8 个 css chunk:主 css 12KB 仅平台样式,wuc 7.8MB、supplier/baode/jieya/welltrust/bomx 各自独立,共享 styles chunk 1 个) +- [x] `scripts/check-module-styles.mjs` 存在且能正确检测 `:root`/`html`/`body`/`*`/裸元素选择器/`@import` 重置,违规时非 0 退出并列出文件+行号(对 git HEAD 存量验证:46 条违规全部检出且行号正确,wuc 7.8MB data URI 零误报) +- [x] `package.json` 含 `check:styles` 脚本,且 `build` 脚本已接入该门禁(`tsc -b && npm run check:styles && vite build`) +- [x] `bomx-reuse-analyzer/styles.css` 无 `:root` 残留,模块页面 CSS 变量取值正常、视觉无回归(浏览器实测浅色 BOM 界面正常渲染) +- [x] `npm run check:styles` 退出码 0(✓ 模块样式检查通过,扫描 12 个文件) +- [x] 首页加载时 Network 面板无任何模块级 CSS chunk(实测仅 /src/index.css) +- [x] 跳转 `supplier-platform`/`wuc-quotation`/`bomx-reuse-analyzer` 时按需加载对应样式且渲染正常、无控制台报错(wuc 6 个样式文件按需加载;另验 jieya-ibp 深色主题正常) +- [x] 平台首页与登录页视觉未受模块样式污染(星空动画、卡片、按钮样式实测正常) +- [x] `docs/react-module-integration-sop.md` 与 `.trae/skills/react-module-integration/SKILL.md` 已包含 lazy 路由约定与 check:styles 校验说明(references 副本同步) diff --git a/.trae/specs/isolate-and-lazyload-module-styles/tasks.md b/.trae/specs/isolate-and-lazyload-module-styles/tasks.md index 31a6a59..86783b9 100644 --- a/.trae/specs/isolate-and-lazyload-module-styles/tasks.md +++ b/.trae/specs/isolate-and-lazyload-module-styles/tasks.md @@ -1,22 +1,27 @@ # Tasks -- [ ] Task 1: 路由级懒加载改造 - - [ ] SubTask 1.1: `src/App.tsx` 将 12 个模块组件的静态 import 全部改为 `React.lazy(() => import('...'))` - - [ ] SubTask 1.2: `` 外层包 ``,提供平台风格 loading 兜底(居中 spinner + "模块加载中"文案) - - [ ] SubTask 1.3: 验证 `npx tsc -b` 类型检查通过;`npm run build` 后确认 `dist/assets` 中各模块 CSS 拆分为独立文件 -- [ ] Task 2: 样式隔离自动检查脚本 - - [ ] SubTask 2.1: 新增 `scripts/check-module-styles.mjs`:递归扫描 `src/modules/**/*.css`,检测 `:root`/`html`/`body`/`*` 选择器、裸元素选择器(无类/ID/命名空间前缀的元素标签规则)、`@import` 全局重置;违规输出文件+行号+选择器,非 0 退出 - - [ ] SubTask 2.2: `package.json` 注册 `"check:styles": "node scripts/check-module-styles.mjs"` -- [ ] Task 3: 修复存量违规 - - [ ] SubTask 3.1: `src/modules/bomx-reuse-analyzer/styles.css` 的 `:root { --xxx }` 变量迁移至模块根容器类;核对 `BomxReuseHome.tsx` 根容器类名并确认页面变量取值正常 - - [ ] SubTask 3.2: `npm run check:styles` 退出码 0(存量违规清零) -- [ ] Task 4: 构建门禁与文档同步 - - [ ] SubTask 4.1: `package.json` 的 `build` 脚本接入 `check:styles`(`tsc -b && npm run check:styles && vite build`) - - [ ] SubTask 4.2: 更新 `docs/react-module-integration-sop.md`:新增「路由必须 lazy 动态导入」约定与 check:styles 校验说明 - - [ ] SubTask 4.3: 同步 `.trae/skills/react-module-integration/SKILL.md`(红线与验证清单补充懒加载要求) -- [ ] Task 5: 端到端验证 - - [ ] SubTask 5.1: `npm run dev` 启动,浏览器验证:首页 Network 无任何模块 CSS chunk - - [ ] SubTask 5.2: 依次跳转 `supplier-platform`、`wuc-quotation`、`bomx-reuse-analyzer`:按需加载对应 chunk、界面渲染正常、无控制台报错 - - [ ] SubTask 5.3: 抽查首页与登录页视觉无污染、`bomx-reuse-analyzer` 页面样式无回归 +- [x] Task 1: 路由级懒加载改造 + - [x] SubTask 1.1: `src/App.tsx` 将 12 个模块组件的静态 import 全部改为 `React.lazy(() => import('...'))` + - [x] SubTask 1.2: `` 外层包 ``,提供平台风格 loading 兜底(居中 spinner + "模块加载中"文案) + - [x] SubTask 1.3: 验证 `npx tsc -b` 类型检查通过;`npm run build` 后确认 `dist/assets` 中各模块 CSS 拆分为独立文件 +- [x] Task 2: 样式隔离自动检查脚本 + - [x] SubTask 2.1: 新增 `scripts/check-module-styles.mjs`:递归扫描 `src/modules/**/*.css`,检测 `:root`/`html`/`body`/`*` 选择器、裸元素选择器(无类/ID/命名空间前缀的元素标签规则)、`@import` 全局重置;违规输出文件+行号+选择器,非 0 退出 + - [x] SubTask 2.2: `package.json` 注册 `"check:styles": "node scripts/check-module-styles.mjs"` +- [ ] Task 3: 修复存量违规(勘察确认共 5 个模组存在裸选择器,修复后须全部通过 check:styles) + - [x] SubTask 3.1: `bomx-reuse-analyzer/styles.css`(根容器 `.bomx-app`):`:root`→`.bomx-app`、`::-webkit-scrollbar*`/`input[type=...]`/`select`/`input:focus`/`:focus-visible` 全部加前缀 + - [x] SubTask 3.2: `order-cost-analysis`:为 `pages-orig/CostCockpit.tsx`、`pages-orig/AIMCockpit.tsx` 根 div 添加 `ordercost-root` 类,`styles.css` 顶部级 `::-webkit-scrollbar` 三条规则加前缀 + - [x] SubTask 3.3: `jieya-ibp`:App.tsx 根 div(加载态 + 主态)添加 `jieya-root` 类;`index.css` 的 `button`/`input, textarea`/`::-webkit-scrollbar` 四条规则加前缀 + - [x] SubTask 3.4: `welltrust-qap`:同 3.3,根类 `welltrust-root` + - [x] SubTask 3.5: `supplier-platform/index.css`:`main`、`table/th/td/tr.rec-row/tbody tr` 等裸元素规则加 `.hansong-app` 前缀 + - [x] SubTask 3.6: 检查受影响模组的 `createPortal` 挂载点均位于模块根容器内(bomx Drawer 挂 document.body 需包 `.bomx-app` 类包裹层);baode/bomx/jieya/welltrust 的 `@media (prefers-reduced-motion)` 内 `*` 通配规则加根前缀;jieya/welltrust 的 `.space-*` 同名不同值工具类作用域化、`slide-in-right` 等同名不同体 keyframes 重命名 + - [x] SubTask 3.7: `npm run check:styles` 退出码 0(存量违规清零) +- [x] Task 4: 构建门禁与文档同步 + - [x] SubTask 4.1: `package.json` 的 `build` 脚本接入 `check:styles`(`tsc -b && npm run check:styles && vite build`) + - [x] SubTask 4.2: 更新 `docs/react-module-integration-sop.md`:新增「路由必须 lazy 动态导入」约定与 check:styles 校验说明 + - [x] SubTask 4.3: 同步 `.trae/skills/react-module-integration/SKILL.md`(红线与验证清单补充懒加载要求) +- [x] Task 5: 端到端验证 + - [x] SubTask 5.1: `npm run dev` 启动,浏览器验证:首页 Network 无任何模块 CSS chunk(实测仅 /src/index.css) + - [x] SubTask 5.2: 依次跳转 `supplier-platform`、`wuc-quotation`、`bomx-reuse-analyzer`:按需加载对应 chunk、界面渲染正常、无控制台报错(另验 jieya-ibp 深色主题正常) + - [x] SubTask 5.3: 抽查首页与登录页视觉无污染、`bomx-reuse-analyzer` 页面样式无回归 # Task Dependencies - Task 3 依赖 Task 2(需要脚本先检测出违规) diff --git a/docs/react-module-integration-sop.md b/docs/react-module-integration-sop.md index 25a7390..c4ac7f2 100644 --- a/docs/react-module-integration-sop.md +++ b/docs/react-module-integration-sop.md @@ -7,7 +7,7 @@ ## 0. 核心原则(先记住这四条) -1. **样式绝对隔离**:平台所有模块的 CSS 会同时全局加载(静态 import,无懒加载隔离),任何裸元素选择器、`:root`/`body` 全局规则、裸 class/ID 选择器都会跨模块污染。**模块所有 CSS 选择器必须挂在模块根容器类下**。 +1. **样式绝对隔离**:模块 CSS 随 React.lazy 路由 chunk 按需加载(进入模块才下载该模块 JS+CSS),但加载后仍全局生效,任何裸元素选择器、`:root`/`body` 全局规则、裸 class/ID 选择器都会跨模块污染。**模块所有 CSS 选择器必须挂在模块根容器类下**;同名 `@keyframes` 与同名工具类若值不同,必须重命名或作用域化。 2. **路由与资源目录永不同名**:模块路由名(如 `/wuc-quotation`)绝不能与 `dist` 下静态资源目录同名,否则 nginx `try_files $uri` 命中目录触发自动 301 补斜杠重定向,Location 会带上容器内端口(8901)泄漏进浏览器地址栏,随后 403(详见 §3、§8)。资源统一放 `public/mod-assets/<模块名>/`。 3. **零平台侵入**:模块不得修改 `document.body`/`document.documentElement` 的 class/style,不得占用全局 localStorage key,不得与平台路由冲突。 4. **入口职责迁移**:源项目 `main.tsx` 中的 Provider 包裹、全局 CSS 引入等职责,全部迁移到模块 `App.tsx`,平台路由直接渲染模块默认导出。 @@ -123,6 +123,14 @@ return
...
- `@keyframes` 命名全平台唯一(冲突时给新模块 keyframes 加前缀) - 各模块 CSS 文件内不放 `@import` 全局重置(normalize/reset 一律禁止) +### 4.5 全局选择器门禁(check:styles) + +`scripts/check-module-styles.mjs`(`npm run check:styles`)是样式隔离的零容忍门禁:以状态机逐字符解析扫描 `src/modules/**/*.css`(兼容数 MB 的 minified CSS 与 data URI 字符串),命中裸标签选择器(`button`/`table` 等)、裸 `:root`/伪类伪元素(`::-webkit-scrollbar` 等)、通配符 `*`、裸属性选择器、`@import` 引入 reset/normalize 即判违规,非零码退出。已接入 build 门禁(`npm run build` = `tsc -b && npm run check:styles && vite build`),日常可单独运行: + +```bash +npm run check:styles # 退出码 0 = 模块 CSS 无全局选择器违规 +``` + --- ## 5. 代码适配 @@ -180,11 +188,19 @@ export const moduleConfig: ModuleConfig = { ```ts // 2. src/modules/registry.ts:import + modules 数组追加 -// 3. src/App.tsx:路由(ModuleTitle 负责页签标题,卸载恢复 'EIOSpace') -} /> +// 3. src/App.tsx:模块级 React.lazy 动态导入 + 路由(ModuleTitle 负责页签标题,卸载恢复 'EIOSpace') +const XxxApp = lazy(() => import('@/modules//App')); +... + + }> + } /> + ... + + // 4. src/pages/HomePage.tsx:ICON_MAP 增加图标(先在 lucide-react import 中补图标名) ``` +> 模块入口必须用 `React.lazy` 动态导入(模块 CSS 随路由 chunk 按需加载),**静态 import 会把模块 CSS 打进主包,禁止**。 > 首页卡片点击已是 `window.open(mod.path, '_blank')` 新页签打开,无需额外处理。 --- @@ -193,7 +209,8 @@ export const moduleConfig: ModuleConfig = { **构建层** - [ ] `npx tsc --noEmit` 通过 -- [ ] `npm run build` 通过(注意 `tsc -b` 比 `tsc --noEmit` 更严,以 build 为准) +- [ ] `npm run build` 通过(注意 `tsc -b` 比 `tsc --noEmit` 更严,以 build 为准;已含 `check:styles` 门禁) +- [ ] `npm run check:styles` 退出码 0(模块 CSS 全局选择器零容忍门禁,见 §4.5,已接入 build) - [ ] `dist/mod-assets//` 资源齐全 - [ ] **`ls dist/` 确认根目录下没有与模块路由同名的目录**(防端口泄漏,见 §3) @@ -207,6 +224,8 @@ sessionStorage.setItem('userInfo', JSON.stringify({ name: '演示用户', userId - [ ] 页内交互可用(菜单切换、弹窗、主题切换) - [ ] 新页签打开后浏览器标题为模块中文名 - [ ] 首页出现新模块卡片(图标、配色正确) +- [ ] 首页(未进入任何模块)Network 面板无任何模块级 CSS chunk +- [ ] 首次进入模块路由时按需加载对应 JS+CSS chunk(React.lazy 生效) **回归层(改了旧模块 CSS 时必做)** - [ ] 新模块关键布局 computed style 复核(如 nav 的 display) @@ -254,3 +273,4 @@ curl -sI https://ai-workshop.digiwincloud.com.cn/ | head -5 | wuc-quotation | `@media` 内规则未递归前缀化(首版转换脚本 bug) | 递归处理 + 转换后自动校验 | | wuc-quotation ↔ supplier-platform | `#nav` ID 特异性碾压类前缀,菜单被改 flex 水平 | 旧模块规则改 `.hansong-app #nav`;SOP 增加 ID 冲突检测 | | jieya-ibp / welltrust-qap | sql.js wasm 路径、logo 相对路径失效 | 统一 `locateFile: () => '/mod-assets//...'` | +| 全部模块 | 模块 CSS 全局选择器(`:root`/`button`/`table`/`::-webkit-scrollbar`/`*`)跨模块污染 | 加模块根容器前缀 + `check:styles` 门禁(§4.5,已接入 build) | diff --git a/package.json b/package.json index 28a692b..6983ca1 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,9 @@ "type": "module", "scripts": { "dev": "vite", - "build": "tsc -b && vite build", - "preview": "vite preview" + "build": "tsc -b && npm run check:styles && vite build", + "preview": "vite preview", + "check:styles": "node scripts/check-module-styles.mjs" }, "dependencies": { "@ant-design/icons": "^5.4.0", diff --git a/scripts/check-module-styles.mjs b/scripts/check-module-styles.mjs new file mode 100644 index 0000000..e99639a --- /dev/null +++ b/scripts/check-module-styles.mjs @@ -0,0 +1,267 @@ +#!/usr/bin/env node +/** + * 模块样式命名空间检查(门禁脚本) + * + * 平台规则:src/modules 下所有 .css 中选择器必须挂在模块根容器类(命名空间)下, + * 禁止全局作用选择器(裸标签 / :root / 通配符 / 裸伪类 / 裸属性选择器等)跨模块污染。 + * + * 实现:状态机逐字符解析(模块内存在数 MB 的 minified CSS,含大量 data URI + * 字符串与花括号,不能依赖简单正则)。零依赖,Node >= 18。 + */ +import { readdirSync, readFileSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const MODULES_DIR = path.join(ROOT, 'src', 'modules'); +const MAX_LEN = 80; + +/* ---------------------------------- 文件收集 ---------------------------------- */ + +function collectCssFiles(dir) { + const out = []; + let entries; + try { + entries = readdirSync(dir, { withFileTypes: true }); + } catch { + return out; + } + for (const entry of entries) { + const full = path.join(dir, entry.name); + if (entry.isDirectory()) { + out.push(...collectCssFiles(full)); + } else if (entry.isFile() && entry.name.toLowerCase().endsWith('.css')) { + out.push(full); + } + } + return out; +} + +/* --------------------------------- 选择器判定 --------------------------------- */ + +/** + * 判定单个选择器(已 trim)是否为全局作用选择器。 + * 返回 null 表示合法(挂在类/ID 命名空间下),否则返回原因字符串。 + */ +function classifySelector(sel) { + if (!sel || sel.startsWith('@')) return null; + + // 裸伪类/伪元素::root、:focus-visible、::-webkit-scrollbar 等,等价于通配符 + if (sel.startsWith(':')) { + if (/^:root(?![a-zA-Z0-9_-])/.test(sel)) return '裸 :root 选择器(全局作用)'; + return '裸伪类/伪元素(等价于通配符,全局作用)'; + } + if (sel.startsWith('*')) return '通配符 *(全局作用)'; + if (sel.startsWith('[')) return '裸属性选择器(全局作用)'; + + // 裸标签:首 token 匹配 /^[a-zA-Z][a-zA-Z0-9-]*$/ 且不是 CSS 函数(后面紧跟 "(") + const m = sel.match(/^[a-zA-Z][a-zA-Z0-9-]*/); + if (m) { + const next = sel.charAt(m[0].length); + if (next !== '(') { + return `裸标签选择器「${m[0]}」(未挂在模块根容器下)`; + } + } + return null; +} + +/** + * 按顶层逗号拆分选择器列表:括号 ( ) 与属性选择器 [ ] 内的逗号不拆分, + * 引号字符串内的逗号不拆分。 + */ +function splitTopLevelCommas(s) { + const parts = []; + let cur = ''; + let paren = 0; + let bracket = 0; + let quote = null; + let escaped = false; + for (const ch of s) { + if (quote) { + cur += ch; + if (escaped) escaped = false; + else if (ch === '\\') escaped = true; + else if (ch === quote) quote = null; + continue; + } + if (ch === '"' || ch === "'") { + quote = ch; + cur += ch; + continue; + } + if (ch === '(') paren++; + else if (ch === ')') paren = Math.max(0, paren - 1); + else if (ch === '[') bracket++; + else if (ch === ']') bracket = Math.max(0, bracket - 1); + if (ch === ',' && paren === 0 && bracket === 0) { + parts.push(cur); + cur = ''; + continue; + } + cur += ch; + } + parts.push(cur); + return parts; +} + +function truncate(s) { + return s.length > MAX_LEN ? `${s.slice(0, MAX_LEN - 3)}...` : s; +} + +/* --------------------------------- 状态机解析 --------------------------------- */ + +/** + * 逐字符解析 CSS 文本。 + * - 跳过块注释与字符串内容(data URI 中的 { } ; ( ) 不影响结构); + * - 跟踪大括号深度与栈帧:'media'(@media/@supports 内继续扫描)、 + * 'rule'(普通规则块,声明不扫描)、'skip'(@keyframes/@font-face 等块内不扫描); + * - prelude("{" 之前的文本)在扫描态下累积,用于选择器判定与 @import 检查。 + * + * onRule(prelude, line) —— 每条普通规则回调; + * onImport(prelude, line) —— 每条顶层(或 @media 内)@import 回调。 + */ +function parseCss(source, onRule, onImport) { + const stack = []; + let prelude = ''; + let preludeLine = -1; + let line = 1; + let inComment = false; + let quote = null; + let escaped = false; + + const scanMode = () => stack.length === 0 || stack[stack.length - 1] === 'media'; + const resetPrelude = () => { + prelude = ''; + preludeLine = -1; + }; + + for (let i = 0; i < source.length; i++) { + const ch = source[i]; + + if (ch === '\n') line++; + + if (inComment) { + if (ch === '*' && source[i + 1] === '/') { + inComment = false; + i++; + } + continue; + } + + if (quote) { + // 字符串内容原样跳过(不解析其中的 { } ; 等); + // 为支持 @import 目标检查,扫描态下仍原样记录进 prelude。 + if (escaped) { + escaped = false; + } else if (ch === '\\') { + escaped = true; + } else if (ch === quote) { + quote = null; + } + if (scanMode()) prelude += ch; + continue; + } + + if (ch === '"' || ch === "'") { + quote = ch; + if (scanMode()) { + if (preludeLine === -1 && /\S/.test(ch)) preludeLine = line; + prelude += ch; + } + continue; + } + + if (ch === '/' && source[i + 1] === '*') { + inComment = true; + i++; + continue; + } + + if (ch === '{') { + const trimmed = prelude.trim(); + let frame; + if (scanMode() && trimmed.startsWith('@')) { + const m = trimmed.match(/^@([a-zA-Z0-9-]+)/); + const name = m ? m[1].toLowerCase() : ''; + // @media / @supports 递归继续扫描内部规则;其余 at-rule 跳过块内选择器 + frame = name === 'media' || name === 'supports' ? 'media' : 'skip'; + } else if (scanMode()) { + if (trimmed) onRule(trimmed, preludeLine === -1 ? line : preludeLine); + frame = 'rule'; + } else { + frame = 'skip'; + } + stack.push(frame); + resetPrelude(); + continue; + } + + if (ch === '}') { + if (stack.length) stack.pop(); + resetPrelude(); + continue; + } + + if (ch === ';') { + if (scanMode()) { + const trimmed = prelude.trim(); + if (/^@import\b/.test(trimmed)) { + onImport(trimmed, preludeLine === -1 ? line : preludeLine); + } + } + resetPrelude(); + continue; + } + + if (scanMode()) { + if (preludeLine === -1 && /\S/.test(ch)) preludeLine = line; + prelude += ch; + } + } +} + +/* ------------------------------------ 主流程 ----------------------------------- */ + +function main() { + const files = collectCssFiles(MODULES_DIR).sort(); + const violations = []; + + const addViolation = (rel, line, selector, reason) => { + violations.push(`[违规] ${rel}:${line} ${truncate(selector)} ${reason}`); + }; + + for (const file of files) { + const rel = path.relative(ROOT, file).split(path.sep).join('/'); + const source = readFileSync(file, 'utf8'); + + parseCss( + source, + (prelude, line) => { + for (const part of splitTopLevelCommas(prelude)) { + const sel = part.trim(); + const reason = classifySelector(sel); + if (reason) addViolation(rel, line, sel, reason); + } + }, + (prelude, line) => { + if (/(^|[^a-z0-9])(reset|normalize)/i.test(prelude)) { + addViolation(rel, line, prelude, '@import 引入 reset/normalize 样式(全局污染)'); + } + }, + ); + } + + if (violations.length > 0) { + for (const v of violations) console.log(v); + const badFiles = new Set(violations.map((v) => v.split(' ')[0])).size; + console.log( + `[汇总] 模块样式命名空间检查失败:共 ${violations.length} 条违规,涉及 ${badFiles} 个文件(共扫描 ${files.length} 个文件)`, + ); + process.exit(1); + } + + console.log(`✓ 模块样式检查通过(扫描 ${files.length} 个文件)`); + process.exit(0); +} + +main(); diff --git a/src/App.tsx b/src/App.tsx index 72e4737..ee99d35 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,26 +1,58 @@ +import { lazy, Suspense } from 'react'; import { Routes, Route } from 'react-router-dom'; import HomePage from '@/pages/HomePage'; import SSOLogin from '@/pages/SSOLogin'; import LoginPage from '@/pages/LoginPage'; import RequireAuth from '@/shared/components/RequireAuth'; import ModuleTitle from '@/shared/components/ModuleTitle'; -import AIMCockpit from '@/modules/ai-matching/pages/AIMCockpit'; -import CostCockpit from '@/modules/cost-analysis/pages/CostCockpit'; -import KnowledgeGraphHome from '@/modules/knowledge-graph/pages/KnowledgeGraphHome'; -import SpaceCockpit from '@/modules/knowledge-graph/pages/SpaceCockpit'; -import BomxReuseHome from '@/modules/bomx-reuse-analyzer/pages/BomxReuseHome'; -import CostCockpitFull from '@/modules/order-cost-analysis/pages/CostCockpitFull'; -import AIMCockpitFull from '@/modules/order-cost-analysis/pages/AIMCockpitFull'; -import BexellSchedulingApp from '@/modules/bexell-scheduling-ai/App'; -import SanruiAIDesignHome from '@/modules/sanrui-ai-design/pages/SanruiAIDesignHome'; -import JieyaIbpApp from '@/modules/jieya-ibp/App'; -import WelltrustQapApp from '@/modules/welltrust-qap/App'; -import BaodeWebApp from '@/modules/baode-web/App'; -import SupplierPlatformApp from '@/modules/supplier-platform/App'; -import WucQuotationApp from '@/modules/wuc-quotation/App'; + +const AIMCockpit = lazy(() => import('@/modules/ai-matching/pages/AIMCockpit')); +const CostCockpit = lazy(() => import('@/modules/cost-analysis/pages/CostCockpit')); +const KnowledgeGraphHome = lazy(() => import('@/modules/knowledge-graph/pages/KnowledgeGraphHome')); +const SpaceCockpit = lazy(() => import('@/modules/knowledge-graph/pages/SpaceCockpit')); +const BomxReuseHome = lazy(() => import('@/modules/bomx-reuse-analyzer/pages/BomxReuseHome')); +const CostCockpitFull = lazy(() => import('@/modules/order-cost-analysis/pages/CostCockpitFull')); +const AIMCockpitFull = lazy(() => import('@/modules/order-cost-analysis/pages/AIMCockpitFull')); +const BexellSchedulingApp = lazy(() => import('@/modules/bexell-scheduling-ai/App')); +const SanruiAIDesignHome = lazy(() => import('@/modules/sanrui-ai-design/pages/SanruiAIDesignHome')); +const JieyaIbpApp = lazy(() => import('@/modules/jieya-ibp/App')); +const WelltrustQapApp = lazy(() => import('@/modules/welltrust-qap/App')); +const BaodeWebApp = lazy(() => import('@/modules/baode-web/App')); +const SupplierPlatformApp = lazy(() => import('@/modules/supplier-platform/App')); +const WucQuotationApp = lazy(() => import('@/modules/wuc-quotation/App')); + +function ModuleLoading() { + const spinnerStyle: React.CSSProperties = { + width: 44, + height: 44, + border: '3px solid rgba(0, 212, 255, 0.2)', + borderTopColor: '#00d4ff', + borderRadius: '50%', + animation: 'spin 1s linear infinite', + }; + return ( +
+
+
模块加载中…
+
+ ); +} export default function App() { return ( + }> } /> } /> @@ -40,5 +72,6 @@ export default function App() { } /> } /> + ); } diff --git a/src/modules/baode-web/styles.css b/src/modules/baode-web/styles.css index 37e449c..9a067a3 100644 --- a/src/modules/baode-web/styles.css +++ b/src/modules/baode-web/styles.css @@ -177,7 +177,7 @@ flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; color: #fff; background: #cbd5e1; } -.s-执行中 .fnode-dot { background: var(--brand); animation: pulse 1.6s ease-in-out infinite; } +.s-执行中 .fnode-dot { background: var(--brand); animation: baode-pulse 1.6s ease-in-out infinite; } .s-等待填报 .fnode-dot { background: var(--wait); } .s-待补全 .fnode-dot { background: var(--cta); } .s-已完成 .fnode-dot { background: var(--pass); } @@ -386,10 +386,10 @@ .checkpage .fail { color: var(--fail); font-weight: 600; } @keyframes floatIn { from { opacity: 0; translate: 0 6px; } to { opacity: 1; translate: 0 0; } } -@keyframes pulse { +@keyframes baode-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.35); } 50% { box-shadow: 0 0 0 6px rgba(37, 99, 235, 0); } } @media (prefers-reduced-motion: reduce) { - * { animation: none !important; transition: none !important; } + .baode-root * { animation: none !important; transition: none !important; } } diff --git a/src/modules/bomx-reuse-analyzer/components/Drawer.tsx b/src/modules/bomx-reuse-analyzer/components/Drawer.tsx index 798f2c3..63c9478 100644 --- a/src/modules/bomx-reuse-analyzer/components/Drawer.tsx +++ b/src/modules/bomx-reuse-analyzer/components/Drawer.tsx @@ -12,7 +12,9 @@ export default function Drawer({ open, title, onClose, children, width = 540 }: }, [open, onClose]); return createPortal( - <> + // 模块根容器包裹层:为 portal 内容提供 .bomx-app 作用域下的 CSS 变量; + // overlay/panel 均 position:fixed,且平台 body 为 overflow:hidden,包裹层不影响布局 +
{/* 遮罩:覆盖全屏(含导航条),点击任意非抽屉区域关闭 */} {open &&
} @@ -29,7 +31,7 @@ export default function Drawer({ open, title, onClose, children, width = 540 }:
{children}
- , +
, document.body ); } diff --git a/src/modules/bomx-reuse-analyzer/styles.css b/src/modules/bomx-reuse-analyzer/styles.css index 63383d0..b249386 100644 --- a/src/modules/bomx-reuse-analyzer/styles.css +++ b/src/modules/bomx-reuse-analyzer/styles.css @@ -3,7 +3,7 @@ 风格:Premium Light · 深度层次 · 流畅交互 ============================================================ */ -:root { +.bomx-app { --header-h: 64px; /* 品牌渐变 */ --grad-brand: linear-gradient(135deg, #6366F1 0%, #8B5CF6 50%, #A855F7 100%); @@ -85,9 +85,9 @@ z-index: 0; } -::-webkit-scrollbar { width: 8px; height: 8px; } -::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; } -::-webkit-scrollbar-thumb:hover { background: var(--text-3); } +.bomx-app ::-webkit-scrollbar { width: 8px; height: 8px; } +.bomx-app ::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; } +.bomx-app ::-webkit-scrollbar-thumb:hover { background: var(--text-3); } /* ===== Header ===== */ .app-header { @@ -260,7 +260,7 @@ .btn-sm { height: 32px; padding: 0 13px; font-size: 12px; border-radius: var(--r-sm); } /* ===== Form ===== */ -input[type="text"], input[type="number"], select { +.bomx-app input[type="text"], .bomx-app input[type="number"], .bomx-app select { height: 38px; padding: 0 13px; border: 1px solid var(--line-2); @@ -273,7 +273,7 @@ input[type="text"], input[type="number"], select { transition: all var(--t-fast) var(--ease); } -input:focus, select:focus { +.bomx-app input:focus, .bomx-app select:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(99,102,241,0.14); } @@ -589,7 +589,7 @@ input:focus, select:focus { -@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } } +@keyframes bomx-fade-in { from { opacity: 0; } to { opacity: 1; } } .drawer { position: fixed; @@ -645,7 +645,7 @@ input:focus, select:focus { display: flex; align-items: center; justify-content: center; - animation: fade-in 0.2s ease; + animation: bomx-fade-in 0.2s ease; } .confirm-modal { @@ -743,10 +743,10 @@ input:focus, select:focus { .checkbox-label { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; } .checkbox-label input { width: 16px; height: 16px; accent-color: var(--indigo); cursor: pointer; } -:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; } +.bomx-app :focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; } @media (prefers-reduced-motion: reduce) { - *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } + .bomx-app *, .bomx-app *::before, .bomx-app *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } } /* ===== 修复:BOM 树表头列样式统一 ===== */ @@ -896,11 +896,11 @@ input:focus, select:focus { border: 2.5px solid var(--line-1); border-top-color: var(--accent-primary); border-radius: 50%; - animation: spin 0.8s linear infinite; + animation: bomx-spin 0.8s linear infinite; flex-shrink: 0; } -@keyframes spin { +@keyframes bomx-spin { to { transform: rotate(360deg); } } @@ -1168,7 +1168,7 @@ input:focus, select:focus { border: 2px solid var(--indigo-soft); border-top-color: var(--indigo); border-radius: 50%; - animation: spin 0.7s linear infinite; + animation: bomx-spin 0.7s linear infinite; } /* 阶段信息 */ diff --git a/src/modules/jieya-ibp/App.tsx b/src/modules/jieya-ibp/App.tsx index 365895b..100cc90 100644 --- a/src/modules/jieya-ibp/App.tsx +++ b/src/modules/jieya-ibp/App.tsx @@ -82,7 +82,7 @@ function AppInner() { if (!dbReady) { const errMsg = dbError ?? (dbTimedOut ? t.common.initTimeout : null); return ( -
@@ -116,7 +116,7 @@ function AppInner() { } return ( -