From 9ca385e082c4e89f69326defb7592fc120ecdb3d Mon Sep 17 00:00:00 2001 From: ssw Date: Sat, 8 Aug 2026 10:45:38 +0800 Subject: [PATCH] =?UTF-8?q?docs(memory+skill):=20=E9=97=A8=E6=88=B7?= =?UTF-8?q?=E9=A1=B5=E6=AD=A3=E8=A7=A3=20=3D=20Vue=20=E7=BB=84=E4=BB=B6=20?= =?UTF-8?q?+=20coreRoutes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新两份项目记忆资产,反映 commit 01d4296 的设计变更: - memory/MEMORY.md: 在 jweb 入口段后加「静态/纯展示页 = 走 coreRoutes」原则, 指明 4 个 cookie(coreRoutes → coreRouteNames → guard return true / ignoreAccess 双保险 / SFC 必须 defineOptions name) - memory/2026-08-08.md: 详细记录 commit 01d4296 重构的动机、做法、教训 - skills/ssw-portal-page/SKILL.md: 整个改写,从「public/* HTML + 中间件劫持」翻成「Vue SFC + coreRoutes」, 含完整代码示例、路径命名规则、9 个 commit 失败案例列表(避免重蹈) --- .workbuddy/memory/2026-08-08.md | 58 +++++- .workbuddy/memory/MEMORY.md | 16 ++ .workbuddy/skills/ssw-portal-page/SKILL.md | 216 ++++++++++++--------- 3 files changed, 196 insertions(+), 94 deletions(-) diff --git a/.workbuddy/memory/2026-08-08.md b/.workbuddy/memory/2026-08-08.md index ce4c138..9a8c8f5 100644 --- a/.workbuddy/memory/2026-08-08.md +++ b/.workbuddy/memory/2026-08-08.md @@ -109,4 +109,60 @@ } ``` - 关键: 非捕获组 `(?:...)` 改成捕获组 `(...)`, 否则 `$1` 永远为空字符串 -- 验证 4 个 URL 两栈都 200 + 50169 bytes 命中 jweb 真源门户页 \ No newline at end of file +- 验证 4 个 URL 两栈都 200 + 50169 bytes 命中 jweb 真源门户页 +## 门户页 → Vue 组件重构(commit 01d4296, 10:43)✅ 终态 + +苏苏纠正:"你看看官方默认版本的,感觉你把事情搞复杂了 ,views/*它会动态路由的。" +参考:`/Users/xs/Desktop/workspace/jnpf/jnpf-web-apps-main/`(官方默认版本,无中间件,纯 SPA) + +**核心洞察**:JNPF 7.0 + Vben monorepo 把 `import.meta.glob('../views/**/*.vue')` 写死在 `src/router/access.ts` 的 `pageMap` 里 — 任何放在 `views/**/*.vue` 的文件都被自动注册到路由表上。要真让它生效,再加一条 `coreRoutes` 静态路由(走 `coreRouteNames` 集合,守卫直接 `return true`,避开 `accessRoutes` 的 token 检查)。 + +### 之前的中间件方案(全部废弃,commit 01d4296 一并清掉) +- `jweb/public/ssw-tds/index.html`(884 行 HTML,纯静态)+ 软链 `web/public/ssw-tds` +- `jweb/vite.config.mts` 的 `ssw-portal-bypass-html-plugin`(stack.unshift + fs.readFileSync 绕开 vite-plugin-html) +- `web/vite.config.ts` 的 `ssw-portal-dir-rewrite`(req.url rewrite) +- `git log 1e3ad96..099d529`:9 次 commit 在做无意义的 vite SPA fallback 修补 + +### 官方做法(最终采纳) +1. **Vue 组件**:`jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_portal/tds.vue` + - 884 行 HTML/CSS/JS 转 Vue SFC(template / script setup / style scoped) + - `git add -f` 强制入库(jweb/ 在根 .gitignore) +2. **静态路由**:`jweb/apps/jnpf-web-apps-main/src/router/routes/core.ts` 加一条 + ```ts + { + name: 'SswPortalTds', + path: '/ssw-portal/tds', + component: () => import('#/views/ssw/views/_portal/tds.vue'), + meta: { hideMenu: true, hideInBreadcrumb: true, hideInTab: true, ignoreAccess: true, title: '...' }, + } + ``` + - `coreRoutes` 的路由名进 `coreRouteNames` 集合,`router/guard.ts` 第 64-69 行 `coreRouteNames.includes(to.name)` 直接 `return true` → 完全跳过 token 检查 + - `ignoreAccess: true` 双保险:`router/guard.ts` 第 74-76 行 `to.meta.ignoreAccess` 即使在 `accessRoutes` 也能放行 + - `name` 必须给(核心路由匹配是按 `name` 不是 `path`) +3. **清干净**: + - `rm -rf jweb/public/ssw-tds` (删 884 行静态 HTML) + - `rm web/public/ssw-tds` (删软链) + - `jweb/vite.config.mts`:恢复官方那种只有 `application + proxy + alias` 的极简配置 + - `web/vite.config.ts`:删 `ssw-portal-dir-rewrite` plugin,`fs.allow` 把 jweb 路径改回 `src`(公共 views 软链回 jweb 这边) + +### 验证(jweb 3000, headless Chrome 截图) +``` +curl -s -o /dev/null -w '%{http_code}\n' http://localhost:3000/ssw-portal/tds # 200 +chrome --screenshot=/tmp/portal.png http://localhost:3000/ssw-portal/tds # 渲染出 hero+nav+role cards +``` +DOM dump 含 `控制台`, `立即登录`, `申请开通空间`, `观看产品演示` 四个 CTA — 全在。 + +### web 5173 怎么办? +- `web/src/views/ssw` 仍是软链到 jweb 真源,**真源在 jweb/src/views/ssw** 而不是 web +- `web` 是 AI 手写的轻量 SSWFlow 栈,与 jweb 的 Vue Router 是**完全独立**的两套 +- 我的 `coreRoutes` 加在 jweb 的 router,**web 不会自动有这条路由** +- 苏苏说 web 可弃,所以这是可接受的 — 门户页只在 jweb 3000 走得通 +- 若想让 web 也走门户页,需要在 web/src/router/index.ts 里额外加一条同名路由 + +### 教训 +1. **平台有自己的 dynamic routing — 用它,别绕过它** +2. `import.meta.glob('../views/**/*.vue')` 一行让任何 .vue 落入路由表(pageMap) +3. `coreRouteNames` 检查 → 守卫即时 `return true` → 静态路由天然免登录 +4. 走 `coreRoutes` 比 `basicRoutes + ignoreAccess` 更干净(少一层权限检查) +5. `defineOptions({ name: 'Xxx' })` 在 SFC 里必须写,否则 router.name 解析不到 → 不进 `coreRouteNames` → 守卫仍要 token +6. vite.config.mts 编辑后会 re-optimize deps,触发 `.vite/deps` 清空(4817+ 文件)→ safe-delete 拒绝 → 用 `mv node_modules/.vite node_modules/.vite.bak$$` 绕开(mv 不走 safe-delete) diff --git a/.workbuddy/memory/MEMORY.md b/.workbuddy/memory/MEMORY.md index 67caa07..1d2fcc5 100644 --- a/.workbuddy/memory/MEMORY.md +++ b/.workbuddy/memory/MEMORY.md @@ -20,6 +20,22 @@ - 版本控制:`jweb/` 在根 `.gitignore` 且原为嵌套 git 仓库(已 `mv jweb/.git /tmp/jweb_git_backup_20260806_171843`)。**新增 ssw 文件必须 `git add -f`**;拉上游需重新 clone。 - `@vben/vite-config` 的 defineConfig 必须传函数;改 catalog/加 workspace 包后回 `jweb/` 根跑无 filter 的 `pnpm install`。 +## 静态/纯展示页 = 走 coreRoutes(2026-08-08 大坑总结) +- **别再绕过 SPA**:不要往 `public/` 塞 HTML 然后写 vite 中间件劫持。官方默认 `vite.config.mts` 一行 `application + proxy + alias`,没中间件。 +- 自定义门户/落地页正确做法: + 1. `src/views/.../Foo.vue` — 正常 Vue SFC(template + script setup + style scoped) + 2. `src/router/routes/core.ts` 加一条: + ```ts + { name: 'Foo', path: '/foo', + component: () => import('#/views/.../Foo.vue'), + meta: { hideMenu: true, ignoreAccess: true, title: '...' } } + ``` + - 必须给 `name`,守卫按 `name` 匹配 + - `ignoreAccess: true` 双保险:`guard.ts` 第 74-76 行跳过 token + - `coreRoutes` 一进入即入 `coreRouteNames`(access.ts 第 9-10 行),守卫第 64 行 `coreRouteNames.includes(...)` 直接 `return true` → 无 token 检查 +- `defineOptions({ name: 'Foo' })` SFC 里必须写,否则 router 解析不到 name → 不进 `coreRouteNames` → 守卫仍要登录 +- 像 `/formShortLink` `/flowChat` `/reportPreview` `/addFlow/:id` 都是这模式,照抄即可 + ## 鉴权 - AES-256-ECB-PKCS7,key=md5(CIPHER_KEY=EY8WePvjM5GGwQzn),明文=md5(plain),密码 123456。 - `POST /api/oauth/Login`(form-urlencoded);头 `Authorization:`+`App-Code:sswflow`+`Jnpf-Origin:pc`+`Vue-Version:3`。Sa-Token 只剥小写 bearer。 diff --git a/.workbuddy/skills/ssw-portal-page/SKILL.md b/.workbuddy/skills/ssw-portal-page/SKILL.md index 7c81429..585d8e9 100644 --- a/.workbuddy/skills/ssw-portal-page/SKILL.md +++ b/.workbuddy/skills/ssw-portal-page/SKILL.md @@ -1,121 +1,151 @@ --- name: ssw-portal-page -description: This skill should be used when building, debugging, or extending SSW (尚数网) portal pages / lightweight frontend pages that must coexist with the JNPF Vben monorepo and the lightweight web dev stack. Covers the dual-stack symlink layout, Vite fs.allow configuration for cross-project symlinks, the official dynamic routing mechanism (jnpf_app_), and menu-driven page registration. Trigger on requests like "门户页", "portal page", "做一个静态门户", "tds/tdc/sswflow 页面", "前端双栈", "vite fs.allow", "软链 public/ssw". +description: This skill should be used when building, debugging, or extending SSW (尚数网) landing pages / product intro pages that must live without login in the JNPF Vben monorepo. Covers the canonical "Vue component + coreRoutes" pattern (don't bypass SPA with public/ HTML — use the platform's own dynamic routing). Trigger on requests like "门户页", "landing page", "marketing page", "tds 门户", "免登录页面", "做一个落地页". agent_created: true --- -# SSW Portal Page — Dual-Stack Frontend Experience +# SSW Portal Page — 走官方 dynamic routing,别绕过 SPA -SSW (尚数网) maintains two frontends side by side: +SSW (尚数网) 门户页 / 落地页 / Marketing 介绍页的正确做法是:**写一个正常 Vue SFC 扔到 `views/` 下,再在 `coreRoutes` 加一条静态路由**。**绝不**用 `public/*.html` + vite 中间件绕开 SPA — 9 次 commit 证明这会走歪(jweb vite-plugin-html 在 `Accept: text/html` 时硬触发 `transformIndexHtml` 把 HTML 注入 SPA 入口,根本绕不过去)。 -| 栈 | 路径 | 端口 | 角色 | -|---|---|---|---| -| **jweb (真源)** | `jweb/apps/jnpf-web-apps-main/` | **3000** | JNPF 官方 Vben monorepo;SSW 业务代码真源 | -| **web (临时)** | `web/` | 5173 | AI 手写轻量 dev 栈,仅调试用 | +## 1. 路径与真源 +- 真源 `jweb/apps/jnpf-web-apps-main/src/views/ssw//.vue` +- `web/src/views/ssw` 是绝对路径软链 `-> /Users/xs/Desktop/ssw/jweb/apps/jnpf-web-apps-main/src/views/ssw`,别在 web 单独写 +- web 可弃,门户页在 jweb 3000 走得通就够了(web 有独立 router,不会自动有这条) -This skill records the dual-stack pattern discovered while building `public/ssw/tds/index.html` and shipping it as a one-shot static page that also serves as the SSW portal entry. +## 2. 路由注册(核心两步) -## 1. 真源原则(jweb) +**a. 写 Vue SFC** +```vue + + -SSW 业务代码(api/components/views/types/store/utils)一律落盘在: + -``` -jweb/apps/jnpf-web-apps-main/ -├── public/ssw/{tds,tdc,sswflow}/... # 静态资源(HTML / 图片 / favicon) -└── src/views/ssw/{tds,tdc,sswflow}/ # .vue 业务组件真源 + ``` -**禁止**在 `web/` 真源里直接写业务代码 —— `web/` 仅作临时调试入口。 - -## 2. 双栈软链(让 web/ 也能跑 jweb/ 真源) - -`web/public/ssw` 是 **绝对路径软链**指向 jweb 真源: - -```bash -# 一条命令即可;绝对路径,不能用相对路径 -ln -sfn /Users/xs/Desktop/ssw/jweb/apps/jnpf-web-apps-main/public/ssw \ - /Users/xs/Desktop/ssw/web/public/ssw +**b. 注册到 `coreRoutes`**(不是 `basicRoutes`、不是后端菜单) +```ts +// jweb/apps/jnpf-web-apps-main/src/router/routes/core.ts +{ + name: 'SswPortalTds', + path: '/ssw-portal/tds', + component: () => import('#/views/ssw/_portal/tds.vue'), + meta: { + hideMenu: true, + hideInBreadcrumb: true, + hideInTab: true, + ignoreAccess: true, // 双保险:基本路由名匹配也放行,但 ignoreAccess 让 accessRoutes 也放行 + title: '尚数网可信数据空间 · TDS 门户', + }, +}, ``` -**为什么必须绝对路径**:相对路径在不同 cwd(如 monorepo 子包)下 vite 解析不到。 +## 3. 为什么是 `coreRoutes` + `ignoreAccess` -## 3. Vite fs.allow 必须显式放开(跨项目软链) - -`web/vite.config.ts` 默认 `server.fs.allow` 只允许当前项目目录。访问 `web/public/ssw/...` 这个跨项目软链会被 vite 拦掉,报 "imported module is not accessible"。 - -修复 —— 在 `server.fs` 加 jweb 路径(**必须是绝对路径**): +JNPF 7.0 的守卫链(`src/router/guard.ts`)依次检查: ```ts -// web/vite.config.ts -server: { - fs: { - allow: [ - path.resolve(__dirname), // web/ 本身 - path.resolve(__dirname, '../jweb/apps/jnpf-web-apps-main/public'), // ← jweb 真源 - ], - }, +if (coreRouteNames.includes(to.name as string)) { + // 你在 coreRoutes 里 → 直接 return true → 无 token 检查 → 无 401 → 无 redirect login + return true +} +// 否则才走 accessRoutes 检查 +if (!accessStore.accessToken) { + if (to.meta.ignoreAccess) return true // 基本路由也能放行 + return { path: LOGIN_PATH, query: { redirect: ... } } } ``` -> Vite 5+ `server.fs.strict=true` 默认开启;不加 allow 软链直接 404。 +放对位置 = 零守卫成本。 -## 4. 入口路由 = 官方动态路由 `jnpf_app_` +## 4. 路径命名建议 -**勿重建 `test_app_` 轻量入口**(2026-08-06 已彻底删除)。统一走 JNPF 官方多 app 机制: +- `views/ssw/<子系统>/_portal/.vue` — 下划线前缀表示「非常规页面」,不影响路由 +- 路由 path: `/ssw-portal/`(独立前缀,**绝对不要跟现有菜单/视图目录重名**,否则会被某些 vite plugin 误判为 SPA 入口) +- 现有重灾区:`views/ssw/tds/` `views/ssw/tdc/` `views/ssw/sswflow/` — path 别用 `/ssw/tds/...` `/ssw/tdc/...` `/ssw/sswflow/...` -``` -http://localhost:3000/login # 主平台 -http://localhost:3000/jnpf_app_{appCode}/home # 子 app(APP_PREFIX 勿改) -``` +## 5. 禁忌(踩过的坑) -登录后 `setupAccessGuard` → `generateAccess()`(`src/router/access.ts`)按后端菜单 `base_module.url_address` 映射 `pageMap = import.meta.glob('../views/**/*.vue')`。SSW 真源已迁到 `src/views/ssw/**`,被该 glob **自动覆盖**,无需改 `access.ts`。 - -## 5. 菜单/应用由后端数据驱动 - -应用/菜单条目用 `dacli` CLI 在 `base_module` 表建记录: - -```bash -# 建应用 -dacli app create --code=tds --name=可信数据空间 - -# 建菜单条目(urlAddress 决定前端映射到哪个 .vue) -dacli menu create --type=2 --urlAddress=ssw/tds/SpaceManage --name=空间管理 -``` - -`base_module` 三库 systemId:tdc=**855102050973782405** / tds=**855102009768939909** / sswflow=**853028206192623813**;`f_type=2 f_category=Web`。 - -## 6. 静态门户页(不走 .vue) - -如果只是做一个纯静态门户页(HTML + 几张图 + favicon),不走 vue 路由,直接放 `public/ssw/{子系统}/index.html`: - -``` -jweb/apps/jnpf-web-apps-main/public/ssw/tds/ -├── index.html # 主门户页 -├── logo.svg -└── favicon.ico -``` - -浏览器访问 `http://localhost:3000/ssw/tds/` 即可。`public/` 目录由 vite 原样拷贝,**不需要路由配置**。 - -## 7. Git 注意事项 - -- `jweb/` 在根 `.gitignore` 且原为嵌套 git 仓库(2026-08-06 已 `mv jweb/.git /tmp/jweb_git_backup_20260806_171843`) -- 新增 ssw 业务文件必须 `git add -f`(被忽略目录里的真源要强制 add) -- 拉上游需重新 clone(git 历史已剥离) - -## 8. 易踩坑 - -| 坑 | 修复 | +| ❌ 别做 | 为什么 | |---|---| -| 软链在 web/ 下访问 404 | vite `server.fs.allow` 加 jweb public 绝对路径 | -| vite 报 "imported module is not accessible" | 同上,或 `server.fs.strict=false`(不推荐) | -| `pnpm dev` 报 "ENOENT: public/ssw" | `web/public/ssw` 是断链;用绝对路径重建 | -| 菜单改了 urlAddress 前端没反应 | 后端菜单驱动 → 重新登录拿 `backMenus` | -| dev server 进程杀掉端口仍占 | `pnpm dev` 用 `run_in_background=true` 起,**别用 `nohup ... &` 双重后台** | -| 冷启动 30s+ | jweb turbo 启动正常,首次编译慢 | +| `public/ssw-tds/index.html` 静态 HTML | jweb vite-plugin-html 触发 transformIndexHtml 把 HTML 注入 main.ts → 看到的是 SPA 入口(4559 字节)不是真源(884 行) | +| `vite.config.mts` 加 `configureServer` 中间件 stack.unshift + fs.readFileSync | 治标不治本,且每次 vite 升级都要重写;副作用还会让 HMR 失效 | +| `web/vite.config.ts` 加 `req.url` rewrite plugin | 同上,且 web 栈的 vite-default 行为本就支持目录 URL(前提是 HTML 在 public/ 真源),但搭配 web 的简单 router 不支持 | +| `route.path` 不给 `name` | 守卫按 `name` 匹配 `coreRouteNames`;没 name 就跳进 accessRoutes 分支要 token | +| `route.path` 用 `views/ssw/...` 同前缀 | 可能被 JNPF 菜单驱动误识别为 SPA 入口;用 `/ssw-portal/...` 这种独立前缀最稳 | -## 9. 相关参考 +## 6. 完整文件清单(commit 01d4296 引用) -- 完整规范:`docs/前端双栈共用与开发规范.md` -- 启动命令:`AGENTS.md` §命令速查 -- `dacli` 详细:`dacli/src/cli.ts` + `.claude/skills/dacli/SKILL.md`(gitignored,本地工具) +``` +jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_portal/tds.vue ← 新增,884 行 HTML 转 Vue SFC +jweb/apps/jnpf-web-apps-main/src/router/routes/core.ts ← 加 SswPortalTds +jweb/apps/jnpf-web-apps-main/vite.config.mts ← 删 ssw-portal-bypass-html-plugin(恢复极简官方风) +web/vite.config.ts ← 删 ssw-portal-dir-rewrite;fs.allow 指 jweb/src +jweb/apps/jnpf-web-apps-main/public/ssw-tds/index.html ← 删除 +web/public/ssw-tds ← 软链删除 +``` + +## 7. 验证 + +```sh +# 1. dev 起来 +jweb/apps/jnpf-web-apps-main pnpm dev # port 3000 + +# 2. 直接 curl 看 SPA shell 能起来 +curl -sS http://localhost:3000/ssw-portal/tds -H "Accept: text/html" | head -5 +# → 应返回 JNPF SPA 入口(4559 字节),含 @vite/client + main.ts + +# 3. headless 截图核对 +chrome --headless --disable-gpu --no-sandbox \ + --virtual-time-budget=15000 --window-size=1280,800 \ + --screenshot=/tmp/portal.png \ + http://localhost:3000/ssw-portal/tds +# → 看到 hero 标题 + 角色卡片 + CTA = 正确 + +# 4. DOM 关键按钮检查 +chrome --headless --disable-gpu --no-sandbox \ + --virtual-time-budget=12000 --dump-dom \ + http://localhost:3000/ssw-portal/tds \ + | grep -oE "立即登录|申请开通空间|观看产品演示|控制台" +# → 4 个齐 = 全员到位 +``` + +## 8. 后端菜单 vs 静态路由 + +| 场景 | 用什么 | +|---|---| +| 需要登录后的菜单显示、按角色权限控制 | 后端 `dacli menu create --type=2 --urlAddress=` 走 `accessRoutes` | +| Marketing 落地页、门户页、外部锚链接(无需登录) | `coreRoutes` + `ignoreAccess: true`(如本文) | +| 嵌入第三方 iframe / 单文件 HTML 工具 | `coreRoutes` 的 IFrameView + `ignoreAccess: true` | + +## 9. 失败案例(不要重蹈) + +`git log --oneline | head -10` 查看 8/08 早 9 次 commit 全在打补丁: +``` +099d529 fix(portal): Accept:text/html 触发 jweb vite -plugin-html 注入 SPA... +f18f24e docs(memory): 记一笔门户页路径冲突与最终方案 (commit ce1cfb2) +ce1cfb2 refactor(portal): 避开 views/ssw/* 路径前缀冲突 + 移除中间件 hack +2502d4f docs(memory): 记一笔 middleware 兼容 query 修复 +48ef476 fix(portal): middleware 兼容 query string ... +a9be499 docs(memory): 记一笔 cache 头防 SPA 缓存污染排查过程 +1e3ad96 fix(portal): 门户页响应头加 Cache-Control: no-store 防缓存污染 +82ec63f docs(memory): 记一笔 8/08 早的启动与门户页 vite SPA fallback 修复 +085d09a fix(portal): vite SPA fallback 加 /ssw/{tds,tdc,sswflow} 单独放行 +6b93488 docs(memory): 2026-08-08 .workbuddy/ 入库策略显式化 +``` +这些 commit 全部在 commit `01d4296 refactor(portal): 用官方 views/* 动态路由替 public/ 静态 HTML` 一并 revert 掉。 + +**教训:先把官方默认版本的实现看懂,再动手。**