Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8699798ea5 | ||
|
|
9c45aedbe8 | ||
|
|
90ee2b30f5 | ||
|
|
4e2459f2c8 | ||
|
|
2a34c94268 | ||
|
|
8f6904b2d1 | ||
|
|
32c16e86b0 |
@@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
name: react-module-integration
|
||||||
|
description: 将独立 React(Vite) 前端项目融合进 ai-platform 平台成为首页可进入的模块,覆盖前期勘察、静态资源迁移、CSS 样式隔离、平台注册与验证部署全流程。当用户要求把 React 项目接入或融合进 ai-platform、新增平台模块、排查模块融合后白屏或部署异常时使用。不用于从零新建独立项目或纯后端接入。
|
||||||
|
---
|
||||||
|
|
||||||
|
# ai-platform React 模块融合
|
||||||
|
|
||||||
|
完整操作手册在 `references/react-module-integration-sop.md`(含命令、代码模板、案例),执行任何一步前先阅读对应章节。以下为必须遵守的红线与执行顺序。
|
||||||
|
|
||||||
|
## 执行顺序
|
||||||
|
|
||||||
|
1. **前期勘察**(SOP §1):对源项目逐项检查——新增依赖、路由方式、入口 Provider、全局 CSS、`document.body` 操作、public 资源清单、存储 key 前缀、`@keyframes` 命名、React 版本差异。
|
||||||
|
2. **目录规划与复制**(SOP §2):源码进 `src/modules/<name>/`,禁止复制 `main.tsx`、`__tests__`。
|
||||||
|
3. **静态资源迁移**(SOP §3):资源统一放 `public/mod-assets/<name>/`,代码引用全部改为绝对路径 `/mod-assets/<name>/xxx`(含 `locateFile`)。
|
||||||
|
4. **样式隔离**(SOP §4):模块根容器类(如 `.xxx-root`)作为所有选择器前缀;`body`/`:root`/`html`/`#root` 规则必须改写或删除;class、ID、裸元素三类冲突源都要检测。
|
||||||
|
5. **代码适配**(SOP §6):源 `main.tsx` 的 Provider 包裹与 CSS import 全部迁入模块 `App.tsx`;`tsc -b` 报错按清单修(TS6133、TS2554)。
|
||||||
|
6. **平台注册**(SOP §7):`moduleConfig` + `registry.ts` + `App.tsx` 路由(模块用 `React.lazy` 动态导入 + `<Suspense fallback={<ModuleLoading />}>` 包 `<Routes>`,禁止静态 import,否则模块 CSS 进主包)+ `HomePage.tsx` ICON_MAP 四件套。
|
||||||
|
7. **验证**(SOP §8):构建层、浏览器层(mock 登录注入)、回归层逐项打勾。
|
||||||
|
8. **部署检查**(SOP §9):nginx 加固与生产地址冒烟。
|
||||||
|
|
||||||
|
## 红线(违反必出事故)
|
||||||
|
|
||||||
|
- **路由与资源目录永不同名**:资源只放 `public/mod-assets/<name>/`,绝不能放 `public/<name>/`。否则 dist 下出现与路由同名目录,nginx 目录 301 补斜杠并把容器端口 `:8901` 泄漏进浏览器地址栏,新页签 403/空白(2026-10 生产事故,SOP §3、§9)。
|
||||||
|
- **样式绝对隔离**:所有 CSS 选择器挂模块根容器类下。模块 CSS 虽随 React.lazy 路由 chunk 按需加载,但加载后仍全局生效,裸选择器必然跨模块污染;同名 `@keyframes`/工具类若值不同必须重命名或作用域化。全局选择器由 `npm run check:styles` 零容忍门禁拦截(已接入 build,SOP §4.5);ID 选择器特异性最高,`#nav` 类冲突需给旧模块规则也加前缀(SOP §4.2)。
|
||||||
|
- **全维度独立零容忍**:禁止写 `document.body`/`document.documentElement` 的 style/classList,禁止向 `document.head` 注入 link/style/script;Portal(弹窗/抽屉)禁止挂 `document.body`,必须挂模块根容器内;localStorage/sessionStorage key 必须带模块前缀(平台 `userToken`/`userInfo` 白名单除外);`document.title` 由平台 `ModuleTitle` 托管;事件监听/定时器必须在 useEffect 返回中清理。由 `npm run check:independence` 零容忍门禁拦截(已接入 build,SOP §5)。
|
||||||
|
- **零平台侵入**:不改 `document.body`/`document.documentElement`,存储 key 带模块前缀,不与平台路由冲突。
|
||||||
|
- **Provider 必须迁移**:漏迁 `AppProvider` 会导致路由渲染时 context 为 null 白屏。
|
||||||
|
|
||||||
|
## 验证捷径
|
||||||
|
|
||||||
|
- 提交/构建前跑 `npm run check:styles`(已接入 build 门禁),退出码 0 = 模块 CSS 无全局选择器违规。
|
||||||
|
- 提交/构建前跑 `npm run check:independence`(已接入 build 门禁),退出码 0 = 无全局 DOM 写入 / body Portal / 无前缀 storage key 违规。
|
||||||
|
- 构建后 `ls dist/` 确认根目录无与路由同名目录。
|
||||||
|
- 部署后 `curl -sI https://生产域名/<name>` 期望 200(或 302 跳登录);出现 301 且 Location 带 `:8901` 即端口泄漏信号。
|
||||||
|
- 浏览器验证前先注入 mock 会话:`sessionStorage.setItem('userToken', 'mock-token-for-ui-check')`。
|
||||||
|
- 进入模块再返回首页,确认 body class/style、CSS 变量、Portal DOM 无残留(视觉无污染)。
|
||||||
|
|
||||||
|
## 历史踩坑速查
|
||||||
|
|
||||||
|
详见 SOP §10 速查表。最高频三坑:同名资源目录端口泄漏、`#nav` ID 冲突、漏迁 Provider。
|
||||||
@@ -0,0 +1,349 @@
|
|||||||
|
# React 前端项目融合 ai-platform 模块化 SOP
|
||||||
|
|
||||||
|
> 适用场景:将独立的 React 前端项目(Vite 构建)融合进 `ai-platform`,作为首页可进入的独立模块。
|
||||||
|
> 已按此 SOP 成功融合:jieya-ibp、welltrust-qap、baode-web、supplier-platform、wuc-quotation。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 0. 核心原则(先记住这五条)
|
||||||
|
|
||||||
|
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、§9)。资源统一放 `public/mod-assets/<模块名>/`。
|
||||||
|
3. **零平台侵入**:模块不得修改 `document.body`/`document.documentElement` 的 class/style,不得占用全局 localStorage key,不得与平台路由冲突。
|
||||||
|
4. **入口职责迁移**:源项目 `main.tsx` 中的 Provider 包裹、全局 CSS 引入等职责,全部迁移到模块 `App.tsx`,平台路由直接渲染模块默认导出。
|
||||||
|
5. **全维度独立**:模块必须做到「挂载即用、卸载即净」——CSS 变量与主题令牌挂模块根容器或 ThemeProvider 作用域 div,靠继承生效、卸载即消失;禁止写 `document.documentElement`/`document.body` 的 style/classList,禁止向 `document.head` 注入 link/style/script;localStorage/sessionStorage key 必须带模块前缀(平台 `userToken`/`userInfo` 白名单除外);Portal 挂载点必须在模块根容器内部;`document.title` 由平台 `ModuleTitle` 托管;事件监听与定时器必须在 `useEffect` 返回中卸载清理。由 `check:independence` 门禁零容忍拦截(见 §5.9)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 前期勘察(融合前必做,约 10 分钟)
|
||||||
|
|
||||||
|
对源项目逐项检查并记录结论:
|
||||||
|
|
||||||
|
| 检查项 | 命令/方法 | 判定 |
|
||||||
|
|---|---|---|
|
||||||
|
| 新增依赖 | 对比 `package.json` 与 ai-platform | 原则上零新增;有新增需评估版本冲突 |
|
||||||
|
| 路由方式 | 看源 `main.tsx`/`App.tsx` | URL 子路由 → 平台路由用 `/xxx/*`;内部 state 切页 → 精确 path 即可 |
|
||||||
|
| 入口 Provider | 看 `main.tsx` 的 `<XxxProvider>` 包裹 | **必须迁移**(否则路由渲染时 context 为 null 白屏) |
|
||||||
|
| 全局 CSS | grep `html`/`body`/`:root`/`#root` | 记录所有需剥离/迁移的全局规则 |
|
||||||
|
| body 操作 | grep `document.body`、`document.documentElement` | classList.toggle/style 修改需改为模块根容器 ref |
|
||||||
|
| public 资源 | `ls public/` | 记录文件清单与代码引用位置(grep 文件名) |
|
||||||
|
| 内嵌资产 | grep `data:` | base64 data URI 无需处理 |
|
||||||
|
| 存储 key | grep `localStorage`/`sessionStorage` | key 必须带项目前缀,无前缀需加 |
|
||||||
|
| keyframes | grep `@keyframes` | 与全平台 CSS 比对命名唯一性 |
|
||||||
|
| React 版本 | `package.json` | 平台为 React 18.3 + @types/react 19,注意类型差异(见 §6.3) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 目录规划与代码复制
|
||||||
|
|
||||||
|
```
|
||||||
|
ai-platform/
|
||||||
|
├── src/modules/<name>/ # 模块源码
|
||||||
|
│ ├── App.tsx # 入口(含 Provider 包裹 + CSS 引入 + 根容器)
|
||||||
|
│ ├── index.ts # moduleConfig 导出
|
||||||
|
│ ├── app/ | pages/ | ... # 源项目 src 业务代码(排除 main.tsx、__tests__)
|
||||||
|
│ └── styles/ | *.css # 源项目样式
|
||||||
|
└── public/mod-assets/<name>/ # 模块静态资源(禁止放 public/<name>/)
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p ai-platform/src/modules/<name> ai-platform/public/mod-assets/<name>
|
||||||
|
cp -R <源项目>/src/app ai-platform/src/modules/<name>/app
|
||||||
|
cp -R <源项目>/src/styles ai-platform/src/modules/<name>/styles
|
||||||
|
cp <源项目>/src/App.tsx ai-platform/src/modules/<name>/App.tsx
|
||||||
|
# 不要复制 main.tsx、__tests__、vite.config 等入口/测试文件
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 静态资源迁移
|
||||||
|
|
||||||
|
1. `public/` 下资源全部复制到 `public/mod-assets/<name>/`;
|
||||||
|
2. grep 源码中所有相对路径引用(`src="xxx.svg"`、`href="xxx.md"`、`locateFile` 等),统一改为绝对路径 `/mod-assets/<name>/xxx`;
|
||||||
|
3. 验证:dev 下直接访问 `http://localhost:<port>/mod-assets/<name>/xxx` 返回 200;
|
||||||
|
4. build 后确认 `dist/mod-assets/<name>/` 存在。
|
||||||
|
|
||||||
|
> 为什么不用 `public/<name>/`:Vite 会把 public 目录原样拷入 dist,形成与模块路由同名的目录。完整故障链(2026-10 生产事故):
|
||||||
|
> 1. 首页卡片 `window.open('/<name>')` → nginx `try_files $uri /index.html` 的 `$uri` 命中该**目录**(非文件);
|
||||||
|
> 2. nginx 对目录请求自动 301 补斜杠(`/`),且 `port_in_redirect` 默认为 on,Location 变成 `https://域名:8901/<name>/`——**容器内端口被泄漏到浏览器地址栏**;
|
||||||
|
> 3. `:8901` 在外网不可达/无该虚拟主机 → 目录又无 index.html → 最终 403 或空白。
|
||||||
|
> 症状特征:只有"新增且带同名静态目录"的模块新页签打开异常(地址栏出现 `:8901`),老模块完全正常。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 样式隔离(核心,必须逐条执行)
|
||||||
|
|
||||||
|
### 4.1 根容器命名空间
|
||||||
|
|
||||||
|
模块 App 最外层包一个根容器,所有 CSS 选择器挂到它下面:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// App.tsx
|
||||||
|
const rootRef = useRef<HTMLDivElement>(null)
|
||||||
|
return <div className="xxx-root" ref={rootRef}>...</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
命名空间化有三种落地方式(按源项目 CSS 规模选择):
|
||||||
|
|
||||||
|
| 方式 | 适用 | 案例 |
|
||||||
|
|---|---|---|
|
||||||
|
| 全量脚本转换 | CSS 大/规则多(尤其 minified) | wuc-quotation:5 个 CSS 全部选择器加 `.wuc-root` 前缀 |
|
||||||
|
| 仅冲突类加前缀 | CSS 小、冲突少 | baode-web:20 处冲突选择器加 `.baode-root` |
|
||||||
|
| 原生自带命名空间 | 源项目已经做好隔离 | supplier-platform:变量与布局挂 `.hansong-app` |
|
||||||
|
|
||||||
|
**脚本转换要点**(已踩坑):
|
||||||
|
- `:root{--var}` → `.xxx-root{--var}`(CSS 变量迁到根容器)
|
||||||
|
- `body` → `.xxx-root`;`body.dark`/`body.collapsed` → `.xxx-root.dark` 等(主题/状态类改挂根容器)
|
||||||
|
- `body > #root > header` → `.xxx-root > header`(层级补偿规则改写)
|
||||||
|
- `html, body{overflow:hidden}` 等 → **直接删除**(会锁死平台整页滚动);视口锁定改由 `.xxx-root{height:100vh}` 承接
|
||||||
|
- `@media` 块内部规则**必须递归处理**(漏掉会造成窄屏规则逃逸成全局)
|
||||||
|
- `@keyframes`/`@font-face` 原样保留;字符串(data URI)不能破坏——需状态机解析而非正则替换
|
||||||
|
- 转换完必须校验:无残留 `body`/`:root`/`html`/`#root` 选择器、brace 平衡
|
||||||
|
|
||||||
|
### 4.2 三类冲突源都要检测(缺一不可)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 检测思路(对每个已存在模块 + 平台全局样式执行)
|
||||||
|
# 1. class 冲突:新模块 TSX className 集合 ∩ 双方 CSS 类名集合
|
||||||
|
# 2. ID 冲突:新模块 TSX 中的 id="xxx" ∩ 其它模块 CSS 中的 #xxx(双向)
|
||||||
|
# 3. 裸元素选择器:新模块 CSS 中 html/body/header/aside/nav/button/input 等无前缀选择器
|
||||||
|
```
|
||||||
|
|
||||||
|
> **ID 冲突是隐藏最深的坑**:`#nav` 特异性(1,0,0)碾压任何 `.wuc-root nav`(0,1,1)。wuc-quotation 上线后菜单被 supplier-platform 的 `#nav{display:flex}` 强制水平排列。修复方式是给**旧模块**的 ID 规则也加根容器前缀(`.hansong-app #nav`)。
|
||||||
|
|
||||||
|
### 4.3 运行时全局副作用清理
|
||||||
|
|
||||||
|
- `document.body.classList.toggle('dark'/'collapsed')` → `rootRef.current?.classList.toggle(...)`
|
||||||
|
- `document.body.style.overflow = ...`(如 LoginPage 的 useEffect)→ 模块内改为根容器样式或卸载时恢复
|
||||||
|
- 弹窗/Portal 挂载点若用 `document.body`,改为模块根容器内渲染
|
||||||
|
- `@media print` 中 `body{...}` 规则 → `.xxx-root{...}`,并放开视口锁定(`height:auto;overflow:visible`)
|
||||||
|
|
||||||
|
### 4.4 其它隔离项
|
||||||
|
|
||||||
|
- localStorage/sessionStorage key 带项目前缀(如 `wuchuan-quotation-v1`)
|
||||||
|
- `@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 && npm run check:independence && vite build`,双门禁见 §5.9),日常可单独运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run check:styles # 退出码 0 = 模块 CSS 无全局选择器违规
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 模组完全独立互不影响(全维度隔离)
|
||||||
|
|
||||||
|
模块在平台中是「挂载即用、卸载即净」的独立单元,任何逃逸到全局的副作用都会污染首页与其它模块。本节是样式隔离(§4)之外的运行时隔离规则,与 `check:styles` 共同构成双门禁。
|
||||||
|
|
||||||
|
### 5.1 CSS 选择器命名空间
|
||||||
|
|
||||||
|
见 §4——所有选择器必须挂模块根容器类(`.xxx-root`),此处不重复。
|
||||||
|
|
||||||
|
### 5.2 CSS 变量与主题令牌作用域
|
||||||
|
|
||||||
|
- **禁止**向 `document.documentElement` / `document.body` 写入 CSS 变量、`style`、`classList`。
|
||||||
|
- 主题令牌(`--xxx` 变量、`background`、`color`、`font-family` 等)一律挂在**模块根容器**或模块内的 `ThemeProvider` 作用域 `div` 上,靠 CSS 继承向下生效。
|
||||||
|
- 模块卸载(路由切走)后,根容器及其子树从 DOM 移除,所有令牌随之消失,不残留到首页。
|
||||||
|
- 若源项目用 `document.documentElement.style.setProperty('--xxx', ...)` 切换主题,改为 `rootRef.current?.style.setProperty(...)` 或在根容器上切类。
|
||||||
|
|
||||||
|
### 5.3 全局 DOM 写入禁令
|
||||||
|
|
||||||
|
- **禁止**修改 `document.body` / `document.documentElement` 的 `style` 或 `classList`(如 `body.style.overflow`、`body.classList.toggle('dark')`)。
|
||||||
|
- **禁止**向 `document.head` 注入 `<link>`、`<style>`、`<script>` 标签。
|
||||||
|
- 需要锁滚动、切主题等副作用时,一律作用于模块根容器 `ref`,并在卸载时恢复。
|
||||||
|
|
||||||
|
### 5.4 存储 key 必须带模块前缀
|
||||||
|
|
||||||
|
- localStorage / sessionStorage 的 key 必须带模块前缀(如 `wuchuan-quotation-v1`、`sp_theme`、`ocDataSourceMode`、`welltrust-qap-*` 等)。
|
||||||
|
- **白名单**:平台级 `userToken`、`userInfo` 可直接读写,模块不得新增其它无前缀全局 key。
|
||||||
|
- 切换主题等本地偏好也用前缀 key,不得复用无命名空间的 `theme` / `darkMode`。
|
||||||
|
|
||||||
|
### 5.5 事件监听与定时器必须卸载清理
|
||||||
|
|
||||||
|
- 所有 `addEventListener`(`window` / `document` / `rootRef`)、`setTimeout`、`setInterval`、`requestAnimationFrame` 必须在 `useEffect` 的返回函数中 `removeEventListener` / `clearTimeout` / `clearInterval` / `cancelAnimationFrame`。
|
||||||
|
- 模块可被用户随时切走,残留监听器会跨模块执行并导致内存泄漏。
|
||||||
|
|
||||||
|
### 5.6 Portal 挂载点必须在模块根容器内部
|
||||||
|
|
||||||
|
- 弹窗、抽屉、Tooltip 等 `ReactDOM.createPortal(...)` 的第二个参数(容器)**必须**指向模块根容器内部的节点(如 `rootRef.current` 或根容器内的 `<div id="xxx-portal-root">`)。
|
||||||
|
- **禁止**挂到 `document.body`——否则模块卸载后 Portal DOM 残留在 body,样式与交互污染全局。
|
||||||
|
- 若第三方组件默认 portal 到 body,需通过 API 指定 `getContainer` / `appendTo` / `container` 为模块根容器。
|
||||||
|
|
||||||
|
### 5.7 document.title 由平台托管
|
||||||
|
|
||||||
|
- 模块**不得**自行 `document.title = ...`。
|
||||||
|
- 平台 `ModuleTitle` 组件在进入模块时设置标题为模块中文名,卸载时恢复 `'EIOSpace'`(见 §7 平台注册)。
|
||||||
|
|
||||||
|
### 5.8 第三方全局样式/脚本注入禁令
|
||||||
|
|
||||||
|
- 禁止在模块代码中动态 `<script src="...">` 注入第三方 SDK 到 `document.head` / `document.body`(如统计、地图、编辑器);必须用时改为 `import` 打包或挂到模块根容器内。
|
||||||
|
- 禁止 `@import` 全局 reset / normalize(见 §4.4)。
|
||||||
|
|
||||||
|
### 5.9 双门禁(check:styles + check:independence)
|
||||||
|
|
||||||
|
| 门禁 | 命令 | 零容忍范围 |
|
||||||
|
|---|---|---|
|
||||||
|
| 样式门禁 | `npm run check:styles` | CSS 全局选择器(裸标签、`:root`、`*`、`@import` reset 等,见 §4.5) |
|
||||||
|
| 独立门禁 | `npm run check:independence` | 全局 DOM 写入(`document.body` / `documentElement` 的 style/classList)、`document.head` 注入 link/style/script、`document.body` Portal、无前缀 storage key |
|
||||||
|
|
||||||
|
双门禁已接入 build:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build # = tsc -b && npm run check:styles && npm run check:independence && vite build
|
||||||
|
```
|
||||||
|
|
||||||
|
日常可单独运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run check:independence # 退出码 0 = 无全局 DOM / Portal / 无前缀 storage 违规
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 代码适配
|
||||||
|
|
||||||
|
### 6.1 入口与 Provider
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// App.tsx 末尾:平台路由直接渲染默认导出,Provider 职责从 main.tsx 移到这里
|
||||||
|
import { AppProvider } from './app/store'
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
return (
|
||||||
|
<AppProvider>
|
||||||
|
<AppShell />
|
||||||
|
</AppProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
同时把源 `main.tsx` 的 CSS import 全部搬到模块 `App.tsx` 顶部(保持原有顺序)。
|
||||||
|
|
||||||
|
### 6.2 严格 tsconfig 适配(tsc -b 报错清单)
|
||||||
|
|
||||||
|
- `TS6133` 未使用变量/import → 删除(含解构中未使用的成员)
|
||||||
|
- `TS2554`:`useRef<T>()` → `useRef<T | undefined>(undefined)`(@types/react 19 要求初始值)
|
||||||
|
- 默认导入 `import React` 未使用 → 删除(react-jsx transform 无需)
|
||||||
|
|
||||||
|
### 6.3 其他常见点
|
||||||
|
|
||||||
|
- 事件监听/定时器在组件卸载时清理(模块可被随时切走)
|
||||||
|
- 弹窗内 `dangerouslySetInnerHTML` 注入的 HTML,其类名也要被命名空间 CSS 覆盖(确认前缀后仍能匹配)
|
||||||
|
- 内部 state 切页的项目保留原交互,不强行改造为 URL 路由
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 平台注册(三件套 + 图标)
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// 1. src/modules/<name>/index.ts
|
||||||
|
import type { ModuleConfig } from '../registry';
|
||||||
|
|
||||||
|
export const moduleConfig: ModuleConfig = {
|
||||||
|
id: '<name>',
|
||||||
|
name: '模块中文名',
|
||||||
|
description: '一句话描述',
|
||||||
|
icon: 'Lucide图标名', // 如 FileSpreadsheet / Radar / Building2
|
||||||
|
path: '/<name>',
|
||||||
|
accentColor: '#7C6FFF', // 暗色强调色
|
||||||
|
accentColorLight: '#5747EF', // 亮色强调色
|
||||||
|
gradient: 'linear-gradient(135deg, ...)', // 暗色卡片渐变
|
||||||
|
gradientLight: 'linear-gradient(135deg, ...)', // 亮色卡片渐变
|
||||||
|
tags: ['标签1', '标签2'],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// 2. src/modules/registry.ts:import + modules 数组追加
|
||||||
|
// 3. src/App.tsx:模块级 React.lazy 动态导入 + 路由(ModuleTitle 负责页签标题,卸载恢复 'EIOSpace')
|
||||||
|
const XxxApp = lazy(() => import('@/modules/<name>/App'));
|
||||||
|
...
|
||||||
|
<Routes>
|
||||||
|
<Suspense fallback={<ModuleLoading />}>
|
||||||
|
<Route path="/<name>" element={<RequireAuth><ModuleTitle title="模块中文名"><XxxApp /></ModuleTitle></RequireAuth>} />
|
||||||
|
...
|
||||||
|
</Suspense>
|
||||||
|
</Routes>
|
||||||
|
// 4. src/pages/HomePage.tsx:ICON_MAP 增加图标(先在 lucide-react import 中补图标名)
|
||||||
|
```
|
||||||
|
|
||||||
|
> 模块入口必须用 `React.lazy` 动态导入(模块 CSS 随路由 chunk 按需加载),**静态 import 会把模块 CSS 打进主包,禁止**。
|
||||||
|
> 首页卡片点击已是 `window.open(mod.path, '_blank')` 新页签打开,无需额外处理。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 验证清单
|
||||||
|
|
||||||
|
**构建层**
|
||||||
|
- [ ] `npx tsc --noEmit` 通过
|
||||||
|
- [ ] `npm run build` 通过(注意 `tsc -b` 比 `tsc --noEmit` 更严,以 build 为准;已含 `check:styles` + `check:independence` 双门禁)
|
||||||
|
- [ ] `npm run check:styles` 退出码 0(模块 CSS 全局选择器零容忍门禁,见 §4.5,已接入 build)
|
||||||
|
- [ ] `npm run check:independence` 退出码 0(全局 DOM 写入 / body Portal / 无前缀 storage key 零容忍门禁,见 §5.9,已接入 build)
|
||||||
|
- [ ] `dist/mod-assets/<name>/` 资源齐全
|
||||||
|
- [ ] **`ls dist/` 确认根目录下没有与模块路由同名的目录**(防端口泄漏,见 §3)
|
||||||
|
|
||||||
|
**浏览器层**(dev server + mock 登录)
|
||||||
|
```js
|
||||||
|
// 平台守卫只查 sessionStorage.userToken,浏览器验证先注入:
|
||||||
|
sessionStorage.setItem('userToken', 'mock-token-for-ui-check');
|
||||||
|
sessionStorage.setItem('userInfo', JSON.stringify({ name: '演示用户', userId: 'demo' }));
|
||||||
|
```
|
||||||
|
- [ ] `/<name>` 页面完整渲染(header/侧栏/内容区),控制台无 React 报错、无 404
|
||||||
|
- [ ] 页内交互可用(菜单切换、弹窗、主题切换)
|
||||||
|
- [ ] 新页签打开后浏览器标题为模块中文名
|
||||||
|
- [ ] 首页出现新模块卡片(图标、配色正确)
|
||||||
|
- [ ] 首页(未进入任何模块)Network 面板无任何模块级 CSS chunk
|
||||||
|
- [ ] 首次进入模块路由时按需加载对应 JS+CSS chunk(React.lazy 生效)
|
||||||
|
- [ ] **进入模块再返回首页,首页视觉无污染**(body class/style 无残留、CSS 变量无残留、无 Portal 残留 DOM)
|
||||||
|
- [ ] **弹窗/抽屉等 Portal 的 DOM 位于模块根容器内部**(Elements 面板检查,非 `document.body` 直接子节点)
|
||||||
|
|
||||||
|
**回归层(改了旧模块 CSS 时必做)**
|
||||||
|
- [ ] 新模块关键布局 computed style 复核(如 nav 的 display)
|
||||||
|
- [ ] 被 CSS 影响的旧模块核心页面正常(如 supplier 顶栏导航)
|
||||||
|
- [ ] 平台首页/登录页样式未受污染
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. 部署注意(nginx)
|
||||||
|
|
||||||
|
- `nginx.conf` SPA 回退必须是 `try_files $uri /index.html;`——**禁止 `$uri/`**(目录命中 → 403 且不回退)
|
||||||
|
- **必须加两条重定向加固**(防止容器内端口泄漏到浏览器地址栏,2026-10 事故根因):
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
listen 8901;
|
||||||
|
...
|
||||||
|
port_in_redirect off; # 301 重定向的 Location 不带 8901 端口
|
||||||
|
absolute_redirect off; # 使用相对路径 Location,彻底避免泄漏 host/port
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 部署后用生产地址冒烟验证(新页签打开路径):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -sI https://ai-workshop.digiwincloud.com.cn/<name> | head -5
|
||||||
|
# 期望:HTTP 200(或 302 跳登录页)
|
||||||
|
# 异常信号:HTTP 301 且 Location 带 :8901 —— 即存在与路由同名的静态目录触发了目录重定向
|
||||||
|
```
|
||||||
|
|
||||||
|
- 模块静态资源引用用绝对路径 `/mod-assets/...`,与部署子路径无关
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. 历史踩坑速查表
|
||||||
|
|
||||||
|
| 案例 | 坑 | 修复 |
|
||||||
|
|---|---|---|
|
||||||
|
| baode-web ↔ supplier-platform | baode 自检页 `.page{max-width:1080px}` 污染 supplier 的 `section.page` | `.page`→`.checkpage` + 冲突类加 `.baode-root` 前缀 |
|
||||||
|
| supplier-platform | 源 tsconfig 宽松,`useRef<T>()` 在 @types/react 19 下报 TS2554 | `useRef<T \| undefined>(undefined)` |
|
||||||
|
| 全部模块 | dist 下与路由同名目录:早期 `try_files $uri/` 命中目录 403;去掉 `$uri/` 后 `$uri` 仍命中目录触发 301 补斜杠,`port_in_redirect` 默认 on 把容器端口 `:8901` 泄漏进浏览器地址栏,新页签跳到带端口地址后 403/空白 | 资源统一迁 `mod-assets/`;nginx 加 `port_in_redirect off; absolute_redirect off;` |
|
||||||
|
| wuc-quotation | 漏迁 `AppProvider` → 白屏 `ctx is null` | Provider 移入模块默认导出 |
|
||||||
|
| wuc-quotation | 001.css 7.8MB 内嵌 data URI + minified,正则替换会破坏资产 | 状态机解析转换,字符串原样保留 |
|
||||||
|
| wuc-quotation | `document.body.classList.toggle('dark')` 污染平台 body | 改挂 `.wuc-root` 根容器 ref |
|
||||||
|
| 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/<name>/...'` |
|
||||||
|
| 全部模块 | 模块 CSS 全局选择器(`:root`/`button`/`table`/`::-webkit-scrollbar`/`*`)跨模块污染 | 加模块根容器前缀 + `check:styles` 门禁(§4.5,已接入 build) |
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Checklist
|
||||||
|
- [x] jieya-ibp/context/ThemeContext.tsx 不再写 document.documentElement / document.body,CSS 变量与背景/文字色由 ThemeProvider 作用域容器承载
|
||||||
|
- [x] welltrust-qap/context/ThemeContext.tsx 同上改造
|
||||||
|
- [x] order-cost-analysis CostCockpit 移除对 documentElement 的 --body-bg 死变量写入
|
||||||
|
- [x] bomx Drawer 的 createPortal 挂载点位于 .bomx-app 子树内,不再挂 document.body(portalMount 必传,无 document.body 兜底)
|
||||||
|
- [x] 浏览器验证:进入 jieya 后返回首页,首页背景与文字色未被模组主题覆盖(body style 串 before==during==after)
|
||||||
|
- [x] 浏览器验证:jieya 明暗主题切换正常(作用于 .jieya-root);welltrust 同构;bomx Drawer 当前未实例化
|
||||||
|
- [x] scripts/check-module-independence.mjs 存在,能检出全局 DOM 写入、head 注入、body Portal、无前缀 storage key,违规非零退出
|
||||||
|
- [x] package.json 含 check:independence,build 已接入 check:styles + check:independence 双门禁
|
||||||
|
- [x] npm run check:independence 退出码 0
|
||||||
|
- [x] npm run check:styles 退出码 0
|
||||||
|
- [x] npm run build 通过
|
||||||
|
- [x] docs/react-module-integration-sop.md 含「模组完全独立互不影响」完整规则与双门禁说明
|
||||||
|
- [x] .trae/skills/react-module-integration/SKILL.md 与 references 副本同步更新
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
# 模组完全独立互不影响 Spec
|
||||||
|
|
||||||
|
## Why
|
||||||
|
此前已完成「模组 CSS 按需加载 + 选择器命名空间隔离」(spec `isolate-and-lazyload-module-styles`),但跨模组污染不止 CSS 一项。审计发现仍存在模组在运行时直接写入全局 DOM 且卸载不恢复的行为(jieya-ibp / welltrust-qap 的 ThemeContext 把 CSS 变量写到 `document.documentElement`、把 `background`/`color` 写到 `document.body`;order-cost-analysis 的 CostCockpit 向 `documentElement` 写 `--body-bg` 死变量)。这些值在用户离开模组后仍残留在全局,会污染首页与其它模组的视觉。从「每个模组完全独立、互不影响」的角度,需要在 CSS 之外补齐全局 DOM、存储、事件、Portal 等维度的隔离,并把规则沉淀进 SOP 与技能文档。
|
||||||
|
|
||||||
|
## What Changes
|
||||||
|
- **修复全局 DOM 写入污染**:jieya-ibp 与 welltrust-qap 的 `ThemeContext` 不再写 `document.documentElement` / `document.body`,改为由 `ThemeProvider` 渲染的作用域容器承载 CSS 变量与背景/文字色(CSS 变量向下继承,模组内所有 `var(--xxx)` 正常取值);order-cost-analysis CostCockpit 移除向 `documentElement` 写 `--body-bg` 的死代码。
|
||||||
|
- **Portal 挂载规范化**:bomx Drawer 目前用 `createPortal(..., document.body)`(已用 `.bomx-app` 包裹层解决 CSS 作用域);作为最佳实践,将 Portal 内容挂到模块根容器内的 Portal 挂载点,避免全局 body 出现非受控 DOM。
|
||||||
|
- **新增模组独立门禁脚本**:`scripts/check-module-independence.mjs`,扫描 `src/modules/**/*.{ts,tsx,js,jsx}`,检测 `document.body.style`/`document.body.classList`、`document.documentElement.style`/`setAttribute`、`document.head.appendChild`/`insertBefore`(注入 link/style)、`createPortal` 第二参数为 `document.body`、`localStorage`/`sessionStorage` key 不带模组前缀等违规模式,非零退出;接入 `npm run check:independence` 并加入 `build` 门禁。
|
||||||
|
- **文档沉淀**:更新 `docs/react-module-integration-sop.md` 与 `.trae/skills/react-module-integration`(含 references 副本),新增「模组独立不互相影响」章节,覆盖:CSS 选择器命名空间、CSS 变量作用域、全局 DOM 写入禁令、storage key 前缀、事件/定时器卸载清理、Portal 挂载、document.title、第三方全局样式/脚本注入禁令,并给出 check:styles + check:independence 双门禁说明。
|
||||||
|
|
||||||
|
## Impact
|
||||||
|
- Affected specs: `isolate-and-lazyload-module-styles`(CSS 隔离已完成,本 spec 扩展到全维度)
|
||||||
|
- Affected code:
|
||||||
|
- `src/modules/jieya-ibp/context/ThemeContext.tsx`、`src/modules/welltrust-qap/context/ThemeContext.tsx`(全局写入改作用域容器)
|
||||||
|
- `src/modules/order-cost-analysis/pages-orig/CostCockpit.tsx`(移除死变量写入)
|
||||||
|
- `src/modules/bomx-reuse-analyzer/components/Drawer.tsx`(Portal 挂载点内移)
|
||||||
|
- `scripts/check-module-independence.mjs`(新增)
|
||||||
|
- `package.json`(新增 `check:independence`,build 接入)
|
||||||
|
- `docs/react-module-integration-sop.md`、`.trae/skills/react-module-integration/SKILL.md`、`.trae/skills/react-module-integration/references/react-module-integration-sop.md`(文档沉淀)
|
||||||
|
|
||||||
|
## ADDED Requirements
|
||||||
|
|
||||||
|
### Requirement: 模组不得写入全局 DOM 且卸载后无残留
|
||||||
|
系统 SHALL 保证每个模组在运行期不修改 `document.body` / `document.documentElement` 的 `style`/`classList`,不向 `document.head` 注入 `<link>`/`<style>`/`<script>`;模组的 CSS 变量、背景色、文字色等主题令牌 SHALL 仅作用于模组根容器及其后代。
|
||||||
|
|
||||||
|
#### Scenario: 访问 jieya-ibp 后回到首页
|
||||||
|
- **WHEN** 用户进入 `/jieya-ibp` 再返回首页 `/`
|
||||||
|
- **THEN** 首页背景色与文字色为平台默认值,未被 jieya 的深色主题覆盖
|
||||||
|
|
||||||
|
#### Scenario: 主题令牌仅在模组内生效
|
||||||
|
- **WHEN** jieya-ibp 切换明暗主题
|
||||||
|
- **THEN** `--body-bg`/`--scroll-thumb`/`--glow-color`/`--hover-bg` 等变量仅在 `.jieya-root` 子树内生效,`getComputedStyle(document.documentElement).getPropertyValue('--body-bg')` 不含模组值
|
||||||
|
|
||||||
|
### Requirement: 模组门户(Portal)挂载于模组根容器内
|
||||||
|
系统 SHALL 保证模组的弹窗/抽屉等 Portal 内容挂载在模组根容器内部的 DOM 节点,而非 `document.body`,避免全局 body 出现非模组受控的 DOM。
|
||||||
|
|
||||||
|
#### Scenario: bomx 抽屉挂载点
|
||||||
|
- **WHEN** 打开 bomx-reuse-analyzer 的 Drawer
|
||||||
|
- **THEN** 抽屉 DOM 节点位于 `.bomx-app` 子树内,而非 `document.body` 的直接子节点
|
||||||
|
|
||||||
|
### Requirement: 模组独立自动化门禁
|
||||||
|
系统 SHALL 提供 `npm run check:independence` 脚本,扫描模组代码中的全局 DOM 写入、head 注入、body Portal、无前缀 storage key 等独立违规,作为构建门禁。
|
||||||
|
|
||||||
|
#### Scenario: 门禁通过
|
||||||
|
- **WHEN** 所有模组均无全局 DOM 写入、Portal 均挂在根容器内、storage key 均带模组前缀
|
||||||
|
- **THEN** `npm run check:independence` 退出码 0
|
||||||
|
|
||||||
|
#### Scenario: 门禁发现违规
|
||||||
|
- **WHEN** 某模组存在 `document.body.style.xxx` 或 `createPortal(x, document.body)`
|
||||||
|
- **THEN** 脚本输出违规文件+行号+原因,退出码非 0,`npm run build` 失败
|
||||||
|
|
||||||
|
### Requirement: 模组独立规则文档化
|
||||||
|
SOP 文档与 react-module-integration 技能 SHALL 包含「模组完全独立互不影响」的完整规则清单与双门禁(check:styles + check:independence)说明。
|
||||||
|
|
||||||
|
#### Scenario: 查阅文档
|
||||||
|
- **WHEN** 查阅 SOP 或技能文件
|
||||||
|
- **THEN** 可找到全局 DOM 写入禁令、CSS 变量作用域、storage key 前缀、事件/定时器清理、Portal 挂载、document.title、第三方注入禁令等规则,以及双门禁运行方式
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Tasks
|
||||||
|
|
||||||
|
- [x] Task 1: 修复全局 DOM 写入污染(jieya-ibp / welltrust-qap ThemeContext)
|
||||||
|
- [x] SubTask 1.1: `jieya-ibp/context/ThemeContext.tsx`:移除 `useEffect` 中对 `document.documentElement` 的 `setProperty` 与 `document.body.style.background/color`;改为 `ThemeProvider` 返回的 `<ThemeContext.Provider>` 内包裹一层作用域 `<div>`,以 inline style 设置 `--body-bg`/`--scroll-thumb`/`--glow-color`/`--hover-bg` 变量与 `background`/`color`(值取自 `tokens`),宽高 100% 承接 `AppInner` 的 100vw/100vh 根容器
|
||||||
|
- [x] SubTask 1.2: `welltrust-qap/context/ThemeContext.tsx`:同 1.1 改造
|
||||||
|
- [x] SubTask 1.3: `order-cost-analysis/pages-orig/CostCockpit.tsx`:移除向 `document.documentElement` 写 `--body-bg` 的 `useEffect`(`var(--body-bg)` 在模组内无引用,属死代码)
|
||||||
|
- [x] SubTask 1.4: 浏览器验证:进入 jieya 再回首页,首页背景/文字色未被覆盖;jieya 明暗主题切换正常(welltrust 同构改造,tsc + build 通过)
|
||||||
|
- [x] Task 2: Portal 挂载点内移(bomx Drawer)
|
||||||
|
- [x] SubTask 2.1: `bomx-reuse-analyzer/pages/BomxReuseHome.tsx` 根容器内新增 Portal 挂载点 `<div ref={portalMountRef} />`
|
||||||
|
- [x] SubTask 2.2: `bomx-reuse-analyzer/components/Drawer.tsx`:`createPortal` 第二参数改为必传 `portalMount: HTMLDivElement`,彻底移除 `document.body` 兜底
|
||||||
|
- [x] SubTask 2.3: Drawer 当前未被任何文件引用(死代码),无运行时实例;`.bomx-app` 根容器无 transform/filter/perspective,不会破坏 fixed 遮罩
|
||||||
|
- [x] Task 3: 新增模组独立门禁脚本
|
||||||
|
- [x] SubTask 3.1: 新增 `scripts/check-module-independence.mjs`(ESM 零依赖),扫描 `src/modules/**/*.{ts,tsx,js,jsx}`,检测 5 类违规(body 样式写入、documentElement 写入、head 注入、body Portal、无前缀 storage key),跳过字符串与注释,违规非零退出
|
||||||
|
- [x] SubTask 3.2: `package.json` 增加 `check:independence`;`build` 改为 `tsc -b && npm run check:styles && npm run check:independence && vite build`
|
||||||
|
- [x] SubTask 3.3: 自测:修复后退出码 0(扫描 270 文件);故意保留/插入的违规样例可正确检出(已验证 bomx Drawer、knowledge-graph 两处真实违规被检出并修复)
|
||||||
|
- [x] Task 4: 文档沉淀(SOP + 技能)
|
||||||
|
- [x] SubTask 4.1: `docs/react-module-integration-sop.md` 新增 §5「模组完全独立互不影响」(5.1–5.9),覆盖全维度规则与双门禁说明;章节顺延
|
||||||
|
- [x] SubTask 4.2: `.trae/skills/react-module-integration/SKILL.md` 红线与验证清单同步
|
||||||
|
- [x] SubTask 4.3: `.trae/skills/react-module-integration/references/react-module-integration-sop.md` 与 docs 完全同源(diff 无输出)
|
||||||
|
- [x] Task 5: 端到端验证
|
||||||
|
- [x] SubTask 5.1: `npm run build` 通过(含双门禁),dist 无回归
|
||||||
|
- [x] SubTask 5.2: 浏览器验证:首页→jieya→首页 body 样式串 before/during/after 完全一致(仅平台深色主题值),jieya 主题背景作用于 `.jieya-root`;控制台无报错
|
||||||
|
- [x] SubTask 5.3: `npm run check:independence` 与 `npm run check:styles` 均退出码 0
|
||||||
|
|
||||||
|
# Task Dependencies
|
||||||
|
- Task 1、Task 2 互相独立,可并行
|
||||||
|
- Task 3 依赖 Task 1、Task 2(修复后门禁才能通过;门禁脚本本身可先写,用 HEAD 版本验证检出能力)
|
||||||
|
- Task 4 与 Task 1/2/3 无代码冲突,可并行
|
||||||
|
- Task 5 依赖 Task 1-4
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Checklist
|
||||||
|
- [x] `src/App.tsx` 全部模块组件改为 `React.lazy()` 动态导入,`<Suspense>` 兜底生效
|
||||||
|
- [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 副本同步)
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
# 模块样式隔离与按需加载 Spec
|
||||||
|
|
||||||
|
## Why
|
||||||
|
当前 `src/App.tsx` 静态 import 全部 12 个模块的 App 组件,导致所有模块的 JS 与 CSS 全部打进主包,用户打开首页即下载全部模块样式(wuc-quotation 单个模块 CSS 约 7.8MB)。同时样式隔离仅依赖 SOP 中的手工命名空间约定,无自动化守护,仍存在残留全局选择器(如 `bomx-reuse-analyzer/styles.css` 的 `:root` 规则)可跨模块污染。
|
||||||
|
|
||||||
|
## What Changes
|
||||||
|
- **路由级懒加载**:`src/App.tsx` 中模块组件改为 `React.lazy()` 动态导入,外层包 `<Suspense>` 加载兜底;Vite 自动将每个模块拆为独立 JS+CSS chunk,仅在跳转到对应路由时才加载该模块样式。
|
||||||
|
- **样式隔离自动化守护**:新增 `scripts/check-module-styles.mjs` 检查脚本,扫描 `src/modules/**/*.css` 中的全局选择器(`:root`/`html`/`body`/`*`/裸元素选择器/`@import` 全局重置),发现违规即报错退出;注册为 `npm run check:styles`。
|
||||||
|
- **修复存量违规**:`bomx-reuse-analyzer/styles.css` 的 `:root` CSS 变量迁移到模块根容器类下。
|
||||||
|
- **构建管线接入**:存量违规清零后,将 `check:styles` 纳入 `build` 脚本,防止后续模块引入全局选择器。
|
||||||
|
- **文档同步**:更新 SOP 文档与 react-module-integration 技能,明确新模块接入必须使用 lazy 路由模式 + 命名空间根容器。
|
||||||
|
|
||||||
|
## Impact
|
||||||
|
- Affected specs: 无既有 spec(首次建立)
|
||||||
|
- Affected code:
|
||||||
|
- `src/App.tsx`(懒加载改造)
|
||||||
|
- `src/modules/bomx-reuse-analyzer/styles.css`(存量违规修复)
|
||||||
|
- `scripts/check-module-styles.mjs`(新增)
|
||||||
|
- `package.json`(新增 check:styles 脚本、build 接入)
|
||||||
|
- `docs/react-module-integration-sop.md`、`.trae/skills/react-module-integration/SKILL.md`(文档同步)
|
||||||
|
|
||||||
|
## ADDED Requirements
|
||||||
|
|
||||||
|
### Requirement: 模块按需加载
|
||||||
|
系统 SHALL 以 `React.lazy()` 动态导入方式注册全部模块路由,保证模块代码与样式拆分为独立 chunk,仅在用户导航至该模块路由时才发起加载。
|
||||||
|
|
||||||
|
#### Scenario: 首页不加载模块样式
|
||||||
|
- **WHEN** 用户登录后停留在平台首页(`/`)
|
||||||
|
- **THEN** Network 面板中不出现任何模块级 CSS chunk(如 `wuc-quotation`、`supplier-platform` 的 CSS 文件)
|
||||||
|
|
||||||
|
#### Scenario: 跳转模块时加载对应样式
|
||||||
|
- **WHEN** 用户首次导航到某模块路由(如 `/supplier-platform`)
|
||||||
|
- **THEN** 浏览器按需加载该模块对应的 JS 与 CSS chunk,模块界面正常渲染
|
||||||
|
|
||||||
|
#### Scenario: 加载期间兜底 UI
|
||||||
|
- **WHEN** 模块 chunk 尚在加载中
|
||||||
|
- **THEN** Suspense 兜底占位展示(平台风格的加载提示),加载完成后无报错切换至模块界面
|
||||||
|
|
||||||
|
#### Scenario: 构建产物按模块拆分
|
||||||
|
- **WHEN** 执行 `npm run build`
|
||||||
|
- **THEN** `dist/assets` 中每个模块生成独立的 JS 与 CSS 产物(含路由引用关系),`tsc -b` 类型检查通过
|
||||||
|
|
||||||
|
### Requirement: 模块样式全局选择器零容忍
|
||||||
|
系统 SHALL 提供自动化检查脚本,确保 `src/modules/**/*.css` 中不出现全局作用选择器;检查结果 SHALL 作为构建门禁。
|
||||||
|
|
||||||
|
#### Scenario: 扫描通过
|
||||||
|
- **WHEN** 执行 `npm run check:styles` 且所有模块 CSS 均挂在模块命名空间根容器类下
|
||||||
|
- **THEN** 脚本以退出码 0 结束,无违规输出
|
||||||
|
|
||||||
|
#### Scenario: 扫描发现违规
|
||||||
|
- **WHEN** 某模块 CSS 中存在 `:root`、`html`、`body`、`*`、裸元素选择器或 `@import` 全局重置
|
||||||
|
- **THEN** 脚本以非 0 退出码失败,并逐条输出违规文件、行号与选择器内容
|
||||||
|
|
||||||
|
#### Scenario: 构建门禁生效
|
||||||
|
- **WHEN** 模块 CSS 存在全局选择器违规时执行 `npm run build`
|
||||||
|
- **THEN** 构建失败并提示先修复样式违规
|
||||||
|
|
||||||
|
### Requirement: 存量违规清零
|
||||||
|
系统 SHALL 保证现有 12 个模块 CSS 无全局选择器残留,不污染平台首页、登录页及其它模块。
|
||||||
|
|
||||||
|
#### Scenario: bomx-reuse-analyzer 变量迁移
|
||||||
|
- **WHEN** `src/modules/bomx-reuse-analyzer/styles.css` 中存在 `:root { --xxx }` 规则
|
||||||
|
- **THEN** 变量定义迁移至该模块根容器类下,模块页面变量取值正常,视觉无回归
|
||||||
|
|
||||||
|
### Requirement: 新模块接入约定同步
|
||||||
|
SOP 文档与 react-module-integration 技能 SHALL 同步更新:新模块路由必须使用 lazy 动态导入模式,CSS 必须挂载在模块命名空间根容器下,并通过 check:styles 校验。
|
||||||
|
|
||||||
|
#### Scenario: 文档含懒加载约定
|
||||||
|
- **WHEN** 查阅 SOP 文档或技能文件
|
||||||
|
- **THEN** 可找到 lazy 路由模式代码约定与 check:styles 校验说明
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# Tasks
|
||||||
|
- [x] Task 1: 路由级懒加载改造
|
||||||
|
- [x] SubTask 1.1: `src/App.tsx` 将 12 个模块组件的静态 import 全部改为 `React.lazy(() => import('...'))`
|
||||||
|
- [x] SubTask 1.2: `<Routes>` 外层包 `<Suspense>`,提供平台风格 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(需要脚本先检测出违规)
|
||||||
|
- Task 4 依赖 Task 2、Task 3(违规清零后才接入构建门禁)
|
||||||
|
- Task 5 依赖 Task 1(懒加载完成后方可验证按需加载);SubTask 5.3 依赖 Task 3
|
||||||
|
- Task 2 与 Task 1 无依赖,可并行
|
||||||
@@ -0,0 +1,349 @@
|
|||||||
|
# React 前端项目融合 ai-platform 模块化 SOP
|
||||||
|
|
||||||
|
> 适用场景:将独立的 React 前端项目(Vite 构建)融合进 `ai-platform`,作为首页可进入的独立模块。
|
||||||
|
> 已按此 SOP 成功融合:jieya-ibp、welltrust-qap、baode-web、supplier-platform、wuc-quotation。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 0. 核心原则(先记住这五条)
|
||||||
|
|
||||||
|
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、§9)。资源统一放 `public/mod-assets/<模块名>/`。
|
||||||
|
3. **零平台侵入**:模块不得修改 `document.body`/`document.documentElement` 的 class/style,不得占用全局 localStorage key,不得与平台路由冲突。
|
||||||
|
4. **入口职责迁移**:源项目 `main.tsx` 中的 Provider 包裹、全局 CSS 引入等职责,全部迁移到模块 `App.tsx`,平台路由直接渲染模块默认导出。
|
||||||
|
5. **全维度独立**:模块必须做到「挂载即用、卸载即净」——CSS 变量与主题令牌挂模块根容器或 ThemeProvider 作用域 div,靠继承生效、卸载即消失;禁止写 `document.documentElement`/`document.body` 的 style/classList,禁止向 `document.head` 注入 link/style/script;localStorage/sessionStorage key 必须带模块前缀(平台 `userToken`/`userInfo` 白名单除外);Portal 挂载点必须在模块根容器内部;`document.title` 由平台 `ModuleTitle` 托管;事件监听与定时器必须在 `useEffect` 返回中卸载清理。由 `check:independence` 门禁零容忍拦截(见 §5.9)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 前期勘察(融合前必做,约 10 分钟)
|
||||||
|
|
||||||
|
对源项目逐项检查并记录结论:
|
||||||
|
|
||||||
|
| 检查项 | 命令/方法 | 判定 |
|
||||||
|
|---|---|---|
|
||||||
|
| 新增依赖 | 对比 `package.json` 与 ai-platform | 原则上零新增;有新增需评估版本冲突 |
|
||||||
|
| 路由方式 | 看源 `main.tsx`/`App.tsx` | URL 子路由 → 平台路由用 `/xxx/*`;内部 state 切页 → 精确 path 即可 |
|
||||||
|
| 入口 Provider | 看 `main.tsx` 的 `<XxxProvider>` 包裹 | **必须迁移**(否则路由渲染时 context 为 null 白屏) |
|
||||||
|
| 全局 CSS | grep `html`/`body`/`:root`/`#root` | 记录所有需剥离/迁移的全局规则 |
|
||||||
|
| body 操作 | grep `document.body`、`document.documentElement` | classList.toggle/style 修改需改为模块根容器 ref |
|
||||||
|
| public 资源 | `ls public/` | 记录文件清单与代码引用位置(grep 文件名) |
|
||||||
|
| 内嵌资产 | grep `data:` | base64 data URI 无需处理 |
|
||||||
|
| 存储 key | grep `localStorage`/`sessionStorage` | key 必须带项目前缀,无前缀需加 |
|
||||||
|
| keyframes | grep `@keyframes` | 与全平台 CSS 比对命名唯一性 |
|
||||||
|
| React 版本 | `package.json` | 平台为 React 18.3 + @types/react 19,注意类型差异(见 §6.3) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 目录规划与代码复制
|
||||||
|
|
||||||
|
```
|
||||||
|
ai-platform/
|
||||||
|
├── src/modules/<name>/ # 模块源码
|
||||||
|
│ ├── App.tsx # 入口(含 Provider 包裹 + CSS 引入 + 根容器)
|
||||||
|
│ ├── index.ts # moduleConfig 导出
|
||||||
|
│ ├── app/ | pages/ | ... # 源项目 src 业务代码(排除 main.tsx、__tests__)
|
||||||
|
│ └── styles/ | *.css # 源项目样式
|
||||||
|
└── public/mod-assets/<name>/ # 模块静态资源(禁止放 public/<name>/)
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p ai-platform/src/modules/<name> ai-platform/public/mod-assets/<name>
|
||||||
|
cp -R <源项目>/src/app ai-platform/src/modules/<name>/app
|
||||||
|
cp -R <源项目>/src/styles ai-platform/src/modules/<name>/styles
|
||||||
|
cp <源项目>/src/App.tsx ai-platform/src/modules/<name>/App.tsx
|
||||||
|
# 不要复制 main.tsx、__tests__、vite.config 等入口/测试文件
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 静态资源迁移
|
||||||
|
|
||||||
|
1. `public/` 下资源全部复制到 `public/mod-assets/<name>/`;
|
||||||
|
2. grep 源码中所有相对路径引用(`src="xxx.svg"`、`href="xxx.md"`、`locateFile` 等),统一改为绝对路径 `/mod-assets/<name>/xxx`;
|
||||||
|
3. 验证:dev 下直接访问 `http://localhost:<port>/mod-assets/<name>/xxx` 返回 200;
|
||||||
|
4. build 后确认 `dist/mod-assets/<name>/` 存在。
|
||||||
|
|
||||||
|
> 为什么不用 `public/<name>/`:Vite 会把 public 目录原样拷入 dist,形成与模块路由同名的目录。完整故障链(2026-10 生产事故):
|
||||||
|
> 1. 首页卡片 `window.open('/<name>')` → nginx `try_files $uri /index.html` 的 `$uri` 命中该**目录**(非文件);
|
||||||
|
> 2. nginx 对目录请求自动 301 补斜杠(`/`),且 `port_in_redirect` 默认为 on,Location 变成 `https://域名:8901/<name>/`——**容器内端口被泄漏到浏览器地址栏**;
|
||||||
|
> 3. `:8901` 在外网不可达/无该虚拟主机 → 目录又无 index.html → 最终 403 或空白。
|
||||||
|
> 症状特征:只有"新增且带同名静态目录"的模块新页签打开异常(地址栏出现 `:8901`),老模块完全正常。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 样式隔离(核心,必须逐条执行)
|
||||||
|
|
||||||
|
### 4.1 根容器命名空间
|
||||||
|
|
||||||
|
模块 App 最外层包一个根容器,所有 CSS 选择器挂到它下面:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// App.tsx
|
||||||
|
const rootRef = useRef<HTMLDivElement>(null)
|
||||||
|
return <div className="xxx-root" ref={rootRef}>...</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
命名空间化有三种落地方式(按源项目 CSS 规模选择):
|
||||||
|
|
||||||
|
| 方式 | 适用 | 案例 |
|
||||||
|
|---|---|---|
|
||||||
|
| 全量脚本转换 | CSS 大/规则多(尤其 minified) | wuc-quotation:5 个 CSS 全部选择器加 `.wuc-root` 前缀 |
|
||||||
|
| 仅冲突类加前缀 | CSS 小、冲突少 | baode-web:20 处冲突选择器加 `.baode-root` |
|
||||||
|
| 原生自带命名空间 | 源项目已经做好隔离 | supplier-platform:变量与布局挂 `.hansong-app` |
|
||||||
|
|
||||||
|
**脚本转换要点**(已踩坑):
|
||||||
|
- `:root{--var}` → `.xxx-root{--var}`(CSS 变量迁到根容器)
|
||||||
|
- `body` → `.xxx-root`;`body.dark`/`body.collapsed` → `.xxx-root.dark` 等(主题/状态类改挂根容器)
|
||||||
|
- `body > #root > header` → `.xxx-root > header`(层级补偿规则改写)
|
||||||
|
- `html, body{overflow:hidden}` 等 → **直接删除**(会锁死平台整页滚动);视口锁定改由 `.xxx-root{height:100vh}` 承接
|
||||||
|
- `@media` 块内部规则**必须递归处理**(漏掉会造成窄屏规则逃逸成全局)
|
||||||
|
- `@keyframes`/`@font-face` 原样保留;字符串(data URI)不能破坏——需状态机解析而非正则替换
|
||||||
|
- 转换完必须校验:无残留 `body`/`:root`/`html`/`#root` 选择器、brace 平衡
|
||||||
|
|
||||||
|
### 4.2 三类冲突源都要检测(缺一不可)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 检测思路(对每个已存在模块 + 平台全局样式执行)
|
||||||
|
# 1. class 冲突:新模块 TSX className 集合 ∩ 双方 CSS 类名集合
|
||||||
|
# 2. ID 冲突:新模块 TSX 中的 id="xxx" ∩ 其它模块 CSS 中的 #xxx(双向)
|
||||||
|
# 3. 裸元素选择器:新模块 CSS 中 html/body/header/aside/nav/button/input 等无前缀选择器
|
||||||
|
```
|
||||||
|
|
||||||
|
> **ID 冲突是隐藏最深的坑**:`#nav` 特异性(1,0,0)碾压任何 `.wuc-root nav`(0,1,1)。wuc-quotation 上线后菜单被 supplier-platform 的 `#nav{display:flex}` 强制水平排列。修复方式是给**旧模块**的 ID 规则也加根容器前缀(`.hansong-app #nav`)。
|
||||||
|
|
||||||
|
### 4.3 运行时全局副作用清理
|
||||||
|
|
||||||
|
- `document.body.classList.toggle('dark'/'collapsed')` → `rootRef.current?.classList.toggle(...)`
|
||||||
|
- `document.body.style.overflow = ...`(如 LoginPage 的 useEffect)→ 模块内改为根容器样式或卸载时恢复
|
||||||
|
- 弹窗/Portal 挂载点若用 `document.body`,改为模块根容器内渲染
|
||||||
|
- `@media print` 中 `body{...}` 规则 → `.xxx-root{...}`,并放开视口锁定(`height:auto;overflow:visible`)
|
||||||
|
|
||||||
|
### 4.4 其它隔离项
|
||||||
|
|
||||||
|
- localStorage/sessionStorage key 带项目前缀(如 `wuchuan-quotation-v1`)
|
||||||
|
- `@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 && npm run check:independence && vite build`,双门禁见 §5.9),日常可单独运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run check:styles # 退出码 0 = 模块 CSS 无全局选择器违规
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 模组完全独立互不影响(全维度隔离)
|
||||||
|
|
||||||
|
模块在平台中是「挂载即用、卸载即净」的独立单元,任何逃逸到全局的副作用都会污染首页与其它模块。本节是样式隔离(§4)之外的运行时隔离规则,与 `check:styles` 共同构成双门禁。
|
||||||
|
|
||||||
|
### 5.1 CSS 选择器命名空间
|
||||||
|
|
||||||
|
见 §4——所有选择器必须挂模块根容器类(`.xxx-root`),此处不重复。
|
||||||
|
|
||||||
|
### 5.2 CSS 变量与主题令牌作用域
|
||||||
|
|
||||||
|
- **禁止**向 `document.documentElement` / `document.body` 写入 CSS 变量、`style`、`classList`。
|
||||||
|
- 主题令牌(`--xxx` 变量、`background`、`color`、`font-family` 等)一律挂在**模块根容器**或模块内的 `ThemeProvider` 作用域 `div` 上,靠 CSS 继承向下生效。
|
||||||
|
- 模块卸载(路由切走)后,根容器及其子树从 DOM 移除,所有令牌随之消失,不残留到首页。
|
||||||
|
- 若源项目用 `document.documentElement.style.setProperty('--xxx', ...)` 切换主题,改为 `rootRef.current?.style.setProperty(...)` 或在根容器上切类。
|
||||||
|
|
||||||
|
### 5.3 全局 DOM 写入禁令
|
||||||
|
|
||||||
|
- **禁止**修改 `document.body` / `document.documentElement` 的 `style` 或 `classList`(如 `body.style.overflow`、`body.classList.toggle('dark')`)。
|
||||||
|
- **禁止**向 `document.head` 注入 `<link>`、`<style>`、`<script>` 标签。
|
||||||
|
- 需要锁滚动、切主题等副作用时,一律作用于模块根容器 `ref`,并在卸载时恢复。
|
||||||
|
|
||||||
|
### 5.4 存储 key 必须带模块前缀
|
||||||
|
|
||||||
|
- localStorage / sessionStorage 的 key 必须带模块前缀(如 `wuchuan-quotation-v1`、`sp_theme`、`ocDataSourceMode`、`welltrust-qap-*` 等)。
|
||||||
|
- **白名单**:平台级 `userToken`、`userInfo` 可直接读写,模块不得新增其它无前缀全局 key。
|
||||||
|
- 切换主题等本地偏好也用前缀 key,不得复用无命名空间的 `theme` / `darkMode`。
|
||||||
|
|
||||||
|
### 5.5 事件监听与定时器必须卸载清理
|
||||||
|
|
||||||
|
- 所有 `addEventListener`(`window` / `document` / `rootRef`)、`setTimeout`、`setInterval`、`requestAnimationFrame` 必须在 `useEffect` 的返回函数中 `removeEventListener` / `clearTimeout` / `clearInterval` / `cancelAnimationFrame`。
|
||||||
|
- 模块可被用户随时切走,残留监听器会跨模块执行并导致内存泄漏。
|
||||||
|
|
||||||
|
### 5.6 Portal 挂载点必须在模块根容器内部
|
||||||
|
|
||||||
|
- 弹窗、抽屉、Tooltip 等 `ReactDOM.createPortal(...)` 的第二个参数(容器)**必须**指向模块根容器内部的节点(如 `rootRef.current` 或根容器内的 `<div id="xxx-portal-root">`)。
|
||||||
|
- **禁止**挂到 `document.body`——否则模块卸载后 Portal DOM 残留在 body,样式与交互污染全局。
|
||||||
|
- 若第三方组件默认 portal 到 body,需通过 API 指定 `getContainer` / `appendTo` / `container` 为模块根容器。
|
||||||
|
|
||||||
|
### 5.7 document.title 由平台托管
|
||||||
|
|
||||||
|
- 模块**不得**自行 `document.title = ...`。
|
||||||
|
- 平台 `ModuleTitle` 组件在进入模块时设置标题为模块中文名,卸载时恢复 `'EIOSpace'`(见 §7 平台注册)。
|
||||||
|
|
||||||
|
### 5.8 第三方全局样式/脚本注入禁令
|
||||||
|
|
||||||
|
- 禁止在模块代码中动态 `<script src="...">` 注入第三方 SDK 到 `document.head` / `document.body`(如统计、地图、编辑器);必须用时改为 `import` 打包或挂到模块根容器内。
|
||||||
|
- 禁止 `@import` 全局 reset / normalize(见 §4.4)。
|
||||||
|
|
||||||
|
### 5.9 双门禁(check:styles + check:independence)
|
||||||
|
|
||||||
|
| 门禁 | 命令 | 零容忍范围 |
|
||||||
|
|---|---|---|
|
||||||
|
| 样式门禁 | `npm run check:styles` | CSS 全局选择器(裸标签、`:root`、`*`、`@import` reset 等,见 §4.5) |
|
||||||
|
| 独立门禁 | `npm run check:independence` | 全局 DOM 写入(`document.body` / `documentElement` 的 style/classList)、`document.head` 注入 link/style/script、`document.body` Portal、无前缀 storage key |
|
||||||
|
|
||||||
|
双门禁已接入 build:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build # = tsc -b && npm run check:styles && npm run check:independence && vite build
|
||||||
|
```
|
||||||
|
|
||||||
|
日常可单独运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run check:independence # 退出码 0 = 无全局 DOM / Portal / 无前缀 storage 违规
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 代码适配
|
||||||
|
|
||||||
|
### 6.1 入口与 Provider
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// App.tsx 末尾:平台路由直接渲染默认导出,Provider 职责从 main.tsx 移到这里
|
||||||
|
import { AppProvider } from './app/store'
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
return (
|
||||||
|
<AppProvider>
|
||||||
|
<AppShell />
|
||||||
|
</AppProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
同时把源 `main.tsx` 的 CSS import 全部搬到模块 `App.tsx` 顶部(保持原有顺序)。
|
||||||
|
|
||||||
|
### 6.2 严格 tsconfig 适配(tsc -b 报错清单)
|
||||||
|
|
||||||
|
- `TS6133` 未使用变量/import → 删除(含解构中未使用的成员)
|
||||||
|
- `TS2554`:`useRef<T>()` → `useRef<T | undefined>(undefined)`(@types/react 19 要求初始值)
|
||||||
|
- 默认导入 `import React` 未使用 → 删除(react-jsx transform 无需)
|
||||||
|
|
||||||
|
### 6.3 其他常见点
|
||||||
|
|
||||||
|
- 事件监听/定时器在组件卸载时清理(模块可被随时切走)
|
||||||
|
- 弹窗内 `dangerouslySetInnerHTML` 注入的 HTML,其类名也要被命名空间 CSS 覆盖(确认前缀后仍能匹配)
|
||||||
|
- 内部 state 切页的项目保留原交互,不强行改造为 URL 路由
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 平台注册(三件套 + 图标)
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// 1. src/modules/<name>/index.ts
|
||||||
|
import type { ModuleConfig } from '../registry';
|
||||||
|
|
||||||
|
export const moduleConfig: ModuleConfig = {
|
||||||
|
id: '<name>',
|
||||||
|
name: '模块中文名',
|
||||||
|
description: '一句话描述',
|
||||||
|
icon: 'Lucide图标名', // 如 FileSpreadsheet / Radar / Building2
|
||||||
|
path: '/<name>',
|
||||||
|
accentColor: '#7C6FFF', // 暗色强调色
|
||||||
|
accentColorLight: '#5747EF', // 亮色强调色
|
||||||
|
gradient: 'linear-gradient(135deg, ...)', // 暗色卡片渐变
|
||||||
|
gradientLight: 'linear-gradient(135deg, ...)', // 亮色卡片渐变
|
||||||
|
tags: ['标签1', '标签2'],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// 2. src/modules/registry.ts:import + modules 数组追加
|
||||||
|
// 3. src/App.tsx:模块级 React.lazy 动态导入 + 路由(ModuleTitle 负责页签标题,卸载恢复 'EIOSpace')
|
||||||
|
const XxxApp = lazy(() => import('@/modules/<name>/App'));
|
||||||
|
...
|
||||||
|
<Routes>
|
||||||
|
<Suspense fallback={<ModuleLoading />}>
|
||||||
|
<Route path="/<name>" element={<RequireAuth><ModuleTitle title="模块中文名"><XxxApp /></ModuleTitle></RequireAuth>} />
|
||||||
|
...
|
||||||
|
</Suspense>
|
||||||
|
</Routes>
|
||||||
|
// 4. src/pages/HomePage.tsx:ICON_MAP 增加图标(先在 lucide-react import 中补图标名)
|
||||||
|
```
|
||||||
|
|
||||||
|
> 模块入口必须用 `React.lazy` 动态导入(模块 CSS 随路由 chunk 按需加载),**静态 import 会把模块 CSS 打进主包,禁止**。
|
||||||
|
> 首页卡片点击已是 `window.open(mod.path, '_blank')` 新页签打开,无需额外处理。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 验证清单
|
||||||
|
|
||||||
|
**构建层**
|
||||||
|
- [ ] `npx tsc --noEmit` 通过
|
||||||
|
- [ ] `npm run build` 通过(注意 `tsc -b` 比 `tsc --noEmit` 更严,以 build 为准;已含 `check:styles` + `check:independence` 双门禁)
|
||||||
|
- [ ] `npm run check:styles` 退出码 0(模块 CSS 全局选择器零容忍门禁,见 §4.5,已接入 build)
|
||||||
|
- [ ] `npm run check:independence` 退出码 0(全局 DOM 写入 / body Portal / 无前缀 storage key 零容忍门禁,见 §5.9,已接入 build)
|
||||||
|
- [ ] `dist/mod-assets/<name>/` 资源齐全
|
||||||
|
- [ ] **`ls dist/` 确认根目录下没有与模块路由同名的目录**(防端口泄漏,见 §3)
|
||||||
|
|
||||||
|
**浏览器层**(dev server + mock 登录)
|
||||||
|
```js
|
||||||
|
// 平台守卫只查 sessionStorage.userToken,浏览器验证先注入:
|
||||||
|
sessionStorage.setItem('userToken', 'mock-token-for-ui-check');
|
||||||
|
sessionStorage.setItem('userInfo', JSON.stringify({ name: '演示用户', userId: 'demo' }));
|
||||||
|
```
|
||||||
|
- [ ] `/<name>` 页面完整渲染(header/侧栏/内容区),控制台无 React 报错、无 404
|
||||||
|
- [ ] 页内交互可用(菜单切换、弹窗、主题切换)
|
||||||
|
- [ ] 新页签打开后浏览器标题为模块中文名
|
||||||
|
- [ ] 首页出现新模块卡片(图标、配色正确)
|
||||||
|
- [ ] 首页(未进入任何模块)Network 面板无任何模块级 CSS chunk
|
||||||
|
- [ ] 首次进入模块路由时按需加载对应 JS+CSS chunk(React.lazy 生效)
|
||||||
|
- [ ] **进入模块再返回首页,首页视觉无污染**(body class/style 无残留、CSS 变量无残留、无 Portal 残留 DOM)
|
||||||
|
- [ ] **弹窗/抽屉等 Portal 的 DOM 位于模块根容器内部**(Elements 面板检查,非 `document.body` 直接子节点)
|
||||||
|
|
||||||
|
**回归层(改了旧模块 CSS 时必做)**
|
||||||
|
- [ ] 新模块关键布局 computed style 复核(如 nav 的 display)
|
||||||
|
- [ ] 被 CSS 影响的旧模块核心页面正常(如 supplier 顶栏导航)
|
||||||
|
- [ ] 平台首页/登录页样式未受污染
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. 部署注意(nginx)
|
||||||
|
|
||||||
|
- `nginx.conf` SPA 回退必须是 `try_files $uri /index.html;`——**禁止 `$uri/`**(目录命中 → 403 且不回退)
|
||||||
|
- **必须加两条重定向加固**(防止容器内端口泄漏到浏览器地址栏,2026-10 事故根因):
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
listen 8901;
|
||||||
|
...
|
||||||
|
port_in_redirect off; # 301 重定向的 Location 不带 8901 端口
|
||||||
|
absolute_redirect off; # 使用相对路径 Location,彻底避免泄漏 host/port
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 部署后用生产地址冒烟验证(新页签打开路径):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -sI https://ai-workshop.digiwincloud.com.cn/<name> | head -5
|
||||||
|
# 期望:HTTP 200(或 302 跳登录页)
|
||||||
|
# 异常信号:HTTP 301 且 Location 带 :8901 —— 即存在与路由同名的静态目录触发了目录重定向
|
||||||
|
```
|
||||||
|
|
||||||
|
- 模块静态资源引用用绝对路径 `/mod-assets/...`,与部署子路径无关
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. 历史踩坑速查表
|
||||||
|
|
||||||
|
| 案例 | 坑 | 修复 |
|
||||||
|
|---|---|---|
|
||||||
|
| baode-web ↔ supplier-platform | baode 自检页 `.page{max-width:1080px}` 污染 supplier 的 `section.page` | `.page`→`.checkpage` + 冲突类加 `.baode-root` 前缀 |
|
||||||
|
| supplier-platform | 源 tsconfig 宽松,`useRef<T>()` 在 @types/react 19 下报 TS2554 | `useRef<T \| undefined>(undefined)` |
|
||||||
|
| 全部模块 | dist 下与路由同名目录:早期 `try_files $uri/` 命中目录 403;去掉 `$uri/` 后 `$uri` 仍命中目录触发 301 补斜杠,`port_in_redirect` 默认 on 把容器端口 `:8901` 泄漏进浏览器地址栏,新页签跳到带端口地址后 403/空白 | 资源统一迁 `mod-assets/`;nginx 加 `port_in_redirect off; absolute_redirect off;` |
|
||||||
|
| wuc-quotation | 漏迁 `AppProvider` → 白屏 `ctx is null` | Provider 移入模块默认导出 |
|
||||||
|
| wuc-quotation | 001.css 7.8MB 内嵌 data URI + minified,正则替换会破坏资产 | 状态机解析转换,字符串原样保留 |
|
||||||
|
| wuc-quotation | `document.body.classList.toggle('dark')` 污染平台 body | 改挂 `.wuc-root` 根容器 ref |
|
||||||
|
| 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/<name>/...'` |
|
||||||
|
| 全部模块 | 模块 CSS 全局选择器(`:root`/`button`/`table`/`::-webkit-scrollbar`/`*`)跨模块污染 | 加模块根容器前缀 + `check:styles` 门禁(§4.5,已接入 build) |
|
||||||
+4
-2
@@ -5,8 +5,10 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && npm run check:styles && npm run check:independence && vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"check:styles": "node scripts/check-module-styles.mjs",
|
||||||
|
"check:independence": "node scripts/check-module-independence.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^5.4.0",
|
"@ant-design/icons": "^5.4.0",
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,51 @@
|
|||||||
|
# 重型装备内外套组件制造供货询价需求书
|
||||||
|
|
||||||
|
编号:RFQ-DEMO-2026-016 版本:A 日期:2026-10-16
|
||||||
|
|
||||||
|
**模拟客户需求,仅供DEMO。不是武汉武船实际订单;所有工程参数均为演示假设,不可据此生产。**
|
||||||
|
|
||||||
|
## 1. 项目与供需双方
|
||||||
|
采购方:华中装备工程有限公司(虚构)。拟询价承制方:武汉武船重型装备工程有限责任公司。
|
||||||
|
项目:重型装备伸缩支承内外套组件制造供货。数量:10套,每套内套1件、外套1件。交期:合同生效、预付款到账及技术资料确认后90日。
|
||||||
|
场景选择依据:客户提供的“213WS03-01(内套).pdf”“213WS03-02(外套).pdf”文件主题。由于本次无法取得可核对图像,未引用其具体尺寸、材质、公差、重量或实际用途。以下模拟结构和编号与原图区分。
|
||||||
|
|
||||||
|
## 2. 供货范围与边界
|
||||||
|
10套内外套组件(每套内套1件、外套1件),含采购、下料、成形、焊接、机加工、检测、防腐、包装运输及技术资料;不含主机、驱动装置及现场安装。
|
||||||
|
内部演示假设为焊接成形后机加工的套筒组件;原图可能采用不同结构或工艺,正式实施必须技术确认。
|
||||||
|
提供材料证明、关键尺寸检测记录、焊接与无损检测记录、出厂合格证及装箱清单。质量验收标准、焊缝等级、配合公差及表面防护要求由双方技术协议明确,不凭演示图替代。
|
||||||
|
|
||||||
|
## 3. 模拟图纸与参考物量
|
||||||
|
模拟内套图SIM-IS-01:筒体外径420mm,内径380mm,筒段长1200mm;法兰外径560mm、内径420mm、厚40mm;加强环外径480mm、内径420mm、厚30mm,每件内套2个。
|
||||||
|
模拟外套图SIM-OS-01:筒体外径540mm,内径500mm,筒段长1300mm;法兰外径680mm、内径540mm、厚50mm。
|
||||||
|
模拟钢材净重按圆环体积×密度7850kg/m³计算,每件重量四舍五入至0.01kg后乘10。加强环为每件2个。公式:π/4×(外径²−内径²)×长度×7.85×10⁻⁶(尺寸mm)。忽略孔槽及焊缝附加量,属于报价阶段几何估算;并非经原图确认的工程重量。
|
||||||
|
|
||||||
|
|参考物料号|物料|10套合计净用量|单位|来源|
|
||||||
|
|---|---|---:|---|---|
|
||||||
|
|M001|内套筒体 Q355B|2367.5|kg|SIM-IS-01 序1;236.75kg×10|
|
||||||
|
|M002|内套法兰 Q355B|338.4|kg|SIM-IS-01 序2;33.84kg×10|
|
||||||
|
|M003|内套加强环 Q355B|199.8|kg|SIM-IS-01 序3;19.98kg×10|
|
||||||
|
|M004|外套筒体 Q355B|3334.2|kg|SIM-OS-01 序1;333.42kg×10|
|
||||||
|
|M005|外套法兰 Q355B|526.5|kg|SIM-OS-01 序2;52.65kg×10|
|
||||||
|
|M006|导向衬套 铜合金|20|件|需求§3;2件×10|
|
||||||
|
|M007|密封组件|10|套|需求§3;1套×10|
|
||||||
|
|M008|配套紧固件|10|套|需求§3;1套×10|
|
||||||
|
|
||||||
|
说明:M001–M008为DEMO物料主数据映射编号,不能当作客户原图真实物料编码;外购物件规格为待澄清项。技术人员应确认实际ERP/PLM物料号。采购损耗由承制方另行核算,客户净用量不含损耗。
|
||||||
|
|
||||||
|
## 4. 图纸之外的补充需求
|
||||||
|
焊丝及焊剂由承制方承担,报价必须覆盖,不应因图纸BOM未列出而遗漏。演示参考用量160kg/项目,由技术人员人工补录并复核;不在自动解析的8项初始BOM中。
|
||||||
|
防腐材料及施工归入独立防腐费用,不重复加入物料表。密封与衬套的规格须在技术澄清环节确认。
|
||||||
|
|
||||||
|
## 5. 制造与检验要求
|
||||||
|
建议工艺路线:工艺深化→下料坡口→卷制组对→焊接→精加工→装配试配→检验→防腐包装。
|
||||||
|
焊接演示工作量480m,估算效率2m/工时;由生产部门复核,不能自动当作原图识别结果。其他工时由承制方工艺定额给出。
|
||||||
|
供应商到料不晚于第60天,预留后续制造与交付30天。任何技术或进度偏离应在报价前提出。
|
||||||
|
|
||||||
|
## 6. 报价响应与商务条款
|
||||||
|
请分别列示不含税单价、总价、税率、税额与含税总价,币种人民币。税率13%仅为DEMO参数,正式业务由财税确认。
|
||||||
|
预付款30%,工厂验收后发运前60%,到货验收后10%;质保12个月;报价有效期30天。
|
||||||
|
报价应说明供货边界、交期起算条件、技术偏离和价格有效期。未明确的技术条件应列入澄清表。
|
||||||
|
|
||||||
|
## 7. 内部演示数据的边界
|
||||||
|
本客户需求书不含供应商报价和企业利润底线。可上传JSON为了便于离线演示,额外包含内部参考单价、损耗与工艺估算,应作为演示种子包而非对外客户原始文件。
|
||||||
|
附件:模拟内套图.svg、模拟外套图.svg。图中模拟图号不得替代用户提供的原图号。
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="1400" height="900" viewBox="0 0 1400 900"><defs><pattern id="h" width="9" height="9" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><line x1="0" y1="0" x2="0" y2="9" stroke="#777"/></pattern><marker id="a" markerWidth="8" markerHeight="8" refX="4" refY="4" orient="auto-start-reverse"><path d="M0,0 L8,4 L0,8" fill="none" stroke="#111"/></marker></defs><rect x="30" y="30" width="1340" height="840" fill="white" stroke="#222" stroke-width="2"/><g font-family="Microsoft YaHei,Arial" fill="#222"><text x="65" y="85" font-size="25">内套组件 — 模拟机械图(仅供报价DEMO)</text><text x="65" y="119" font-size="17" fill="#bd4444">非附件复刻 · 尺寸、材质及结构均为假设 · 禁止作为生产依据</text><g stroke="#222" stroke-width="2" fill="none"><rect x="140" y="260" width="600" height="210"/><rect x="140" y="260" width="600" height="32" fill="url(#h)"/><rect x="140" y="438" width="600" height="32" fill="url(#h)"/><rect x="160" y="205" width="35" height="320" fill="url(#h)"/><rect x="650" y="225" width="30" height="280" fill="url(#h)"/><circle cx="1030" cy="365" r="145"/><circle cx="1030" cy="365" r="112"/><circle cx="1030" cy="365" r="90"/><path d="M100 365h690M1030 185v360M850 365h360" stroke-dasharray="12 6 3 6" stroke="#777"/><path d="M140 490v90M740 490v90M140 565h600"/><path d="M790 260h45M790 470h45M820 260v210"/><path d="M140 565h600" marker-start="url(#a)" marker-end="url(#a)"/><path d="M820 260v210" marker-start="url(#a)" marker-end="url(#a)"/></g><text x="370" y="552" font-size="20">筒段长 1200</text><text x="835" y="340" font-size="18">Φ420</text><text x="930" y="550" font-size="18">内径 Φ380 / 法兰 Φ560</text><text x="220" y="190" font-size="18">② 法兰</text><text x="370" y="245" font-size="18">① 筒体(剖视示意)</text><text x="620" y="195" font-size="18">③ 加强环</text><text x="65" y="625" font-size="18">技术说明(模拟):1. 材料暂定Q355B;2. 先成形焊接后机加工;3. 配合、公差、焊缝等级待技术协议。</text><text x="65" y="663" font-size="18">净重按模拟圆环体积估算(见需求书);孔槽未扣除,BOM须技术审核,图纸未含焊材。</text><path d="M30 710h1340M800 710v160M1100 710v160M800 765h570M800 820h570" stroke="#222" fill="none"/><text x="65" y="755" font-size="20">武汉武船重型装备工程有限责任公司 · AI报价平台</text><text x="65" y="793" font-size="16">场景参考:用户提供内套 / 外套附件主题,未核实原图工程参数</text><text x="65" y="832" font-size="16">净重、数量和材料号见《客户需求书》 §3;本图单位 mm,不按比例。</text><text x="825" y="746" font-size="23">内套组件</text><text x="1120" y="746" font-size="20">SIM-IS-01</text><text x="825" y="800" font-size="18">版本:A / 模拟</text><text x="1120" y="800" font-size="18">数量:10件</text><text x="825" y="855" font-size="18">2026-10-16</text><text x="1120" y="855" font-size="18">非生产图纸</text></g></svg>
|
||||||
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="1400" height="900" viewBox="0 0 1400 900"><defs><pattern id="h" width="9" height="9" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><line x1="0" y1="0" x2="0" y2="9" stroke="#777"/></pattern><marker id="a" markerWidth="8" markerHeight="8" refX="4" refY="4" orient="auto-start-reverse"><path d="M0,0 L8,4 L0,8" fill="none" stroke="#111"/></marker></defs><rect x="30" y="30" width="1340" height="840" fill="white" stroke="#222" stroke-width="2"/><g font-family="Microsoft YaHei,Arial" fill="#222"><text x="65" y="85" font-size="25">外套组件 — 模拟机械图(仅供报价DEMO)</text><text x="65" y="119" font-size="17" fill="#bd4444">非附件复刻 · 尺寸、材质及结构均为假设 · 禁止作为生产依据</text><g stroke="#222" stroke-width="2" fill="none"><rect x="140" y="260" width="600" height="210"/><rect x="140" y="260" width="600" height="32" fill="url(#h)"/><rect x="140" y="438" width="600" height="32" fill="url(#h)"/><rect x="160" y="205" width="35" height="320" fill="url(#h)"/><rect x="650" y="225" width="30" height="280" fill="url(#h)"/><circle cx="1030" cy="365" r="145"/><circle cx="1030" cy="365" r="112"/><circle cx="1030" cy="365" r="90"/><path d="M100 365h690M1030 185v360M850 365h360" stroke-dasharray="12 6 3 6" stroke="#777"/><path d="M140 490v90M740 490v90M140 565h600"/><path d="M790 260h45M790 470h45M820 260v210"/><path d="M140 565h600" marker-start="url(#a)" marker-end="url(#a)"/><path d="M820 260v210" marker-start="url(#a)" marker-end="url(#a)"/></g><text x="370" y="552" font-size="20">筒段长 1300</text><text x="835" y="340" font-size="18">Φ540</text><text x="930" y="550" font-size="18">内径 Φ500 / 法兰 Φ680</text><text x="220" y="190" font-size="18">② 法兰</text><text x="370" y="245" font-size="18">① 筒体(剖视示意)</text><text x="620" y="195" font-size="18">③ 导向配合区</text><text x="65" y="625" font-size="18">技术说明(模拟):1. 材料暂定Q355B;2. 先成形焊接后机加工;3. 配合、公差、焊缝等级待技术协议。</text><text x="65" y="663" font-size="18">净重按模拟圆环体积估算(见需求书);孔槽未扣除,BOM须技术审核,图纸未含焊材。</text><path d="M30 710h1340M800 710v160M1100 710v160M800 765h570M800 820h570" stroke="#222" fill="none"/><text x="65" y="755" font-size="20">武汉武船重型装备工程有限责任公司 · AI报价平台</text><text x="65" y="793" font-size="16">场景参考:用户提供内套 / 外套附件主题,未核实原图工程参数</text><text x="65" y="832" font-size="16">净重、数量和材料号见《客户需求书》 §3;本图单位 mm,不按比例。</text><text x="825" y="746" font-size="23">外套组件</text><text x="1120" y="746" font-size="20">SIM-OS-01</text><text x="825" y="800" font-size="18">版本:A / 模拟</text><text x="1120" y="800" font-size="18">数量:10件</text><text x="825" y="855" font-size="18">2026-10-16</text><text x="1120" y="855" font-size="18">非生产图纸</text></g></svg>
|
||||||
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,349 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* 模组独立性检查(门禁脚本)
|
||||||
|
*
|
||||||
|
* 平台规则:src/modules 下每个模组必须完全独立、互不影响,禁止运行时写入全局 DOM、
|
||||||
|
* 向 head 注入全局样式/脚本、将 Portal 挂到 document.body、使用无前缀的 storage key。
|
||||||
|
*
|
||||||
|
* 实现:先做词法剥离(注释 + 字符串/模板字面量),再用正则检测违规模式。
|
||||||
|
* 零依赖,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 EXTS = new Set(['.ts', '.tsx', '.js', '.jsx']);
|
||||||
|
|
||||||
|
// 平台级共享 storage key 白名单(不计模组前缀)
|
||||||
|
const STORAGE_WHITELIST = new Set(['userToken', 'userInfo']);
|
||||||
|
|
||||||
|
/* ---------------------------------- 文件收集 ---------------------------------- */
|
||||||
|
|
||||||
|
function collectFiles(dir, 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()) {
|
||||||
|
collectFiles(full, out);
|
||||||
|
} else if (entry.isFile() && EXTS.has(path.extname(entry.name))) {
|
||||||
|
out.push(full);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------- 词法剥离 -------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 剥离源码中的注释与字符串/模板字面量,保留换行以维持行号对齐。
|
||||||
|
* 返回两份结果:
|
||||||
|
* - commentStripped:仅去掉 // 与 /* *\/ 注释,字符串内容保留(用于需要读取
|
||||||
|
* 字符串字面量的检查,如 storage key、createElement 标签名)。
|
||||||
|
* - fullyStripped:注释 + 字符串/模板全部替换为空格(用于避免字符串内关键字误报)。
|
||||||
|
*
|
||||||
|
* 被剥离的非换行字符统一替换为空格,保证字符偏移与行号不变。
|
||||||
|
*/
|
||||||
|
function stripSource(source) {
|
||||||
|
let commentStripped = '';
|
||||||
|
let fullyStripped = '';
|
||||||
|
let inBlockComment = false;
|
||||||
|
let inTemplate = false;
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
|
const pushSpace = (ch) => {
|
||||||
|
const sp = ch === '\n' ? '\n' : ' ';
|
||||||
|
commentStripped += sp;
|
||||||
|
fullyStripped += sp;
|
||||||
|
};
|
||||||
|
|
||||||
|
while (i < source.length) {
|
||||||
|
const ch = source[i];
|
||||||
|
const next = source[i + 1];
|
||||||
|
|
||||||
|
if (inBlockComment) {
|
||||||
|
if (ch === '*' && next === '/') {
|
||||||
|
inBlockComment = false;
|
||||||
|
commentStripped += ' ';
|
||||||
|
fullyStripped += ' ';
|
||||||
|
i += 2;
|
||||||
|
} else {
|
||||||
|
pushSpace(ch);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inTemplate) {
|
||||||
|
if (ch === '\\') {
|
||||||
|
// 转义字符整体跳过
|
||||||
|
commentStripped += ch + (next || '');
|
||||||
|
fullyStripped += ' ' + (next === '\n' ? '\n' : ' ');
|
||||||
|
i += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ch === '`') {
|
||||||
|
inTemplate = false;
|
||||||
|
pushSpace(ch);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ch === '$' && next === '{') {
|
||||||
|
// 模板插值:按大括号深度跳过(插值内代码也一并剥离)
|
||||||
|
let depth = 1;
|
||||||
|
commentStripped += ' ';
|
||||||
|
fullyStripped += ' ';
|
||||||
|
i += 2;
|
||||||
|
while (i < source.length && depth > 0) {
|
||||||
|
const c = source[i];
|
||||||
|
if (c === '{') depth++;
|
||||||
|
else if (c === '}') depth--;
|
||||||
|
pushSpace(c);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pushSpace(ch);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// —— 普通代码态 ——
|
||||||
|
if (ch === '/' && next === '/') {
|
||||||
|
// 行注释:跳到行尾
|
||||||
|
while (i < source.length && source[i] !== '\n') {
|
||||||
|
commentStripped += ' ';
|
||||||
|
fullyStripped += ' ';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ch === '/' && next === '*') {
|
||||||
|
inBlockComment = true;
|
||||||
|
commentStripped += ' ';
|
||||||
|
fullyStripped += ' ';
|
||||||
|
i += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ch === '`') {
|
||||||
|
inTemplate = true;
|
||||||
|
pushSpace(ch);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ch === '"' || ch === "'") {
|
||||||
|
const quote = ch;
|
||||||
|
commentStripped += ch; // commentStripped 保留字符串内容
|
||||||
|
fullyStripped += ' ';
|
||||||
|
i++;
|
||||||
|
while (i < source.length) {
|
||||||
|
const c = source[i];
|
||||||
|
if (c === '\\') {
|
||||||
|
commentStripped += c + (source[i + 1] || '');
|
||||||
|
fullyStripped += ' ' + (source[i + 1] === '\n' ? '\n' : ' ');
|
||||||
|
i += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c === quote) {
|
||||||
|
commentStripped += quote;
|
||||||
|
fullyStripped += ' ';
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (c === '\n') {
|
||||||
|
// 字符串跨行(非法 JS,但容错)
|
||||||
|
commentStripped += '\n';
|
||||||
|
fullyStripped += '\n';
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
commentStripped += c;
|
||||||
|
fullyStripped += ' ';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
commentStripped += ch;
|
||||||
|
fullyStripped += ch;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { commentStripped, fullyStripped };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------ 工具:顶层逗号切分 ------------------------------ */
|
||||||
|
|
||||||
|
/** 按顶层逗号切分参数列表,括号/方括号/花括号内的逗号不切分。 */
|
||||||
|
function splitTopLevel(s) {
|
||||||
|
const parts = [];
|
||||||
|
let cur = '';
|
||||||
|
let paren = 0, bracket = 0, brace = 0;
|
||||||
|
for (const ch of s) {
|
||||||
|
if (ch === '(') paren++;
|
||||||
|
else if (ch === ')') paren--;
|
||||||
|
else if (ch === '[') bracket++;
|
||||||
|
else if (ch === ']') bracket--;
|
||||||
|
else if (ch === '{') brace++;
|
||||||
|
else if (ch === '}') brace--;
|
||||||
|
if (ch === ',' && paren === 0 && bracket === 0 && brace === 0) {
|
||||||
|
parts.push(cur);
|
||||||
|
cur = '';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cur += ch;
|
||||||
|
}
|
||||||
|
parts.push(cur);
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 计算字符串中 index 位置对应的行号(1-based)。 */
|
||||||
|
function lineAt(text, index) {
|
||||||
|
let line = 1;
|
||||||
|
for (let k = 0; k < index && k < text.length; k++) {
|
||||||
|
if (text[k] === '\n') line++;
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------- 违规判定 -------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判定 storage key 是否合规:
|
||||||
|
* - 在白名单内;或
|
||||||
|
* - 包含 - / _ / . ;或
|
||||||
|
* - 匹配小写驼峰模块前缀 ^[a-z]{2,}[A-Z](如 ocDataSourceMode)。
|
||||||
|
*/
|
||||||
|
function isStorageKeyCompliant(key) {
|
||||||
|
if (STORAGE_WHITELIST.has(key)) return true;
|
||||||
|
if (/[-_.]/.test(key)) return true;
|
||||||
|
if (/^[a-z]{2,}[A-Z]/.test(key)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫描单个文件,返回违规列表 [{ line, reason }]。
|
||||||
|
*/
|
||||||
|
function scanFile(source) {
|
||||||
|
const violations = [];
|
||||||
|
const { commentStripped, fullyStripped } = stripSource(source);
|
||||||
|
|
||||||
|
const commentLines = commentStripped.split('\n');
|
||||||
|
const fullyLines = fullyStripped.split('\n');
|
||||||
|
|
||||||
|
// —— 预扫描:收集被赋值为 createElement('link'|'style'|'script') 的变量名 ——
|
||||||
|
// 用于跨行判定 document.head.appendChild(var) 是否为注入全局样式/脚本。
|
||||||
|
const injectVars = new Set();
|
||||||
|
const assignRe = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*document\.createElement\s*\(\s*['"`](link|style|script)['"`]/g;
|
||||||
|
for (const line of commentLines) {
|
||||||
|
let m;
|
||||||
|
while ((m = assignRe.exec(line)) !== null) {
|
||||||
|
injectVars.add(m[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// —— 逐行检测(a / b / c / e)——
|
||||||
|
for (let idx = 0; idx < fullyLines.length; idx++) {
|
||||||
|
const lineNo = idx + 1;
|
||||||
|
const fLine = fullyLines[idx];
|
||||||
|
const cLine = commentLines[idx];
|
||||||
|
|
||||||
|
// a. document.body.(style|classList).
|
||||||
|
if (/document\.body\.(style|classList)\./.test(fLine)) {
|
||||||
|
violations.push({ line: lineNo, reason: '写入 document.body 的 style/classList(应仅作用于模组根容器)' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// b. document.documentElement.(style|setAttribute|classList).
|
||||||
|
if (/document\.documentElement\.(style|setAttribute|classList)\./.test(fLine)) {
|
||||||
|
violations.push({ line: lineNo, reason: '写入 document.documentElement 的 style/setAttribute/classList(CSS 变量应挂在模组根容器)' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// c. document.head.appendChild/insertBefore 注入 link/style/script
|
||||||
|
if (/document\.head\.(appendChild|insertBefore)\s*\(/.test(cLine)) {
|
||||||
|
// 同行内是否直接 createElement('link'|'style'|'script')
|
||||||
|
const inlineInject = /createElement\s*\(\s*['"`](link|style|script)['"`]/.test(cLine);
|
||||||
|
// 或参数为前面收集到的注入变量
|
||||||
|
let varInject = false;
|
||||||
|
if (!inlineInject) {
|
||||||
|
const argMatch = cLine.match(/document\.head\.(?:appendChild|insertBefore)\s*\(\s*([A-Za-z_$][\w$]*)/);
|
||||||
|
if (argMatch && injectVars.has(argMatch[1])) varInject = true;
|
||||||
|
}
|
||||||
|
if (inlineInject || varInject) {
|
||||||
|
violations.push({ line: lineNo, reason: '向 document.head 注入 link/style/script 元素(禁止模组注入全局样式/脚本)' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// e. localStorage/sessionStorage key 无前缀
|
||||||
|
const storageRe = /(local|session)Storage\.(getItem|setItem|removeItem)\s*\(\s*['"`]([^'"`]+)['"`]/g;
|
||||||
|
let sm;
|
||||||
|
while ((sm = storageRe.exec(cLine)) !== null) {
|
||||||
|
const key = sm[3];
|
||||||
|
if (!isStorageKeyCompliant(key)) {
|
||||||
|
violations.push({ line: lineNo, reason: `storage key「${key}」未带模组前缀(需含 -/_/. 或以小写驼峰模块名开头)` });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// —— 整段检测(d. createPortal 第二参数为 document.body,可能跨多行)——
|
||||||
|
const portalRe = /createPortal\s*\(/g;
|
||||||
|
let pm;
|
||||||
|
while ((pm = portalRe.exec(fullyStripped)) !== null) {
|
||||||
|
const start = pm.index;
|
||||||
|
let depth = 1;
|
||||||
|
let j = start + pm[0].length;
|
||||||
|
while (j < fullyStripped.length && depth > 0) {
|
||||||
|
const c = fullyStripped[j];
|
||||||
|
if (c === '(') depth++;
|
||||||
|
else if (c === ')') depth--;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
if (depth === 0) {
|
||||||
|
const args = fullyStripped.slice(start + pm[0].length, j - 1);
|
||||||
|
const parts = splitTopLevel(args);
|
||||||
|
// 第二参数为 Portal 挂载容器:若其中出现 document.body(含兜底表达式
|
||||||
|
// 如 portalMount ?? document.body),即视为挂到全局 body,判违规。
|
||||||
|
if (parts.length >= 2 && /\bdocument\.body\b/.test(parts[1])) {
|
||||||
|
const lineNo = lineAt(fullyStripped, start);
|
||||||
|
violations.push({ line: lineNo, reason: 'createPortal 挂载点含 document.body(Portal 应挂在模组根容器内,禁止兜底到全局 body)' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return violations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------ 主流程 ----------------------------------- */
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
const files = collectFiles(MODULES_DIR).sort();
|
||||||
|
const violations = [];
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const rel = path.relative(ROOT, file).split(path.sep).join('/');
|
||||||
|
const source = readFileSync(file, 'utf8');
|
||||||
|
const fileViolations = scanFile(source);
|
||||||
|
for (const v of fileViolations) {
|
||||||
|
violations.push(`[违规] ${rel}:${v.line} ${v.reason}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (violations.length > 0) {
|
||||||
|
for (const v of violations) console.log(v);
|
||||||
|
const badFiles = new Set(violations.map((v) => v.split(':')[0].replace('[违规] ', ''))).size;
|
||||||
|
console.log(
|
||||||
|
`[汇总] 模组独立检查失败:共 ${violations.length} 条违规,涉及 ${badFiles} 个文件(共扫描 ${files.length} 个文件)`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`✓ 模组独立检查通过(扫描 ${files.length} 个文件)`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
@@ -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();
|
||||||
+48
-13
@@ -1,25 +1,58 @@
|
|||||||
|
import { lazy, Suspense } from 'react';
|
||||||
import { Routes, Route } from 'react-router-dom';
|
import { Routes, Route } from 'react-router-dom';
|
||||||
import HomePage from '@/pages/HomePage';
|
import HomePage from '@/pages/HomePage';
|
||||||
import SSOLogin from '@/pages/SSOLogin';
|
import SSOLogin from '@/pages/SSOLogin';
|
||||||
import LoginPage from '@/pages/LoginPage';
|
import LoginPage from '@/pages/LoginPage';
|
||||||
import RequireAuth from '@/shared/components/RequireAuth';
|
import RequireAuth from '@/shared/components/RequireAuth';
|
||||||
import ModuleTitle from '@/shared/components/ModuleTitle';
|
import ModuleTitle from '@/shared/components/ModuleTitle';
|
||||||
import AIMCockpit from '@/modules/ai-matching/pages/AIMCockpit';
|
|
||||||
import CostCockpit from '@/modules/cost-analysis/pages/CostCockpit';
|
const AIMCockpit = lazy(() => import('@/modules/ai-matching/pages/AIMCockpit'));
|
||||||
import KnowledgeGraphHome from '@/modules/knowledge-graph/pages/KnowledgeGraphHome';
|
const CostCockpit = lazy(() => import('@/modules/cost-analysis/pages/CostCockpit'));
|
||||||
import SpaceCockpit from '@/modules/knowledge-graph/pages/SpaceCockpit';
|
const KnowledgeGraphHome = lazy(() => import('@/modules/knowledge-graph/pages/KnowledgeGraphHome'));
|
||||||
import BomxReuseHome from '@/modules/bomx-reuse-analyzer/pages/BomxReuseHome';
|
const SpaceCockpit = lazy(() => import('@/modules/knowledge-graph/pages/SpaceCockpit'));
|
||||||
import CostCockpitFull from '@/modules/order-cost-analysis/pages/CostCockpitFull';
|
const BomxReuseHome = lazy(() => import('@/modules/bomx-reuse-analyzer/pages/BomxReuseHome'));
|
||||||
import AIMCockpitFull from '@/modules/order-cost-analysis/pages/AIMCockpitFull';
|
const CostCockpitFull = lazy(() => import('@/modules/order-cost-analysis/pages/CostCockpitFull'));
|
||||||
import BexellSchedulingApp from '@/modules/bexell-scheduling-ai/App';
|
const AIMCockpitFull = lazy(() => import('@/modules/order-cost-analysis/pages/AIMCockpitFull'));
|
||||||
import SanruiAIDesignHome from '@/modules/sanrui-ai-design/pages/SanruiAIDesignHome';
|
const BexellSchedulingApp = lazy(() => import('@/modules/bexell-scheduling-ai/App'));
|
||||||
import JieyaIbpApp from '@/modules/jieya-ibp/App';
|
const SanruiAIDesignHome = lazy(() => import('@/modules/sanrui-ai-design/pages/SanruiAIDesignHome'));
|
||||||
import WelltrustQapApp from '@/modules/welltrust-qap/App';
|
const JieyaIbpApp = lazy(() => import('@/modules/jieya-ibp/App'));
|
||||||
import BaodeWebApp from '@/modules/baode-web/App';
|
const WelltrustQapApp = lazy(() => import('@/modules/welltrust-qap/App'));
|
||||||
import SupplierPlatformApp from '@/modules/supplier-platform/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 (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
inset: 0,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 18,
|
||||||
|
background: '#000a1e',
|
||||||
|
zIndex: 9999,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={spinnerStyle} />
|
||||||
|
<div style={{ color: '#00d4ff', fontSize: 14, letterSpacing: 2 }}>模块加载中…</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
return (
|
return (
|
||||||
|
<Suspense fallback={<ModuleLoading />}>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/login" element={<LoginPage />} />
|
<Route path="/login" element={<LoginPage />} />
|
||||||
<Route path="/sso-login" element={<SSOLogin />} />
|
<Route path="/sso-login" element={<SSOLogin />} />
|
||||||
@@ -37,6 +70,8 @@ export default function App() {
|
|||||||
<Route path="/welltrust-qap" element={<RequireAuth><ModuleTitle title="品质异常预防工作台"><WelltrustQapApp /></ModuleTitle></RequireAuth>} />
|
<Route path="/welltrust-qap" element={<RequireAuth><ModuleTitle title="品质异常预防工作台"><WelltrustQapApp /></ModuleTitle></RequireAuth>} />
|
||||||
<Route path="/baode-web" element={<RequireAuth><ModuleTitle title="需求评审多智能体"><BaodeWebApp /></ModuleTitle></RequireAuth>} />
|
<Route path="/baode-web" element={<RequireAuth><ModuleTitle title="需求评审多智能体"><BaodeWebApp /></ModuleTitle></RequireAuth>} />
|
||||||
<Route path="/supplier-platform" element={<RequireAuth><ModuleTitle title="供应商智能管控平台"><SupplierPlatformApp /></ModuleTitle></RequireAuth>} />
|
<Route path="/supplier-platform" element={<RequireAuth><ModuleTitle title="供应商智能管控平台"><SupplierPlatformApp /></ModuleTitle></RequireAuth>} />
|
||||||
|
<Route path="/wuc-quotation" element={<RequireAuth><ModuleTitle title="武船AI智能报价平台"><WucQuotationApp /></ModuleTitle></RequireAuth>} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
</Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ export function Header({ onOpenHistory }: { onOpenHistory: () => void }) {
|
|||||||
<strong>订单需求评审智能体</strong>
|
<strong>订单需求评审智能体</strong>
|
||||||
</div>
|
</div>
|
||||||
<div className="topbar-right">
|
<div className="topbar-right">
|
||||||
|
<a
|
||||||
|
className="btn"
|
||||||
|
href="/mod-assets/baode-web/demo-text.zip"
|
||||||
|
download="演示文档.zip"
|
||||||
|
>
|
||||||
|
演示文档下载
|
||||||
|
</a>
|
||||||
<button type="button" className="btn" onClick={onOpenHistory}>
|
<button type="button" className="btn" onClick={onOpenHistory}>
|
||||||
评审历史
|
评审历史
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -177,7 +177,7 @@
|
|||||||
flex: none; width: 18px; height: 18px; border-radius: 50%;
|
flex: none; width: 18px; height: 18px; border-radius: 50%;
|
||||||
display: grid; place-items: center; font-size: 11px; color: #fff; background: #cbd5e1;
|
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(--wait); }
|
||||||
.s-待补全 .fnode-dot { background: var(--cta); }
|
.s-待补全 .fnode-dot { background: var(--cta); }
|
||||||
.s-已完成 .fnode-dot { background: var(--pass); }
|
.s-已完成 .fnode-dot { background: var(--pass); }
|
||||||
@@ -351,6 +351,7 @@
|
|||||||
transition: background 0.18s, border-color 0.18s, color 0.18s;
|
transition: background 0.18s, border-color 0.18s, color 0.18s;
|
||||||
}
|
}
|
||||||
.baode-root .btn:hover { border-color: var(--brand); color: var(--brand-600); }
|
.baode-root .btn:hover { border-color: var(--brand); color: var(--brand-600); }
|
||||||
|
.baode-root a.btn { text-decoration: none; display: inline-flex; align-items: center; }
|
||||||
.baode-root .btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
|
.baode-root .btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
|
||||||
.baode-root .btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
|
.baode-root .btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
|
||||||
.baode-root .btn-danger { background: var(--fail); border-color: var(--fail); color: #fff; font-weight: 600; }
|
.baode-root .btn-danger { background: var(--fail); border-color: var(--fail); color: #fff; font-weight: 600; }
|
||||||
@@ -385,10 +386,10 @@
|
|||||||
.checkpage .fail { color: var(--fail); font-weight: 600; }
|
.checkpage .fail { color: var(--fail); font-weight: 600; }
|
||||||
|
|
||||||
@keyframes floatIn { from { opacity: 0; translate: 0 6px; } to { opacity: 1; translate: 0 0; } }
|
@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); }
|
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); }
|
50% { box-shadow: 0 0 0 6px rgba(37, 99, 235, 0); }
|
||||||
}
|
}
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
* { animation: none !important; transition: none !important; }
|
.baode-root * { animation: none !important; transition: none !important; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,13 @@ import { useEffect } from 'react';
|
|||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { IconX } from './Icons';
|
import { IconX } from './Icons';
|
||||||
|
|
||||||
// 使用 Portal 渲染到 body,避免被父级层叠上下文/导航条遮挡
|
// Portal 渲染到模块根容器内的挂载点(必传 portalMount),
|
||||||
export default function Drawer({ open, title, onClose, children, width = 540 }: any) {
|
// 保持 DOM 节点位于模块作用域内,禁止挂到 document.body
|
||||||
|
export default function Drawer({ open, title, onClose, children, width = 540, portalMount }: {
|
||||||
|
open: boolean; title?: React.ReactNode; onClose: () => void;
|
||||||
|
children?: React.ReactNode; width?: number;
|
||||||
|
portalMount: HTMLDivElement;
|
||||||
|
}) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
|
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
|
||||||
@@ -12,7 +17,9 @@ export default function Drawer({ open, title, onClose, children, width = 540 }:
|
|||||||
}, [open, onClose]);
|
}, [open, onClose]);
|
||||||
|
|
||||||
return createPortal(
|
return createPortal(
|
||||||
<>
|
// 模块根容器包裹层:为 portal 内容提供 .bomx-app 作用域下的 CSS 变量;
|
||||||
|
// overlay/panel 均 position:fixed,且平台 body 为 overflow:hidden,包裹层不影响布局
|
||||||
|
<div className="bomx-app">
|
||||||
{/* 遮罩:覆盖全屏(含导航条),点击任意非抽屉区域关闭 */}
|
{/* 遮罩:覆盖全屏(含导航条),点击任意非抽屉区域关闭 */}
|
||||||
{open && <div className="drawer-overlay" onClick={onClose} />}
|
{open && <div className="drawer-overlay" onClick={onClose} />}
|
||||||
|
|
||||||
@@ -29,7 +36,7 @@ export default function Drawer({ open, title, onClose, children, width = 540 }:
|
|||||||
</div>
|
</div>
|
||||||
<div className="drawer-content">{children}</div>
|
<div className="drawer-content">{children}</div>
|
||||||
</div>
|
</div>
|
||||||
</>,
|
</div>,
|
||||||
document.body
|
portalMount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState, useCallback } from 'react';
|
import { useEffect, useState, useCallback, useRef } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { initStore } from '../core/store';
|
import { initStore } from '../core/store';
|
||||||
import BomBrowser from '../components/BomBrowser';
|
import BomBrowser from '../components/BomBrowser';
|
||||||
@@ -47,6 +47,9 @@ export default function BomxReuseHome() {
|
|||||||
const [loadError, setLoadError] = useState<any>(null);
|
const [loadError, setLoadError] = useState<any>(null);
|
||||||
const [fadingOut, setFadingOut] = useState(false);
|
const [fadingOut, setFadingOut] = useState(false);
|
||||||
|
|
||||||
|
// Drawer Portal 挂载点:位于 .bomx-app 根容器内部,使 Drawer DOM 节点留在模块作用域内
|
||||||
|
const portalMountRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const loadData = useCallback(async (sourceKey: string) => {
|
const loadData = useCallback(async (sourceKey: string) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setFadingOut(false);
|
setFadingOut(false);
|
||||||
@@ -164,6 +167,9 @@ export default function BomxReuseHome() {
|
|||||||
</div>
|
</div>
|
||||||
<ToastContainer />
|
<ToastContainer />
|
||||||
|
|
||||||
|
{/* Drawer Portal 挂载点:Drawer 通过 createPortal 将内容渲染到此节点内 */}
|
||||||
|
<div ref={portalMountRef} />
|
||||||
|
|
||||||
{data && (
|
{data && (
|
||||||
<div className="data-source-switch">
|
<div className="data-source-switch">
|
||||||
<select
|
<select
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
风格:Premium Light · 深度层次 · 流畅交互
|
风格:Premium Light · 深度层次 · 流畅交互
|
||||||
============================================================ */
|
============================================================ */
|
||||||
|
|
||||||
:root {
|
.bomx-app {
|
||||||
--header-h: 64px;
|
--header-h: 64px;
|
||||||
/* 品牌渐变 */
|
/* 品牌渐变 */
|
||||||
--grad-brand: linear-gradient(135deg, #6366F1 0%, #8B5CF6 50%, #A855F7 100%);
|
--grad-brand: linear-gradient(135deg, #6366F1 0%, #8B5CF6 50%, #A855F7 100%);
|
||||||
@@ -85,9 +85,9 @@
|
|||||||
z-index: 0;
|
z-index: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
::-webkit-scrollbar { width: 8px; height: 8px; }
|
.bomx-app ::-webkit-scrollbar { width: 8px; height: 8px; }
|
||||||
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
|
.bomx-app ::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
|
||||||
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
|
.bomx-app ::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
|
||||||
|
|
||||||
/* ===== Header ===== */
|
/* ===== Header ===== */
|
||||||
.app-header {
|
.app-header {
|
||||||
@@ -260,7 +260,7 @@
|
|||||||
.btn-sm { height: 32px; padding: 0 13px; font-size: 12px; border-radius: var(--r-sm); }
|
.btn-sm { height: 32px; padding: 0 13px; font-size: 12px; border-radius: var(--r-sm); }
|
||||||
|
|
||||||
/* ===== Form ===== */
|
/* ===== Form ===== */
|
||||||
input[type="text"], input[type="number"], select {
|
.bomx-app input[type="text"], .bomx-app input[type="number"], .bomx-app select {
|
||||||
height: 38px;
|
height: 38px;
|
||||||
padding: 0 13px;
|
padding: 0 13px;
|
||||||
border: 1px solid var(--line-2);
|
border: 1px solid var(--line-2);
|
||||||
@@ -273,7 +273,7 @@ input[type="text"], input[type="number"], select {
|
|||||||
transition: all var(--t-fast) var(--ease);
|
transition: all var(--t-fast) var(--ease);
|
||||||
}
|
}
|
||||||
|
|
||||||
input:focus, select:focus {
|
.bomx-app input:focus, .bomx-app select:focus {
|
||||||
border-color: var(--indigo);
|
border-color: var(--indigo);
|
||||||
box-shadow: 0 0 0 3px rgba(99,102,241,0.14);
|
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 {
|
.drawer {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -645,7 +645,7 @@ input:focus, select:focus {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
animation: fade-in 0.2s ease;
|
animation: bomx-fade-in 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.confirm-modal {
|
.confirm-modal {
|
||||||
@@ -743,10 +743,10 @@ input:focus, select:focus {
|
|||||||
.checkbox-label { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
|
.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; }
|
.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) {
|
@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 树表头列样式统一 ===== */
|
/* ===== 修复:BOM 树表头列样式统一 ===== */
|
||||||
@@ -896,11 +896,11 @@ input:focus, select:focus {
|
|||||||
border: 2.5px solid var(--line-1);
|
border: 2.5px solid var(--line-1);
|
||||||
border-top-color: var(--accent-primary);
|
border-top-color: var(--accent-primary);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
animation: spin 0.8s linear infinite;
|
animation: bomx-spin 0.8s linear infinite;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes spin {
|
@keyframes bomx-spin {
|
||||||
to { transform: rotate(360deg); }
|
to { transform: rotate(360deg); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1168,7 +1168,7 @@ input:focus, select:focus {
|
|||||||
border: 2px solid var(--indigo-soft);
|
border: 2px solid var(--indigo-soft);
|
||||||
border-top-color: var(--indigo);
|
border-top-color: var(--indigo);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
animation: spin 0.7s linear infinite;
|
animation: bomx-spin 0.7s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 阶段信息 */
|
/* 阶段信息 */
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ function AppInner() {
|
|||||||
if (!dbReady) {
|
if (!dbReady) {
|
||||||
const errMsg = dbError ?? (dbTimedOut ? t.common.initTimeout : null);
|
const errMsg = dbError ?? (dbTimedOut ? t.common.initTimeout : null);
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div className="jieya-root" style={{
|
||||||
width: '100vw', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center',
|
width: '100vw', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||||
background: tokens.bodyBgImage, color: tokens.textSub, fontSize: 14,
|
background: tokens.bodyBgImage, color: tokens.textSub, fontSize: 14,
|
||||||
}}>
|
}}>
|
||||||
@@ -116,7 +116,7 @@ function AppInner() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div className="jieya-root" style={{
|
||||||
width: '100vw', height: '100vh', display: 'flex', flexDirection: 'column',
|
width: '100vw', height: '100vh', display: 'flex', flexDirection: 'column',
|
||||||
background: tokens.bodyBgImage, color: tokens.text, overflow: 'hidden',
|
background: tokens.bodyBgImage, color: tokens.text, overflow: 'hidden',
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
import { createContext, useContext, useState, useCallback } from 'react';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode, CSSProperties } from 'react';
|
||||||
|
|
||||||
export type Theme = 'dark' | 'light';
|
export type Theme = 'dark' | 'light';
|
||||||
|
|
||||||
@@ -185,19 +185,20 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const root = document.documentElement;
|
|
||||||
root.style.setProperty('--body-bg', tokens.bodyBg);
|
|
||||||
root.style.setProperty('--scroll-thumb', tokens.scrollThumb);
|
|
||||||
root.style.setProperty('--glow-color', tokens.accentGlow);
|
|
||||||
root.style.setProperty('--hover-bg', tokens.tableRowHover);
|
|
||||||
document.body.style.background = tokens.bodyBgImage;
|
|
||||||
document.body.style.color = tokens.text;
|
|
||||||
}, [tokens]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeContext.Provider value={{ theme, tokens, toggleTheme }}>
|
<ThemeContext.Provider value={{ theme, tokens, toggleTheme }}>
|
||||||
|
<div style={{
|
||||||
|
'--body-bg': tokens.bodyBg,
|
||||||
|
'--scroll-thumb': tokens.scrollThumb,
|
||||||
|
'--glow-color': tokens.accentGlow,
|
||||||
|
'--hover-bg': tokens.tableRowHover,
|
||||||
|
background: tokens.bodyBgImage,
|
||||||
|
color: tokens.text,
|
||||||
|
width: '100%',
|
||||||
|
minHeight: '100vh',
|
||||||
|
} as CSSProperties}>
|
||||||
{children}
|
{children}
|
||||||
|
</div>
|
||||||
</ThemeContext.Provider>
|
</ThemeContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* 本模块样式仅保留动效/工具类;base 重置与 tailwind 由平台全局 index.css 提供 */
|
/* 本模块样式仅保留动效/工具类;base 重置与 tailwind 由平台全局 index.css 提供 */
|
||||||
|
|
||||||
button { cursor: pointer; }
|
.jieya-root button { cursor: pointer; }
|
||||||
input, textarea { font-family: inherit; }
|
.jieya-root input, .jieya-root textarea { font-family: inherit; }
|
||||||
|
|
||||||
/* ═══════════════════════════════════════════
|
/* ═══════════════════════════════════════════
|
||||||
太空舱 / 三栏工作区 动效层
|
太空舱 / 三栏工作区 动效层
|
||||||
@@ -23,7 +23,7 @@ input, textarea { font-family: inherit; }
|
|||||||
from { opacity: 0; transform: translateX(-20px); }
|
from { opacity: 0; transform: translateX(-20px); }
|
||||||
to { opacity: 1; transform: translateX(0); }
|
to { opacity: 1; transform: translateX(0); }
|
||||||
}
|
}
|
||||||
@keyframes slide-in-right {
|
@keyframes jieya-slide-in-right {
|
||||||
from { opacity: 0; transform: translateX(20px); }
|
from { opacity: 0; transform: translateX(20px); }
|
||||||
to { opacity: 1; transform: translateX(0); }
|
to { opacity: 1; transform: translateX(0); }
|
||||||
}
|
}
|
||||||
@@ -43,11 +43,11 @@ input, textarea { font-family: inherit; }
|
|||||||
from { opacity: 0; transform: translateY(18px) scale(0.97); }
|
from { opacity: 0; transform: translateY(18px) scale(0.97); }
|
||||||
to { opacity: 1; transform: translateY(0) scale(1); }
|
to { opacity: 1; transform: translateY(0) scale(1); }
|
||||||
}
|
}
|
||||||
@keyframes space-pulse {
|
@keyframes jieya-space-pulse {
|
||||||
0%, 100% { opacity: 0.55; }
|
0%, 100% { opacity: 0.55; }
|
||||||
50% { opacity: 1; }
|
50% { opacity: 1; }
|
||||||
}
|
}
|
||||||
@keyframes glow-pulse {
|
@keyframes jieya-glow-pulse {
|
||||||
0%, 100% { box-shadow: 0 0 0 rgba(79,70,229,0); }
|
0%, 100% { box-shadow: 0 0 0 rgba(79,70,229,0); }
|
||||||
50% { box-shadow: 0 0 18px var(--glow-color, rgba(79,70,229,0.35)); }
|
50% { box-shadow: 0 0 18px var(--glow-color, rgba(79,70,229,0.35)); }
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ input, textarea { font-family: inherit; }
|
|||||||
0%, 100% { opacity: 1; transform: scale(1); }
|
0%, 100% { opacity: 1; transform: scale(1); }
|
||||||
50% { opacity: 0.35; transform: scale(0.78); }
|
50% { opacity: 0.35; transform: scale(0.78); }
|
||||||
}
|
}
|
||||||
@keyframes scan-sweep {
|
@keyframes jieya-scan-sweep {
|
||||||
0% { left: -30%; }
|
0% { left: -30%; }
|
||||||
100% { left: 110%; }
|
100% { left: 110%; }
|
||||||
}
|
}
|
||||||
@@ -128,27 +128,27 @@ input, textarea { font-family: inherit; }
|
|||||||
.animate-slide-in { animation: slide-in-left 0.3s ease-out; }
|
.animate-slide-in { animation: slide-in-left 0.3s ease-out; }
|
||||||
.animate-number { animation: number-roll 0.5s ease-out; }
|
.animate-number { animation: number-roll 0.5s ease-out; }
|
||||||
.space-animate-left { animation: slide-in-left 0.4s cubic-bezier(0.4,0,0.2,1); }
|
.space-animate-left { animation: slide-in-left 0.4s cubic-bezier(0.4,0,0.2,1); }
|
||||||
.space-animate-right{ animation: slide-in-right 0.4s cubic-bezier(0.4,0,0.2,1); }
|
.jieya-root .space-animate-right{ animation: jieya-slide-in-right 0.4s cubic-bezier(0.4,0,0.2,1); }
|
||||||
.space-animate-up { animation: slide-in-up 0.4s cubic-bezier(0.4,0,0.2,1); }
|
.space-animate-up { animation: slide-in-up 0.4s cubic-bezier(0.4,0,0.2,1); }
|
||||||
.card-in { animation: card-in 0.35s cubic-bezier(0.4,0,0.2,1) both; }
|
.card-in { animation: card-in 0.35s cubic-bezier(0.4,0,0.2,1) both; }
|
||||||
.notice-in { animation: notice-in 0.35s cubic-bezier(0.4,0,0.2,1) both; }
|
.notice-in { animation: notice-in 0.35s cubic-bezier(0.4,0,0.2,1) both; }
|
||||||
.content-reveal { animation: content-reveal 0.5s cubic-bezier(0.34,1.56,0.64,1) both; }
|
.jieya-root .content-reveal { animation: content-reveal 0.5s cubic-bezier(0.34,1.56,0.64,1) both; }
|
||||||
.stream-cursor { animation: stream-cursor-blink 0.9s step-end infinite; }
|
.stream-cursor { animation: stream-cursor-blink 0.9s step-end infinite; }
|
||||||
.space-pulse { animation: space-pulse 2.4s ease-in-out infinite; }
|
.jieya-root .space-pulse { animation: jieya-space-pulse 2.4s ease-in-out infinite; }
|
||||||
.dot-blink { animation: dot-blink 1.6s ease-in-out infinite; }
|
.dot-blink { animation: dot-blink 1.6s ease-in-out infinite; }
|
||||||
.glow-pulse { animation: glow-pulse 3s ease-in-out infinite; }
|
.jieya-root .glow-pulse { animation: jieya-glow-pulse 3s ease-in-out infinite; }
|
||||||
.bar-grow { animation: bar-grow 0.6s cubic-bezier(0.4,0,0.2,1) both; transform-origin: bottom; }
|
.bar-grow { animation: bar-grow 0.6s cubic-bezier(0.4,0,0.2,1) both; transform-origin: bottom; }
|
||||||
.dash-flow { animation: dash-flow 1.2s linear infinite; }
|
.dash-flow { animation: dash-flow 1.2s linear infinite; }
|
||||||
|
|
||||||
/* 滚动条:颜色由 --scroll-thumb 注入(跟随主题 token) */
|
/* 滚动条:颜色由 --scroll-thumb 注入(跟随主题 token) */
|
||||||
::-webkit-scrollbar { width: 5px; height: 5px; }
|
.jieya-root ::-webkit-scrollbar { width: 5px; height: 5px; }
|
||||||
::-webkit-scrollbar-track { background: transparent; }
|
.jieya-root ::-webkit-scrollbar-track { background: transparent; }
|
||||||
::-webkit-scrollbar-thumb { background: var(--scroll-thumb, rgba(79,70,229,0.22)); border-radius: 10px; }
|
.jieya-root ::-webkit-scrollbar-thumb { background: var(--scroll-thumb, rgba(79,70,229,0.22)); border-radius: 10px; }
|
||||||
::-webkit-scrollbar-corner { background: transparent; }
|
.jieya-root ::-webkit-scrollbar-corner { background: transparent; }
|
||||||
|
|
||||||
.space-scroll::-webkit-scrollbar { width: 4px; height: 8px; }
|
.jieya-root .space-scroll::-webkit-scrollbar { width: 4px; height: 8px; }
|
||||||
.space-scroll::-webkit-scrollbar-track { background: transparent; }
|
.jieya-root .space-scroll::-webkit-scrollbar-track { background: transparent; }
|
||||||
.space-scroll::-webkit-scrollbar-thumb { background: var(--scroll-thumb, rgba(79,70,229,0.22)); border-radius: 4px; }
|
.jieya-root .space-scroll::-webkit-scrollbar-thumb { background: var(--scroll-thumb, rgba(79,70,229,0.22)); border-radius: 4px; }
|
||||||
|
|
||||||
/* 面板通用过渡 */
|
/* 面板通用过渡 */
|
||||||
.panel-shell { transition: width 0.3s cubic-bezier(0.4,0,0.2,1); }
|
.panel-shell { transition: width 0.3s cubic-bezier(0.4,0,0.2,1); }
|
||||||
@@ -156,7 +156,7 @@ input, textarea { font-family: inherit; }
|
|||||||
.ghost-btn:hover { background: var(--hover-bg, rgba(79,70,229,0.07)); }
|
.ghost-btn:hover { background: var(--hover-bg, rgba(79,70,229,0.07)); }
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
*, *::before, *::after {
|
.jieya-root *, .jieya-root *::before, .jieya-root *::after {
|
||||||
animation-duration: 0.01ms !important;
|
animation-duration: 0.01ms !important;
|
||||||
animation-iteration-count: 1 !important;
|
animation-iteration-count: 1 !important;
|
||||||
transition-duration: 0.01ms !important;
|
transition-duration: 0.01ms !important;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export default function KnowledgeGraphHome() {
|
|||||||
const [sideTab, setSideTab] = useState<SideTab>('stats');
|
const [sideTab, setSideTab] = useState<SideTab>('stats');
|
||||||
const [sidebarWidth, setSidebarWidth] = useState(320);
|
const [sidebarWidth, setSidebarWidth] = useState(320);
|
||||||
const isDragging = useRef(false);
|
const isDragging = useRef(false);
|
||||||
|
const rootRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const handleNodeSelect = (node: SelectedNode | null) => setSelectedNode(node);
|
const handleNodeSelect = (node: SelectedNode | null) => setSelectedNode(node);
|
||||||
const handleMaterialSelect = (mat: Material | null) => {
|
const handleMaterialSelect = (mat: Material | null) => {
|
||||||
@@ -46,8 +47,8 @@ export default function KnowledgeGraphHome() {
|
|||||||
isDragging.current = true;
|
isDragging.current = true;
|
||||||
const startX = e.clientX;
|
const startX = e.clientX;
|
||||||
const startWidth = sidebarWidth;
|
const startWidth = sidebarWidth;
|
||||||
document.body.style.cursor = 'col-resize';
|
rootRef.current?.style.setProperty('cursor', 'col-resize');
|
||||||
document.body.style.userSelect = 'none';
|
rootRef.current?.style.setProperty('userSelect', 'none');
|
||||||
|
|
||||||
const onMouseMove = (ev: MouseEvent) => {
|
const onMouseMove = (ev: MouseEvent) => {
|
||||||
if (!isDragging.current) return;
|
if (!isDragging.current) return;
|
||||||
@@ -57,8 +58,8 @@ export default function KnowledgeGraphHome() {
|
|||||||
};
|
};
|
||||||
const onMouseUp = () => {
|
const onMouseUp = () => {
|
||||||
isDragging.current = false;
|
isDragging.current = false;
|
||||||
document.body.style.cursor = '';
|
rootRef.current?.style.setProperty('cursor', '');
|
||||||
document.body.style.userSelect = '';
|
rootRef.current?.style.setProperty('userSelect', '');
|
||||||
document.removeEventListener('mousemove', onMouseMove);
|
document.removeEventListener('mousemove', onMouseMove);
|
||||||
document.removeEventListener('mouseup', onMouseUp);
|
document.removeEventListener('mouseup', onMouseUp);
|
||||||
};
|
};
|
||||||
@@ -69,7 +70,7 @@ export default function KnowledgeGraphHome() {
|
|||||||
const viewLabels: Record<ViewMode, string> = { category: '按分类', project: '按项目', aging: '按账龄' };
|
const viewLabels: Record<ViewMode, string> = { category: '按分类', project: '按项目', aging: '按账龄' };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen w-screen overflow-hidden" style={{ backgroundColor:'#f5f5f7' }}>
|
<div ref={rootRef} className="flex h-screen w-screen overflow-hidden" style={{ backgroundColor:'#f5f5f7' }}>
|
||||||
{/* Sidebar */}
|
{/* Sidebar */}
|
||||||
<aside className="flex-shrink-0 flex flex-col sidebar-bg" style={{ width:sidebarWidth, borderRight:'none' }}>
|
<aside className="flex-shrink-0 flex flex-col sidebar-bg" style={{ width:sidebarWidth, borderRight:'none' }}>
|
||||||
{/* Logo header */}
|
{/* Logo header */}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default function AIMCockpit() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div className="ordercost-root" style={{
|
||||||
width: '100vw', height: '100vh',
|
width: '100vw', height: '100vh',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
display: 'flex', flexDirection: 'column',
|
display: 'flex', flexDirection: 'column',
|
||||||
|
|||||||
@@ -24,11 +24,6 @@ export default function CostCockpit() {
|
|||||||
const { theme, tokens, toggleTheme } = useTheme();
|
const { theme, tokens, toggleTheme } = useTheme();
|
||||||
const { orders } = useOrders();
|
const { orders } = useOrders();
|
||||||
|
|
||||||
// 同步 body 背景色(CSS 变量)
|
|
||||||
useEffect(() => {
|
|
||||||
document.documentElement.style.setProperty('--body-bg', tokens.bodyBg);
|
|
||||||
}, [tokens.bodyBg]);
|
|
||||||
|
|
||||||
const [selectedOrder, setSelectedOrder] = useState<Order | null>(null);
|
const [selectedOrder, setSelectedOrder] = useState<Order | null>(null);
|
||||||
const [leftExpanded, setLeftExpanded] = useState(false);
|
const [leftExpanded, setLeftExpanded] = useState(false);
|
||||||
const [rightExpanded, setRightExpanded] = useState(false);
|
const [rightExpanded, setRightExpanded] = useState(false);
|
||||||
@@ -83,7 +78,7 @@ export default function CostCockpit() {
|
|||||||
}, [centerFullscreen]);
|
}, [centerFullscreen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div className="ordercost-root" style={{
|
||||||
width: '100vw', height: '100vh',
|
width: '100vw', height: '100vh',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
display: 'flex', flexDirection: 'column',
|
display: 'flex', flexDirection: 'column',
|
||||||
|
|||||||
@@ -91,9 +91,9 @@
|
|||||||
.space-scroll::-webkit-scrollbar-thumb { background: rgba(0,212,255,0.25); border-radius: 4px; }
|
.space-scroll::-webkit-scrollbar-thumb { background: rgba(0,212,255,0.25); border-radius: 4px; }
|
||||||
.space-scroll::-webkit-scrollbar-thumb:hover { background: rgba(0,212,255,0.45); }
|
.space-scroll::-webkit-scrollbar-thumb:hover { background: rgba(0,212,255,0.45); }
|
||||||
|
|
||||||
::-webkit-scrollbar { width: 5px; height: 5px; }
|
.ordercost-root ::-webkit-scrollbar { width: 5px; height: 5px; }
|
||||||
::-webkit-scrollbar-track { background: transparent; }
|
.ordercost-root ::-webkit-scrollbar-track { background: transparent; }
|
||||||
::-webkit-scrollbar-thumb { background: rgba(0,212,255,0.2); border-radius: 10px; }
|
.ordercost-root ::-webkit-scrollbar-thumb { background: rgba(0,212,255,0.2); border-radius: 10px; }
|
||||||
|
|
||||||
/* 拖入模块处理动画 */
|
/* 拖入模块处理动画 */
|
||||||
@keyframes module-spin {
|
@keyframes module-spin {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { moduleConfig as jieyaIbpConfig } from './jieya-ibp';
|
|||||||
import { moduleConfig as welltrustQapConfig } from './welltrust-qap';
|
import { moduleConfig as welltrustQapConfig } from './welltrust-qap';
|
||||||
import { moduleConfig as baodeWebConfig } from './baode-web';
|
import { moduleConfig as baodeWebConfig } from './baode-web';
|
||||||
import { moduleConfig as supplierPlatformConfig } from './supplier-platform';
|
import { moduleConfig as supplierPlatformConfig } from './supplier-platform';
|
||||||
|
import { moduleConfig as wucQuotationConfig } from './wuc-quotation';
|
||||||
|
|
||||||
// 新增模块只需在此数组添加一条配置即可
|
// 新增模块只需在此数组添加一条配置即可
|
||||||
export const modules: ModuleConfig[] = [
|
export const modules: ModuleConfig[] = [
|
||||||
@@ -36,4 +37,5 @@ export const modules: ModuleConfig[] = [
|
|||||||
welltrustQapConfig,
|
welltrustQapConfig,
|
||||||
baodeWebConfig,
|
baodeWebConfig,
|
||||||
supplierPlatformConfig,
|
supplierPlatformConfig,
|
||||||
|
wucQuotationConfig,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* ===== 顶栏:Logo / 导航 / 主题切换 ===== */
|
/* ===== 顶栏:Logo / 导航 / 主题切换 ===== */
|
||||||
import { useApp } from '../store/AppStore';
|
import { useApp } from '../store/AppStore';
|
||||||
import type { PageId } from '../store/AppStore';
|
import type { PageId } from '../store/AppStore';
|
||||||
|
import { getUserInfo } from '@/shared/services/iamAuth';
|
||||||
|
|
||||||
const NAVS: { id: PageId; label: string }[] = [
|
const NAVS: { id: PageId; label: string }[] = [
|
||||||
{ id: 'work', label: '智能匹配工作台' },
|
{ id: 'work', label: '智能匹配工作台' },
|
||||||
@@ -15,6 +16,14 @@ export default function TopBar() {
|
|||||||
const auditCnt = derived.counts.s2;
|
const auditCnt = derived.counts.s2;
|
||||||
const rfqCnt = derived.rfqActive;
|
const rfqCnt = derived.rfqActive;
|
||||||
|
|
||||||
|
// 当前真实登录者(IAM 会话);IAM 未提供角色字段时不展示角色行
|
||||||
|
const sessionUser = getUserInfo();
|
||||||
|
const displayName = sessionUser?.userName ?? sessionUser?.userId ?? '未登录';
|
||||||
|
const displayRole = (sessionUser?.roleName as string | undefined)
|
||||||
|
?? (sessionUser?.title as string | undefined)
|
||||||
|
?? '';
|
||||||
|
const avatarChar = displayName.charAt(0).toUpperCase();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header id="topbar">
|
<header id="topbar">
|
||||||
<div className="logo">
|
<div className="logo">
|
||||||
@@ -35,10 +44,10 @@ export default function TopBar() {
|
|||||||
</nav>
|
</nav>
|
||||||
<div className="top-right">
|
<div className="top-right">
|
||||||
<div className="user-info">
|
<div className="user-info">
|
||||||
<span className="user-avatar">蕫</span>
|
<span className="user-avatar">{avatarChar}</span>
|
||||||
<span className="user-meta">
|
<span className="user-meta">
|
||||||
<span className="user-name">蕫书康</span>
|
<span className="user-name">{displayName}</span>
|
||||||
<span className="user-role">采购专员</span>
|
{displayRole && <span className="user-role">{displayRole}</span>}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<button className="top-btn icon-btn" onClick={api.toggleTheme} title={state.dark ? '切换浅色' : '切换深色'}>
|
<button className="top-btn icon-btn" onClick={api.toggleTheme} title={state.dark ? '切换浅色' : '切换深色'}>
|
||||||
|
|||||||
@@ -39,9 +39,10 @@
|
|||||||
.logo-sub{font-size:10px;color:var(--faint);letter-spacing:1.5px}
|
.logo-sub{font-size:10px;color:var(--faint);letter-spacing:1.5px}
|
||||||
.live{display:inline-flex;align-items:center;gap:4px;font-size:10px;font-weight:700;color:var(--blue);
|
.live{display:inline-flex;align-items:center;gap:4px;font-size:10px;font-weight:700;color:var(--blue);
|
||||||
border:1px solid var(--blue);border-radius:20px;padding:2px 8px;margin-left:8px}
|
border:1px solid var(--blue);border-radius:20px;padding:2px 8px;margin-left:8px}
|
||||||
.live i{width:6px;height:6px;border-radius:50%;background:var(--blue);animation:pulse 1.4s infinite}
|
.live i{width:6px;height:6px;border-radius:50%;background:var(--blue);animation:hansong-pulse 1.4s infinite}
|
||||||
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.25}}
|
@keyframes hansong-pulse{0%,100%{opacity:1}50%{opacity:.25}}
|
||||||
#nav{display:flex;gap:6px;margin-left:14px;flex:1;justify-content:flex-end}
|
/* 加 .hansong-app 前缀:#nav 会误命中 wuc-quotation 模块的 <nav id="nav">(ID 特异性高于类选择器) */
|
||||||
|
.hansong-app #nav{display:flex;gap:6px;margin-left:14px;flex:1;justify-content:flex-end}
|
||||||
.nav-btn{border:1px solid transparent;background:transparent;color:var(--sub);font-size:13px;font-weight:600;
|
.nav-btn{border:1px solid transparent;background:transparent;color:var(--sub);font-size:13px;font-weight:600;
|
||||||
padding:7px 16px;border-radius:22px;cursor:pointer;transition:.2s;display:flex;align-items:center;gap:6px;white-space:nowrap}
|
padding:7px 16px;border-radius:22px;cursor:pointer;transition:.2s;display:flex;align-items:center;gap:6px;white-space:nowrap}
|
||||||
.nav-btn:hover{color:var(--blue);background:var(--blue-bg)}
|
.nav-btn:hover{color:var(--blue);background:var(--blue-bg)}
|
||||||
@@ -63,7 +64,7 @@
|
|||||||
.user-role{font-size:10px;color:var(--faint)}
|
.user-role{font-size:10px;color:var(--faint)}
|
||||||
|
|
||||||
/* ===== 页面容器 ===== */
|
/* ===== 页面容器 ===== */
|
||||||
main{flex:1;overflow:hidden;position:relative}
|
.hansong-app main{flex:1;overflow:hidden;position:relative}
|
||||||
.page{position:absolute;inset:0;padding:14px 18px;display:none;flex-direction:column;gap:12px;overflow:hidden}
|
.page{position:absolute;inset:0;padding:14px 18px;display:none;flex-direction:column;gap:12px;overflow:hidden}
|
||||||
.page.on{display:flex;animation:fadeIn .35s}
|
.page.on{display:flex;animation:fadeIn .35s}
|
||||||
@keyframes fadeIn{from{opacity:0;transform:translateY(6px)}to{opacity:1}}
|
@keyframes fadeIn{from{opacity:0;transform:translateY(6px)}to{opacity:1}}
|
||||||
@@ -181,13 +182,13 @@ main{flex:1;overflow:hidden;position:relative}
|
|||||||
/* ===== 比价表 ===== */
|
/* ===== 比价表 ===== */
|
||||||
.tbl-wrap{margin:0 14px 12px;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--card-solid)}
|
.tbl-wrap{margin:0 14px 12px;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--card-solid)}
|
||||||
.tbl-title{padding:9px 14px;font-size:12px;font-weight:800;border-bottom:1px solid var(--line);display:flex;align-items:center;gap:8px}
|
.tbl-title{padding:9px 14px;font-size:12px;font-weight:800;border-bottom:1px solid var(--line);display:flex;align-items:center;gap:8px}
|
||||||
table{width:100%;border-collapse:collapse;font-size:12px}
|
.hansong-app table{width:100%;border-collapse:collapse;font-size:12px}
|
||||||
th{background:var(--blue-bg);color:var(--sub);font-weight:700;text-align:left;padding:8px 10px;white-space:nowrap;font-size:11px}
|
.hansong-app th{background:var(--blue-bg);color:var(--sub);font-weight:700;text-align:left;padding:8px 10px;white-space:nowrap;font-size:11px}
|
||||||
td{padding:8px 10px;border-top:1px solid var(--line);vertical-align:middle}
|
.hansong-app td{padding:8px 10px;border-top:1px solid var(--line);vertical-align:middle}
|
||||||
tr.rec-row{background:linear-gradient(90deg,var(--blue-bg),transparent)}
|
.hansong-app tr.rec-row{background:linear-gradient(90deg,var(--blue-bg),transparent)}
|
||||||
tr.rec-row td:first-child{box-shadow:inset 3px 0 0 var(--blue)}
|
.hansong-app tr.rec-row td:first-child{box-shadow:inset 3px 0 0 var(--blue)}
|
||||||
tbody tr{transition:.15s}
|
.hansong-app tbody tr{transition:.15s}
|
||||||
tbody tr:hover{background:var(--blue-bg)}
|
.hansong-app tbody tr:hover{background:var(--blue-bg)}
|
||||||
.score-cell{display:flex;align-items:center;gap:6px}
|
.score-cell{display:flex;align-items:center;gap:6px}
|
||||||
.score-bar{width:52px;height:6px;border-radius:3px;background:rgba(120,135,170,.18);overflow:hidden}
|
.score-bar{width:52px;height:6px;border-radius:3px;background:rgba(120,135,170,.18);overflow:hidden}
|
||||||
.score-bar i{display:block;height:100%;border-radius:3px;background:linear-gradient(90deg,var(--blue),var(--purple))}
|
.score-bar i{display:block;height:100%;border-radius:3px;background:linear-gradient(90deg,var(--blue),var(--purple))}
|
||||||
@@ -308,10 +309,10 @@ tbody tr:hover{background:var(--blue-bg)}
|
|||||||
/* ===== AI 思考动画 ===== */
|
/* ===== AI 思考动画 ===== */
|
||||||
.ai-think{padding:34px 20px;text-align:center}
|
.ai-think{padding:34px 20px;text-align:center}
|
||||||
.ai-think .orb{width:52px;height:52px;margin:0 auto 14px;border-radius:50%;
|
.ai-think .orb{width:52px;height:52px;margin:0 auto 14px;border-radius:50%;
|
||||||
background:conic-gradient(var(--blue),var(--purple),var(--cyan),var(--blue));animation:spin 1.2s linear infinite;
|
background:conic-gradient(var(--blue),var(--purple),var(--cyan),var(--blue));animation:hansong-spin 1.2s linear infinite;
|
||||||
display:flex;align-items:center;justify-content:center}
|
display:flex;align-items:center;justify-content:center}
|
||||||
.ai-think .orb::after{content:"";width:42px;height:42px;border-radius:50%;background:var(--card-solid)}
|
.ai-think .orb::after{content:"";width:42px;height:42px;border-radius:50%;background:var(--card-solid)}
|
||||||
@keyframes spin{to{transform:rotate(360deg)}}
|
@keyframes hansong-spin{to{transform:rotate(360deg)}}
|
||||||
.think-step{font-size:12px;color:var(--sub);padding:3px 0;opacity:0;animation:fadeUp .3s forwards}
|
.think-step{font-size:12px;color:var(--sub);padding:3px 0;opacity:0;animation:fadeUp .3s forwards}
|
||||||
.think-step b{color:var(--blue)}
|
.think-step b{color:var(--blue)}
|
||||||
.empty-hint{padding:40px 20px;text-align:center;color:var(--faint);font-size:12px}
|
.empty-hint{padding:40px 20px;text-align:center;color:var(--faint);font-size:12px}
|
||||||
@@ -319,5 +320,5 @@ tbody tr:hover{background:var(--blue-bg)}
|
|||||||
.sec-label{font-size:11px;font-weight:800;color:var(--faint);letter-spacing:1px;margin:14px 14px 6px}
|
.sec-label{font-size:11px;font-weight:800;color:var(--faint);letter-spacing:1px;margin:14px 14px 6px}
|
||||||
.mini-list{font-size:11px}
|
.mini-list{font-size:11px}
|
||||||
.mini-list .row{display:flex;gap:8px;padding:5px 0;border-top:1px dashed var(--line);align-items:center}
|
.mini-list .row{display:flex;gap:8px;padding:5px 0;border-top:1px dashed var(--line);align-items:center}
|
||||||
select.sel{border:1px solid var(--line2);background:var(--card-solid);color:var(--ink);border-radius:9px;
|
.hansong-app select.sel{border:1px solid var(--line2);background:var(--card-solid);color:var(--ink);border-radius:9px;
|
||||||
padding:6px 10px;font-size:12px;outline:none;cursor:pointer;font-weight:600}
|
padding:6px 10px;font-size:12px;outline:none;cursor:pointer;font-weight:600}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ function AppInner() {
|
|||||||
if (!dbReady) {
|
if (!dbReady) {
|
||||||
const errMsg = dbError ?? (dbTimedOut ? t.common.initTimeout : null);
|
const errMsg = dbError ?? (dbTimedOut ? t.common.initTimeout : null);
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div className="welltrust-root" style={{
|
||||||
width: '100vw', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center',
|
width: '100vw', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||||
background: tokens.bodyBgImage, color: tokens.textSub, fontSize: 14,
|
background: tokens.bodyBgImage, color: tokens.textSub, fontSize: 14,
|
||||||
}}>
|
}}>
|
||||||
@@ -116,7 +116,7 @@ function AppInner() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div className="welltrust-root" style={{
|
||||||
width: '100vw', height: '100vh', display: 'flex', flexDirection: 'column',
|
width: '100vw', height: '100vh', display: 'flex', flexDirection: 'column',
|
||||||
background: tokens.bodyBgImage, color: tokens.text, overflow: 'hidden',
|
background: tokens.bodyBgImage, color: tokens.text, overflow: 'hidden',
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
import { createContext, useContext, useState, useCallback } from 'react';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode, CSSProperties } from 'react';
|
||||||
|
|
||||||
export type Theme = 'dark' | 'light';
|
export type Theme = 'dark' | 'light';
|
||||||
|
|
||||||
@@ -193,19 +193,20 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const root = document.documentElement;
|
|
||||||
root.style.setProperty('--body-bg', tokens.bodyBg);
|
|
||||||
root.style.setProperty('--scroll-thumb', tokens.scrollThumb);
|
|
||||||
root.style.setProperty('--glow-color', tokens.accentGlow);
|
|
||||||
root.style.setProperty('--hover-bg', tokens.tableRowHover);
|
|
||||||
document.body.style.background = tokens.bodyBgImage;
|
|
||||||
document.body.style.color = tokens.text;
|
|
||||||
}, [tokens]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeContext.Provider value={{ theme, tokens, toggleTheme }}>
|
<ThemeContext.Provider value={{ theme, tokens, toggleTheme }}>
|
||||||
|
<div style={{
|
||||||
|
'--body-bg': tokens.bodyBg,
|
||||||
|
'--scroll-thumb': tokens.scrollThumb,
|
||||||
|
'--glow-color': tokens.accentGlow,
|
||||||
|
'--hover-bg': tokens.tableRowHover,
|
||||||
|
background: tokens.bodyBgImage,
|
||||||
|
color: tokens.text,
|
||||||
|
width: '100%',
|
||||||
|
minHeight: '100vh',
|
||||||
|
} as CSSProperties}>
|
||||||
{children}
|
{children}
|
||||||
|
</div>
|
||||||
</ThemeContext.Provider>
|
</ThemeContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* 本模块样式仅保留动效/工具类;base 重置与 tailwind 由平台全局 index.css 提供 */
|
/* 本模块样式仅保留动效/工具类;base 重置与 tailwind 由平台全局 index.css 提供 */
|
||||||
|
|
||||||
button { cursor: pointer; }
|
.welltrust-root button { cursor: pointer; }
|
||||||
input, textarea { font-family: inherit; }
|
.welltrust-root input, .welltrust-root textarea { font-family: inherit; }
|
||||||
|
|
||||||
/* ═══════════════════════════════════════════
|
/* ═══════════════════════════════════════════
|
||||||
太空舱 / 三栏工作区 动效层
|
太空舱 / 三栏工作区 动效层
|
||||||
@@ -23,7 +23,7 @@ input, textarea { font-family: inherit; }
|
|||||||
from { opacity: 0; transform: translateX(-20px); }
|
from { opacity: 0; transform: translateX(-20px); }
|
||||||
to { opacity: 1; transform: translateX(0); }
|
to { opacity: 1; transform: translateX(0); }
|
||||||
}
|
}
|
||||||
@keyframes slide-in-right {
|
@keyframes welltrust-slide-in-right {
|
||||||
from { opacity: 0; transform: translateX(20px); }
|
from { opacity: 0; transform: translateX(20px); }
|
||||||
to { opacity: 1; transform: translateX(0); }
|
to { opacity: 1; transform: translateX(0); }
|
||||||
}
|
}
|
||||||
@@ -43,11 +43,11 @@ input, textarea { font-family: inherit; }
|
|||||||
from { opacity: 0; transform: translateY(18px) scale(0.97); }
|
from { opacity: 0; transform: translateY(18px) scale(0.97); }
|
||||||
to { opacity: 1; transform: translateY(0) scale(1); }
|
to { opacity: 1; transform: translateY(0) scale(1); }
|
||||||
}
|
}
|
||||||
@keyframes space-pulse {
|
@keyframes welltrust-space-pulse {
|
||||||
0%, 100% { opacity: 0.55; }
|
0%, 100% { opacity: 0.55; }
|
||||||
50% { opacity: 1; }
|
50% { opacity: 1; }
|
||||||
}
|
}
|
||||||
@keyframes glow-pulse {
|
@keyframes welltrust-glow-pulse {
|
||||||
0%, 100% { box-shadow: 0 0 0 rgba(79,70,229,0); }
|
0%, 100% { box-shadow: 0 0 0 rgba(79,70,229,0); }
|
||||||
50% { box-shadow: 0 0 18px var(--glow-color, rgba(79,70,229,0.35)); }
|
50% { box-shadow: 0 0 18px var(--glow-color, rgba(79,70,229,0.35)); }
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ input, textarea { font-family: inherit; }
|
|||||||
0%, 100% { opacity: 1; transform: scale(1); }
|
0%, 100% { opacity: 1; transform: scale(1); }
|
||||||
50% { opacity: 0.35; transform: scale(0.78); }
|
50% { opacity: 0.35; transform: scale(0.78); }
|
||||||
}
|
}
|
||||||
@keyframes scan-sweep {
|
@keyframes welltrust-scan-sweep {
|
||||||
0% { left: -30%; }
|
0% { left: -30%; }
|
||||||
100% { left: 110%; }
|
100% { left: 110%; }
|
||||||
}
|
}
|
||||||
@@ -125,27 +125,27 @@ input, textarea { font-family: inherit; }
|
|||||||
.animate-slide-in { animation: slide-in-left 0.3s ease-out; }
|
.animate-slide-in { animation: slide-in-left 0.3s ease-out; }
|
||||||
.animate-number { animation: number-roll 0.5s ease-out; }
|
.animate-number { animation: number-roll 0.5s ease-out; }
|
||||||
.space-animate-left { animation: slide-in-left 0.4s cubic-bezier(0.4,0,0.2,1); }
|
.space-animate-left { animation: slide-in-left 0.4s cubic-bezier(0.4,0,0.2,1); }
|
||||||
.space-animate-right{ animation: slide-in-right 0.4s cubic-bezier(0.4,0,0.2,1); }
|
.welltrust-root .space-animate-right{ animation: welltrust-slide-in-right 0.4s cubic-bezier(0.4,0,0.2,1); }
|
||||||
.space-animate-up { animation: slide-in-up 0.4s cubic-bezier(0.4,0,0.2,1); }
|
.space-animate-up { animation: slide-in-up 0.4s cubic-bezier(0.4,0,0.2,1); }
|
||||||
.card-in { animation: card-in 0.35s cubic-bezier(0.4,0,0.2,1) both; }
|
.card-in { animation: card-in 0.35s cubic-bezier(0.4,0,0.2,1) both; }
|
||||||
.notice-in { animation: notice-in 0.35s cubic-bezier(0.4,0,0.2,1) both; }
|
.notice-in { animation: notice-in 0.35s cubic-bezier(0.4,0,0.2,1) both; }
|
||||||
.content-reveal { animation: content-reveal 0.5s cubic-bezier(0.34,1.56,0.64,1) both; }
|
.welltrust-root .content-reveal { animation: content-reveal 0.5s cubic-bezier(0.34,1.56,0.64,1) both; }
|
||||||
.stream-caret { display: inline-block; width: 2px; height: 0.95em; margin-left: 2px; vertical-align: -0.12em; background: currentColor; animation: stream-caret-blink 1s steps(1) infinite; }
|
.stream-caret { display: inline-block; width: 2px; height: 0.95em; margin-left: 2px; vertical-align: -0.12em; background: currentColor; animation: stream-caret-blink 1s steps(1) infinite; }
|
||||||
.space-pulse { animation: space-pulse 2.4s ease-in-out infinite; }
|
.welltrust-root .space-pulse { animation: welltrust-space-pulse 2.4s ease-in-out infinite; }
|
||||||
.dot-blink { animation: dot-blink 1.6s ease-in-out infinite; }
|
.dot-blink { animation: dot-blink 1.6s ease-in-out infinite; }
|
||||||
.glow-pulse { animation: glow-pulse 3s ease-in-out infinite; }
|
.welltrust-root .glow-pulse { animation: welltrust-glow-pulse 3s ease-in-out infinite; }
|
||||||
.bar-grow { animation: bar-grow 0.6s cubic-bezier(0.4,0,0.2,1) both; transform-origin: bottom; }
|
.bar-grow { animation: bar-grow 0.6s cubic-bezier(0.4,0,0.2,1) both; transform-origin: bottom; }
|
||||||
.dash-flow { animation: dash-flow 1.2s linear infinite; }
|
.dash-flow { animation: dash-flow 1.2s linear infinite; }
|
||||||
|
|
||||||
/* 滚动条:颜色由 --scroll-thumb 注入(跟随主题 token) */
|
/* 滚动条:颜色由 --scroll-thumb 注入(跟随主题 token) */
|
||||||
::-webkit-scrollbar { width: 5px; height: 5px; }
|
.welltrust-root ::-webkit-scrollbar { width: 5px; height: 5px; }
|
||||||
::-webkit-scrollbar-track { background: transparent; }
|
.welltrust-root ::-webkit-scrollbar-track { background: transparent; }
|
||||||
::-webkit-scrollbar-thumb { background: var(--scroll-thumb, rgba(79,70,229,0.22)); border-radius: 10px; }
|
.welltrust-root ::-webkit-scrollbar-thumb { background: var(--scroll-thumb, rgba(79,70,229,0.22)); border-radius: 10px; }
|
||||||
::-webkit-scrollbar-corner { background: transparent; }
|
.welltrust-root ::-webkit-scrollbar-corner { background: transparent; }
|
||||||
|
|
||||||
.space-scroll::-webkit-scrollbar { width: 4px; height: 8px; }
|
.welltrust-root .space-scroll::-webkit-scrollbar { width: 4px; height: 8px; }
|
||||||
.space-scroll::-webkit-scrollbar-track { background: transparent; }
|
.welltrust-root .space-scroll::-webkit-scrollbar-track { background: transparent; }
|
||||||
.space-scroll::-webkit-scrollbar-thumb { background: var(--scroll-thumb, rgba(79,70,229,0.22)); border-radius: 4px; }
|
.welltrust-root .space-scroll::-webkit-scrollbar-thumb { background: var(--scroll-thumb, rgba(79,70,229,0.22)); border-radius: 4px; }
|
||||||
|
|
||||||
/* 面板通用过渡 */
|
/* 面板通用过渡 */
|
||||||
.panel-shell { transition: width 0.3s cubic-bezier(0.4,0,0.2,1); }
|
.panel-shell { transition: width 0.3s cubic-bezier(0.4,0,0.2,1); }
|
||||||
@@ -153,7 +153,7 @@ input, textarea { font-family: inherit; }
|
|||||||
.ghost-btn:hover { background: var(--hover-bg, rgba(79,70,229,0.07)); }
|
.ghost-btn:hover { background: var(--hover-bg, rgba(79,70,229,0.07)); }
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
*, *::before, *::after {
|
.welltrust-root *, .welltrust-root *::before, .welltrust-root *::after {
|
||||||
animation-duration: 0.01ms !important;
|
animation-duration: 0.01ms !important;
|
||||||
animation-iteration-count: 1 !important;
|
animation-iteration-count: 1 !important;
|
||||||
transition-duration: 0.01ms !important;
|
transition-duration: 0.01ms !important;
|
||||||
|
|||||||
@@ -0,0 +1,206 @@
|
|||||||
|
// 应用外壳:header + 左侧固定菜单 + 右侧内容区(内滚动)+ toast/弹窗
|
||||||
|
import { useEffect, useRef } from 'react'
|
||||||
|
// 沿用原离线版五段样式(001-005,已命名空间化到 .wuc-root),叠加 React 布局覆盖
|
||||||
|
import './styles/001.css'
|
||||||
|
import './styles/002.css'
|
||||||
|
import './styles/003.css'
|
||||||
|
import './styles/004.css'
|
||||||
|
import './styles/005.css'
|
||||||
|
import './app/react-layout.css'
|
||||||
|
import { useApp, AppProvider } from './app/store'
|
||||||
|
import type { Flows } from './app/store'
|
||||||
|
import { VIEWS } from './app/views'
|
||||||
|
import { ModalHost } from './app/modals'
|
||||||
|
import { BRAND_LOGO } from './app/logo'
|
||||||
|
import { NAV_ICONS, TITLES } from './app/data'
|
||||||
|
import type { State } from './app/types'
|
||||||
|
|
||||||
|
// 原 workflowStepStates:rail 六步状态(纯函数,archived 由调用方计算)
|
||||||
|
function stepStates(s: State, flows: Flows, archived: boolean) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
done: !!s.parsed && !!s.clarified,
|
||||||
|
running: !!flows.aiRun.running,
|
||||||
|
hint: s.parsed ? (s.clarified ? '已确认' : '待人工确认') : '待解析',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
done: !!s.tech,
|
||||||
|
running: !!flows.kb.running,
|
||||||
|
hint: flows.kb.running ? '清单分析中' : s.tech ? '技术已确认' : '待技术确认',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
done: !!s.review,
|
||||||
|
running: !!flows.aiInquiry.running || !!flows.productionAI.running,
|
||||||
|
hint: s.review
|
||||||
|
? '经营已确认'
|
||||||
|
: s.supply && s.production
|
||||||
|
? '待经营确认'
|
||||||
|
: s.supply
|
||||||
|
? '待生产提交'
|
||||||
|
: s.production
|
||||||
|
? '待物供提交'
|
||||||
|
: '待部门核价',
|
||||||
|
},
|
||||||
|
{ done: !!s.report, running: false, hint: s.report ? '报告已生成' : '待生成报告' },
|
||||||
|
{ done: !!s.approved, running: !!flows.strategyRun.running, hint: s.approved ? '策略已批准' : '待策略审批' },
|
||||||
|
{ done: archived, running: false, hint: archived ? '报价已入库' : s.approved ? '可输出 / 待入库' : '待生成报价' },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
function AppShell() {
|
||||||
|
const ctx = useApp()
|
||||||
|
const { s, flows, go, toastMsg, openModal, startKnowledge, exportState, resetAll, quotationIsArchived } = ctx
|
||||||
|
|
||||||
|
// 模块根容器:主题(dark)与侧栏折叠(collapsed)状态挂在根容器而非 document.body,
|
||||||
|
// 避免污染平台全局 body(原离线版直接 toggle body class)
|
||||||
|
const rootRef = useRef<HTMLDivElement>(null)
|
||||||
|
const toggleRootClass = (cls: string) => rootRef.current?.classList.toggle(cls)
|
||||||
|
|
||||||
|
// just-completed 高亮:对比上一轮 done 状态
|
||||||
|
const prevDoneRef = useRef<boolean[] | null>(null)
|
||||||
|
const states = stepStates(s, flows, s.approved && quotationIsArchived())
|
||||||
|
const changed = (i: number) => !!prevDoneRef.current && states[i].done && !prevDoneRef.current[i]
|
||||||
|
useEffect(() => {
|
||||||
|
prevDoneRef.current = states.map((x) => x.done)
|
||||||
|
})
|
||||||
|
|
||||||
|
const View = VIEWS[s.page]
|
||||||
|
// 流程轨道仅项目工作台隐藏;物量清单页与"AI分析"按钮一起出现
|
||||||
|
const railHidden = s.page === 0
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="wuc-root" ref={rootRef}>
|
||||||
|
<header>
|
||||||
|
<div className="brand company-brand">
|
||||||
|
<img
|
||||||
|
className="company-logo"
|
||||||
|
src={BRAND_LOGO}
|
||||||
|
alt="CSSC 武昌船舶重工集团有限公司 / WUCHANG SHIPBUILDING INDUSTRY GROUP CO., LTD."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="head-name">
|
||||||
|
<b>AI智能报价平台</b>
|
||||||
|
</div>
|
||||||
|
<button type="button" style={{ marginLeft: 'auto' }} onClick={() => openModal('guide', '操作指南')}>
|
||||||
|
操作指南
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={() => toggleRootClass('dark')}>
|
||||||
|
◐ 主题
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="app-shell">
|
||||||
|
<aside>
|
||||||
|
<div className="side-label">
|
||||||
|
QUOTE WORKSPACE{' '}
|
||||||
|
<button type="button" onClick={() => toggleRootClass('collapsed')}>
|
||||||
|
☰
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<nav id="nav">
|
||||||
|
{TITLES.map((t, i) => (
|
||||||
|
<button key={t} type="button" className={s.page === i ? 'active' : ''} onClick={() => go(i)}>
|
||||||
|
<span>{NAV_ICONS[i]}</span>
|
||||||
|
{t}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
<div className="side-bottom">
|
||||||
|
<button type="button" onClick={exportState}>
|
||||||
|
↓ 导出项目备份
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={resetAll}>
|
||||||
|
↺ 重置本次演示
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<div className="workspace-banner">
|
||||||
|
<div id="titlebar">
|
||||||
|
<div>
|
||||||
|
<div className="title-line">
|
||||||
|
<h1>{TITLES[s.page]}</h1>
|
||||||
|
{s.page === 2 && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={'primary btn-sm' + (flows.kb.shown ? ' list-analysis-clicked' : '')}
|
||||||
|
disabled={!s.parsed || flows.kb.running}
|
||||||
|
onClick={startKnowledge}
|
||||||
|
>
|
||||||
|
AI物量与资源清单分析
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="subtitle">
|
||||||
|
{s.project.code} · 成本版本 V{s.revision} ·{' '}
|
||||||
|
{s.approved ? '策略已审批' : s.review ? '经营已确认' : '编制中'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="actions">
|
||||||
|
<span className="badge">{s.approved ? '已批准' : s.parsed ? '需求已解析' : '待解析'}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{!railHidden && (
|
||||||
|
<div className="rail" role="navigation" aria-label="报价业务流程">
|
||||||
|
<ol className="workflow-progress">
|
||||||
|
{states.map((step, i) => (
|
||||||
|
<li
|
||||||
|
key={TITLES[i + 1]}
|
||||||
|
className={
|
||||||
|
'workflow-progress-item ' +
|
||||||
|
(step.done ? 'is-complete ' : '') +
|
||||||
|
(s.page === i + 1 ? 'is-current ' : '') +
|
||||||
|
(step.running ? 'is-running ' : '') +
|
||||||
|
(changed(i) ? 'just-completed' : '')
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="workflow-progress-button"
|
||||||
|
onClick={() => go(i + 1)}
|
||||||
|
aria-current={s.page === i + 1 ? 'step' : undefined}
|
||||||
|
aria-label={TITLES[i + 1] + ',' + step.hint}
|
||||||
|
title={step.hint}
|
||||||
|
>
|
||||||
|
<span className="workflow-step-circle" aria-hidden="true">
|
||||||
|
{step.done ? '✓' : i + 1}
|
||||||
|
</span>
|
||||||
|
<span className="workflow-step-name">{TITLES[i + 1]}</span>
|
||||||
|
<span className="workflow-step-state">{step.hint}</span>
|
||||||
|
</button>
|
||||||
|
{i < 5 && (
|
||||||
|
<span className="workflow-connector" aria-hidden="true">
|
||||||
|
<i></i>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div id="content" data-view={s.page}>
|
||||||
|
<View />
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{toastMsg ? (
|
||||||
|
<div id="toast" className="is-visible">
|
||||||
|
{toastMsg}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<ModalHost />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 平台路由直接渲染本模块,AppProvider 职责由原独立入口 main.tsx 移至此处
|
||||||
|
export default function App() {
|
||||||
|
return (
|
||||||
|
<AppProvider>
|
||||||
|
<AppShell />
|
||||||
|
</AppProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// 共享 UI 原语(对应原 btn/notice/table/metric/audit 模板助手)
|
||||||
|
import React from 'react'
|
||||||
|
import { useApp } from './store'
|
||||||
|
|
||||||
|
export function Btn({ t, onClick, disabled = false, cls = '' }: { t: React.ReactNode; onClick?: () => void; disabled?: boolean; cls?: string }) {
|
||||||
|
return (
|
||||||
|
<button className={cls} disabled={disabled || undefined} onClick={onClick}>
|
||||||
|
{t}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Notice({ t, cls = '' }: { t: React.ReactNode; cls?: string }) {
|
||||||
|
return <div className={'notice ' + cls}>{t}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Table({ head, rows }: { head: React.ReactNode[]; rows: React.ReactNode[][] }) {
|
||||||
|
return (
|
||||||
|
<div className="table-scroll">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>{head.map((x, i) => <th key={i}>{x}</th>)}</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{rows.map((r, i) => <tr key={i}>{r.map((x, j) => <td key={j}>{x}</td>)}</tr>)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Metric({ label, value, unit = '' }: { label: string; value: React.ReactNode; unit?: string }) {
|
||||||
|
return (
|
||||||
|
<div className="metric">
|
||||||
|
<div>
|
||||||
|
<label>{label}</label>
|
||||||
|
<div><strong>{value}</strong><small>{unit}</small></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function NumInput({ v, onCommit, wide = false, min = 0, disabled = false, placeholder, ariaLabel }: {
|
||||||
|
v: React.ReactNode; onCommit: (v: string) => void; wide?: boolean; min?: number
|
||||||
|
disabled?: boolean; placeholder?: string; ariaLabel?: string
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
className={wide ? 'wide' : undefined}
|
||||||
|
type="number"
|
||||||
|
min={min}
|
||||||
|
step="0.01"
|
||||||
|
defaultValue={v as any}
|
||||||
|
key={String(v) + '-' + String(ariaLabel)}
|
||||||
|
disabled={disabled || undefined}
|
||||||
|
placeholder={placeholder}
|
||||||
|
aria-label={ariaLabel}
|
||||||
|
onChange={(e) => onCommit(e.target.value)}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Audit() {
|
||||||
|
const { s } = useApp()
|
||||||
|
return (
|
||||||
|
<div className="audit">
|
||||||
|
{s.log.slice(0, 30).map((l, i) => (
|
||||||
|
<div className="log" key={i}>
|
||||||
|
<small>{l.time}</small>
|
||||||
|
<b>版本 V{l.rev}</b>
|
||||||
|
<span>{l.text}</span>
|
||||||
|
</div>
|
||||||
|
)) || <p>尚无操作记录,开始上传或载入需求。</p>}
|
||||||
|
{!s.log.length && <p>尚无操作记录,开始上传或载入需求。</p>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
// 内置样例数据 / 模拟供应商 / 历史案例(对应原 001-sample-data.js 与 HISTORY_CASES)
|
||||||
|
import type { HistoryCase, Material, Project, Resource } from './types'
|
||||||
|
|
||||||
|
export const SAMPLE: Project & { missing: Material } = {
|
||||||
|
schema: 'wuchuan-quote-v1',
|
||||||
|
project: '重型装备伸缩支承内外套组件制造供货',
|
||||||
|
customer: '华中装备工程有限公司(虚构)',
|
||||||
|
code: 'RFQ-DEMO-2026-016',
|
||||||
|
delivery: 90,
|
||||||
|
sets: 10,
|
||||||
|
scope: '10套内外套组件(每套内套1件、外套1件),含采购、下料、成形、焊接、机加工、检测、防腐、包装运输及技术资料;不含主机、驱动装置及现场安装。',
|
||||||
|
terms: '预付款30%,工厂验收后发运前60%,到货验收后10%;质保12个月;报价有效期30天。',
|
||||||
|
materials: [
|
||||||
|
{ id: 'M001', name: '内套筒体 Q355B', unit: 'kg', qty: 2367.5, price: 5.2, ref: 'SIM-IS-01 序1;236.75kg×10', confidence: 96 },
|
||||||
|
{ id: 'M002', name: '内套法兰 Q355B', unit: 'kg', qty: 338.4, price: 5.4, ref: 'SIM-IS-01 序2;33.84kg×10', confidence: 93 },
|
||||||
|
{ id: 'M003', name: '内套加强环 Q355B', unit: 'kg', qty: 199.8, price: 5.3, ref: 'SIM-IS-01 序3;19.98kg×10', confidence: 91 },
|
||||||
|
{ id: 'M004', name: '外套筒体 Q355B', unit: 'kg', qty: 3334.2, price: 5.2, ref: 'SIM-OS-01 序1;333.42kg×10', confidence: 96 },
|
||||||
|
{ id: 'M005', name: '外套法兰 Q355B', unit: 'kg', qty: 526.5, price: 5.4, ref: 'SIM-OS-01 序2;52.65kg×10', confidence: 93 },
|
||||||
|
{ id: 'M006', name: '导向衬套 铜合金', unit: '件', qty: 20, price: 850, ref: '需求§3;2件×10', confidence: 85 },
|
||||||
|
{ id: 'M007', name: '密封组件', unit: '套', qty: 10, price: 420, ref: '需求§3;1套×10', confidence: 84 },
|
||||||
|
{ id: 'M008', name: '配套紧固件', unit: '套', qty: 10, price: 180, ref: '需求§3;1套×10', confidence: 88 },
|
||||||
|
],
|
||||||
|
resources: [
|
||||||
|
{ id: 'R01', name: '工艺深化', qty: 40, rate: 120, ref: '内部工艺 P01', note: '技术部门估算' },
|
||||||
|
{ id: 'R02', name: '下料与坡口', qty: 60, rate: 95, ref: '内部工艺 P02', note: '含人工、设备、能耗' },
|
||||||
|
{ id: 'R03', name: '卷制与组对', qty: 100, rate: 85, ref: '内部工艺 P03', note: '含人工、设备、能耗' },
|
||||||
|
{ id: 'R04', name: '焊接', qty: 240, rate: 110, ref: '模拟焊缝480m ÷ 2m/工时', note: '不含焊材;另列BOM' },
|
||||||
|
{ id: 'R05', name: '精加工', qty: 180, rate: 150, ref: '内外圆、端面与孔加工', note: '含人工、设备、能耗' },
|
||||||
|
{ id: 'R06', name: '装配与试配', qty: 60, rate: 100, ref: '内部工艺 P06', note: '含人工、设备、能耗' },
|
||||||
|
],
|
||||||
|
missing: { id: 'M009', name: '焊丝与焊剂配套', unit: 'kg', qty: 160, price: 8.5, ref: '需求§4文字补充;技术人工确认', confidence: 60 },
|
||||||
|
assumptions: '全部数量为10套项目合计。仅参考附件内套/外套主题,未核实附件尺寸材质。SIM图、重量、价格、工时均为演示假设;非生产依据。',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TITLES = ['项目工作台', '需求与图纸解析', '物量与资源清单', '跨部门询价与审核', '全成本测算报告', 'AI报价策略', '正式报价单']
|
||||||
|
export const NAV_ICONS = ['◈', '▤', '▦', '⇄', '▥', '✦', '▧']
|
||||||
|
|
||||||
|
export const offers = (m: Material, project: Project) => {
|
||||||
|
const base = project.materials.find((x) => x.id === m.id)?.price ?? m.price
|
||||||
|
return [
|
||||||
|
{ name: '华中材料供应商(模拟)', price: base, days: 30, quality: '材质证明齐全', index: 0 },
|
||||||
|
{ name: '长江配套供应商(模拟)', price: +(base * 0.94).toFixed(2), days: 105, quality: '低价,但超期', index: 1 },
|
||||||
|
{ name: '江城优选供应商(模拟)', price: +(base * 1.06).toFixed(2), days: 20, quality: '交期更短', index: 2 },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const kbRecords = {
|
||||||
|
material: [...SAMPLE.materials, SAMPLE.missing] as Material[],
|
||||||
|
resource: SAMPLE.resources as Resource[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const HISTORY_CASES: Record<string, HistoryCase> = {
|
||||||
|
H01: {
|
||||||
|
name: '相似内外套组件制造项目',
|
||||||
|
customer: '华中重装设备有限公司(虚拟)',
|
||||||
|
code: 'H01-DEMO',
|
||||||
|
date: '2025-09(模拟)',
|
||||||
|
sets: 8,
|
||||||
|
days: 100,
|
||||||
|
price: 180000,
|
||||||
|
margin: 18,
|
||||||
|
costs: [
|
||||||
|
['物料', 60000],
|
||||||
|
['制造资源', 64000],
|
||||||
|
['专项直接费', 12000],
|
||||||
|
['间接费', 7600],
|
||||||
|
['风险准备', 4000],
|
||||||
|
],
|
||||||
|
scope: '8套内外套组件,含筒体、法兰、加强环、衬套、密封及紧固件;含制造、检测、防腐、包装运输及现场技术服务,不含主机与现场安装。',
|
||||||
|
materials: [
|
||||||
|
['内外套筒体', 'Q355B', '8套配套', '模拟图纸物料表'],
|
||||||
|
['法兰 / 加强环', 'Q355B', '8套配套', '模拟组件明细'],
|
||||||
|
['导向衬套 / 密封', '铜合金 / 密封组合', '8套配套', '模拟采购技术条款'],
|
||||||
|
['紧固件 / 焊材', '按工艺配套', '项目合计', '模拟工艺补充清单'],
|
||||||
|
],
|
||||||
|
process: [
|
||||||
|
['工艺深化', 32, 120],
|
||||||
|
['下料与坡口', 48, 95],
|
||||||
|
['卷制与组对', 80, 85],
|
||||||
|
['焊接', 192, 110],
|
||||||
|
['精加工', 144, 150],
|
||||||
|
['装配与试配', 48, 100],
|
||||||
|
['专项工装与过程协调', 16, 80],
|
||||||
|
],
|
||||||
|
milestones: [
|
||||||
|
['技术资料确认', '第1–10天'],
|
||||||
|
['采购与下料', '第11–35天'],
|
||||||
|
['组焊及机加工', '第36–80天'],
|
||||||
|
['检验、试配与交付', '第81–100天'],
|
||||||
|
],
|
||||||
|
terms: '模拟付款:30%预付、60%交付、10%质保;报价有效期30天;质保期12个月;运输与验收边界按技术协议。',
|
||||||
|
quality: '材料证明、焊接过程记录、尺寸检验报告及试配记录齐套;模拟案例设定为按100天计划交付。',
|
||||||
|
reason: '同类内外套组件结构与制造路径可参考;8套项目的单位成本受批量和固定工装分摊影响。18%为模拟成交利润率,不能直接套用本项目。',
|
||||||
|
risk: '焊接变形、精加工余量与外购件到货是主要风险;实际尺寸、净重、检验要求与价格需重新核定。',
|
||||||
|
},
|
||||||
|
H02: {
|
||||||
|
name: '高精度导向套制造项目',
|
||||||
|
customer: '长江精密装备有限公司(虚拟)',
|
||||||
|
code: 'H02-DEMO',
|
||||||
|
date: '2025-12(模拟)',
|
||||||
|
sets: 12,
|
||||||
|
days: 90,
|
||||||
|
price: 240000,
|
||||||
|
margin: 22,
|
||||||
|
costs: [
|
||||||
|
['物料', 72000],
|
||||||
|
['制造资源', 88000],
|
||||||
|
['专项直接费', 14000],
|
||||||
|
['间接费', 8200],
|
||||||
|
['风险准备', 5000],
|
||||||
|
],
|
||||||
|
scope: '12套高精度导向套及配套件,含采购、下料、热处理协同、精密加工、检测、装配及包装运输;不含主机及现场安装。',
|
||||||
|
materials: [
|
||||||
|
['导向套毛坯', '合金钢(模拟规格)', '12套', '模拟毛坯清单'],
|
||||||
|
['配合衬套', '铜合金(模拟规格)', '12套配套', '模拟装配明细'],
|
||||||
|
['密封 / 紧固件', '按配套清单', '12套配套', '模拟采购技术条款'],
|
||||||
|
],
|
||||||
|
process: [
|
||||||
|
['工艺与检验策划', 40, 120],
|
||||||
|
['毛坯下料及预加工', 80, 100],
|
||||||
|
['热处理协同及复检', 40, 120],
|
||||||
|
['精密车削', 200, 160],
|
||||||
|
['内孔精加工', 160, 180],
|
||||||
|
['装配检测', 80, 120],
|
||||||
|
],
|
||||||
|
milestones: [
|
||||||
|
['技术与精度要求确认', '第1–10天'],
|
||||||
|
['毛坯采购与预加工', '第11–30天'],
|
||||||
|
['精密加工及过程复检', '第31–70天'],
|
||||||
|
['装配验收与交付', '第71–90天'],
|
||||||
|
],
|
||||||
|
terms: '模拟付款:30%预付、60%交付、10%质保;报价有效期30天;质保期12个月;关键配合尺寸需双方确认。',
|
||||||
|
quality: '重点控制配合精度、圆度、同轴度和表面质量;数值公差以项目技术文件为准;模拟案例设定为按90天计划交付。',
|
||||||
|
reason: '精密加工与过程追溯工作量高,22%模拟利润率反映质量风险与服务投入。该项目结构与当前组件不同,仅用于比较加工强度及商业定位。',
|
||||||
|
risk: '毛坯稳定性、热处理变形、刀具消耗及重复检测影响工时;特殊精度与验收标准需要单独确认。',
|
||||||
|
},
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,436 @@
|
|||||||
|
// 确定性业务计算(对应原 calc/baseStrategies/competitorReference/strategies/issues 等)
|
||||||
|
import { HISTORY_CASES, offers } from './data'
|
||||||
|
import type { AnalysisCard, CompetitorQuote, State, StrategyCard } from './types'
|
||||||
|
import { REPORT_LOGO } from './reportLogo'
|
||||||
|
|
||||||
|
export const money = (n: number) =>
|
||||||
|
Number(n).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||||
|
|
||||||
|
export const num = (v: unknown, zero = false): number | null => {
|
||||||
|
const n = Number(v)
|
||||||
|
return Number.isFinite(n) && (zero ? n >= 0 : n > 0) && n < 1e9 ? n : null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fresh(): State {
|
||||||
|
return {
|
||||||
|
version: 1,
|
||||||
|
page: 0,
|
||||||
|
project: JSON.parse(JSON.stringify({
|
||||||
|
schema: 'wuchuan-quote-v1',
|
||||||
|
project: '重型装备伸缩支承内外套组件制造供货',
|
||||||
|
customer: '华中装备工程有限公司(虚构)',
|
||||||
|
code: 'RFQ-DEMO-2026-016',
|
||||||
|
delivery: 90,
|
||||||
|
sets: 10,
|
||||||
|
scope: '10套内外套组件(每套内套1件、外套1件),含采购、下料、成形、焊接、机加工、检测、防腐、包装运输及技术资料;不含主机、驱动装置及现场安装。',
|
||||||
|
terms: '预付款30%,工厂验收后发运前60%,到货验收后10%;质保12个月;报价有效期30天。',
|
||||||
|
materials: [
|
||||||
|
{ id: 'M001', name: '内套筒体 Q355B', unit: 'kg', qty: 2367.5, price: 5.2, ref: 'SIM-IS-01 序1;236.75kg×10', confidence: 96 },
|
||||||
|
{ id: 'M002', name: '内套法兰 Q355B', unit: 'kg', qty: 338.4, price: 5.4, ref: 'SIM-IS-01 序2;33.84kg×10', confidence: 93 },
|
||||||
|
{ id: 'M003', name: '内套加强环 Q355B', unit: 'kg', qty: 199.8, price: 5.3, ref: 'SIM-IS-01 序3;19.98kg×10', confidence: 91 },
|
||||||
|
{ id: 'M004', name: '外套筒体 Q355B', unit: 'kg', qty: 3334.2, price: 5.2, ref: 'SIM-OS-01 序1;333.42kg×10', confidence: 96 },
|
||||||
|
{ id: 'M005', name: '外套法兰 Q355B', unit: 'kg', qty: 526.5, price: 5.4, ref: 'SIM-OS-01 序2;52.65kg×10', confidence: 93 },
|
||||||
|
{ id: 'M006', name: '导向衬套 铜合金', unit: '件', qty: 20, price: 850, ref: '需求§3;2件×10', confidence: 85 },
|
||||||
|
{ id: 'M007', name: '密封组件', unit: '套', qty: 10, price: 420, ref: '需求§3;1套×10', confidence: 84 },
|
||||||
|
{ id: 'M008', name: '配套紧固件', unit: '套', qty: 10, price: 180, ref: '需求§3;1套×10', confidence: 88 },
|
||||||
|
],
|
||||||
|
resources: [
|
||||||
|
{ id: 'R01', name: '工艺深化', qty: 40, rate: 120, ref: '内部工艺 P01', note: '技术部门估算' },
|
||||||
|
{ id: 'R02', name: '下料与坡口', qty: 60, rate: 95, ref: '内部工艺 P02', note: '含人工、设备、能耗' },
|
||||||
|
{ id: 'R03', name: '卷制与组对', qty: 100, rate: 85, ref: '内部工艺 P03', note: '含人工、设备、能耗' },
|
||||||
|
{ id: 'R04', name: '焊接', qty: 240, rate: 110, ref: '模拟焊缝480m ÷ 2m/工时', note: '不含焊材;另列BOM' },
|
||||||
|
{ id: 'R05', name: '精加工', qty: 180, rate: 150, ref: '内外圆、端面与孔加工', note: '含人工、设备、能耗' },
|
||||||
|
{ id: 'R06', name: '装配与试配', qty: 60, rate: 100, ref: '内部工艺 P06', note: '含人工、设备、能耗' },
|
||||||
|
],
|
||||||
|
missing: { id: 'M009', name: '焊丝与焊剂配套', unit: 'kg', qty: 160, price: 8.5, ref: '需求§4文字补充;技术人工确认', confidence: 60 },
|
||||||
|
assumptions: '全部数量为10套项目合计。仅参考附件内套/外套主题,未核实附件尺寸材质。SIM图、重量、价格、工时均为演示假设;非生产依据。',
|
||||||
|
})),
|
||||||
|
materials: [],
|
||||||
|
resources: [],
|
||||||
|
parsed: false,
|
||||||
|
tech: false,
|
||||||
|
supply: false,
|
||||||
|
production: false,
|
||||||
|
review: false,
|
||||||
|
report: false,
|
||||||
|
approved: false,
|
||||||
|
selected: 1,
|
||||||
|
revision: 1,
|
||||||
|
floor: 15,
|
||||||
|
targets: [15, 20, 25],
|
||||||
|
other: { 检测: 6000, 防腐: 8000, 包装运输: 5000, 现场技术服务: 3000 },
|
||||||
|
overhead: 6,
|
||||||
|
risk: 3,
|
||||||
|
tax: 13,
|
||||||
|
context: '客户重视精加工质量与交付稳定性,建议采用平衡方案。',
|
||||||
|
quotes: {},
|
||||||
|
log: [],
|
||||||
|
files: [],
|
||||||
|
fileText: '',
|
||||||
|
clarified: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function calc(s: State) {
|
||||||
|
const material = s.materials.reduce((a, m) => a + m.qty * m.price, 0)
|
||||||
|
const process = s.resources.reduce((a, r) => a + r.qty * (r.rate || 0), 0)
|
||||||
|
const other = Object.values(s.other).reduce((a, b) => a + b, 0)
|
||||||
|
const direct = material + process + other
|
||||||
|
const overhead = (direct * s.overhead) / 100
|
||||||
|
const risk = ((direct + overhead) * s.risk) / 100
|
||||||
|
return { material, process, other, direct, overhead, risk, total: direct + overhead + risk }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function baseStrategies(s: State): StrategyCard[] {
|
||||||
|
const c = calc(s)
|
||||||
|
return s.targets.map((g, i) => {
|
||||||
|
const price = Math.ceil(c.total / (1 - g / 100) / 100) * 100
|
||||||
|
return {
|
||||||
|
label: ['A · 竞争优先', 'B · 综合平衡', 'C · 价值保障'][i],
|
||||||
|
g,
|
||||||
|
price,
|
||||||
|
profit: price - c.total,
|
||||||
|
margin: ((price - c.total) / price) * 100,
|
||||||
|
valid: g >= s.floor,
|
||||||
|
days: s.project.delivery,
|
||||||
|
reason: [
|
||||||
|
'以最低合规利润争取订单;价格让利,不削减技术范围。',
|
||||||
|
'覆盖质量与交付风险,兼顾客户接受度和利润空间。',
|
||||||
|
'以加工精度、过程追溯和服务价值支撑溢价;服务范围不变。',
|
||||||
|
][i],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function competitorQuote(s: State): CompetitorQuote {
|
||||||
|
return (
|
||||||
|
s.competitorQuote ?? {
|
||||||
|
name: '',
|
||||||
|
price: NaN,
|
||||||
|
taxMode: 'exclusive',
|
||||||
|
taxRate: s.tax,
|
||||||
|
sets: s.project.sets,
|
||||||
|
days: s.project.delivery,
|
||||||
|
position: 'balanced',
|
||||||
|
comparable: false,
|
||||||
|
source: '',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function competitorReference(
|
||||||
|
s: State,
|
||||||
|
): { used: false; status: string } | { used: true; price: number; q: CompetitorQuote; status: string } {
|
||||||
|
const q = competitorQuote(s)
|
||||||
|
if (!(Number.isFinite(q.price) && q.price > 0))
|
||||||
|
return { used: false, status: '尚未录入友商报价,沿用利润目标生成方案。' }
|
||||||
|
if (!q.comparable)
|
||||||
|
return { used: false, status: '友商供货范围尚未确认,仅展示信息,不用于调价。' }
|
||||||
|
if (q.sets !== s.project.sets || q.days !== s.project.delivery)
|
||||||
|
return { used: false, status: '友商数量或交期与当前项目不一致,仅供参考,不直接参与同口径定价。' }
|
||||||
|
const price = q.taxMode === 'inclusive' ? q.price / (1 + q.taxRate / 100) : q.price
|
||||||
|
if (!Number.isFinite(price) || price <= 0)
|
||||||
|
return { used: false, status: '友商报价口径无效,请复核。' }
|
||||||
|
return {
|
||||||
|
used: true,
|
||||||
|
price: Math.round(price * 100) / 100,
|
||||||
|
q,
|
||||||
|
status: '已按同范围、' + q.sets + '套、' + q.days + '天比较;友商不含税总价 ' + money(price) + ' 元。',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function strategies(s: State): StrategyCard[] {
|
||||||
|
const base = baseStrategies(s)
|
||||||
|
const ref = competitorReference(s)
|
||||||
|
if (!ref.used)
|
||||||
|
return base.map((x) => ({ ...x, reason: x.reason + (competitorQuote(s).price ? ' ' + ref.status : '') }))
|
||||||
|
const cost = calc(s).total
|
||||||
|
const floorPrice = Math.ceil(cost / (1 - s.floor / 100) / 100) * 100
|
||||||
|
const factors =
|
||||||
|
({ low: [0.995, 1.025, 1.08], balanced: [0.99, 1, 1.06], quality: [0.98, 0.99, 1.03] } as Record<string, number[]>)[
|
||||||
|
ref.q.position
|
||||||
|
] || [0.99, 1, 1.06]
|
||||||
|
const comp = ref.price
|
||||||
|
const baseline = base.map((x) => x.price)
|
||||||
|
const raw = [
|
||||||
|
Math.min(baseline[0], comp * factors[0]),
|
||||||
|
(baseline[1] + comp * factors[1]) / 2,
|
||||||
|
Math.max(baseline[2], comp * factors[2]),
|
||||||
|
]
|
||||||
|
const prices = raw.map((n) => Math.max(floorPrice, Math.ceil((n - 1e-7) / 100) * 100))
|
||||||
|
prices[1] = Math.max(prices[0], prices[1])
|
||||||
|
prices[2] = Math.max(prices[1], prices[2])
|
||||||
|
const labels: Record<string, string> = { low: '低价竞争', balanced: '综合平衡', quality: '质量与服务溢价' }
|
||||||
|
const below = comp < floorPrice
|
||||||
|
return base.map((x, i) => {
|
||||||
|
const price = prices[i]
|
||||||
|
const margin = price ? ((price - cost) / price) * 100 : 0
|
||||||
|
const gap = price - comp
|
||||||
|
const rule = [
|
||||||
|
'取利润目标基准价与友商参考价×' + factors[0] + '中较低值,再受利润底价约束。',
|
||||||
|
'将利润目标基准价与友商参考价×' + factors[1] + '取均值,再受利润底价约束。',
|
||||||
|
'取利润目标基准价与友商参考价×' + factors[2] + '中较高值,再受利润底价约束。',
|
||||||
|
][i]
|
||||||
|
return {
|
||||||
|
...x,
|
||||||
|
price,
|
||||||
|
profit: price - cost,
|
||||||
|
margin,
|
||||||
|
valid: x.g >= s.floor && margin + 1e-8 >= s.floor,
|
||||||
|
competition: { reference: comp, gap, floorPrice },
|
||||||
|
reason:
|
||||||
|
x.reason +
|
||||||
|
' 综合判定:目标利润率 ' +
|
||||||
|
x.g +
|
||||||
|
'%,利润底线 ' +
|
||||||
|
s.floor +
|
||||||
|
'%,底价 ' +
|
||||||
|
money(floorPrice) +
|
||||||
|
' 元;' +
|
||||||
|
(ref.q.name || '友商') +
|
||||||
|
'定位为“' +
|
||||||
|
labels[ref.q.position] +
|
||||||
|
'”,同口径不含税报价 ' +
|
||||||
|
money(comp) +
|
||||||
|
' 元。' +
|
||||||
|
rule +
|
||||||
|
' 本方案较友商' +
|
||||||
|
(gap >= 0 ? '高 ' : '低 ') +
|
||||||
|
money(Math.abs(gap)) +
|
||||||
|
' 元。' +
|
||||||
|
(below ? '友商报价低于本项目利润底价,不跟随至底线以下。' : '') +
|
||||||
|
'以上为离线规则推演,需经营复核。',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function issues(s: State) {
|
||||||
|
const a: string[] = []
|
||||||
|
if (!s.tech) a.push('技术清单未确认')
|
||||||
|
if (!s.materials.some((m) => m.id === 'M009')) a.push('遗漏:焊材未计入')
|
||||||
|
if (!s.materials.every((m) => s.quotes[m.id])) a.push('存在未选择供应商的物料')
|
||||||
|
if (s.materials.some((m) => s.quotes[m.id]?.days > s.project.delivery - 30))
|
||||||
|
a.push('采购交期超过最迟到料时间(总交期减制造预留30天)')
|
||||||
|
if (!s.supply) a.push('物供部门未提交')
|
||||||
|
if (!s.production) a.push('生产部门未提交')
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reportText(s: State) {
|
||||||
|
const c = calc(s)
|
||||||
|
const bom = s.materials.map((m) => `${m.id} ${m.name}:${m.qty} ${m.unit} × ${m.price}元;来源 ${m.ref}`).join('\n')
|
||||||
|
const proc = s.resources.map((r) => `${r.name}:${r.qty}h × ${r.rate}元/h`).join('\n')
|
||||||
|
return (
|
||||||
|
`<p align="center"><img src="${REPORT_LOGO}" height="auto" /></p>\n\n` +
|
||||||
|
`# 内外套组件项目成本测算报告\n\n项目:${s.project.project}\n成本版本:V${s.revision}\n数据性质:模拟,不作为正式报价或生产依据。\n\n` +
|
||||||
|
`|成本项|金额(人民币元,不含税)|\n|---|---:|\n|物料|${money(c.material)}|\n|制造资源|${money(c.process)}|\n|专项直接费|${money(c.other)}|\n|间接费|${money(c.overhead)}|\n|风险准备|${money(c.risk)}|\n|全成本|${money(c.total)}|\n\n` +
|
||||||
|
`数量${s.project.sets}套,单位成本${money(c.total / s.project.sets)}元。\n最低项目利润率${s.floor}%,底价=C/(1-r)=${money(c.total / (1 - s.floor / 100))}元。\n` +
|
||||||
|
`计算采用未四舍五入值,展示保留两位;报价向上取整到百元。\n风险:工程参数为模拟值,需复核原图、外购规格、工艺与价格有效期。\n\n## BOM\n` +
|
||||||
|
bom +
|
||||||
|
`\n\n## 工序\n` +
|
||||||
|
proc
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function quotationSignature(s: State) {
|
||||||
|
const a = strategies(s)[s.selected]
|
||||||
|
return JSON.stringify([
|
||||||
|
s.project, s.revision, s.selected, s.approvedAt, a.price, s.tax, s.materials, s.resources,
|
||||||
|
s.other, s.overhead, s.risk, s.floor, s.targets, s.context, ...(s.competitorQuote ? [s.competitorQuote] : []),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
export const esc = (x: unknown) =>
|
||||||
|
String(x ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c] as string))
|
||||||
|
|
||||||
|
export const htmlTable = (head: (string | number)[], rows: (string | number)[][]) =>
|
||||||
|
'<div class="table-scroll"><table><thead><tr>' + head.map((x) => `<th>${x}</th>`).join('') +
|
||||||
|
'</tr></thead><tbody>' + rows.map((r) => '<tr>' + r.map((x) => `<td>${x}</td>`).join('') + '</tr>').join('') + '</tbody></table></div>'
|
||||||
|
|
||||||
|
export function quoteHTML(s: State) {
|
||||||
|
const a = strategies(s)[s.selected]
|
||||||
|
const tax = +(a.price * s.tax / 100).toFixed(2)
|
||||||
|
return `<div class="quote-paper"><div class="quote-brand">武汉武船重型装备工程有限责任公司</div><h1>项目报价单</h1><p class="right">编号:QT-DEMO-2026-016-V${s.revision}<br>日期:${new Date().toLocaleDateString('zh-CN')}</p><p><b>致:${esc(s.project.customer)}</b></p><p>感谢贵司询价,现就“${esc(s.project.project)}”提交如下报价:</p>${htmlTable(['货物名称', '数量', '单位', '不含税单价(元)', '不含税金额(元)'], [['内外套组件制造供货', s.project.sets, '套', money(a.price / s.project.sets), money(a.price)]])}<p class="right">不含税总额:¥ ${money(a.price)}<br>税额(演示税率${s.tax}%):¥ ${money(tax)}<br><b>含税总额:人民币 ¥ ${money(a.price + tax)}</b></p><h3>供货范围</h3><p>${esc(s.project.scope)}</p><h3>交付及商务条件</h3><p>合同生效、预付款到账及技术资料确认后 ${s.project.delivery} 天交付。<br>${esc(s.project.terms)}</p><h3>技术依据与变更</h3><p>模拟需求RFQ-DEMO-2026-016及模拟图SIM-IS-01、SIM-OS-01。技术要求或供货范围发生变更时,需双方书面确认价格及交期调整。</p><p>报价联系人:项目经营部(待填写)<br>联系电话:待填写<br>授权签章:________________</p><p style="font-size:11px;border-top:1px solid #ddd;padding-top:15px">演示报价样张:项目、工程参数和价格为模拟数据,未经真实授权签章不得用于商务承诺。模板不包含内部成本、利润及供应商报价。</p></div>`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 报价智能体:自然语言检索与归因分析 =====
|
||||||
|
export function quotationHistoryRows(s: State, library: any[]) {
|
||||||
|
return allHistoryRows(s, library)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function baseFilteredQuotationRows(s: State, library: any[], f: Record<string, string>) {
|
||||||
|
if (f.from && f.to && f.from > f.to) return []
|
||||||
|
return allHistoryRows(s, library).filter(
|
||||||
|
(r: any) =>
|
||||||
|
(!f.project || String(r.project).toLowerCase().includes(f.project.toLowerCase())) &&
|
||||||
|
(!f.customer || String(r.customer).toLowerCase().includes(f.customer.toLowerCase())) &&
|
||||||
|
(!f.number || String(r.number).toLowerCase().includes(f.number.toLowerCase())) &&
|
||||||
|
(!f.from || r.date >= f.from) &&
|
||||||
|
(!f.to || r.date <= f.to),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function allHistoryRows(s: State, library: any[]) {
|
||||||
|
void s
|
||||||
|
return [
|
||||||
|
...library.map((r: any) => ({ ...r, kind: 'saved' })),
|
||||||
|
...Object.entries(HISTORY_CASES).map(([id, c]) => ({
|
||||||
|
id,
|
||||||
|
number: c.code,
|
||||||
|
project: c.name,
|
||||||
|
customer: c.customer,
|
||||||
|
date: c.date.startsWith('2025-09') ? '2025-09-01' : '2025-12-01',
|
||||||
|
sets: c.sets,
|
||||||
|
days: c.days,
|
||||||
|
price: c.price,
|
||||||
|
total: c.price * 1.13,
|
||||||
|
kind: 'example',
|
||||||
|
})),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findNaturalQuotation(s: State, library: any[], text: string) {
|
||||||
|
let rows: any[] = baseFilteredQuotationRows(s, library, { project: '', customer: '', number: '', from: '', to: '' })
|
||||||
|
const terms: string[] = []
|
||||||
|
const constraints: string[] = []
|
||||||
|
const numMatch = text.match(/(?:QT-[A-Z0-9-]+|H0[12](?:-DEMO)?|V\d+)/i)
|
||||||
|
if (numMatch) {
|
||||||
|
const value = numMatch[0].toLowerCase()
|
||||||
|
rows = rows.filter((r) => (r.number + ' ' + r.id).toLowerCase().includes(value))
|
||||||
|
constraints.push('编号 ' + numMatch[0])
|
||||||
|
}
|
||||||
|
const dates = [...text.matchAll(/(20\d{2})[-/年](\d{1,2})[-/月](\d{1,2})日?/g)].map(
|
||||||
|
(m) => m[1] + '-' + m[2].padStart(2, '0') + '-' + m[3].padStart(2, '0'),
|
||||||
|
)
|
||||||
|
if (dates.length >= 2) {
|
||||||
|
rows = rows.filter((r) => r.date >= dates[0] && r.date <= dates[1])
|
||||||
|
constraints.push(dates[0] + ' 至 ' + dates[1])
|
||||||
|
} else {
|
||||||
|
const year = text.match(/(20\d{2})年/)
|
||||||
|
if (year) {
|
||||||
|
rows = rows.filter((r) => r.date.startsWith(year[1]))
|
||||||
|
constraints.push('年份 ' + year[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const keys = ['内外套', '导向套', '筒体', '法兰', '精密', '高精度', '华中', '长江', '重型', '重装']
|
||||||
|
for (const k of keys) if (text.includes(k)) terms.push(k)
|
||||||
|
if (terms.length) {
|
||||||
|
rows = rows.filter((r) => {
|
||||||
|
const hay = r.project + ' ' + r.customer
|
||||||
|
return /或|任一/.test(text) ? terms.some((k) => hay.includes(k)) : terms.every((k) => hay.includes(k))
|
||||||
|
})
|
||||||
|
constraints.push('关键词 ' + terms.join('、'))
|
||||||
|
}
|
||||||
|
const amount = text.match(/(?:报价|金额|总价|不含税)[^\d]{0,8}(\d+(?:\.\d+)?)\s*(万)?(?:元)?\s*(以下|以内|低于|不超过|以上|高于|超过)/)
|
||||||
|
if (amount) {
|
||||||
|
const limit = Number(amount[1]) * (amount[2] ? 10000 : 1)
|
||||||
|
const above = /以上|高于|超过/.test(amount[3])
|
||||||
|
rows = rows.filter((r) => (above ? r.price >= limit : r.price <= limit))
|
||||||
|
constraints.push('不含税金额 ' + (above ? '≥' : '≤') + money(limit) + '元')
|
||||||
|
}
|
||||||
|
const days = text.match(/(?:交期|交付)[^\d]{0,5}(\d+)\s*天\s*(以内|以下|不超过|以上|超过)?/)
|
||||||
|
if (days) {
|
||||||
|
const d = Number(days[1])
|
||||||
|
const above = /以上|超过/.test(days[2] || '')
|
||||||
|
rows = rows.filter((r) => (above ? r.days >= d : r.days <= d))
|
||||||
|
constraints.push('交期 ' + (above ? '≥' : '≤') + d + '天')
|
||||||
|
}
|
||||||
|
const quoted = text.match(/[“「"]([^”」"]{2,60})[”」"]/)
|
||||||
|
if (quoted) {
|
||||||
|
rows = rows.filter((r) => (r.project + ' ' + r.customer + ' ' + r.number).includes(quoted[1]))
|
||||||
|
constraints.push('精确关键词 ' + quoted[1])
|
||||||
|
}
|
||||||
|
if (!constraints.length && !/全部|所有|查看项目|有哪些|历史报价|项目列表|报价列表/.test(text)) {
|
||||||
|
rows = []
|
||||||
|
constraints.push('未提取到支持的字段;可用引号指定客户或项目关键词')
|
||||||
|
}
|
||||||
|
return { rows, description: constraints.length ? constraints.join(';') : '全部历史报价' }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function quoteAnalysisFacts(s: State, library: any[], id: string) {
|
||||||
|
const r = allHistoryRows(s, library).find((x: any) => x.id === id)
|
||||||
|
if (!r) return null
|
||||||
|
const snapshot = library.find((x: any) => x.id === id)?.snapshot
|
||||||
|
const c = HISTORY_CASES[id]
|
||||||
|
let parts: [string, number][]
|
||||||
|
let resources: any[]
|
||||||
|
let risk: string
|
||||||
|
let scope: string
|
||||||
|
let source: string
|
||||||
|
if (snapshot) {
|
||||||
|
const material = snapshot.materials.reduce((n: number, m: any) => n + m.qty * m.price, 0)
|
||||||
|
const process = snapshot.resources.reduce((n: number, x: any) => n + x.qty * (x.rate || 0), 0)
|
||||||
|
const other = Object.values(snapshot.other).reduce((n: number, v: any) => n + v, 0)
|
||||||
|
const direct = material + process + other
|
||||||
|
const overhead = (direct * snapshot.overhead) / 100
|
||||||
|
const reserve = ((direct + overhead) * snapshot.risk) / 100
|
||||||
|
parts = [
|
||||||
|
['物料', material],
|
||||||
|
['制造资源', process],
|
||||||
|
['专项直接费', other],
|
||||||
|
['间接费', overhead],
|
||||||
|
['风险准备', reserve],
|
||||||
|
]
|
||||||
|
resources = snapshot.resources
|
||||||
|
risk = '归档中未包含实际采购、实耗工时、实际交付及售后问题数据。'
|
||||||
|
scope = snapshot.project.scope
|
||||||
|
source = r.number + ' / 归档快照'
|
||||||
|
} else {
|
||||||
|
parts = c!.costs
|
||||||
|
resources = c!.process.map((x, i) => ({ name: x[0], qty: x[1], rate: x[2], ref: c!.code + ' 工序' + (i + 1) }))
|
||||||
|
risk = c!.risk
|
||||||
|
scope = c!.scope
|
||||||
|
source = c!.code + ' / 内置模拟案例'
|
||||||
|
}
|
||||||
|
const cost = parts.reduce((n, x) => n + x[1], 0)
|
||||||
|
const margin = r.price ? ((r.price - cost) / r.price) * 100 : 0
|
||||||
|
const sorted = [...parts].sort((a, b) => b[1] - a[1])
|
||||||
|
const top = [...resources].sort((a, b) => b.qty * (b.rate || 0) - a.qty * (a.rate || 0))[0]
|
||||||
|
return { r, c, snapshot, parts, cost, margin, sorted, top, risk, scope, source }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildQuotationAnalysis(s: State, library: any[], id: string, question = ''): AnalysisCard[] {
|
||||||
|
const f = quoteAnalysisFacts(s, library, id)
|
||||||
|
if (!f) return []
|
||||||
|
const { r, c, snapshot, parts, cost, margin, sorted, top, risk, scope, source } = f
|
||||||
|
const largest = sorted[0]
|
||||||
|
const share = cost ? (largest[1] / cost) * 100 : 0
|
||||||
|
const missingRates = snapshot
|
||||||
|
? snapshot.resources.filter((x: any) => !Number.isFinite(x.rate) || x.rate <= 0).length
|
||||||
|
: 0
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
title: '01 项目基线与证据范围',
|
||||||
|
kind: 'fact',
|
||||||
|
text: r.project + ';' + r.sets + '套 / ' + r.days + '天;不含税报价 ' + money(r.price) + ' 元。分析依据为 ' + source + '。' + (question ? '本次关注:' + question : '本次关注成本结构与历史风险。'),
|
||||||
|
evidence: '报价编号、数量、交期、归档来源字段',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '02 成本结构:定位主要贡献项',
|
||||||
|
kind: 'fact',
|
||||||
|
text: '全成本 ' + money(cost) + ' 元;' + largest[0] + ' 为最大成本项,金额 ' + money(largest[1]) + ' 元,占全成本 ' + share.toFixed(1) + '%。' + (top ? '工序中“' + top.name + '”成本最高:' + top.qty + 'h × ' + money(top.rate || 0) + '元/h = ' + money(top.qty * (top.rate || 0)) + '元。' : ''),
|
||||||
|
bars: parts.map((x) => ({ name: x[0], value: x[1], share: cost ? (x[1] / cost) * 100 : 0 })),
|
||||||
|
evidence: parts.map((x) => x[0] + ' ' + money(x[1]) + '元').join(';'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '03 利润与费用口径核对',
|
||||||
|
kind: margin < 0 || missingRates ? 'attention' : 'fact',
|
||||||
|
text: '按(不含税报价 − 全成本)÷ 不含税报价计算,项目利润率为 ' + margin.toFixed(2) + '%。' + (snapshot ? '归档利润底线 ' + snapshot.floor + '%,' + (margin + 1e-7 < snapshot.floor ? '低于归档底线,需重点复核。' : '达到归档底线。') : '与案例记录 ' + c!.margin + '% 的模拟成交利润率一致。') + (missingRates ? ' 有 ' + missingRates + ' 道工序缺少有效费率,当前成本与利润不可作为完整测算结论。' : '税额单列,未计入利润。'),
|
||||||
|
evidence: '成本分项合计、报价金额、费率字段与利润率公式',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '04 历史问题与可能原因:区分事实和线索',
|
||||||
|
kind: 'hypothesis',
|
||||||
|
text: c ? '案例记录中的风险线索:' + risk + ' 这些属于示例风险说明,不是已发生的质量或延期事件。' : '现有快照可以定位成本集中环节,但缺少实际执行数据,不能确认超支、延期或质量问题已发生,更不能据此确定根因。',
|
||||||
|
evidence: c ? source + ' / 风险说明字段' : '归档仅含计划与报价字段,缺少实际结果及事件记录',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '05 建议核验路径',
|
||||||
|
kind: 'action',
|
||||||
|
text: '优先核验' + (top ? '“' + top.name + '”工序的实际工时、设备和能耗记录' : '制造资源实际工时') + ';核对采购订单与材料实际耗用;补充交付偏差、质量检验与返工记录,再将计划与实际逐项对比。当前可确认的是成本贡献,具体问题根因仍待证据验证。',
|
||||||
|
evidence: '供货范围:' + scope,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export { offers }
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,605 @@
|
|||||||
|
// 弹窗系统(对应原 modal/guide/openHistoricalCase/openQuotationLibrary/知识图谱/表单弹窗)
|
||||||
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||||
|
import { money, esc } from './logic'
|
||||||
|
import { HISTORY_CASES, kbRecords } from './data'
|
||||||
|
import type { Material, Resource, State } from './types'
|
||||||
|
import { useApp } from './store'
|
||||||
|
import { Btn, Notice, Table } from './components'
|
||||||
|
|
||||||
|
// ============ 知识图谱 ============
|
||||||
|
function materialNetworkData(s: State, type: 'material' | 'resource') {
|
||||||
|
const list: any[] = type === 'resource' ? (s.resources as any[]) : (s.materials as any[])
|
||||||
|
const sources: { key: string; known: boolean; x: number; y: number }[] = []
|
||||||
|
const nodes = list.map((m, i) => {
|
||||||
|
const record: any = (kbRecords as any)[type].find((r: any) => r.id === m.id && r.name === m.name && r.ref === m.ref)
|
||||||
|
const key = type === 'resource'
|
||||||
|
? (record ? (record.ref.includes('内部工艺') ? '内部工艺定额' : record.name.includes('焊接') ? '焊接工时依据' : '机加工工艺依据') : '上传 / 人工数据')
|
||||||
|
: record
|
||||||
|
? (record.ref.includes('SIM-IS') ? 'SIM-IS-01' : record.ref.includes('SIM-OS') ? 'SIM-OS-01' : record.ref.includes('§4') ? '需求书 §4' : '需求书 §3')
|
||||||
|
: '上传 / 人工数据'
|
||||||
|
let source = sources.findIndex((x) => x.key === key)
|
||||||
|
if (source < 0) { source = sources.length; sources.push({ key, known: !!record, x: 0, y: 0 }) }
|
||||||
|
const angle = -Math.PI / 2 + (i * Math.PI * 2) / Math.max(1, list.length)
|
||||||
|
return { m, record, source, x: 480 + 338 * Math.cos(angle), y: 248 + 174 * Math.sin(angle), i }
|
||||||
|
})
|
||||||
|
sources.forEach((src, i) => {
|
||||||
|
const a = -Math.PI / 2 + (i * Math.PI * 2) / sources.length
|
||||||
|
src.x = 480 + 147 * Math.cos(a)
|
||||||
|
src.y = 248 + 88 * Math.sin(a)
|
||||||
|
})
|
||||||
|
return { sources, nodes }
|
||||||
|
}
|
||||||
|
|
||||||
|
function NetworkSvg() {
|
||||||
|
const { s, flows, selectMaterialNetwork } = useApp()
|
||||||
|
const a = flows.materialNetwork
|
||||||
|
const type = a.type || 'material'
|
||||||
|
const { sources, nodes } = useMemo(() => materialNetworkData(s, type), [s, type])
|
||||||
|
const shown = a.done ? nodes.length : Math.max(0, a.stage - 1)
|
||||||
|
const visible = nodes.slice(0, shown)
|
||||||
|
const resource = type === 'resource'
|
||||||
|
return (
|
||||||
|
<svg viewBox="0 0 960 500" role="img"
|
||||||
|
aria-label={resource ? '项目与工艺依据、工时记录、工序的来源关系网络' : '项目与图纸、需求条款、物料的来源关系网络'}>
|
||||||
|
<defs>
|
||||||
|
<radialGradient id="networkBg"><stop stopColor="#233252" /><stop offset="1" stopColor="#0c1428" /></radialGradient>
|
||||||
|
<filter id="networkGlow"><feGaussianBlur stdDeviation="4" /></filter>
|
||||||
|
</defs>
|
||||||
|
<rect width="960" height="500" rx="12" fill="url(#networkBg)" />
|
||||||
|
<g fill="none" stroke="#5e79ad" strokeOpacity=".25" strokeDasharray="2 8">
|
||||||
|
<ellipse cx="480" cy="248" rx="338" ry="174" />
|
||||||
|
<ellipse cx="480" cy="248" rx="230" ry="129" />
|
||||||
|
<ellipse cx="480" cy="248" rx="147" ry="88" />
|
||||||
|
</g>
|
||||||
|
<g className="network-links">
|
||||||
|
{a.stage >= 1 && (
|
||||||
|
<>
|
||||||
|
{sources.map((src, i) => (
|
||||||
|
<path key={'s' + i} d={`M480 248 L${src.x} ${src.y}`} stroke="#50bfbd" strokeWidth="1.5" fill="none" opacity=".55" />
|
||||||
|
))}
|
||||||
|
{visible.map((n) => {
|
||||||
|
const src = sources[n.source]
|
||||||
|
return <path key={'n' + n.i} d={`M${src.x} ${src.y} Q480 248 ${n.x} ${n.y}`}
|
||||||
|
stroke={n.record ? '#55b9b0' : '#d9ac4e'} opacity=".45" fill="none" />
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</g>
|
||||||
|
<g fontFamily="Microsoft YaHei,Segoe UI" textAnchor="middle">
|
||||||
|
<circle cx="480" cy="248" r="41" fill="#8a79ff" opacity=".25" filter="url(#networkGlow)" />
|
||||||
|
<circle cx="480" cy="248" r="30" fill="#7160ce" stroke="#c6b8ff" />
|
||||||
|
<text x="480" y="245" fontSize="13" fill="white" fontWeight="700">当前项目</text>
|
||||||
|
<text x="480" y="262" fontSize="10" fill="#ece9ff">{resource ? '工艺资源关联' : '物料知识关联'}</text>
|
||||||
|
{a.stage >= 1 && sources.map((src, i) => (
|
||||||
|
<g key={'g' + i} className="network-node">
|
||||||
|
<circle cx={src.x} cy={src.y} r="16" fill="#163e50" stroke={src.known ? '#66d4c5' : '#e1b451'} strokeWidth="2" />
|
||||||
|
<circle cx={src.x} cy={src.y} r="5" fill={src.known ? '#66d4c5' : '#e1b451'} />
|
||||||
|
<text x={src.x} y={src.y + 31} fill="#a9e4dc" fontSize="12">{src.key}</text>
|
||||||
|
</g>
|
||||||
|
))}
|
||||||
|
{visible.map((n) => {
|
||||||
|
const active = a.selected === n.i && a.done
|
||||||
|
const color = n.record ? '#f18e84' : '#e3bc5b'
|
||||||
|
return (
|
||||||
|
<g key={'m' + n.i} className="network-node network-material" role="button" tabIndex={0}
|
||||||
|
aria-label={'查看 ' + n.m.name + ' 来源'}
|
||||||
|
style={{ cursor: 'pointer' }}
|
||||||
|
onClick={() => selectMaterialNetwork(n.i)}
|
||||||
|
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); selectMaterialNetwork(n.i) } }}>
|
||||||
|
<title>{n.m.name + ';来源:' + n.m.ref}</title>
|
||||||
|
<circle cx={n.x} cy={n.y} r="23" fill={color} opacity=".15" />
|
||||||
|
<circle cx={n.x} cy={n.y} r={active ? 16 : 12} fill={color} stroke={active ? '#fff' : color} strokeWidth="2" />
|
||||||
|
<text x={n.x} y={n.y + 34} fontSize="12" fill="#edf3ff">{n.m.name.length > 16 ? n.m.name.slice(0, 15) + '…' : n.m.name}</text>
|
||||||
|
<text x={n.x} y={n.y + 49} fontSize="10" fill="#92a9c9">{n.m.id}</text>
|
||||||
|
</g>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
<g textAnchor="start">
|
||||||
|
<circle cx="24" cy="477" r="4" fill="#8a79ff" /><text x="34" y="481" fill="#a8b8d5" fontSize="11">项目</text>
|
||||||
|
<circle cx="92" cy="477" r="4" fill="#66d4c5" /><text x="102" y="481" fill="#a8b8d5" fontSize="11">来源</text>
|
||||||
|
<circle cx="160" cy="477" r="4" fill="#f18e84" /><text x="170" y="481" fill="#a8b8d5" fontSize="11">{resource ? '匹配工序' : '匹配物料'}</text>
|
||||||
|
<circle cx="255" cy="477" r="4" fill="#e3bc5b" /><text x="265" y="481" fill="#a8b8d5" fontSize="11">待核验数据</text>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function MaterialNetworkModal() {
|
||||||
|
const { s, flows, replayKnowledgeNetwork } = useApp()
|
||||||
|
const a = flows.materialNetwork
|
||||||
|
const type = a.type || 'material'
|
||||||
|
const { sources, nodes } = useMemo(() => materialNetworkData(s, type), [s, type])
|
||||||
|
const resource = type === 'resource'
|
||||||
|
const n = nodes[a.selected]
|
||||||
|
const status = a.done
|
||||||
|
? `关联构建完成:${sources.length} 个${resource ? '工艺依据' : '来源'}节点 · ${nodes.length} ${resource ? '道工序' : '项物料'} · ${sources.length + nodes.length} 条关联。点击${resource ? '工序' : '物料'}节点核对详情。`
|
||||||
|
: a.stage === 0
|
||||||
|
? (resource ? '索引检索 Agent:读取当前项目与工艺资源索引…' : '索引检索 Agent:读取当前项目与物料索引…')
|
||||||
|
: a.stage === 1
|
||||||
|
? (resource ? '关系映射 Agent:建立工艺定额与工时依据节点…' : '关系映射 Agent:建立图纸与需求条款来源节点…')
|
||||||
|
: shown2() < nodes.length
|
||||||
|
? `关系映射 Agent:逐项关联${resource ? '工序' : '物料'} ${shown2()} / ${nodes.length}…`
|
||||||
|
: (resource ? '来源校核 Agent:核对工时、综合费率与计价口径…' : '来源校核 Agent:比对记录与当前用量,整理追溯信息…')
|
||||||
|
|
||||||
|
function shown2() { return a.done ? nodes.length : Math.max(0, a.stage - 1) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="material-network">
|
||||||
|
<div className="network-toolbar">
|
||||||
|
<div>
|
||||||
|
<b>✦ AI {resource ? '工艺资源' : '数据'}关联网络</b>
|
||||||
|
<small>{resource ? '项目 → 工艺依据 / 工时记录 → 工序资源 → 来源核对' : '项目 → 图纸 / 需求条款 → 物料 → 来源核对'}</small>
|
||||||
|
</div>
|
||||||
|
<Btn t="↻ 重播构建" onClick={replayKnowledgeNetwork} />
|
||||||
|
</div>
|
||||||
|
<div className="network-agents">
|
||||||
|
<span>01 索引检索 Agent</span><span>02 关系映射 Agent</span><span>03 来源校核 Agent</span>
|
||||||
|
</div>
|
||||||
|
<div className="network-canvas-wrap"><NetworkSvg /></div>
|
||||||
|
<div className="network-status" role="status">{status}</div>
|
||||||
|
<p className="network-boundary">
|
||||||
|
{resource
|
||||||
|
? '离线关联演示:依据当前工序、内置工艺记录与工时来源字段构建,未连接企业实际工艺库;未匹配记录显示为上传 / 人工数据。'
|
||||||
|
: '离线关联演示:图谱依据当前物料及内置来源字段构建;未匹配记录显示为上传 / 人工数据。'}
|
||||||
|
</p>
|
||||||
|
{n ? (
|
||||||
|
resource ? <ResourceNetworkDetail r={n.m as Resource} record={n.record} /> : <MaterialNetworkDetail m={n.m as Material} record={n.record} />
|
||||||
|
) : (
|
||||||
|
<Notice t={resource ? '暂无工艺资源记录。' : '暂无物料记录。'} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function MaterialNetworkDetail({ m, record }: { m: Material; record?: any }) {
|
||||||
|
const { s, flows, selectMaterialNetwork } = useApp()
|
||||||
|
const ref = m.ref || '待补充'
|
||||||
|
const doc = record ? (ref.includes('SIM-IS') ? '/mod-assets/wuc-quotation/模拟内套图.svg' : ref.includes('SIM-OS') ? '/mod-assets/wuc-quotation/模拟外套图.svg' : '/mod-assets/wuc-quotation/客户需求书.md') : null
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="kg-items">
|
||||||
|
{s.materials.map((r, i) => (
|
||||||
|
<Btn key={r.id + i} t={r.id} onClick={() => selectMaterialNetwork(i)} cls={flows.materialNetwork.selected === i ? 'primary' : ''} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="kg-detail network-detail">
|
||||||
|
<span className={'chip ' + (record ? 'purple' : 'amber')}>{record ? '本地示例记录匹配' : '未匹配内置记录 / 人工数据'}</span>
|
||||||
|
<h3>{m.id} · {m.name}</h3>
|
||||||
|
<p>来源关联:{ref}</p>
|
||||||
|
<Table head={['字段', '来源记录值', '当前清单值']} rows={[
|
||||||
|
['用量', record ? `${record.qty} ${record.unit}` : '未匹配', `${m.qty} ${m.unit}`],
|
||||||
|
['参考单价', record ? money(record.price) + ' 元' : '未匹配', money(m.price) + ' 元'],
|
||||||
|
['成本口径', '用量 × 单价', money(m.qty * m.price) + ' 元'],
|
||||||
|
]} />
|
||||||
|
{doc
|
||||||
|
? <a className="kg-link" href={doc} target="_blank" rel="noopener">打开来源文件 ↗</a>
|
||||||
|
: <Notice cls="warn" t="请技术人员补充原始依据,此条目不声称历史匹配。" />}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ResourceNetworkDetail({ r, record }: { r: Resource; record?: any }) {
|
||||||
|
const { s, flows, selectMaterialNetwork } = useApp()
|
||||||
|
const hasRate = r.rate != null && Number.isFinite(r.rate) && r.rate > 0
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="kg-items">
|
||||||
|
{s.resources.map((item, i) => (
|
||||||
|
<Btn key={item.id + i} t={item.id} onClick={() => selectMaterialNetwork(i)} cls={flows.materialNetwork.selected === i ? 'primary' : ''} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="kg-detail network-detail">
|
||||||
|
<span className={'chip ' + (record ? 'purple' : 'amber')}>{record ? '本地工艺示例记录匹配' : '未匹配内置记录 / 人工数据'}</span>
|
||||||
|
<h3>{r.id} · {r.name}</h3>
|
||||||
|
<p>工时来源:{r.ref || '待补充'}</p>
|
||||||
|
<Table head={['字段', '来源记录值', '当前清单值']} rows={[
|
||||||
|
['计划工时', record ? record.qty + ' h' : '未匹配', r.qty + ' h'],
|
||||||
|
['综合费率', record ? money(record.rate) + ' 元/h' : '未匹配', hasRate ? money(r.rate!) + ' 元/h' : '待核价'],
|
||||||
|
['工序成本', record ? money(record.qty * record.rate) + ' 元' : '未匹配', hasRate ? money(r.qty * (r.rate || 0)) + ' 元' : '待核价'],
|
||||||
|
['工艺说明', record ? record.note || '待补充' : '未匹配', r.note || '待补充'],
|
||||||
|
]} />
|
||||||
|
<Notice cls="warn" t={record
|
||||||
|
? '来源为DEMO内置工艺与工时估算记录,未连接真实历史工单;工时与费率仍需生产部门复核。'
|
||||||
|
: '此工序为上传或人工补充记录,请补充工艺文件、工时定额及费率依据,不自动声称历史匹配。'} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 历史案例 ============
|
||||||
|
function HistoricalCaseModal({ id }: { id: string }) {
|
||||||
|
const { s, openModal, closeModal } = useApp()
|
||||||
|
const c = HISTORY_CASES[id]
|
||||||
|
if (!c) return null
|
||||||
|
const total = c.costs.reduce((sum, x) => sum + x[1], 0)
|
||||||
|
const profit = c.price - total
|
||||||
|
const manufacturing = c.process.reduce((sum, x) => sum + x[1] * x[2], 0)
|
||||||
|
void manufacturing
|
||||||
|
return (
|
||||||
|
<div className="history-case-detail">
|
||||||
|
<Notice cls="warn" t="DEMO模拟案例:以下项目、客户、金额、工序与履约信息均为演示补充数据,并非真实合同或历史档案。仅供报价参考,不自动带入当前项目。" />
|
||||||
|
<h3>项目概况</h3>
|
||||||
|
<Table head={['字段', '案例信息']} rows={[
|
||||||
|
['案例编号 / 版本', c.code + ' / DEMO V1'],
|
||||||
|
['项目名称', c.name],
|
||||||
|
['客户', c.customer],
|
||||||
|
['案例时间', c.date],
|
||||||
|
['数量 / 交期', `${c.sets}套 / ${c.days}天`],
|
||||||
|
['记录来源', `本地内置案例记录 ${id};未连接企业历史项目库`],
|
||||||
|
]} />
|
||||||
|
<h3>供货范围与技术要求</h3>
|
||||||
|
<p>{c.scope}</p>
|
||||||
|
<p>{c.quality}</p>
|
||||||
|
<h3>物料与依据</h3>
|
||||||
|
<Table head={['物料', '规格', '数量口径', '依据(模拟)']} rows={c.materials} />
|
||||||
|
<h3>制造工艺与资源</h3>
|
||||||
|
<Table head={['工序', '计划工时 h', '综合费率 元/h', '成本 元']}
|
||||||
|
rows={c.process.map((r) => [r[0], r[1], money(r[2]), money(r[1] * r[2])])} />
|
||||||
|
<h3>成本与成交报价</h3>
|
||||||
|
<Table head={['项目', '金额 / 口径']} rows={[
|
||||||
|
...c.costs.map((r) => [r[0], money(r[1]) + ' 元']),
|
||||||
|
['项目全成本', money(total) + ' 元'],
|
||||||
|
['不含税成交总价', money(c.price) + ' 元'],
|
||||||
|
['不含税单位报价', money(c.price / c.sets) + ' 元/套'],
|
||||||
|
['项目利润', money(profit) + ' 元'],
|
||||||
|
['实际项目利润率', ((profit / c.price) * 100).toFixed(2) + '%'],
|
||||||
|
['模拟税额(13%)', money(c.price * 0.13) + ' 元'],
|
||||||
|
['模拟含税总额', money(c.price * 1.13) + ' 元'],
|
||||||
|
]} />
|
||||||
|
<h3>交付计划与商务条件</h3>
|
||||||
|
<Table head={['里程碑', '计划周期']} rows={c.milestones} />
|
||||||
|
<p>{c.terms}</p>
|
||||||
|
<h3>报价参考与差异</h3>
|
||||||
|
<p>{c.reason}</p>
|
||||||
|
<p>{c.risk}</p>
|
||||||
|
<Table head={['比较项', '历史案例', '当前项目']} rows={[
|
||||||
|
['数量', c.sets + '套', s.project.sets + '套'],
|
||||||
|
['交期', c.days + '天', s.project.delivery + '天'],
|
||||||
|
['成本基准', money(total) + ' 元(模拟)', money(s.materials.reduce((a, m) => a + m.qty * m.price, 0) + s.resources.reduce((a, r) => a + r.qty * (r.rate || 0), 0)) + ' 元(当前清单,未含专项与间接费)'],
|
||||||
|
['利润率参考', c.margin + '%(模拟成交)', s.floor + '%(硬性底线)'],
|
||||||
|
]} />
|
||||||
|
<div className="actions section">
|
||||||
|
<Btn t={'查看 ' + (id === 'H01' ? 'H02' : 'H01') + ' 案例'}
|
||||||
|
onClick={() => openModal('case', '历史案例 ' + (id === 'H01' ? 'H02' : 'H01') + ' / 完整项目参考', id === 'H01' ? 'H02' : 'H01')} />
|
||||||
|
<Btn t="关闭" onClick={closeModal} cls="primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 历史报价信息库 / 报价智能体 ============
|
||||||
|
function QuoteAgentProgress() {
|
||||||
|
const { flows } = useApp()
|
||||||
|
const a = flows.quoteAssistant
|
||||||
|
if (!a.mode) return null
|
||||||
|
const steps = a.mode === 'analysis'
|
||||||
|
? ['读取归档字段', '核算成本结构', '核对风险依据', '整理分析结论']
|
||||||
|
: ['理解查询条件', '检索本地记录', '核对项目字段', '逐项展示结果']
|
||||||
|
return (
|
||||||
|
<div className="quote-agent-progress">
|
||||||
|
<b>{a.running ? '● Agent 协同处理中' : a.cancelled ? '处理已停止' : a.mode === 'analysis' ? '分析已完成' : '检索已完成'}</b>
|
||||||
|
{steps.map((t, i) => (
|
||||||
|
<div key={i} className={i < a.stage ? 'done' : i === a.stage && a.running ? 'active' : ''}>
|
||||||
|
<span>{i < a.stage ? '✓' : '0' + (i + 1)}</span>{t}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<small>展示检索与计算步骤,不代表外部模型实时调用。</small>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function QuoteAgentAnalysis() {
|
||||||
|
const { flows, library } = useApp()
|
||||||
|
const a = flows.quoteAssistant
|
||||||
|
void library
|
||||||
|
if (!a.analysis.length) {
|
||||||
|
return (
|
||||||
|
<div className="quote-analysis-idle">
|
||||||
|
<span>◈</span>
|
||||||
|
<div><b>选择一个项目,开启证据驱动的归因分析</b><p>逐项呈现成本结构、风险线索和待核验依据。</p></div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const shown = a.analysis.slice(0, a.analysisCount)
|
||||||
|
const kindLabel: Record<string, string> = { fact: '可核算事实', attention: '需复核', hypothesis: '风险线索 / 非因果结论', action: '核验建议' }
|
||||||
|
return (
|
||||||
|
<section className="quote-analysis-panel">
|
||||||
|
<div className="quote-analysis-heading">
|
||||||
|
<div><small>PROJECT DIAGNOSTICS</small><h3>{a.analysisTitle}</h3></div>
|
||||||
|
<span className="chip purple">{a.running && a.mode === 'analysis' ? '正在构建分析' : '分析记录'}</span>
|
||||||
|
</div>
|
||||||
|
{!shown.length
|
||||||
|
? <div className="kb-empty">正在读取项目档案与成本字段…</div>
|
||||||
|
: shown.map((x, i) => (
|
||||||
|
<article key={i} className={'quote-analysis-card ' + x.kind}>
|
||||||
|
<span className="chip">{kindLabel[x.kind]}</span>
|
||||||
|
<h3>{x.title}</h3>
|
||||||
|
<p>{x.text}</p>
|
||||||
|
{x.bars && (
|
||||||
|
<div className="quote-cost-bars">
|
||||||
|
{x.bars.map((b, j) => (
|
||||||
|
<div key={j}>
|
||||||
|
<span>{b.name}</span>
|
||||||
|
<i><em style={{ width: b.share.toFixed(2) + '%' }} /></i>
|
||||||
|
<strong>{money(b.value)}</strong>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="quote-evidence"><b>依据</b> {x.evidence}</div>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function QuotationLibraryModal() {
|
||||||
|
const {
|
||||||
|
library, filters, setFilters, flows, useQuoteAgentPrompt, runQuoteAgentQuery,
|
||||||
|
analyzeSelectedQuotation, selectAgentQuotation, showAllAgentQuotes, openModal,
|
||||||
|
} = useApp()
|
||||||
|
const a = flows.quoteAssistant
|
||||||
|
const [input, setInput] = useState('')
|
||||||
|
const messagesRef = useRef<HTMLDivElement>(null)
|
||||||
|
const messages = a.messages.length ? a.messages : [{ role: 'assistant' as const, text: '你好,我可以帮你查找历史报价,并对选中项目核算成本结构、梳理风险依据。可按项目、客户、编号、年份、金额和交期查找。' }]
|
||||||
|
useEffect(() => {
|
||||||
|
const el = messagesRef.current
|
||||||
|
if (el) el.scrollTop = el.scrollHeight
|
||||||
|
}, [a.messages.length, a.stage, a.analysisCount])
|
||||||
|
|
||||||
|
let rows = filters.from && filters.to && filters.from > filters.to ? [] : libraryAll()
|
||||||
|
function libraryAll() {
|
||||||
|
const saved = library.map((r) => ({ ...r, kind: 'saved' }))
|
||||||
|
const examples = Object.entries(HISTORY_CASES).map(([id, c]) => ({
|
||||||
|
id, number: c.code, project: c.name, customer: c.customer,
|
||||||
|
date: c.date.startsWith('2025-09') ? '2025-09-01' : '2025-12-01',
|
||||||
|
sets: c.sets, days: c.days, price: c.price, total: c.price * 1.13, kind: 'example',
|
||||||
|
}))
|
||||||
|
return [...saved, ...examples]
|
||||||
|
}
|
||||||
|
if (a.ids !== null) rows = rows.filter((r: any) => a.ids!.includes(r.id))
|
||||||
|
const shown = a.mode === 'search' && a.running ? rows.slice(0, a.revealed) : rows
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="quote-agent-workspace">
|
||||||
|
<aside className="quote-agent-sidebar">
|
||||||
|
<div className="quote-agent-brand">
|
||||||
|
<span>✦</span>
|
||||||
|
<div><b>历史报价智能助手</b><small>检索项目 · 核对依据 · 归因线索</small></div>
|
||||||
|
</div>
|
||||||
|
<div className="quote-agent-note">基于本机报价快照与内置示例分析。自然语言由本地规则解析,未连接外部大模型。</div>
|
||||||
|
<div className="quote-agent-messages" ref={messagesRef}>
|
||||||
|
{messages.map((m, i) => (
|
||||||
|
<div className={'quote-agent-bubble ' + m.role} key={i}>
|
||||||
|
<small>{m.role === 'user' ? '你的需求' : '✦ 报价智能助手'}</small>
|
||||||
|
<p>{m.text}</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<QuoteAgentProgress />
|
||||||
|
<div className="quote-agent-prompts">
|
||||||
|
{['查找2025年的导向套项目', '查找交期90天以内的项目', '查找不含税报价20万元以下的项目'].map((t, i) => (
|
||||||
|
<Btn key={i} t={t} onClick={() => { setInput(t); useQuoteAgentPrompt(i) }} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<label className="quote-agent-input-label" htmlFor="qAgentInput">用自然语言查找或分析项目</label>
|
||||||
|
<textarea id="qAgentInput" rows={3} maxLength={600} value={input}
|
||||||
|
placeholder="例如:查找内外套项目;分析 H01 的成本与历史风险"
|
||||||
|
onChange={(e) => setInput(e.target.value)}
|
||||||
|
onKeyDown={(e) => { if (e.key === 'Enter' && !e.shiftKey && !(e as any).isComposing) { e.preventDefault(); runQuoteAgentQuery(input); setInput('') } }} />
|
||||||
|
<div className="actions quote-agent-send">
|
||||||
|
<Btn t="✦ 发送并检索" onClick={() => { runQuoteAgentQuery(input); setInput('') }} cls="primary" />
|
||||||
|
<Btn t="分析选中项目" onClick={() => analyzeSelectedQuotation()} />
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
<section className="quote-agent-main">
|
||||||
|
<div className="quote-agent-heading">
|
||||||
|
<div>
|
||||||
|
<div className="eyebrow">QUOTATION INTELLIGENCE</div>
|
||||||
|
<h2>历史项目与报价证据</h2>
|
||||||
|
<p>先定位项目,再核对成本与风险依据。</p>
|
||||||
|
</div>
|
||||||
|
<Btn t="查看全部" onClick={showAllAgentQuotes} />
|
||||||
|
</div>
|
||||||
|
<details className="quote-agent-filters">
|
||||||
|
<summary>精确筛选 · 项目 / 客户 / 编号 / 日期</summary>
|
||||||
|
<div className="quotation-search">
|
||||||
|
{([['project', '项目名称', 'text'], ['customer', '客户名称', 'text'], ['number', '报价编号', 'text'], ['from', '开始日期', 'date'], ['to', '结束日期', 'date']] as const).map(([key, label, type]) => (
|
||||||
|
<label key={key}>{label}
|
||||||
|
<input type={type} value={filters[key]} onChange={(e) => setFilters((f) => ({ ...f, [key]: e.target.value.trim() }))} />
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
<div className="quote-result-heading">
|
||||||
|
<b>项目匹配结果 <span>{shown.length}</span></b>
|
||||||
|
<small>本机快照 {library.length} 条 · 示例 2 条</small>
|
||||||
|
</div>
|
||||||
|
{filters.from && filters.to && filters.from > filters.to
|
||||||
|
? <Notice cls="warn" t="开始日期不得晚于结束日期。" />
|
||||||
|
: shown.length ? (
|
||||||
|
<div className="quote-project-grid">
|
||||||
|
{shown.map((r: any) => (
|
||||||
|
<article className={'quote-project-card ' + (a.selected === r.id ? 'is-selected' : '')} key={r.id}>
|
||||||
|
<div className="quote-project-top">
|
||||||
|
<span className={'chip ' + (r.kind === 'saved' ? 'purple' : '')}>{r.kind === 'saved' ? '本机归档快照' : 'DEMO参考案例'}</span>
|
||||||
|
<small>{r.date}</small>
|
||||||
|
</div>
|
||||||
|
<h3>{r.project}</h3>
|
||||||
|
<p>{r.customer}</p>
|
||||||
|
<small className="muted">{r.number} · {r.sets}套 · {r.days}天</small>
|
||||||
|
<div className="quote-project-price"><strong>¥ {money(r.price)}</strong><span>不含税总价</span></div>
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t={a.selected === r.id ? '✓ 已选中' : '选择项目'} onClick={() => selectAgentQuotation(r.id)} cls={a.selected === r.id ? 'primary' : ''} />
|
||||||
|
<Btn t="归因分析" onClick={() => analyzeSelectedQuotation(r.id)} />
|
||||||
|
<Btn t="完整档案" onClick={() => openHistoryDetail(r.id)} />
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : a.running && a.mode === 'search' ? (
|
||||||
|
<div className="quote-search-empty">
|
||||||
|
<span className="quote-agent-orbit">✦</span>
|
||||||
|
<b>AI 正在检索报价记录</b>
|
||||||
|
<p>匹配结果将逐项展示…</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="kb-empty">未找到符合条件的报价,请调整自然语言或筛选条件。</div>
|
||||||
|
)}
|
||||||
|
<QuoteAgentAnalysis />
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
function openHistoryDetail(id: string) {
|
||||||
|
const r = library.find((x) => x.id === id)
|
||||||
|
if (!r) {
|
||||||
|
if (HISTORY_CASES[id]) openModal('case', '历史案例 ' + id + ' / 完整项目参考', id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
openModal('historyDetail', '历史报价详情 / ' + r.number, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function QuotationHistoryDetail({ id }: { id: string }) {
|
||||||
|
const { library, openModal } = useApp()
|
||||||
|
const r = library.find((x) => x.id === id)
|
||||||
|
if (!r) return null
|
||||||
|
const snap = r.snapshot
|
||||||
|
const material = snap.materials.reduce((sum, m) => sum + m.qty * m.price, 0)
|
||||||
|
const process = snap.resources.reduce((sum, x) => sum + x.qty * (x.rate || 0), 0)
|
||||||
|
return (
|
||||||
|
<div className="quotation-history-detail">
|
||||||
|
<div className="actions"><Btn t="← 返回历史报价信息库" onClick={() => openModal('library', '历史报价信息库 / AI智能体工作台')} /></div>
|
||||||
|
<Notice t={'归档快照:' + esc(r.date) + '入库 · V' + esc(r.revision) + ' · 此处数据固定为入库时内容,不随当前项目修改。'} />
|
||||||
|
<Table head={['归档字段', '信息']} rows={[
|
||||||
|
['项目', snap.project.project],
|
||||||
|
['客户', snap.project.customer],
|
||||||
|
['报价编号', r.number],
|
||||||
|
['数量 / 交期', `${r.sets}套 / ${r.days}天`],
|
||||||
|
['批准策略', r.strategy],
|
||||||
|
['批准时间', r.approvedAt || ''],
|
||||||
|
['不含税 / 含税总额', `${money(r.price)} 元 / ${money(r.total)} 元`],
|
||||||
|
['税率', r.tax + '%'],
|
||||||
|
['供货范围', snap.project.scope],
|
||||||
|
['商务条件', snap.project.terms],
|
||||||
|
['项目补充说明', snap.context],
|
||||||
|
...(snap.competitorQuote ? [
|
||||||
|
['友商报价参考', `${snap.competitorQuote.name || '友商'} / ${money(snap.competitorQuote.price)} 元(${snap.competitorQuote.taxMode === 'inclusive' ? '含税' : '不含税'})`],
|
||||||
|
['友商数量 / 交期', `${snap.competitorQuote.sets}套 / ${snap.competitorQuote.days}天`],
|
||||||
|
['友商信息来源', snap.competitorQuote.source || '未填写'],
|
||||||
|
] : []),
|
||||||
|
]} />
|
||||||
|
<h3 className="section">入库报价单原件</h3>
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: r.html }} />
|
||||||
|
<h3 className="section">内部物料依据</h3>
|
||||||
|
<Table head={['物料号', '物料', '用量', '单价', '金额', '来源']}
|
||||||
|
rows={snap.materials.map((m) => [m.id, m.name, `${m.qty} ${m.unit}`, money(m.price), money(m.qty * m.price), m.ref])} />
|
||||||
|
<h3 className="section">内部工艺资源</h3>
|
||||||
|
<Table head={['工序', '工时', '费率', '金额', '来源']}
|
||||||
|
rows={snap.resources.map((x) => [x.name, x.qty, money(x.rate || 0), money(x.qty * (x.rate || 0)), x.ref])} />
|
||||||
|
<p>物料合计:{money(material)} 元;工艺资源合计:{money(process)} 元。</p>
|
||||||
|
<Table head={['补充成本 / 参数', '归档值']} rows={[
|
||||||
|
...Object.entries(snap.other).map(([k, v]) => [k, money(v) + ' 元']),
|
||||||
|
['间接费率', snap.overhead + '%'],
|
||||||
|
['风险准备', snap.risk + '%'],
|
||||||
|
['利润底线', snap.floor + '%'],
|
||||||
|
]} />
|
||||||
|
<div className="actions section">
|
||||||
|
<Btn t="返回历史报价信息库" onClick={() => openModal('library', '历史报价信息库 / AI智能体工作台')} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 简单表单弹窗 ============
|
||||||
|
function NewMaterialModal() {
|
||||||
|
const { submitMaterial, closeModal } = useApp()
|
||||||
|
const [name, setName] = useState('人工补充物料')
|
||||||
|
const [qty, setQty] = useState('1')
|
||||||
|
const [unit, setUnit] = useState('件')
|
||||||
|
const [price, setPrice] = useState('100')
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<label>名称 <input value={name} onChange={(e) => setName(e.target.value)} /></label>
|
||||||
|
<div className="formrow">
|
||||||
|
数量 <input type="number" value={qty} onChange={(e) => setQty(e.target.value)} />
|
||||||
|
单位 <input value={unit} onChange={(e) => setUnit(e.target.value)} />
|
||||||
|
单价 <input type="number" value={price} onChange={(e) => setPrice(e.target.value)} />
|
||||||
|
</div>
|
||||||
|
<div className="actions">
|
||||||
|
<button className="primary" onClick={() => submitMaterial({ name, unit, qty, price })}>保存并纳入成本</button>
|
||||||
|
<Btn t="取消" onClick={closeModal} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function NewResourceModal() {
|
||||||
|
const { submitResource, closeModal } = useApp()
|
||||||
|
const [name, setName] = useState('')
|
||||||
|
const [ref, setRef] = useState('')
|
||||||
|
const [qty, setQty] = useState('1')
|
||||||
|
const [note, setNote] = useState('')
|
||||||
|
return (
|
||||||
|
<div className="resource-form">
|
||||||
|
<label>工序名称 <input maxLength={100} placeholder="例如:表面处理" value={name} onChange={(e) => setName(e.target.value)} /></label>
|
||||||
|
<label>工时来源 <input maxLength={240} placeholder="例如:技术人工估算 / 工艺文件编号" value={ref} onChange={(e) => setRef(e.target.value)} /></label>
|
||||||
|
<label>计划工时(h) <input type="number" min="0.01" step="0.01" value={qty} onChange={(e) => setQty(e.target.value)} /></label>
|
||||||
|
<label>工序说明(选填) <input maxLength={240} placeholder="填写工序范围或补充说明" value={note} onChange={(e) => setNote(e.target.value)} /></label>
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t="保存工序" onClick={() => submitResource({ name, ref, qty, note })} cls="primary" />
|
||||||
|
<Btn t="取消" onClick={closeModal} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function PreviewModal({ payload }: { payload: { url: string; name: string; pdf: boolean } }) {
|
||||||
|
return payload.pdf
|
||||||
|
? <iframe title="PDF预览" src={payload.url} width="100%" height="520" />
|
||||||
|
: <img alt="上传图纸" src={payload.url} style={{ maxWidth: '100%' }} />
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 弹窗宿主 ============
|
||||||
|
export function ModalHost() {
|
||||||
|
const { modal, closeModal } = useApp()
|
||||||
|
const dlg = useRef<HTMLDialogElement>(null)
|
||||||
|
useEffect(() => {
|
||||||
|
const el = dlg.current
|
||||||
|
if (!el) return
|
||||||
|
if (modal.open && !el.open) el.showModal()
|
||||||
|
if (!modal.open && el.open) el.close()
|
||||||
|
}, [modal.open])
|
||||||
|
const cls = modal.kind === 'library' ? 'quote-agent-dialog quotation-library-dialog'
|
||||||
|
: modal.kind === 'network' ? 'material-network-dialog' : ''
|
||||||
|
return (
|
||||||
|
<dialog ref={dlg} id="modal" className={cls} onClose={closeModal}>
|
||||||
|
<div className="modal-head">
|
||||||
|
<b>{modal.title}</b>
|
||||||
|
<button onClick={closeModal}>关闭</button>
|
||||||
|
</div>
|
||||||
|
<div id="modalBody">
|
||||||
|
{modal.kind === 'guide' && (
|
||||||
|
<ol>
|
||||||
|
<li>需求解析:载入样例 → 解析 → 确认澄清(1分钟)。</li>
|
||||||
|
<li>清单:追溯来源 → 补入焊材 → 确认技术(1.5分钟)。</li>
|
||||||
|
<li>询价:尝试低价超期供应商 → 合规选择 → 物供提交 → 生产提交 → 经营确认(2分钟)。</li>
|
||||||
|
<li>成本:核对材料、工时、间接费与风险准备 → 生成报告(1分钟)。</li>
|
||||||
|
<li>策略:比较A/B/C → 演示低于底线的阻断 → 选择B → 审批(1.5分钟)。</li>
|
||||||
|
<li>报价:打印/导出 → 返回修改工时,演示审批失效(1分钟)。</li>
|
||||||
|
</ol>
|
||||||
|
)}
|
||||||
|
{modal.kind === 'network' && <MaterialNetworkModal />}
|
||||||
|
{modal.kind === 'library' && <QuotationLibraryModal />}
|
||||||
|
{modal.kind === 'case' && <HistoricalCaseModal id={modal.payload} />}
|
||||||
|
{modal.kind === 'historyDetail' && <QuotationHistoryDetail id={modal.payload} />}
|
||||||
|
{modal.kind === 'newMaterial' && <NewMaterialModal />}
|
||||||
|
{modal.kind === 'newResource' && <NewResourceModal />}
|
||||||
|
{modal.kind === 'preview' && <PreviewModal payload={modal.payload} />}
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/* React 版布局调整:左侧菜单固定不动,右侧内容区独立滚动
|
||||||
|
说明:原应用 header 实际高度为 80px(002.css 顶层覆盖 001.css 的 90px),现压缩为 65px(上下 padding 减半),
|
||||||
|
且原 sticky 规则依赖 body>header 直属结构,融合到平台后改由模块根容器 .wuc-root 承载(不触碰全局 html/body)。 */
|
||||||
|
|
||||||
|
/* ===== 桌面端(>900px):锁定视口,左栏与 header 固定,main 内部滚动 ===== */
|
||||||
|
@media (min-width: 901px) {
|
||||||
|
.wuc-root {
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wuc-root > header {
|
||||||
|
height: 65px; /* 原 80px:上下 padding 15px 减半为 7.5px(内容区 50px 不变) */
|
||||||
|
padding-top: 7.5px;
|
||||||
|
padding-bottom: 7.5px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell {
|
||||||
|
height: calc(100vh - 65px);
|
||||||
|
min-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell aside {
|
||||||
|
height: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell main {
|
||||||
|
height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 页面标题与流程轨道固定,不随内容滚动 */
|
||||||
|
.app-shell main .workspace-banner {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell main > #content {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 需求解析页:左右两栏等高充满内容区,各自溢出内部滚动 */
|
||||||
|
.app-shell main > #content[data-view='1'] {
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell main > #content[data-view='1'] .demand-grid {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
grid-template-rows: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell main > #content[data-view='1'] .demand-grid > .panel {
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ===== 窄屏(≤900px):沿用原 block 布局 + 整页滚动,仅补偿 header 置顶 ===== */
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.wuc-root > header {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 40;
|
||||||
|
background-color: var(--bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 打印时放开视口锁定,避免内容被裁剪 */
|
||||||
|
@media print {
|
||||||
|
.wuc-root {
|
||||||
|
height: auto;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 页面标题行:h1 与页面动作按钮同行,紧凑按钮样式 */
|
||||||
|
#titlebar .title-line {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#titlebar .title-line h1 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wuc-root .btn-sm {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 4px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 原 002.css 依赖 body>header 的层级补偿(header 现位于模块根容器内) */
|
||||||
|
.wuc-root header .head-name,
|
||||||
|
.wuc-root header .head-status,
|
||||||
|
.wuc-root header > button {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* React 条件渲染的 toast(覆盖原 #toast{display:none!important}) */
|
||||||
|
#toast.is-visible {
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// 提取自原 002-app.js reportText() 的报告抬头 Logo(base64 PNG)
|
||||||
|
export const REPORT_LOGO="data:image/png;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNDAwIiBoZWlnaHQ9IjkwMCIgdmlld0JveD0iMCAwIDE0MDAgOTAwIj48ZGVmcz48cGF0dGVybiBpZD0iaCIgd2lkdGg9IjkiIGhlaWdodD0iOSIgcGF0dGVyblVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgcGF0dGVyblRyYW5zZm9ybT0icm90YXRlKDQ1KSI+PGxpbmUgeDE9IjAiIHkxPSIwIiB4Mj0iMCIgeTI9IjkiIHN0cm9rZT0iIzc3NyIvPjwvcGF0dGVybj48bWFya2VyIGlkPSJhIiBtYXJrZXJXaWR0aD0iOCIgbWFya2VySGVpZ2h0PSI4IiByZWZYPSI0IiByZWZZPSI0IiBvcmllbnQ9ImF1dG8tc3RhcnQtcmV2ZXJzZSI+PHBhdGggZD0iTTAsMCBMOCw0IEwwLDgiIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzExMSIvPjwvbWFya2VyPjwvZGVmcz48cmVjdCB4PSIzMCIgeT0iMzAiIHdpZHRoPSIxMzQwIiBoZWlnaHQ9Ijg0MCIgZmlsbD0id2hpdGUiIHN0cm9rZT0iIzIyMiIgc3Ryb2tlLXdpZHRoPSIyIi8+PGcgZm9udC1mYW1pbHk9Ik1pY3Jvc29mdCBZYUhlaSxBcmlhbCIgZmlsbD0iIzIyMiI+PHRleHQgeD0iNjUiIHk9Ijg1IiBmb250LXNpemU9IjI1Ij7lhoXlpZfnu4Tku7Yg4oCUIOaooeaLn+acuuaisOWbvu+8iOS7heS+m+aKpeS7t0RFTU/vvIk8L3RleHQ+PHRleHQgeD0iNjUiIHk9IjExOSIgZm9udC1zaXplPSIxNyIgZmlsbD0iI2JkNDQ0NCI+6Z2e6ZmE5Lu25aSN5Yi7IMK3IOWwuuWvuOOAgeadkOi0qOWPiue7k+aehOWdh+S4uuWBh+iuviDCtyDnpoHmraLkvZzkuLrnlJ/kuqfkvp3mja48L3RleHQ+PGcgc3Ryb2tlPSIjMjIyIiBzdHJva2Utd2lkdGg9IjIiIGZpbGw9Im5vbmUiPjxyZWN0IHg9IjE0MCIgeT0iMjYwIiB3aWR0aD0iNjAwIiBoZWlnaHQ9IjIxMCIvPjxyZWN0IHg9IjE0MCIgeT0iMjYwIiB3aWR0aD0iNjAwIiBoZWlnaHQ9IjMyIiBmaWxsPSJ1cmwoI2gpIi8+PHJlY3QgeD0iMTQwIiB5PSI0MzgiIHdpZHRoPSI2MDAiIGhlaWdodD0iMzIiIGZpbGw9InVybCgjaCkiLz48cmVjdCB4PSIxNjAiIHk9IjIwNSIgd2lkdGg9IjM1IiBoZWlnaHQ9IjMyMCIgZmlsbD0idXJsKCNoKSIvPjxyZWN0IHg9IjY1MCIgeT0iMjI1IiB3aWR0aD0iMzAiIGhlaWdodD0iMjgwIiBmaWxsPSJ1cmwoI2gpIi8+PGNpcmNsZSBjeD0iMTAzMCIgY3k9IjM2NSIgcj0iMTQ1Ii8+PGNpcmNsZSBjeD0iMTAzMCIgY3k9IjM2NSIgcj0iMTEyIi8+PGNpcmNsZSBjeD0iMTAzMCIgY3k9IjM2NSIgcj0iOTAiLz48cGF0aCBkPSJNMTAwIDM2NWg2OTBNMTAzMCAxODV2MzYwTTg1MCAzNjVoMzYwIiBzdHJva2UtZGFzaGFycmF5PSIxMiA2IDMgNiIgc3Ryb2tlPSIjNzc3Ii8+PHBhdGggZD0iTTE0MCA0OTB2OTBNNzQwIDQ5MHY5ME0xNDAgNTY1aDYwMCIvPjxwYXRoIGQ9Ik03OTAgMjYwaDQ1TTc5MCA0NzBoNDVNODIwIDI2MHYyMTAiLz48cGF0aCBkPSJNMTQwIDU2NWg2MDAiIG1hcmtlci1zdGFydD0idXJsKCNhKSIgbWFya2VyLWVuZD0idXJsKCNhKSIvPjxwYXRoIGQ9Ik04MjAgMjYwdjIxMCIgbWFya2VyLXN0YXJ0PSJ1cmwoI2EpIiBtYXJrZXItZW5kPSJ1cmwoI2EpIi8+PC9nPjx0ZXh0IHg9IjM3MCIgeT0iNTUyIiBmb250LXNpemU9IjIwIj7nrZLmrrXplb8gMTIwMDwvdGV4dD48dGV4dCB4PSI4MzUiIHk9IjM0MCIgZm9udC1zaXplPSIxOCI+zqY0MjA8L3RleHQ+PHRleHQgeD0iOTMwIiB5PSI1NTAiIGZvbnQtc2l6ZT0iMTgiPuWGheW+hCDOpjM4MCAvIOazleWFsCDOpjU2MDwvdGV4dD48dGV4dCB4PSIyMjAiIHk9IjE5MCIgZm9udC1zaXplPSIxOCI+4pGhIOazleWFsDwvdGV4dD48dGV4dCB4PSIzNzAiIHk9IjI0NSIgZm9udC1zaXplPSIxOCI+4pGgIOetkuS9k++8iOWJluinhuekuuaEj++8iTwvdGV4dD48dGV4dCB4PSI2MjAiIHk9IjE5NSIgZm9udC1zaXplPSIxOCI+4pGiIOWKoOW8uueOrzwvdGV4dD48dGV4dCB4PSI2NSIgeT0iNjI1IiBmb250LXNpemU9IjE4Ij7mioDmnK/or7TmmI7vvIjmqKHmi5/vvInvvJoxLiDmnZDmlpnmmoLlrppRMzU1Qu+8mzIuIOWFiOaIkOW9oueEiuaOpeWQjuacuuWKoOW3pe+8mzMuIOmFjeWQiOOAgeWFrOW3ruOAgeeEiue8neetiee6p+W+heaKgOacr+WNj+iuruOAgjwvdGV4dD48dGV4dCB4PSI2NSIgeT0iNjYzIiBmb250LXNpemU9IjE4Ij7lh4Dph43mjInmqKHmi5/lnIbnjq/kvZPnp6/kvLDnrpfvvIjop4HpnIDmsYLkuabvvInvvJvlrZTmp73mnKrmiaPpmaTvvIxCT03pobvmioDmnK/lrqHmoLjvvIzlm77nurjmnKrlkKvnhIrmnZDjgII8L3RleHQ+PHBhdGggZD0iTTMwIDcxMGgxMzQwTTgwMCA3MTB2MTYwTTExMDAgNzEwdjE2ME04MDAgNzY1aDU3ME04MDAgODIwaDU3MCIgc3Ryb2tlPSIjMjIyIiBmaWxsPSJub25lIi8+PHRleHQgeD0iNjUiIHk9Ijc1NSIgZm9udC1zaXplPSIyMCI+5q2m5rGJ5q2m6Ii56YeN5Z6L6KOF5aSH5bel56iL5pyJ6ZmQ6LSj5Lu75YWs5Y+4IMK3IEFJ5oql5Lu35bmz5Y+wPC90ZXh0Pjx0ZXh0IHg9IjY1IiB5PSI3OTMiIGZvbnQtc2l6ZT0iMTYiPuWcuuaZr+WPguiAg++8mueUqOaIt+aPkOS+m+WGheWllyAvIOWkluWll+mZhOS7tuS4u+mimO+8jOacquaguOWunuWOn+WbvuW3peeoi+WPguaVsDwvdGV4dD48dGV4dCB4PSI2NSIgeT0iODMyIiBmb250LXNpemU9IjE2Ij7lh4Dph43jgIHmlbDph4/lkozmnZDmlpnlj7fop4HjgIrlrqLmiLfpnIDmsYLkuabjgIsgwqcz77yb5pys5Zu+5Y2V5L2NIG1t77yM5LiN5oyJ5q+U5L6L44CCPC90ZXh0Pjx0ZXh0IHg9IjgyNSIgeT0iNzQ2IiBmb250LXNpemU9IjIzIj7lhoXlpZfnu4Tku7Y8L3RleHQ+PHRleHQgeD0iMTEyMCIgeT0iNzQ2IiBmb250LXNpemU9IjIwIj5TSU0tSVMtMDE8L3RleHQ+PHRleHQgeD0iODI1IiB5PSI4MDAiIGZvbnQtc2l6ZT0iMTgiPueJiOacrO+8mkEgLyDmqKHmi588L3RleHQ+PHRleHQgeD0iMTEyMCIgeT0iODAwIiBmb250LXNpemU9IjE4Ij7mlbDph4/vvJoxMOS7tjwvdGV4dD48dGV4dCB4PSI4MjUiIHk9Ijg1NSIgZm9udC1zaXplPSIxOCI+MjAyNi0xMC0xNjwvdGV4dD48dGV4dCB4PSIxMTIwIiB5PSI4NTUiIGZvbnQtc2l6ZT0iMTgiPumdnueUn+S6p+Wbvue6uDwvdGV4dD48L2c+PC9zdmc+"
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,215 @@
|
|||||||
|
// 武船AI智能报价平台 — 状态与实体类型定义(对应原 fresh() 状态结构)
|
||||||
|
export interface Material {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
unit: string
|
||||||
|
qty: number
|
||||||
|
price: number
|
||||||
|
ref: string
|
||||||
|
confidence?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Resource {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
ref: string
|
||||||
|
qty: number
|
||||||
|
rate: number | null
|
||||||
|
note?: string
|
||||||
|
aiRateReason?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Project {
|
||||||
|
schema?: string
|
||||||
|
project: string
|
||||||
|
customer: string
|
||||||
|
code: string
|
||||||
|
delivery: number
|
||||||
|
sets: number
|
||||||
|
scope: string
|
||||||
|
terms: string
|
||||||
|
materials: Material[]
|
||||||
|
resources: Resource[]
|
||||||
|
missing?: Material
|
||||||
|
assumptions: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SupplierOffer {
|
||||||
|
name: string
|
||||||
|
price: number
|
||||||
|
days: number
|
||||||
|
quality: string
|
||||||
|
index: number
|
||||||
|
aiReason?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LogEntry {
|
||||||
|
time: string
|
||||||
|
text: string
|
||||||
|
rev: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileEntry {
|
||||||
|
name: string
|
||||||
|
size: number
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CompetitorQuote {
|
||||||
|
name: string
|
||||||
|
price: number
|
||||||
|
taxMode: 'exclusive' | 'inclusive'
|
||||||
|
taxRate: number
|
||||||
|
sets: number
|
||||||
|
days: number
|
||||||
|
position: 'low' | 'balanced' | 'quality'
|
||||||
|
comparable: boolean
|
||||||
|
source: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StrategyCard {
|
||||||
|
label: string
|
||||||
|
g: number
|
||||||
|
price: number
|
||||||
|
profit: number
|
||||||
|
margin: number
|
||||||
|
valid: boolean
|
||||||
|
days: number
|
||||||
|
reason: string
|
||||||
|
competition?: { reference: number; gap: number; floorPrice: number }
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface State {
|
||||||
|
version: number
|
||||||
|
page: number
|
||||||
|
project: Project
|
||||||
|
materials: Material[]
|
||||||
|
resources: Resource[]
|
||||||
|
parsed: boolean
|
||||||
|
tech: boolean
|
||||||
|
supply: boolean
|
||||||
|
production: boolean
|
||||||
|
review: boolean
|
||||||
|
report: boolean
|
||||||
|
approved: boolean
|
||||||
|
approvedAt?: string
|
||||||
|
selected: number
|
||||||
|
revision: number
|
||||||
|
floor: number
|
||||||
|
targets: number[]
|
||||||
|
other: Record<string, number>
|
||||||
|
overhead: number
|
||||||
|
risk: number
|
||||||
|
tax: number
|
||||||
|
context: string
|
||||||
|
quotes: Record<string, SupplierOffer>
|
||||||
|
log: LogEntry[]
|
||||||
|
files: FileEntry[]
|
||||||
|
fileText: string
|
||||||
|
clarified: boolean
|
||||||
|
competitorQuote?: CompetitorQuote
|
||||||
|
unsupported?: boolean
|
||||||
|
productionRatesInitialized?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
// 运行时 AI 演示流程(不持久化,对应原模块级变量)
|
||||||
|
export interface Flow {
|
||||||
|
running: boolean
|
||||||
|
visible: boolean
|
||||||
|
tick: number
|
||||||
|
token: number
|
||||||
|
cancelled?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AiRunFlow extends Flow {
|
||||||
|
sheet: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface KbFlow extends Flow {
|
||||||
|
shown: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InquiryFlow extends Flow {
|
||||||
|
done: number
|
||||||
|
failed: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductionAIFlow extends InquiryFlow {
|
||||||
|
unmatched: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StrategyRunFlow extends Flow {
|
||||||
|
reveal: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MaterialNetwork {
|
||||||
|
token: number
|
||||||
|
stage: number
|
||||||
|
selected: number
|
||||||
|
done: boolean
|
||||||
|
active: boolean
|
||||||
|
type: 'material' | 'resource'
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QuoteAssistant {
|
||||||
|
open: boolean
|
||||||
|
running: boolean
|
||||||
|
token: number
|
||||||
|
cancelled?: boolean
|
||||||
|
mode: '' | 'search' | 'analysis'
|
||||||
|
stage: number
|
||||||
|
revealed: number
|
||||||
|
ids: string[] | null
|
||||||
|
selected: string | null
|
||||||
|
messages: { role: 'user' | 'assistant'; text: string }[]
|
||||||
|
analysis: AnalysisCard[]
|
||||||
|
analysisCount: number
|
||||||
|
analysisTitle: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AnalysisCard {
|
||||||
|
title: string
|
||||||
|
kind: 'fact' | 'attention' | 'hypothesis' | 'action'
|
||||||
|
text: string
|
||||||
|
evidence: string
|
||||||
|
bars?: { name: string; value: number; share: number }[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QuotationRecord {
|
||||||
|
id: string
|
||||||
|
signature: string
|
||||||
|
number: string
|
||||||
|
project: string
|
||||||
|
customer: string
|
||||||
|
date: string
|
||||||
|
sets: number
|
||||||
|
days: number
|
||||||
|
price: number
|
||||||
|
tax: number
|
||||||
|
total: number
|
||||||
|
strategy: string
|
||||||
|
revision: number
|
||||||
|
approvedAt?: string
|
||||||
|
snapshot: State
|
||||||
|
html: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HistoryCase {
|
||||||
|
name: string
|
||||||
|
customer: string
|
||||||
|
code: string
|
||||||
|
date: string
|
||||||
|
sets: number
|
||||||
|
days: number
|
||||||
|
price: number
|
||||||
|
margin: number
|
||||||
|
costs: [string, number][]
|
||||||
|
scope: string
|
||||||
|
materials: string[][]
|
||||||
|
process: [string, number, number][]
|
||||||
|
milestones: string[][]
|
||||||
|
terms: string
|
||||||
|
quality: string
|
||||||
|
reason: string
|
||||||
|
risk: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,790 @@
|
|||||||
|
// 7 个业务视图(对应原 home/demand/lists/inquiry/cost/strategy/quote 渲染函数)
|
||||||
|
import React from 'react'
|
||||||
|
import { ENGINEERING_DRAWING } from './drawing-assets'
|
||||||
|
import { money, quoteHTML, strategies, issues as calcIssues, calc as calcCost } from './logic'
|
||||||
|
import { SAMPLE, TITLES, offers } from './data'
|
||||||
|
import type { State } from './types'
|
||||||
|
import { useApp } from './store'
|
||||||
|
import { Audit, Btn, Metric, Notice, NumInput, Table } from './components'
|
||||||
|
|
||||||
|
const aiIsSample = (s: State) =>
|
||||||
|
s.project.code === SAMPLE.code && JSON.stringify(s.project.materials) === JSON.stringify(SAMPLE.materials)
|
||||||
|
|
||||||
|
// ============ 0 项目工作台 ============
|
||||||
|
export function Home() {
|
||||||
|
const { s, go } = useApp()
|
||||||
|
const c = calcCost(s)
|
||||||
|
const depts = ['技术部', '技术部', '物供 · 生产 · 经营', '经营部', '经营 · 审批', '经营部']
|
||||||
|
const descs = ['上传需求与模拟图纸,提取并核对', '补全BOM、用量与工时', '比较交期与价格,识别遗漏', '全成本汇总,生成可追溯报告', '历史案例辅助,生成A/B/C策略', '审批后生成,打印与导出']
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section className="project-hero hero-grid">
|
||||||
|
<div>
|
||||||
|
<div className="eyebrow">ENGINEERING TO QUOTATION</div>
|
||||||
|
<div className="hero-title">从一张图纸,到一份可信报价</div>
|
||||||
|
<p className="hero-text">围绕技术、物供、生产与经营的协同流程,让每一项成本有来源,每一次决策有依据。</p>
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t="开始需求解析 →" onClick={() => go(1)} cls="primary" />
|
||||||
|
<Btn t="查看全流程数据" onClick={() => go(4)} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="engineering-drawing-card" dangerouslySetInnerHTML={{ __html: ENGINEERING_DRAWING }} />
|
||||||
|
</section>
|
||||||
|
<div className="metrics">
|
||||||
|
<Metric label="项目交付数量" value={s.project.sets} unit="套" />
|
||||||
|
<Metric label="目标交期" value={s.project.delivery} unit="天" />
|
||||||
|
<Metric label="当前测算成本" value={money(c.total / 10000)} unit="万元" />
|
||||||
|
<Metric label="利润率底线" value={s.floor} unit="%" />
|
||||||
|
</div>
|
||||||
|
<div className="flow">
|
||||||
|
{TITLES.slice(1).map((t, i) => (
|
||||||
|
<button key={i} onClick={() => go(i + 1)}>
|
||||||
|
<small>0{i + 1} / {depts[i]}</small>
|
||||||
|
<b>{t}</b>
|
||||||
|
<small>{descs[i]}</small>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<Notice t="演示边界:AI解析与策略为本地规则模拟;可编辑成本、询价、审批与导出是真实交互。所有商业数据为模拟数据。原始附件尺寸与材质未核实。" />
|
||||||
|
<div className="panel section"><h2>项目动态 / 审核追溯</h2><Audit /></div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 1 需求与图纸解析 ============
|
||||||
|
function AiPanel() {
|
||||||
|
const { s, flows, aiSheet, parse, clarify, go } = useApp()
|
||||||
|
const aiRun = flows.aiRun
|
||||||
|
if (!aiRun.visible) return null
|
||||||
|
const running = aiRun.running
|
||||||
|
const done = !running && s.parsed
|
||||||
|
const len = s.project.materials.length
|
||||||
|
const t = done ? len + 7 : aiRun.tick
|
||||||
|
const phase = done ? 4 : t < 2 ? 0 : t < 3 ? 1 : t < len + 3 ? 2 : 3
|
||||||
|
const found = done ? len : Math.max(0, Math.min(len, t - 2))
|
||||||
|
const warnings = done || t >= len + 3
|
||||||
|
const sample = aiIsSample(s)
|
||||||
|
const sheet = aiRun.sheet
|
||||||
|
const points = sheet ? [[3, 10, 28, 44, 25], [4, 11, 22, 6, 37]] : [[0, 14, 29, 39, 24], [1, 10, 22, 6, 37], [2, 45, 25, 5, 32]]
|
||||||
|
const status = ['图纸解析 Agent · 读取图框与视图', '语义理解 Agent · 拆解组件与装配关系', '多模态 Agent + OCR Agent · 交叉核对物料', '校核 Agent · 检查遗漏与规格冲突', '解析完成 · 等待人工确认'][phase]
|
||||||
|
return (
|
||||||
|
<div className="panel ai ai-workbench">
|
||||||
|
<div className="ai-top">
|
||||||
|
<h2>✦ AI 协同图纸解析</h2>
|
||||||
|
<span className={'chip ' + (running ? 'purple' : done ? 'green' : '')}>{running ? '协同处理中' : done ? '待人工确认' : '准备就绪'}</span>
|
||||||
|
</div>
|
||||||
|
<p className="ai-caption">离线流程演示 · 多模态大模型 + OCR 协同概念,未调用真实模型</p>
|
||||||
|
<div className="ai-agents">
|
||||||
|
{['图纸解析', '理解与拆解', '多模态 + OCR', '遗漏校核'].map((name, i) => (
|
||||||
|
<div key={i} className={'ai-agent ' + (phase > i ? 'done' : phase === i && (running || done) ? 'active' : '')}>
|
||||||
|
<b>{phase > i ? '✓' : '0' + (i + 1)} {name}</b>
|
||||||
|
{['图框 / 视图定位', '组件 / 信息关联', '逐项识别 / 核对', '缺项 / 人工确认'][i]}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="ai-track"><i style={{ width: (done ? 100 : running ? Math.max(3, (t / (len + 7)) * 100) : 0) + '%' }} /></div>
|
||||||
|
<div className="ai-status" role="status"><b>{!running && !done ? '等待启动解析' : status}</b><span>{found} / {len} 项</span></div>
|
||||||
|
{sample ? (
|
||||||
|
<>
|
||||||
|
<div className="ai-sheet-tabs">
|
||||||
|
{['内套 · SIM-IS-01', '外套 · SIM-OS-01'].map((name, i) => (
|
||||||
|
<button key={i} className={sheet === i ? 'primary' : ''} onClick={() => aiSheet(i)}>{name}</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="ai-sheet">
|
||||||
|
<img src={sheet ? '/mod-assets/wuc-quotation/模拟外套图.svg' : '/mod-assets/wuc-quotation/模拟内套图.svg'} alt="用于识别动画的模拟机械图" />
|
||||||
|
{running && <div className="ai-scan" />}
|
||||||
|
{points.filter((p) => p[0] < found).map((p, i) => (
|
||||||
|
<div key={i} className="ai-mark" style={{ left: p[1] + '%', top: p[2] + '%', width: p[3] + '%', height: p[4] + '%' }}>
|
||||||
|
<span>✓ {s.project.materials[p[0]].name}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{warnings && (
|
||||||
|
<div className="ai-mark warn" style={{ left: '5%', top: '67%', width: '88%', height: '10%' }}>
|
||||||
|
<span>! 焊材未覆盖 / 配合与焊缝要求待确认</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="ai-legend">绿色:模拟图示物料定位 橙色虚线:信息缺失区域 · 可切换图纸查看</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div className="ai-idle">结构化需求映射<br /><small>当前按 JSON 来源字段展示候选信息;无对应图纸坐标,不生成定位标记。</small></div>
|
||||||
|
)}
|
||||||
|
{(running || done) && (
|
||||||
|
<div className="ai-events" aria-label="物料识别记录">
|
||||||
|
{s.project.materials.slice(0, found).map((m, i) => (
|
||||||
|
<div className="ai-event" key={i}>
|
||||||
|
<b>✓ {m.id} · {m.name}</b> <span>{m.qty} {m.unit}</span>
|
||||||
|
<small>{m.ref}{sample && i >= 5 ? ' · 需求文本补充,非图纸直接识别' : ''}</small>
|
||||||
|
</div>
|
||||||
|
)).reverse()}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{warnings && (
|
||||||
|
<Notice cls="warn" t={sample
|
||||||
|
? '校核发现:焊材未覆盖,需补充清单;导向衬套、密封组件规格及配合公差待技术确认。'
|
||||||
|
: '请核对结构化数据中的材料规格、数量、来源和图纸覆盖范围;当前未进行真实 OCR。'} />
|
||||||
|
)}
|
||||||
|
{done && (
|
||||||
|
<div className="ai-summary">
|
||||||
|
<h3>识别总结 / 人工确认</h3>
|
||||||
|
<Table head={['提取字段', '识别结果']} rows={[
|
||||||
|
['项目', s.project.project],
|
||||||
|
['客户', s.project.customer || '待补充'],
|
||||||
|
['数量 / 交期', `${s.project.sets}套 / ${s.project.delivery}天`],
|
||||||
|
['物料 / 工艺', `${s.materials.length}项候选 / ${s.resources.length}道工序`],
|
||||||
|
]} />
|
||||||
|
<p className="ai-caption">候选数据来源:{sample ? '内置模拟图与需求书,尺寸和净重均为演示假设。' : '上传的结构化需求,需人工对照原始图纸核验。'}</p>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" checked={s.clarified} onChange={(e) => clarify(e.target.checked)} />
|
||||||
|
已按演示假设确认数量、材质与外购件规格
|
||||||
|
</label>
|
||||||
|
<div className="actions section">
|
||||||
|
<Btn t="确认并进入清单 →" onClick={() => go(2)} disabled={!s.clarified} cls="primary" />
|
||||||
|
<Btn t="重播解析动画" onClick={parse} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Demand() {
|
||||||
|
const { s, flows, loadSample, uploadFiles, parse } = useApp()
|
||||||
|
return (
|
||||||
|
<div className="grid2 demand-grid">
|
||||||
|
<div className="panel">
|
||||||
|
<h2>01 / 上传客户需求与图纸</h2>
|
||||||
|
<p>支持结构化JSON、UTF-8 Markdown/TXT需求;PDF、图像及SVG可预览归档,离线模式不做通用OCR。</p>
|
||||||
|
<input type="file" accept=".json,.md,.txt,.pdf,.png,.jpg,.jpeg,.svg" multiple
|
||||||
|
onChange={(e) => { uploadFiles(e.target.files); e.currentTarget.value = '' }} />
|
||||||
|
<div className="actions section">
|
||||||
|
<Btn t="载入模拟客户需求" onClick={loadSample} cls="primary" />
|
||||||
|
<button type="button"
|
||||||
|
className={'parse-demand-button ' + (flows.aiRun.visible ? 'is-clicked' : '')}
|
||||||
|
onClick={parse}
|
||||||
|
aria-pressed={flows.aiRun.visible ? 'true' : 'false'}
|
||||||
|
aria-busy={flows.aiRun.running ? 'true' : 'false'}
|
||||||
|
disabled={!s.project || flows.aiRun.running}>
|
||||||
|
解析当前需求
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<Notice cls="warn" t="参考附件:213WS03-01(内套)、213WS03-02(外套)。当前仅使用主题参考,未读取确认原图工程参数。模拟图与原图严格区分。" />
|
||||||
|
<div className="docs-list">
|
||||||
|
{s.files.length
|
||||||
|
? s.files.map((f, i) => <div className="doc-row" key={i}><b>{f.name}</b><span className="muted">{f.size} KB · {f.type}</span></div>)
|
||||||
|
: <div className="muted">暂无本次上传文件,可直接载入样例开始。</div>}
|
||||||
|
</div>
|
||||||
|
<div className="previewtext">{s.fileText || s.project.scope}</div>
|
||||||
|
<div className="actions section">
|
||||||
|
<a href="/mod-assets/wuc-quotation/模拟内套图.svg" target="_blank" rel="noreferrer">查看模拟内套图 ↗</a>
|
||||||
|
<a href="/mod-assets/wuc-quotation/模拟外套图.svg" target="_blank" rel="noreferrer">查看模拟外套图 ↗</a>
|
||||||
|
<a href="/mod-assets/wuc-quotation/客户需求书.md" download>下载客户需求书</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<AiPanel />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 2 物量与资源清单 ============
|
||||||
|
function KbBanner() {
|
||||||
|
const { s, flows, startKnowledge } = useApp()
|
||||||
|
const kb = flows.kb
|
||||||
|
const total = s.materials.length + s.resources.length
|
||||||
|
const shown = Math.min(total, Math.max(0, kb.tick - 2))
|
||||||
|
const phase = !kb.running ? 3 : kb.tick < 2 ? 0 : shown < s.materials.length ? 1 : 2
|
||||||
|
return (
|
||||||
|
<section className="kb-banner">
|
||||||
|
<div className="panel-head">
|
||||||
|
<div>
|
||||||
|
<b>✦ AI 知识库检索与来源匹配</b><br />
|
||||||
|
<small role="status">
|
||||||
|
{(kb.running
|
||||||
|
? ['检索本地索引,定位可引用的依据…', '逐项关联物料、图纸序号与需求条款…', '匹配工艺记录、工时与计价依据…'][phase] + ' ' + shown + ' / ' + total
|
||||||
|
: '检索展示完成 · 可打开图谱逐项核对来源')}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<Btn t="↻ 重播检索过程" onClick={startKnowledge} disabled={kb.running} />
|
||||||
|
</div>
|
||||||
|
<div className="kb-stages">
|
||||||
|
{['检索索引', '物料映射', '工艺关联', '来源核对'].map((n, i) => <span key={i} className={i === phase ? 'on' : ''}>{i + 1} {n}</span>)}
|
||||||
|
</div>
|
||||||
|
<div className="ai-track"><i style={{ width: (!kb.running ? 100 : Math.max(3, (kb.tick / (total + 3)) * 100)) + '%' }} /></div>
|
||||||
|
<small>离线知识库演示:检索内置模拟需求 / 工艺记录;未连接企业真实历史库。候选值按来源映射呈现,未匹配记录标为人工补充。</small>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Lists() {
|
||||||
|
const { s, flows, go, editM, editR, addMissing, deleteListRow, confirmTech, startMaterialNetwork, openModal } = useApp()
|
||||||
|
const kb = flows.kb
|
||||||
|
if (!kb.shown) return null
|
||||||
|
if (!s.parsed) {
|
||||||
|
return <>
|
||||||
|
<Notice t="请先上传/载入需求并完成解析。" />
|
||||||
|
<Btn t="前往需求解析" onClick={() => go(1)} />
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
const busy = kb.running
|
||||||
|
const mc = busy ? Math.min(s.materials.length, Math.max(0, kb.tick - 2)) : s.materials.length
|
||||||
|
const rc = busy ? Math.min(s.resources.length, Math.max(0, kb.tick - 2 - s.materials.length)) : s.resources.length
|
||||||
|
return (
|
||||||
|
<div className="quantity-lists">
|
||||||
|
<div className="metrics quantity-metrics">
|
||||||
|
<Metric label="物料项" value={busy ? mc : s.materials.length} unit="项" />
|
||||||
|
<Metric label="制造工序" value={rc} unit="道" />
|
||||||
|
</div>
|
||||||
|
<KbBanner />
|
||||||
|
<div className="panel">
|
||||||
|
<div className="panel-head">
|
||||||
|
<h2>物量清单 / BOM</h2>
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t="◈ 物料知识匹配图谱" onClick={() => startMaterialNetwork(0, 'material')} cls="primary" />
|
||||||
|
<Btn t="补入遗漏焊材" onClick={addMissing} disabled={busy || s.materials.some((m) => m.id === 'M009')} />
|
||||||
|
<Btn t="+ 手工新增物料" onClick={() => openModal('newMaterial', '新增人工补充物料')} disabled={busy} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Notice t="用量为项目合计;采购量=用量。来源匹配与当前值可在图谱中核对。" />
|
||||||
|
<Table
|
||||||
|
head={['物料号 / 来源', '物料', '用量', '单位', '采购量', '操作']}
|
||||||
|
rows={s.materials.slice(0, mc).map((m, i) => [
|
||||||
|
<>{m.id}<br /><small className="muted">{m.ref}</small></>,
|
||||||
|
m.name,
|
||||||
|
busy ? m.qty : <NumInput v={m.qty} onCommit={(v) => editM(i, 'qty', v)} ariaLabel={m.name + '用量'} />,
|
||||||
|
m.unit,
|
||||||
|
money(m.qty),
|
||||||
|
<Btn t="删除" onClick={() => deleteListRow('material', i)} disabled={busy} cls="row-delete" />,
|
||||||
|
])}
|
||||||
|
/>
|
||||||
|
{busy && mc === 0 && <div className="kb-empty">正在检索图纸物料索引与需求条款…</div>}
|
||||||
|
</div>
|
||||||
|
<div className="panel section">
|
||||||
|
<div className="panel-head">
|
||||||
|
<h2>资源清单 / 制造工艺路线</h2>
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t="+ 手工添加工序" onClick={() => openModal('newResource', '手工添加工序')} disabled={busy} />
|
||||||
|
<Btn t="◈ 工艺知识匹配图谱" onClick={() => startMaterialNetwork(0, 'resource')} cls="primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Table
|
||||||
|
head={['工序', '工时来源', '计划工时', '操作']}
|
||||||
|
rows={s.resources.slice(0, rc).map((r, i) => [
|
||||||
|
<>{r.name}<br /><small className="muted">{r.note}</small></>,
|
||||||
|
r.ref,
|
||||||
|
busy ? r.qty : <NumInput v={r.qty} onCommit={(v) => editR(i, 'qty', v)} ariaLabel={r.name + '计划工时'} />,
|
||||||
|
<Btn t="删除" onClick={() => deleteListRow('resource', i)} disabled={busy} cls="row-delete" />,
|
||||||
|
])}
|
||||||
|
/>
|
||||||
|
{busy && rc === 0 && <div className="kb-empty">等待物料关系匹配,随后检索工序与工时依据…</div>}
|
||||||
|
<Notice t="费率含直接人工、设备及能耗;焊材计入BOM,检测/防腐独立列项,避免重复归集。" />
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t={s.tech ? '✓ 技术已确认' : '确认技术清单'} onClick={confirmTech} cls="primary"
|
||||||
|
disabled={busy || !s.materials.length || !s.resources.length || s.tech || !s.clarified || !s.materials.some((m) => m.id === 'M009')} />
|
||||||
|
<Btn t="进入询价与审核 →" onClick={() => go(3)} disabled={busy} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 3 跨部门询价与审核 ============
|
||||||
|
function AiInquiryPanel() {
|
||||||
|
const { s, flows } = useApp()
|
||||||
|
const a = flows.aiInquiry
|
||||||
|
if (!a.visible) return null
|
||||||
|
const phase = a.tick < 1 ? 0 : a.tick < 2 ? 1 : a.tick < 3 ? 2 : a.running ? 3 : 4
|
||||||
|
const valid = s.materials.filter((r) => !!s.quotes[r.id] && Number.isFinite(r.price) && r.price > 0)
|
||||||
|
const amount = valid.reduce((sum, r) => sum + Math.round(r.qty * r.price * 100) / 100, 0)
|
||||||
|
const pending = s.materials.length - valid.length
|
||||||
|
return (
|
||||||
|
<section className="ai-inquiry-panel">
|
||||||
|
<div className="panel-head">
|
||||||
|
<b>✦ AI Agent 协同询价</b>
|
||||||
|
<span className={'chip ' + (a.running ? 'purple' : 'green')}>
|
||||||
|
{a.running ? '处理中' : a.cancelled ? '已暂停' : a.failed ? '部分物料待人工询价' : '推荐完成'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="ai-inquiry-steps">
|
||||||
|
{['需求核对 Agent', '报价检索 Agent', '交期比价 Agent', '推荐回填 Agent'].map((n, i) => (
|
||||||
|
<div key={i} className={phase > i ? 'done' : phase === i ? 'active' : ''}>
|
||||||
|
<b>{phase > i ? '✓' : i + 1} {n}</b>
|
||||||
|
<small>{['读取物料与采购数量', '检索内置供应商报价', '过滤超期 / 比较单价', '逐项填写并说明理由'][i]}</small>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="ai-track"><i style={{ width: Math.min(100, (a.tick / (s.materials.length + 3)) * 100) + '%' }} /></div>
|
||||||
|
<div role="status">
|
||||||
|
{a.running
|
||||||
|
? ['正在核对物料清单与项目交付要求…', '正在检索每项物料的模拟供应商报价…', '正在检查最迟到料时间并比较合规报价…'][Math.min(a.tick, 2)] + (a.tick >= 3 ? ` 已处理 ${a.done} / ${s.materials.length} 项。` : '')
|
||||||
|
: a.cancelled ? '处理已暂停,可重新点击 AI询价。'
|
||||||
|
: `已处理 ${a.done} 项;` + (a.failed ? `${a.failed} 项无交期合规报价,需人工处理。` : '推荐结果已回填,可手工调整后提交审核。')}
|
||||||
|
</div>
|
||||||
|
<small className="muted">离线规则演示:基于内置模拟报价,先满足交期,再选合规最低价;不向供应商发送询价,不自动提交审核。</small>
|
||||||
|
<div className="ai-panel-total" role="status">
|
||||||
|
<span>采购总金额(不含税){pending ? ' · 已回填小计' : ''}</span>
|
||||||
|
<strong>¥ {money(amount)}</strong>
|
||||||
|
{pending ? <small>{pending} 项待核价</small> : null}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProductionAIFlow() {
|
||||||
|
const { s, flows } = useApp()
|
||||||
|
const a = flows.productionAI
|
||||||
|
if (!a.visible) return null
|
||||||
|
const phase = a.running ? Math.min(3, a.tick) : 4
|
||||||
|
const valid = s.resources.filter((r) => r.rate != null && Number.isFinite(r.rate) && r.rate > 0)
|
||||||
|
const amount = valid.reduce((sum, r) => sum + Math.round(r.qty * (r.rate || 0) * 100) / 100, 0)
|
||||||
|
const pending = s.resources.length - valid.length
|
||||||
|
return (
|
||||||
|
<section className="ai-inquiry-panel">
|
||||||
|
<div className="panel-head">
|
||||||
|
<b>✦ AI Agent 协同工序核价</b>
|
||||||
|
<span className="chip purple">{a.running ? '处理中' : a.cancelled ? '已暂停' : a.failed ? '部分待人工核价' : '推荐完成'}</span>
|
||||||
|
</div>
|
||||||
|
<div className="ai-inquiry-steps">
|
||||||
|
{['工序理解 Agent', '费率检索 Agent', '口径校核 Agent', '推荐回填 Agent'].map((name, i) => (
|
||||||
|
<div key={i} className={phase > i ? 'done' : phase === i ? 'active' : ''}>
|
||||||
|
<b>{phase > i ? '✓' : i + 1} {name}</b>
|
||||||
|
<small>{['核对工序与工时范围', '查找可追溯费率记录', '核对人工 / 设备 / 能耗', '逐项填写费率与理由'][i]}</small>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="ai-track"><i style={{ width: Math.min(100, (a.tick / (s.resources.length + 3)) * 100) + '%' }} /></div>
|
||||||
|
<div role="status">
|
||||||
|
{a.running
|
||||||
|
? ['正在理解工序范围与计划工时…', '正在检索本地工艺费率记录…', '正在校核综合费率与费用归集口径…', '正在逐项回填推荐综合费率…'][Math.min(3, a.tick)] + ` 已处理 ${a.done} / ${s.resources.length} 项。`
|
||||||
|
: a.cancelled ? '处理已暂停,可重新点击 AI询价。'
|
||||||
|
: `已处理 ${a.done} 项,${a.failed} 项待人工核价;请核对后提交。`}
|
||||||
|
</div>
|
||||||
|
<small className="muted">离线规则演示:依据内置模拟工艺费率或上传需求中的费率记录;未连接企业实际历史库,不自动提交审核。</small>
|
||||||
|
<div className="ai-panel-total" role="status">
|
||||||
|
<span>工序总金额{pending ? ' · 已回填小计' : ''}</span>
|
||||||
|
<strong>¥ {money(amount)}</strong>
|
||||||
|
{pending ? <small>{pending} 项待核价</small> : null}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProductionPricing() {
|
||||||
|
const { s, flows, editR, startProductionAI, submitProduction } = useApp()
|
||||||
|
const ai = flows.productionAI
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="production-inquiry-actions">
|
||||||
|
<Btn t={ai.running ? 'AI询价处理中…' : '✦ AI询价'} onClick={startProductionAI} cls="primary"
|
||||||
|
disabled={!s.tech || !s.resources.length || ai.running} />
|
||||||
|
<Notice t="由制造部门确认工时与综合费率;直接修改会使经营审核和报价审批失效。" />
|
||||||
|
</div>
|
||||||
|
<ProductionAIFlow />
|
||||||
|
<div className="production-rate-table">
|
||||||
|
<Table
|
||||||
|
head={['工序', '工时', '综合费率(元/时)', 'AI推荐理由', '总成本']}
|
||||||
|
rows={s.resources.map((r, i) => [
|
||||||
|
r.name,
|
||||||
|
ai.running ? r.qty : <NumInput v={r.qty} onCommit={(v) => editR(i, 'qty', v)} ariaLabel={r.name + '计划工时'} />,
|
||||||
|
<input type="number" min="0.01" step="0.01" aria-label={r.name + '综合费率'}
|
||||||
|
placeholder="待填写"
|
||||||
|
defaultValue={r.rate != null && r.rate > 0 ? r.rate : ''}
|
||||||
|
key={r.id + '-' + (r.rate ?? '')}
|
||||||
|
disabled={ai.running || undefined}
|
||||||
|
onChange={(e) => editR(i, 'rate', e.target.value)} />,
|
||||||
|
r.aiRateReason
|
||||||
|
? <div className="ai-inquiry-reason">{r.aiRateReason}</div>
|
||||||
|
: ai.unmatched?.includes(r.id)
|
||||||
|
? <span className="muted">未匹配可靠费率依据,请人工核价。</span>
|
||||||
|
: <span className="muted">待询价 / 人工核价</span>,
|
||||||
|
r.rate && r.rate > 0 ? money(r.qty * r.rate) : <span className="muted">待核价</span>,
|
||||||
|
])}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="section">
|
||||||
|
<Btn t={s.production ? '✓ 生产已提交' : '生产核价并提交'} onClick={submitProduction} cls="primary"
|
||||||
|
disabled={!s.tech || s.production || ai.running || !s.resources.length || s.resources.some((r) => r.rate == null || !Number.isFinite(r.rate) || r.rate <= 0)} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Inquiry() {
|
||||||
|
const { s, sub, setSub, pick, pickAll, submitSupply, returnSupply, returnProduction, confirmReview, flows, startAIInquiry } = useApp()
|
||||||
|
if (!s.parsed) return <Notice t="请先解析客户需求。" />
|
||||||
|
const iss = calcIssues(s)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="panel">
|
||||||
|
<div className="panel-head">
|
||||||
|
<h2>三部门并行核价 / 统一经营确认</h2>
|
||||||
|
<span className="chip purple">当前演示:{['物供部', '生产部', '经营部'][sub]}</span>
|
||||||
|
</div>
|
||||||
|
<div className="actions subtabs">
|
||||||
|
{['物供询价', '生产核价', '经营审核'].map((x, i) => (
|
||||||
|
<Btn key={i} t={x} onClick={() => setSub(i)} cls={sub === i ? 'primary' : ''} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{sub === 0 && (
|
||||||
|
<>
|
||||||
|
<Notice t={'全部报价均为模拟回填,不向供应商发出询价。最迟到料:第' + (s.project.delivery - 30) + '天;报价有效期30天。'} />
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t="批量采用交期合规报价" onClick={pickAll} disabled={!s.tech || flows.aiInquiry.running} />
|
||||||
|
<Btn t={s.supply ? '✓ 已提交物供报价' : '物供提交审核'} onClick={submitSupply} cls="primary"
|
||||||
|
disabled={!s.tech || s.supply || flows.aiInquiry.running} />
|
||||||
|
<Btn t={flows.aiInquiry.running ? 'AI询价处理中…' : '✦ AI询价'} onClick={startAIInquiry} cls="primary"
|
||||||
|
disabled={!s.tech || !s.materials.length || flows.aiInquiry.running} />
|
||||||
|
</div>
|
||||||
|
<AiInquiryPanel />
|
||||||
|
<div className="supplier-quote-table">
|
||||||
|
<Table
|
||||||
|
head={['物料 / 单位', '报价选择(不含税)', 'AI推荐理由', '采购数量', '采购金额']}
|
||||||
|
rows={s.materials.map((m, i) => {
|
||||||
|
const q = s.quotes[m.id]
|
||||||
|
const over = q && q.days > s.project.delivery - 30
|
||||||
|
return [
|
||||||
|
<>{m.name}<br /><small>{m.id} / {m.unit}</small></>,
|
||||||
|
<>
|
||||||
|
<select aria-label={m.name + '供应商'} disabled={flows.aiInquiry.running || undefined}
|
||||||
|
value={q ? String(q.index) : ''} onChange={(e) => pick(i, e.target.value)}>
|
||||||
|
<option value="">请选择</option>
|
||||||
|
{offers(m, s.project).map((o, j) => (
|
||||||
|
<option key={j} value={j}>{o.name} / ¥{o.price} / {o.days}天</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<br />
|
||||||
|
<small className={over ? 'danger' : 'muted'}>{q?.quality || '待回填供应商报价'}</small>
|
||||||
|
</>,
|
||||||
|
q?.aiReason ? <div className="ai-inquiry-reason"><b>✦ AI推荐理由</b><br />{q.aiReason}</div> : '',
|
||||||
|
money(m.qty),
|
||||||
|
money(m.qty * m.price),
|
||||||
|
]
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{sub === 1 && <ProductionPricing />}
|
||||||
|
{sub === 2 && (
|
||||||
|
<div className="grid2">
|
||||||
|
<div>
|
||||||
|
<h3>✦ 经营审核提示(规则扫描)</h3>
|
||||||
|
{iss.length ? iss.map((x, i) => <Notice key={i} cls="warn" t={x} />) : <Notice cls="good" t="完整性、采购交期、部门提交状态均已通过。" />}
|
||||||
|
<Notice t="关注:衬套/密封为外购件;焊材不能遗漏;综合费率与独立费用不得重复计费。" />
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t="退回物供修订" onClick={returnSupply} />
|
||||||
|
<Btn t="退回工艺资源修订" onClick={returnProduction} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3>部门确认状态</h3>
|
||||||
|
<Table head={['责任部门', '状态']} rows={[
|
||||||
|
['技术部', s.tech ? '已确认' : '待确认'],
|
||||||
|
['物供部', s.supply ? '已提交' : '待提交'],
|
||||||
|
['生产部', s.production ? '已提交' : '待提交'],
|
||||||
|
['经营部', s.review ? '已确认' : '待审核'],
|
||||||
|
]} />
|
||||||
|
<div className="section">
|
||||||
|
<Btn t={s.review ? '✓ 经营已确认' : '经营最终确认'} onClick={confirmReview} cls="primary"
|
||||||
|
disabled={!!iss.length || s.review} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="panel section"><h2>修改与审核记录</h2><Audit /></div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 4 全成本测算报告 ============
|
||||||
|
export function Cost() {
|
||||||
|
const { s, editOther, editParam, generateReport, downloadReport, go } = useApp()
|
||||||
|
const c = calcCost(s)
|
||||||
|
const parts: [string, number][] = [['物料成本', c.material], ['制造资源', c.process], ['专项直接费', c.other], ['项目间接费', c.overhead], ['风险准备', c.risk]]
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="metrics">
|
||||||
|
<Metric label="项目全成本" value={money(c.total / 10000)} unit="万元" />
|
||||||
|
<Metric label="单位成本" value={money(c.total / s.project.sets)} unit="元/套" />
|
||||||
|
<Metric label="保底不含税价" value={money(c.total / (1 - s.floor / 100) / 10000)} unit="万元" />
|
||||||
|
<Metric label="审核状态" value={s.review ? '已确认' : '待确认'} />
|
||||||
|
</div>
|
||||||
|
<div className="grid2">
|
||||||
|
<div className="panel">
|
||||||
|
<h2>成本构成与归集</h2>
|
||||||
|
{parts.map(([n, v]) => (
|
||||||
|
<div className="chartrow" key={n}>
|
||||||
|
<span>{n}</span>
|
||||||
|
<div className="bar"><i style={{ width: (c.total ? (v / c.total) * 100 : 0) + '%' }} /></div>
|
||||||
|
<strong>{money(v)}</strong>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<Table head={['成本项', '计价基础']} rows={[
|
||||||
|
['物料', 'Σ用量×不含税采购单价'],
|
||||||
|
['工序', 'Σ工时×综合费率'],
|
||||||
|
['专项直接费', '检测 + 防腐 + 包装运输 + 现场技术服务'],
|
||||||
|
['间接费', '直接成本×' + s.overhead + '%'],
|
||||||
|
['风险准备', '(直接成本+间接费)×' + s.risk + '%'],
|
||||||
|
]} />
|
||||||
|
</div>
|
||||||
|
<div className="panel">
|
||||||
|
<h2>补充成本与参数</h2>
|
||||||
|
{Object.entries(s.other).map(([k, v]) => (
|
||||||
|
<div className="formrow" key={k}>
|
||||||
|
<label>{k}(元)</label>
|
||||||
|
<NumInput v={v} onCommit={(nv) => editOther(k, nv)} ariaLabel={k} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<div className="formrow">
|
||||||
|
间接费率% <NumInput v={s.overhead} onCommit={(v) => editParam('overhead', v)} ariaLabel="间接费率" />
|
||||||
|
{' '}风险准备% <NumInput v={s.risk} onCommit={(v) => editParam('risk', v)} ariaLabel="风险准备" />
|
||||||
|
</div>
|
||||||
|
<Notice t="管理口径项目利润率=(不含税报价−项目全成本)÷不含税报价,非企业净利率;税额不计入利润。费用均为模拟估算。" />
|
||||||
|
{!s.review && <Notice cls="warn" t="参数调整后可直接生成成本测算报告;经营审核状态仍需单独确认。" />}
|
||||||
|
<Btn t={s.report ? '重新生成成本报告' : '生成成本测算报告'} onClick={generateReport} cls="primary" />{' '}
|
||||||
|
<Btn t="下载成本报告" onClick={downloadReport} disabled={!s.report} />
|
||||||
|
</div>
|
||||||
|
{s.report && (
|
||||||
|
<div className="panel ai section">
|
||||||
|
<h2>✦ 初步测算结论</h2>
|
||||||
|
<p>项目全成本为 <b>{money(c.total)}元</b>,{s.project.sets}套平均成本 {money(c.total / s.project.sets)}元/套。制造资源占比 {((c.process / c.total) * 100).toFixed(1)}%。
|
||||||
|
{s.floor}%利润率要求对应不含税报价不低于 {money(c.total / (1 - s.floor / 100))}元。</p>
|
||||||
|
<p>主要敏感项:焊接和精加工工时、材料用量、外购件规格。建议完成技术澄清并锁定采购交期后承诺交付。</p>
|
||||||
|
<Btn t="生成报价策略 →" onClick={() => go(5)} cls="primary" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 5 AI报价策略 ============
|
||||||
|
function CompetitorQuoteForm() {
|
||||||
|
const { s, cqPresetCleared, saveCompetitorQuote, clearCompetitorQuote, flows } = useApp()
|
||||||
|
const preset = !s.competitorQuote && !cqPresetCleared
|
||||||
|
const q: any = preset
|
||||||
|
? { ...(s.competitorQuote || { name: '', price: null, taxMode: 'exclusive', taxRate: s.tax, sets: s.project.sets, days: s.project.delivery, position: 'balanced', comparable: false, source: '' }), name: '江城重装设备有限公司(模拟)', price: 220000, source: '演示预设报价,仅供模拟比较,非真实友商数据' }
|
||||||
|
: s.competitorQuote || { name: '', price: null, taxMode: 'exclusive', taxRate: s.tax, sets: s.project.sets, days: s.project.delivery, position: 'balanced', comparable: false, source: '' }
|
||||||
|
const [form, setForm] = React.useState(q)
|
||||||
|
const [compChecked, setCompChecked] = React.useState(q.comparable)
|
||||||
|
// 状态切换(预设/清空/项目更换)时同步表单
|
||||||
|
React.useEffect(() => { setForm(q); setCompChecked(q.comparable) }, [preset, s.competitorQuote, s.project])
|
||||||
|
const q0 = s.competitorQuote
|
||||||
|
const refUsed = !!(q0 && Number.isFinite(q0.price) && q0.price > 0 && q0.comparable &&
|
||||||
|
q0.sets === s.project.sets && q0.days === s.project.delivery &&
|
||||||
|
Number.isFinite(q0.taxMode === 'inclusive' ? q0.price / (1 + q0.taxRate / 100) : q0.price) &&
|
||||||
|
(q0.taxMode === 'inclusive' ? q0.price / (1 + q0.taxRate / 100) : q0.price) > 0)
|
||||||
|
const statusText = preset
|
||||||
|
? '已预填可编辑的模拟报价,核对供货范围后保存,即可参与AI策略判定。'
|
||||||
|
: !s.competitorQuote ? '尚未录入友商报价,沿用利润目标生成方案。'
|
||||||
|
: !(Number.isFinite(s.competitorQuote.price) && s.competitorQuote.price > 0) ? '尚未录入友商报价,沿用利润目标生成方案。'
|
||||||
|
: !s.competitorQuote.comparable ? '友商供货范围尚未确认,仅展示信息,不用于调价。'
|
||||||
|
: s.competitorQuote.sets !== s.project.sets || s.competitorQuote.days !== s.project.delivery ? '友商数量或交期与当前项目不一致,仅供参考,不直接参与同口径定价。'
|
||||||
|
: `已按同范围、${s.competitorQuote.sets}套、${s.competitorQuote.days}天比较;友商不含税总价 ${money(s.competitorQuote.taxMode === 'inclusive' ? s.competitorQuote.price / (1 + s.competitorQuote.taxRate / 100) : s.competitorQuote.price)} 元。`
|
||||||
|
const busy = flows.strategyRun.running
|
||||||
|
const set = (k: string, v: any) => setForm((f: any) => ({ ...f, [k]: v }))
|
||||||
|
return (
|
||||||
|
<section className="competitor-quote-panel">
|
||||||
|
<div className="panel-head"><h3>友商报价参考</h3><span className="chip">{preset ? '模拟预设 · 可修改' : '手工录入'}</span></div>
|
||||||
|
<div className="competitor-fields">
|
||||||
|
<label>友商名称<input maxLength={100} value={form.name} placeholder="填写友商或报价来源" disabled={busy} onChange={(e) => set('name', e.target.value)} /></label>
|
||||||
|
<label>报价总额(元)<input type="number" min="0.01" step="0.01" value={form.price ?? ''} placeholder="填写整个项目总价" disabled={busy} onChange={(e) => set('price', e.target.value)} /></label>
|
||||||
|
<label>报价口径
|
||||||
|
<select value={form.taxMode} disabled={busy} onChange={(e) => set('taxMode', e.target.value)}>
|
||||||
|
<option value="exclusive">不含税总价</option>
|
||||||
|
<option value="inclusive">含税总价</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>友商税率 %<input type="number" min="0" max="100" step="0.01" value={form.taxRate} disabled={busy} onChange={(e) => set('taxRate', e.target.value)} /></label>
|
||||||
|
<label>供货数量(套)<input type="number" min="1" step="1" value={form.sets} disabled={busy} onChange={(e) => set('sets', e.target.value)} /></label>
|
||||||
|
<label>交期(天)<input type="number" min="1" step="1" value={form.days} disabled={busy} onChange={(e) => set('days', e.target.value)} /></label>
|
||||||
|
<label>友商报价策略
|
||||||
|
<select value={form.position} disabled={busy} onChange={(e) => set('position', e.target.value)}>
|
||||||
|
<option value="low">低价竞争</option>
|
||||||
|
<option value="balanced">综合平衡</option>
|
||||||
|
<option value="quality">质量与服务溢价</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>信息来源 / 备注<input maxLength={400} value={form.source} placeholder="报价单、客户反馈等" disabled={busy} onChange={(e) => set('source', e.target.value)} /></label>
|
||||||
|
</div>
|
||||||
|
<label className="competitor-scope">
|
||||||
|
<input type="checkbox" checked={compChecked} disabled={busy} onChange={(e) => setCompChecked(e.target.checked)} />
|
||||||
|
已核对友商供货范围和技术要求与本项目一致
|
||||||
|
</label>
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t="保存友商信息" onClick={() => saveCompetitorQuote({ ...form, comparable: compChecked })} disabled={busy} cls="primary" />
|
||||||
|
<Btn t="清空" onClick={clearCompetitorQuote} disabled={busy} />
|
||||||
|
</div>
|
||||||
|
<p className={'competitor-status ' + (refUsed ? 'matched' : '')} role="status">{statusText}</p>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function StrategyAIFlow() {
|
||||||
|
const { flows } = useApp()
|
||||||
|
const a = flows.strategyRun
|
||||||
|
if (!a.visible) return null
|
||||||
|
const phase = a.running ? Math.min(3, Math.floor(a.tick / 2)) : 4
|
||||||
|
return (
|
||||||
|
<section className="ai-inquiry-panel">
|
||||||
|
<div className="panel-head">
|
||||||
|
<b>✦ 多 Agent 协同报价决策</b>
|
||||||
|
<span className="chip purple">{a.running ? '协同处理中' : a.cancelled ? '已暂停' : '策略生成完成'}</span>
|
||||||
|
</div>
|
||||||
|
<div className="ai-inquiry-steps">
|
||||||
|
{['案例与友商检索 Agent', '成本校核 Agent', '方案推演 Agent', '审批整理 Agent'].map((n, i) => (
|
||||||
|
<div key={i} className={phase > i ? 'done' : phase === i ? 'active' : ''}>
|
||||||
|
<b>{phase > i ? '✓' : i + 1} {n}</b>
|
||||||
|
<small>{['检索模拟案例与项目背景', '核对成本、底线与友商口径', '综合利润与友商生成方案', '整理依据与人工审批项'][i]}</small>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="ai-track"><i style={{ width: Math.min(100, (a.tick / 8) * 100) + '%' }} /></div>
|
||||||
|
<div role="status">
|
||||||
|
{a.running
|
||||||
|
? ['正在读取成本版本与项目要求…', '正在检索模拟历史案例…', '案例依据已匹配,正在校核成本与利润底线…', '正在结合利润底线与可比友商报价推演方案…', '已生成 A · 竞争优先方案…', '已生成 B · 综合平衡方案…', '已生成 C · 价值保障方案…', '正在整理内部审批资料…'][Math.min(a.tick, 7)]
|
||||||
|
: a.cancelled ? '生成已暂停,可点击 AI报价策略 重新开始。'
|
||||||
|
: '三种策略及审批资料已准备,请人工选择并确认。'}
|
||||||
|
</div>
|
||||||
|
<small className="muted">离线规则演示 · 多 Agent 协同动画,未调用外部模型;报价仍按项目成本与利润约束计算。</small>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Strategy() {
|
||||||
|
const { s, flows, setFloor, startStrategyAI, setTarget, selectStrategy, approve, rejectStrategy, go, setContext, openModal } = useApp()
|
||||||
|
const st = strategies(s)
|
||||||
|
const reveal = flows.strategyRun.reveal
|
||||||
|
const running = flows.strategyRun.running
|
||||||
|
const cases: [string, string, string][] = [
|
||||||
|
['历史案例 H01', '相似内外套组件 / 8套', '历史成交利润率18%,交期100天'],
|
||||||
|
['历史案例 H02', '高精度导向套 / 12套', '历史成交利润率22%,交期90天'],
|
||||||
|
['当前项目', `10套 / 交期${s.project.delivery}天`, '以本次已审批成本为报价基准'],
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="panel">
|
||||||
|
<div className="strategy-input-grid">
|
||||||
|
<div className="strategy-input-main">
|
||||||
|
<h2>✦ 报价策略模拟 / 以利润底线约束决策</h2>
|
||||||
|
<p>历史案例用于解释,不直接替换本项目成本。三个方案供货范围、交期相同,仅利润与商业定位不同。</p>
|
||||||
|
<div className="formrow">
|
||||||
|
硬性利润率底线% <NumInput v={s.floor} onCommit={setFloor} ariaLabel="利润底线" disabled={running} />
|
||||||
|
<Btn t={running ? 'AI报价策略生成中…' : 'AI报价策略'} onClick={startStrategyAI} disabled={!s.report || running} cls="primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<CompetitorQuoteForm />
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
style={{ width: '100%', height: 70 }}
|
||||||
|
aria-label="当前项目要求"
|
||||||
|
disabled={running}
|
||||||
|
defaultValue={s.context}
|
||||||
|
key={s.context}
|
||||||
|
onBlur={(e) => { if (e.target.value !== s.context) setContext(e.target.value) }}
|
||||||
|
/>
|
||||||
|
<StrategyAIFlow />
|
||||||
|
{reveal >= 1 && (
|
||||||
|
<div className="strategy-revealed">
|
||||||
|
<Notice t="离线AI采用透明规则生成建议,项目补充信息原文附入审批。不会声称已理解任意文本或调用外部大模型。" />
|
||||||
|
<div className="grid3">
|
||||||
|
{cases.map((x, i) =>
|
||||||
|
i < 2 ? (
|
||||||
|
<button key={i} type="button" className="file-card history-case-button"
|
||||||
|
onClick={() => openModal('case', '历史案例 ' + (i === 0 ? 'H01' : 'H02') + ' / 完整项目参考', i === 0 ? 'H01' : 'H02')}
|
||||||
|
title="双击查看完整模拟案例">
|
||||||
|
<b>{x[0]}</b>
|
||||||
|
<p>{x[1]}<br />{x[2]}</p>
|
||||||
|
<span className="history-case-hint">双击查看完整信息 ↗</span>
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<div className="file-card" key={i}><b>{x[0]}</b><p>{x[1]}<br />{x[2]}</p></div>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{reveal >= 2 && (
|
||||||
|
<div className="grid3 strategies section">
|
||||||
|
{st.map((a, i) => (
|
||||||
|
<div key={i} data-strategy-index={i} style={{ display: reveal < i + 2 ? 'none' : undefined }}
|
||||||
|
className={'panel ' + (s.selected === i ? 'selected' : '')}>
|
||||||
|
<span className={'chip ' + (a.valid ? 'green' : 'red')}>{a.valid ? '达到利润底线' : '低于底线 · 禁止审批'}</span>
|
||||||
|
<h2 className="section">{a.label}</h2>
|
||||||
|
<div className="price">¥ {money(a.price)}</div>
|
||||||
|
<small className="muted">项目不含税总价 / {s.project.sets}套</small>
|
||||||
|
<div className="formrow">目标利润率% <NumInput v={s.targets[i]} onCommit={(v) => setTarget(i, v)} ariaLabel={a.label + '目标利润率'} disabled={running} /></div>
|
||||||
|
<p>实际利润率 <b>{a.margin.toFixed(2)}%</b><br />项目利润 <b>{money(a.profit)}元</b><br />含税总额 <b>{money(a.price * (1 + s.tax / 100))}元</b></p>
|
||||||
|
<p>{a.reason}</p>
|
||||||
|
<Btn t={s.selected === i ? '✓ 已选择' : '选择此方案'} onClick={() => selectStrategy(i)} disabled={!s.report || !a.valid} cls="primary" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{reveal >= 5 && (
|
||||||
|
<div className="strategy-revealed">
|
||||||
|
<div className="panel section">
|
||||||
|
<h2>内部策略审批</h2>
|
||||||
|
<p>当前选择:{st[s.selected].label};成本版本 V{s.revision};项目补充说明:{s.context}</p>
|
||||||
|
<Notice t="审批模拟角色:经营负责人。成本、询价、利润率或策略修改后,既有审批自动失效。" />
|
||||||
|
<Btn t={s.approved ? '✓ 策略已批准' : '批准选定策略'} onClick={approve} cls="primary"
|
||||||
|
disabled={!s.report || !s.review || !st[s.selected].valid || s.approved} />{' '}
|
||||||
|
<Btn t="驳回策略" onClick={rejectStrategy} disabled={!s.report} />{' '}
|
||||||
|
<Btn t="生成正式报价单 →" onClick={() => go(6)} disabled={!s.approved} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ 6 正式报价单 ============
|
||||||
|
export function Quote() {
|
||||||
|
const { s, go, archiveQuotation, quotationIsArchived, openModal } = useApp()
|
||||||
|
const archived = quotationIsArchived()
|
||||||
|
if (!s.approved) {
|
||||||
|
return (
|
||||||
|
<div className="panel">
|
||||||
|
<h2>报价单待解锁</h2>
|
||||||
|
<Notice cls="warn" t="需完成技术清单、两部门询价、经营确认、成本报告及策略内部审批后生成报价单。" />
|
||||||
|
<div className="actions"><Btn t="前往策略审批" onClick={() => go(5)} cls="primary" /></div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const exportQuote = () => {
|
||||||
|
const blob = new Blob([
|
||||||
|
`<!doctype html><html lang="zh"><meta charset="utf-8"><title>报价单</title><style>body{font:15px/1.8 'Microsoft YaHei';padding:40px;color:#24324b}h1{text-align:center}table{width:100%;border-collapse:collapse}td,th{border:1px solid #ddd;padding:12px}.right{text-align:right}.quote-brand{font-size:22px;border-bottom:3px solid #5747ef}</style>`,
|
||||||
|
quoteHTML(s),
|
||||||
|
`</html>`,
|
||||||
|
], { type: 'text/html;charset=utf-8' })
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = URL.createObjectURL(blob)
|
||||||
|
a.download = '武船_正式报价样张_V' + s.revision + '.html'
|
||||||
|
a.click()
|
||||||
|
setTimeout(() => URL.revokeObjectURL(a.href), 1000)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="panel noprint" style={{ marginBottom: 18 }}>
|
||||||
|
<div className="panel-head">
|
||||||
|
<h2>✓ 已批准,可生成对客报价样张</h2>
|
||||||
|
<div className="actions">
|
||||||
|
<Btn t="打印 / 保存为PDF" onClick={() => window.print()} cls="primary" />
|
||||||
|
<Btn t="下载报价单HTML" onClick={exportQuote} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p>审批时间:{s.approvedAt} · V{s.revision} · 对客单据不展示内部成本与利润。</p>
|
||||||
|
</div>
|
||||||
|
<div className="actions quotation-library-actions noprint">
|
||||||
|
<Btn t={archived ? '✓ 已进入报价信息库' : '进入报价信息库'} onClick={archiveQuotation} disabled={archived}
|
||||||
|
cls={archived ? 'quotation-archived' : ''} />
|
||||||
|
<Btn t="查询历史报价信息库" onClick={() => openModal('library', '历史报价信息库 / AI智能体工作台')} cls="primary" />
|
||||||
|
</div>
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: quoteHTML(s) }} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const VIEWS = [Home, Demand, Lists, Inquiry, Cost, Strategy, Quote]
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import type { ModuleConfig } from '../registry';
|
||||||
|
|
||||||
|
export const moduleConfig: ModuleConfig = {
|
||||||
|
id: 'wuc-quotation',
|
||||||
|
name: '武船AI智能报价平台',
|
||||||
|
description: '武昌船舶重工 AI 智能报价 DEMO:需求解析、物量清单分析、部门核价、报价生成与策略审批全流程',
|
||||||
|
icon: 'FileSpreadsheet',
|
||||||
|
path: '/wuc-quotation',
|
||||||
|
accentColor: '#7C6FFF',
|
||||||
|
accentColorLight: '#5747EF',
|
||||||
|
gradient: 'linear-gradient(135deg, #1b1840, #2e2870, #5747EF)',
|
||||||
|
gradientLight: 'linear-gradient(135deg, #efecff, #e3ddff, #d2caff)',
|
||||||
|
tags: ['智能报价', '成本核价', '策略审批'],
|
||||||
|
};
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
|||||||
|
.wuc-root header{height:80px}.wuc-root .app-shell{min-height:calc(100vh - 80px)}.wuc-root aside{width:218px}.wuc-root main{padding:24px 28px}.wuc-root .big{font-size:34px;font-weight:700;letter-spacing:-1px}.wuc-root .kicker{color:var(--accent);font-size:11px;letter-spacing:2px}.wuc-root .section{margin-top:18px}.wuc-root .table-scroll input{width:92px;padding:5px}.wuc-root .table-scroll input.wide{width:175px}.wuc-root .panel p{color:var(--muted)}.wuc-root .flow{display:grid;grid-template-columns:repeat(3,1fr);gap:14px}.wuc-root .flow button{padding:24px;text-align:left}.wuc-root .flow b{font-size:17px;display:block;margin:8px 0}.wuc-root .flow small{color:var(--muted)}.wuc-root .badge{border-radius:20px;padding:3px 10px;background:var(--accent-soft);color:var(--accent);font-size:11px}.wuc-root .hero-grid{display:grid;grid-template-columns:1.6fr 1fr;gap:30px}.wuc-root .blueprint{height:200px;width:100%;background:#263858;border-radius:10px}.wuc-root .ai{border:1px solid #c6bfff;background:linear-gradient(120deg,var(--panel),var(--accent-soft))}.wuc-root .price{font-size:32px;color:var(--accent);margin:15px 0}.wuc-root .strategies .panel.selected{border:2px solid var(--accent)}.wuc-root .formrow{display:flex;gap:15px;flex-wrap:wrap;align-items:center;margin:15px 0}.wuc-root .formrow input{width:100px}.wuc-root .good{color:var(--good)}.wuc-root .danger{color:var(--red)}.wuc-root .right{text-align:right}.wuc-root .audit{max-height:320px;overflow:auto}.wuc-root .quote-paper{background:white;color:#1d2943;padding:42px;max-width:960px;margin:auto;border:1px solid #ddd}.wuc-root .quote-paper p{color:#48556b}.wuc-root .quote-paper h1{text-align:center;font-size:28px}.wuc-root .quote-paper .quote-brand{font-size:18px;border-bottom:3px solid #5747ef;padding-bottom:18px;margin-bottom:28px}.wuc-root .previewtext{white-space:pre-wrap;max-height:250px;overflow:auto;background:var(--soft);padding:15px;font:12px/1.7 Consolas,monospace}.wuc-root .chartrow{display:grid;grid-template-columns:110px 1fr 100px;gap:15px;align-items:center;margin:16px 0}.wuc-root .bar{height:12px;background:var(--accent-soft);border-radius:10px;overflow:hidden}.wuc-root .bar i{display:block;background:var(--accent);height:100%}.wuc-root .subtabs{margin:15px 0}.wuc-root .notice{font-size:13px}.wuc-root .rail{display:flex;gap:7px;flex-wrap:wrap;margin-bottom:20px}.wuc-root .rail button{font-size:12px}.wuc-root .pending{color:var(--warn)}.wuc-root .doclinks a{display:block;margin:9px 0}.wuc-root .themebtn{margin-left:10px}@media print{.wuc-root header,.wuc-root aside,.wuc-root #titlebar,.wuc-root .rail,.wuc-root .noprint,.wuc-root footer,.wuc-root #toast{display:none!important}.wuc-root main{padding:0}.wuc-root .quote-paper{border:0;padding:0}.wuc-root{background:white}.wuc-root .app-shell{display:block}}@media(max-width:1100px){.wuc-root .hero-grid{grid-template-columns:1fr}.wuc-root .hero-grid svg{display:none}.wuc-root .flow{grid-template-columns:1fr 1fr}.wuc-root .grid3{grid-template-columns:1fr}.wuc-root .head-status{display:none}}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.wuc-root>header{position:sticky;top:0;z-index:40;background-color:var(--bg)}
|
||||||
|
@media print{.wuc-root>header{position:static;top:auto;z-index:auto}}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
.wuc-root #rail.rail{display:block;margin-bottom:20px;padding:14px 16px;background:var(--panel);border:1px solid var(--line);border-radius:10px;overflow-x:auto}.wuc-root .workflow-progress{list-style:none;display:flex;align-items:center;gap:0;margin:0;padding:0;min-width:1070px}.wuc-root .workflow-progress-item{display:flex;align-items:center;flex:1;min-width:0}.wuc-root .workflow-progress-item:last-child{flex:0 0 auto}.wuc-root .workflow-progress-button{display:grid;grid-template-columns:30px auto;column-gap:8px;row-gap:3px;align-items:center;background:transparent;border:0;border-radius:7px;text-align:left;padding:5px 4px;white-space:nowrap;color:var(--muted)}.wuc-root #rail .workflow-progress-button{font-size:12px}.wuc-root #rail .workflow-progress-button:hover{background:var(--accent-soft);border-color:transparent}.wuc-root .workflow-step-circle{grid-row:1/3;display:grid;place-items:center;width:30px;height:30px;border-radius:50%;background:var(--line);color:var(--muted);font-size:15px;font-weight:700;transition:background .35s,color .35s,box-shadow .35s}.wuc-root .workflow-step-name{font-size:12px;font-weight:600;line-height:1.35}.wuc-root .workflow-step-state{font-size:9px;color:var(--muted);line-height:1.4;font-weight:400}.wuc-root .workflow-connector{display:block;flex:1;min-width:14px;max-width:52px;height:3px;background:var(--line);margin:0 10px;border-radius:4px;overflow:hidden}.wuc-root .workflow-connector i{display:block;width:100%;height:100%;background:var(--good);transform:scaleX(0);transform-origin:left;transition:transform .65s ease}.wuc-root .is-complete .workflow-step-circle{background:var(--good);color:white}.wuc-root .is-complete .workflow-step-name{color:var(--good)}.wuc-root .is-complete .workflow-connector i{transform:scaleX(1)}.wuc-root .is-current:not(.is-complete) .workflow-step-circle{background:var(--accent);color:white;box-shadow:0 0 0 5px var(--accent-soft)}.wuc-root .is-current:not(.is-complete) .workflow-step-name{color:var(--accent)}.wuc-root .is-current.is-complete .workflow-step-circle{box-shadow:0 0 0 4px #00896717}.wuc-root .is-current .workflow-step-state{color:var(--ink)}.wuc-root .is-running .workflow-step-circle{animation:workflowPulse 1.8s ease-in-out infinite}.wuc-root .just-completed .workflow-step-circle{animation:workflowDone .55s ease both}.wuc-root .just-completed .workflow-connector i{animation:workflowConnect .7s ease both}@keyframes workflowPulse{50%{box-shadow:0 0 0 7px #5747ef16}}@keyframes workflowDone{0%{transform:scale(.7);opacity:.5}70%{transform:scale(1.12)}100%{transform:scale(1);opacity:1}}@keyframes workflowConnect{from{transform:scaleX(0)}to{transform:scaleX(1)}}@media(max-width:900px){.wuc-root #rail.rail{padding:12px 10px}.wuc-root .workflow-progress{min-width:1030px}}@media(prefers-reduced-motion:reduce){.wuc-root .workflow-step-circle,.wuc-root .workflow-connector i{animation:none!important;transition:none}}@media print{.wuc-root #rail.rail{display:none!important}}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
.wuc-root .strategy-input-grid{display:grid;grid-template-columns:minmax(300px,.9fr) minmax(420px,1.1fr);gap:24px;align-items:start;margin-bottom:14px}.wuc-root .strategy-input-main>p{font-size:12px;color:var(--muted)}.wuc-root .competitor-quote-panel{padding:16px;border:1px solid var(--line);background:var(--soft);border-radius:10px}.wuc-root .competitor-quote-panel .panel-head{margin-bottom:10px}.wuc-root .competitor-quote-panel h3{margin:0}.wuc-root .competitor-fields{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px 10px}.wuc-root .competitor-fields label{display:grid;gap:4px;color:var(--muted);font-size:10px}.wuc-root .competitor-fields input,.wuc-root .competitor-fields select{width:100%;min-width:0;padding:6px 8px;font-size:11px}.wuc-root .competitor-scope{display:flex;gap:6px;align-items:center;font-size:11px;margin:12px 0}.wuc-root .competitor-scope input{flex-shrink:0}.wuc-root .competitor-status{font-size:10px;line-height:1.7;color:var(--muted);margin:10px 0 0}.wuc-root .competitor-status.matched{color:var(--good)}@media(max-width:1200px){.wuc-root .strategy-input-grid{grid-template-columns:1fr}.wuc-root .competitor-fields{grid-template-columns:repeat(4,minmax(0,1fr))}}@media(max-width:650px){.wuc-root .competitor-fields{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import { BrainCircuit, Calculator, Network, Boxes, ReceiptText, CalendarClock, Sparkles, LogOut, Radar, ShieldCheck, ClipboardCheck, Building2 } from 'lucide-react';
|
import { BrainCircuit, Calculator, Network, Boxes, ReceiptText, CalendarClock, Sparkles, LogOut, Radar, ShieldCheck, ClipboardCheck, Building2, FileSpreadsheet } from 'lucide-react';
|
||||||
import { useTheme } from '@/shared/context/ThemeContext';
|
import { useTheme } from '@/shared/context/ThemeContext';
|
||||||
import StarBackground from '@/shared/components/StarBackground';
|
import StarBackground from '@/shared/components/StarBackground';
|
||||||
import ThemeToggle from '@/shared/components/ThemeToggle';
|
import ThemeToggle from '@/shared/components/ThemeToggle';
|
||||||
@@ -19,6 +19,7 @@ const ICON_MAP: Record<string, React.ComponentType<{ size?: number; color?: stri
|
|||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
ClipboardCheck,
|
ClipboardCheck,
|
||||||
Building2,
|
Building2,
|
||||||
|
FileSpreadsheet,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
|
|||||||
Reference in New Issue
Block a user