From 8ad432963224a32b546cb71f921a5eb29a293a5b Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 25 May 2026 13:45:46 +0800 Subject: [PATCH] =?UTF-8?q?chore(mp):=20=E9=85=8D=E7=BD=AE=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20+=20=E6=96=87=E6=A1=A3=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - config: virtualHost + native-components 拷贝配置 - project.config: skylineRenderEnable=false 调试用 - app.config: 移除 lazyCodeLoading 注释(已在 config/index.ts 控制) - dev.ps1: WECHAT_DEV_MODE=false(真机测试用) - wiki: 更新 DevTools 卡死根因 + 构建模式说明 - CLAUDE.md: 添加 graphify 知识图谱规则 --- CLAUDE.md | 10 ++++++++++ apps/miniprogram/config/index.ts | 7 +++++++ apps/miniprogram/project.config.json | 3 ++- apps/miniprogram/src/app.config.ts | 1 - dev.ps1 | 2 +- wiki/index.md | 14 ++++++++++---- wiki/infrastructure.md | 13 ++++++++++--- 7 files changed, 40 insertions(+), 10 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 455f69a..605b05b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -504,3 +504,13 @@ chore(docker): 添加 PostgreSQL 健康检查 | 设计文档索引 | `wiki/index.md` | | 开发进度、模块状态 | `wiki/index.md` 关键数字 | | 环境配置、连接信息、登录凭据 | `wiki/infrastructure.md` §2 | + +## graphify + +This project has a knowledge graph at graphify-out/ with god nodes, community structure, and cross-file relationships. + +Rules: +- For codebase questions, first run `graphify query ""` when graphify-out/graph.json exists. Use `graphify path "" ""` for relationships and `graphify explain ""` for focused concepts. These return a scoped subgraph, usually much smaller than GRAPH_REPORT.md or raw grep output. +- If graphify-out/wiki/index.md exists, use it for broad navigation instead of raw source browsing. +- Read graphify-out/GRAPH_REPORT.md only for broad architecture review or when query/path/explain do not surface enough context. +- After modifying code, run `graphify update .` to keep the graph current (AST-only, no API cost). diff --git a/apps/miniprogram/config/index.ts b/apps/miniprogram/config/index.ts index c10559c..18bc4d9 100644 --- a/apps/miniprogram/config/index.ts +++ b/apps/miniprogram/config/index.ts @@ -44,6 +44,13 @@ export default defineConfig(async (merge) => { resource: ['src/styles/variables.scss'], }, mini: { + virtualHost: true, + copy: { + patterns: [ + { from: 'src/native-components/', to: 'dist/native-components/', ignore: ['*.ts'] }, + ], + options: {}, + }, compile: { exclude: [], include: [], diff --git a/apps/miniprogram/project.config.json b/apps/miniprogram/project.config.json index 0225de0..f13a73a 100644 --- a/apps/miniprogram/project.config.json +++ b/apps/miniprogram/project.config.json @@ -14,7 +14,8 @@ "minifyWXML": true, "packNpmManually": false, "packNpmRelationList": [], - "ignoreUploadUnusedFiles": true + "ignoreUploadUnusedFiles": true, + "skylineRenderEnable": false }, "condition": {} } \ No newline at end of file diff --git a/apps/miniprogram/src/app.config.ts b/apps/miniprogram/src/app.config.ts index 7c8b4a7..c9825d8 100644 --- a/apps/miniprogram/src/app.config.ts +++ b/apps/miniprogram/src/app.config.ts @@ -1,5 +1,4 @@ export default defineAppConfig({ - // 仅生产构建启用,dev 模式下 lazyCodeLoading 导致 DevTools / 真机调试卡死 ...(process.env.NODE_ENV === 'production' ? { lazyCodeLoading: 'requiredComponents' as const } : {}), pages: [ 'pages/index/index', diff --git a/dev.ps1 b/dev.ps1 index 34928f6..188866a 100644 --- a/dev.ps1 +++ b/dev.ps1 @@ -26,7 +26,7 @@ $env:ERP__AUTH__SUPER_ADMIN_PASSWORD = "Admin@2026" $env:ERP__REDIS__URL = "redis://localhost:6379" $env:ERP__WECHAT__APPID = "wx20f4ef9cc2ec66c5" $env:ERP__WECHAT__SECRET = "52679a563af519590e882c4b8d846f7b" -$env:ERP__WECHAT__DEV_MODE = "true" +$env:ERP__WECHAT__DEV_MODE = "false" $env:ERP__HEALTH__AES_KEY = "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2" $env:ERP__HEALTH__HMAC_KEY = "f6e5d4c3b2a1f6e5d4c3b2a1f6e5d4c3b2a1f6e5d4c3b2a1f6e5d4c3b2a1f6e5" $env:ERP__RATE_LIMIT__FAIL_CLOSE = "false" diff --git a/wiki/index.md b/wiki/index.md index 426ef32..5a6dd76 100644 --- a/wiki/index.md +++ b/wiki/index.md @@ -4,7 +4,7 @@ ## 关键数字 -> 最后更新: 2026-05-24 | 数据截止: feat/media-library-banner 分支(小程序 Phase 2+3 实施完成) +> 最后更新: 2026-05-24 | 数据截止: feat/media-library-banner 分支(小程序 DevTools 卡死排查 + 构建优化) | 指标 | 值 | |------|-----| @@ -18,7 +18,7 @@ | erp-ai 实体 | 20 个 Entity(95 文件,4 AI Provider,chat_handler 支持 FC/Ollama fallback) | | 全系统 Entity | **115 个**(58 health + 20 ai + 33 基础 + 4 core) | | Web 前端 | 316 个 TS/TSX 文件(54 活跃路由,83 API 模块,108 页面) | -| 微信小程序 | Taro 4.2 + React 18,180 个 TS/TSX 文件 / 61 页面(15 主包 + 46 分包) / 4 TabBar + 医生端独立分包,34 组件(ui 21 + patterns 4 + 独立 9) / 45 service 文件 / 4 Zustand store / 12 hooks,统一组件库 + CSS 变量主题(102 SCSS 全量接入 `var(--tk-*)`,字号 token 对齐原型统计,医生端 `.doctor-mode` 靛蓝覆盖,登录页账号密码+微信一键登录);**Phase 2+3 完成**:Token 构建时生成 + Canvas 适老 + PII 清理 + 缓存加密 + any 清零 + 大文件拆分(3→6) + 触觉反馈 + 导航状态保持 + 独立分包 + CI 集成 + HMAC 请求签名;**并发安全**:长轮询独立通道 `requestUnlimited` + ConcurrencyLimiter(12) + safeNavigateTo 全局页栈保护 + reLaunch 去重 + 分包预加载 preloadRule;**构建优化**:`lazyCodeLoading: requiredComponents` 按需注入,主包 2.0MB→766KB(taro.js 526→131KB / vendors.js 230→28KB);**离线抑制**:指数退避(3s→6s→12s→30s cap)防请求洪泛;**五维度分析评分 6.7/10**(架构7.25/安全6.0/UX7.4/工程6.2) | +| 微信小程序 | Taro 4.2 + React 18,180 个 TS/TSX 文件 / 61 页面(15 主包 + 46 分包) / 4 TabBar + 医生端独立分包,34 组件(ui 21 + patterns 4 + 独立 9) / 45 service 文件 / 4 Zustand store / 12 hooks,统一组件库 + CSS 变量主题(102 SCSS 全量接入 `var(--tk-*)`,字号 token 对齐原型统计,医生端 `.doctor-mode` 靛蓝覆盖,登录页账号密码+微信一键登录);**Phase 2+3 完成**:Token 构建时生成 + Canvas 适老 + PII 清理 + 缓存加密 + any 清零 + 大文件拆分(3→6) + 触觉反馈 + 导航状态保持 + 独立分包 + CI 集成 + HMAC 请求签名;**并发安全**:长轮询独立通道 `requestUnlimited` + ConcurrencyLimiter(12) + safeNavigateTo 全局页栈保护 + reLaunch 去重 + 分包预加载 preloadRule;**构建优化**:`lazyCodeLoading: requiredComponents` 仅生产构建启用(dev 下已知 DevTools 卡死 bug),`addChunkPages` 仅 TabBar 页注入 common chunk,主包 dev 892KB / prod 766KB(taro.js 526→131KB / vendors.js 230→28KB);**DevTools 兼容**:游客首页 Swiper dev 模式禁用 circular + 间隔 15s,防 DevTools Chromium 渲染进程逐渐卡死;**离线抑制**:指数退避(3s→6s→12s→30s cap)防请求洪泛;**五维度分析评分 6.7/10**(架构7.25/安全6.0/UX7.4/工程6.2) | | 前端测试 | Web 62 单元测试文件(~693 断言) + 17 E2E spec(13 Web + 4 MP,~64 断言);小程序 12 单元测试文件(127 断言) + 4 E2E spec(~16 断言),覆盖率 ~6% | | 后端测试 | **1030 个函数**(839 同步 + 191 异步),96 个文件含测试 | | 事件系统 | 31 事件类型(health)/ 51 全系统 / 82 发布点 / 15 消费者模块 / Outbox + LISTEN/NOTIFY | @@ -66,7 +66,7 @@ | 告警管理按钮不显示 | [[frontend]] 权限码拼写 | AlertList.tsx | `health.alert.manage` → `health.alerts.manage`(缺 s) | | 小程序晚间血压丢失 | [[miniprogram]] 体征录入 | indicator_type 映射 | **已修复:** 新增 `blood_pressure_evening` 类型,录入页+日常监测页+后端+测试全覆盖 | | 咨询页长轮询 CPU 飙升 | [[miniprogram]] §5 审查 | longPoll delay=0 递归 | **已修复:** 成功路径加 3s 间隔 + 连续失败上限 50 次 | -| 小程序 DevTools 卡死(所有 API ERR_SSL_PROTOCOL_ERROR) | [[miniprogram]] request.ts | `process.env.NODE_ENV === 'production'` 时 http→https 自动转换 | **已修复:** 移除 `getHeaders` 中自动 http→https 升级,URL 以 `.env` 为唯一来源 | +| 小程序 DevTools 卡死(所有 API ERR_SSL_PROTOCOL_ERROR) | [[infrastructure]] 构建模式 | 用了 `build:weapp`(生产构建)→ `.env.production` 中 `https://api.hms.example.com`(无 TLS)→ 全部 SSL 错误 → 离线抑制 → 卡死 | **解决:** DevTools 调试用 `dev:weapp`(使用 `.env` 中 `http://` 开发地址),不用 `build:weapp`(2026-05-25 确认根因) | | 小程序 Tab 切换卡死(并发请求阻塞 30s) | [[miniprogram]] request.ts | `getHeaders()` 中 `await tryRefreshToken()` 预检查 | **已修复:** 移除 getHeaders 中的同步 Token 刷新预检查,仅依赖 401 重试路径 | | 小程序患者端登录后卡死(Tab 切换频繁卡死) | [[miniprogram]] §5 审查 | 并发请求超微信 10 限制排队 + 长轮询重叠 + 防重入缺失 | **已修复:** 全局并发限制 MAX_CONCURRENT=8 + generation counter 长轮询 + loadingRef 防重入 | | 小程序咨询页闭会话崩溃(pollingRef is not defined) | [[miniprogram]] 审计第二轮 | generation counter 重构后 loadData 残留 pollingRef 引用 | **已修复:** 移除 loadData 中 `pollingRef.current = false` 残余行 | @@ -140,7 +140,13 @@ | Article Handler 缺 .validate() | [[erp-health]] article_handler | ~15 个 handler 缺少 .validate() 调用 | **已修复:** article/category/tag handler 全部补齐 .validate() + DTO Validate derive(2026-05-21) | | 前端 16 处 any 类型 | [[frontend]] 多文件 | client/points/usePaginatedData/MediaLibrary/ArticleEditor | **已修复:** AxiosRequestConfig 增强 + OptionsConfig 类型 + TreeNode 接口,16→1(2026-05-21) | | 小程序患者端 403(health-records/lab-reports/alerts/analytics/followups) | [[miniprogram]] 权限配置 | patient 角色缺少 .manage 权限 | **已修复:** `m20260522_000162` 补齐 15 个 manage 权限 + 注册 `system.analytics.submit` 幽灵权限(2026-05-22) | -| DevTools 打开即卡死 / 游客首页停留后 CPU 30%+ | [[miniprogram]] 构建配置 + request.ts | 主包 2MB 全量组件注入 + 离线时请求洪泛 | **已修复:** `lazyCodeLoading: requiredComponents`(主包 2.0→0.77MB)+ 离线抑制指数退避 + TS readonly 兼容(2026-05-24) | +| DevTools 打开即卡死 / 真机调试卡死 | [[miniprogram]] app.config.ts | `lazyCodeLoading: requiredComponents` 在 dev 模式下触发微信 DevTools 已知 bug | **已修复:** 仅 `NODE_ENV=production` 时启用 lazyCodeLoading,dev 构建不注入(2026-05-24) | +| 小程序主包 2MB 超限 | [[miniprogram]] config/index.ts | `addChunkPages` 将 common chunk 注入所有主包页面 | **已修复:** 仅 TabBar 页面 + 根级页面注入 common chunk,分包页面由自身 vendors.js 承载(dev 892KB / prod 766KB)(2026-05-24) | +| 离线请求洪泛(每 3s 重试) | [[miniprogram]] request.ts | 固定 OFFLINE_SUPPRESS_MS=3000 无退避,断网时请求排队占满并发槽 | **已修复:** 指数退避 3s→6s→12s→30s cap + consecutiveNetErrors 累计计数(2026-05-24) | +| DevTools 逐渐卡死(CPU 15-30%,轮播图仍在动画但 UI 不可点击) | [[miniprogram]] 游客首页 Swiper | Swiper `circular` 克隆 DOM 节点 + 5s 间隔动画在 DevTools Chromium 渲染进程中持续积累内存 | **已修复:** dev 模式禁用 circular + interval 改为 15s,生产模式不变(2026-05-24) | +| TS 编译错误 `readonly Tab[]` 不可赋值给 `Tab[]` | [[miniprogram]] SegmentTabs | 页面组件用 `as const` 创建的 readonly 数组无法传入 mutable `Tab[]` 类型 | **已修复:** SegmentTabs 的 `Tab` 属性改为 `readonly` + `tabs` prop 改为 `readonly Tab[]`(2026-05-24) | +| 重建失败 `dist/` 被锁定 | [[miniprogram]] 构建流程 | 微信 DevTools 进程持有 dist 目录文件句柄,taro build 无法写入 | **解决:** `taskkill /F /IM wechatdevtools.exe` 后重新构建(2026-05-24) | +| DevTools 打开即卡死(所有项目,Taro/原生均复现) | [[miniprogram]] appid 配置 | appid `wx20f4ef9cc2ec66c5` 的微信后台配置触发 `WAServiceMainContext.js` 内部 timeout,导致 DevTools 渲染进程逐渐无响应;**根因定位:** 换用其他 appid(如测试 appid `wx97debf52c9547da4`)后 Taro/原生均不卡死,确认是 appid 后台服务配置问题而非框架/代码问题 | **待解决:** 需到微信公众平台(mp.weixin.qq.com)检查该 appid 是否开通了云开发/云函数/第三方插件等导致 DevTools 初始化时连接超时的服务;临时方案:开发调试时使用测试 appid(2026-05-24) | ## 模块导航 diff --git a/wiki/infrastructure.md b/wiki/infrastructure.md index dfd17a8..d5e3ede 100644 --- a/wiki/infrastructure.md +++ b/wiki/infrastructure.md @@ -1,6 +1,6 @@ --- title: 开发环境 -updated: 2026-05-16 +updated: 2026-05-25 status: stable tags: [infrastructure, dev-environment, windows, postgresql] --- @@ -128,12 +128,18 @@ cd apps/web && pnpm build # 构建生产版本 ### 微信小程序 ```bash -cd apps/miniprogram && pnpm run dev:weapp # 小程序开发模式(微信开发者工具打开 dist/) -cd apps/miniprogram && pnpm run build:weapp # 小程序生产构建 +cd apps/miniprogram && pnpm run dev:weapp # ✅ 开发调试(必须用这个!使用 .env 中的开发地址) +cd apps/miniprogram && pnpm run build:weapp # 生产构建(使用 .env.production 中的生产域名,DevTools 中不可用) cd apps/miniprogram && pnpm run dev:h5 # H5 浏览器预览(端口 10086,推荐调试用) cd apps/miniprogram && pnpm run build:h5 # H5 生产构建 ``` +> **构建模式区分(重要):** +> - `dev:weapp` → `NODE_ENV=development` → 加载 `.env` → `TARO_APP_API_URL=http://192.168.31.123:3000/api/v1` +> - `build:weapp` → `NODE_ENV=production` → 加载 `.env.production` → `TARO_APP_API_URL=https://api.hms.example.com/api/v1` +> +> **DevTools 中调试必须用 `dev:weapp`**,否则请求打到生产域名(无 TLS)→ `ERR_SSL_PROTOCOL_ERROR` → 离线抑制触发 → DevTools 卡死。这是一个已踩坑的陷阱(2026-05-25)。 + > **调试建议:** 日常 UI 开发和页面调试优先用 `dev:h5`(浏览器热更新 + DevTools),完成后在微信开发者工具中做最终验证。H5 模式下微信特有 API(`wx.login`、`Taro.request` 微信登录态等)不可用,但页面布局和交互可完整预览。 > > H5 模式通过 `.env.h5` 将 API URL 设为 `/api/v1`(相对路径),dev server 自动代理到 `localhost:3000`,无需处理 CORS。 @@ -190,6 +196,7 @@ cd apps/web && pnpm install && pnpm dev | 日期 | 变更 | |------|------| +| 2026-05-25 | 明确 dev:weapp vs build:weapp 构建模式区分,记录 .env.production 导致 DevTools 卡死的陷阱 | | 2026-04-26 | 从 CLAUDE.md 迁移:常用命令(§9) | | 2026-04-25 | 外部化微信凭据和健康加密密钥为环境变量;添加 4 个新的必设环境变量 | | 2026-04-24 | 添加微信小程序配置信息和集成契约 |