diff --git a/CHANGELOG.md b/CHANGELOG.md index c95841fe..19a21080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ > 本仓 CHANGELOG 自重建起记(POC 明细见归档仓 /data/poc-archive/repos/go-sms.git 的 CHANGELOG.md,已冻结)。 +## 2026-11-16(傍晚)· Issue#2:管理前端多标签导航 + 页签缓存 + +- **工单**:Gitea Issue#2「优化:管理前端V1」——增加菜单 Tab 页(可独立关闭/一次全部关闭),切换后页面状态保留。 +- **多标签导航**:stores/tabs.ts(tab 身份=fullPath;home 固定不可关;登出 $reset 防跨角色残留)+TagsBar.vue(纯原生元素,aurora token 风格;✕ 独立关闭+中键关闭[auxclick button===1,@click.middle 对中键永不触发]+关闭其他+全部关闭;关当前回退相邻 tab 右邻优先)。 +- **页签缓存**:MainLayout ``+`:key="fullPath"`(参数页/查询变体独立实例);**29 个业务视图 defineOptions name=路由名**(28 新增+stats/profit 对齐;script setup 文件名推断名永不命中 include——15 个 index.vue 全叫 "index");ComingSoon(11 路由共用)刻意豁免(无本地状态,不缓存零副作用)。 +- **守门**:view-cache-name.spec.ts 固化「组件名=路由名」约定(漏写=缓存静默失效,测试红而非线上发现)+MainLayout keep-alive 结构断言;verify-layout.mjs +5 项 tags-bar 断言(18→23)且凭据 env 化(SHOT_USER/SHOT_PASS 缺省 s2demo;内置 admin 原密码首启打印一次已不可知,原硬编码 admin123 已不可登录)。 +- **门禁**:eslint0/vue-tsc0/vitest **165**(+17:tabs-store 7+守门 4+tags-bar 6)/build 9.99s(chunk 剖面不变);verify-layout **23/23**;Chrome 157 实机走查 **17/17** 含两项核心状态保留实证(结算页内 Tab 选中+筛选 账号ID=2 切走切回均保留);验收单 issue2-frontend-tabs.md。 + ## 2026-11-16(下午)· S4-D3:明细按天分区+CH 冷热切换——S4 泳道收官(三项验收全过) - **分区**:迁移 v22 `PARTITION BY RANGE (id)`(雪花时间位当天零点边界,主键即分区键零唯一键改造;热 5 天+未来 3 天+pmax 兜底;MySQL 守卫 sqlite 跳过)+EnsurePartitions 幂等滚动(archive/partition.go);真机 9 分区落地存量无损。 diff --git a/docs/acceptance/issue2-frontend-tabs.md b/docs/acceptance/issue2-frontend-tabs.md new file mode 100644 index 00000000..799083a8 --- /dev/null +++ b/docs/acceptance/issue2-frontend-tabs.md @@ -0,0 +1,40 @@ +# Issue#2 验收单:管理前端多标签导航 + 页签缓存(2026-11-16) + +> 工单:Gitea `Tory/go-sms-V2` Issue #2「优化:管理前端V1」(2026-11-16 11:07)。 +> 需求原文:*增加菜单Tab页(可独立关闭,一次全部关闭),现状是每个菜单独立打开,且切换后没有缓存,对运营非常不友好。* + +## 一、交付范围 + +| 组件 | 文件 | 说明 | +|---|---|---| +| 标签状态 | `web/src/stores/tabs.ts` | pinia:visited[](tab 身份=fullPath);addTab 去重/错误页与 redirect 过滤;close(右邻优先回退)/closeOthers/closeAll;cachedNames(include 锚,同名去重);home 固定不可关 | +| 标签条 | `web/src/components/TagsBar.vue` | 纯原生元素(G2 断言语义:EP 导航壳不进布局壳);✕ 独立关闭+中键关闭(auxclick button===1;@click.middle 对中键永不触发)+关闭其他+全部关闭;aurora token 风格(primary-soft 激活/圆角 10px) | +| 布局挂载 | `web/src/layouts/MainLayout.vue` | ``+``+``;watch fullPath→addTab(immediate);登出 `$reset()` 清标签防跨角色残留 | +| 缓存命名 | 29 个业务视图 SFC | 各加 `defineOptions({ name: <路由名> })`(28 新增+stats/profit 原名 StatsProfitView 对齐 'stats-profit');**ComingSoon(11 路由共用)刻意豁免**:无本地状态可保,不缓存零副作用 | +| 守门测试 | `web/tests/view-cache-name.spec.ts` | 遍历路由断言「组件名=路由名」——新增页面漏写 defineOptions 会**缓存静默失效**(页面照常、仅切 tab 丢状态),此类回归必须在测试红而非线上发现 | +| 配套测试 | `web/tests/tabs-store.spec.ts`(7)+`web/tests/tags-bar.spec.ts`(6) | 状态机全链(去重/关闭导航语义/固定标签/缓存名去重)+组件渲染与交互 | +| 断言扩展 | `web/scripts/verify-layout.mjs` | +5 项:tags-bar 唯一/登录即 home chip/固定无 ✕/点菜单 chip+1/独立关闭回退;凭据 env 化(SHOT_USER/SHOT_PASS,缺省 s2demo——内置 admin 原密码首启打印一次已不可知) | + +## 二、验证证据(2026-11-16) + +| 门禁 | 结果 | +|---|---| +| eslint(max-warnings 0) | ✅ 0 | +| vue-tsc --noEmit | ✅ 0 | +| vitest | ✅ **165/165**(148→+17:tabs-store 7+view-cache-name 4+tags-bar 6) | +| vite build | ✅ 9.99s(chunk 剖面不变,gzip 逐块<500KB 基线保持) | +| verify-layout(实渲染) | ✅ **23/23**(原 18+新 5) | +| Chrome 157 实机走查(:5173,s2demo,单 page 铁律) | ✅ **17/17**,两项**核心 keep-alive 状态保留实证**:①结算页内 Tab 切第 2 个→切走通道配置→切回**仍选中**;②筛选 账号ID=2→切走→切回**保留**;独立关后台不跳转/关当前回退相邻/全部关闭仅剩 home 回 /home;截图 /tmp/issue2-{settle-state,state-preserved,close-all}.png | + +## 三、设计口径(评审可追溯) + +1. **tab 身份=route.fullPath**:参数页(account/:id、channel/edit/:id?)每实例一 tab(标题带 `#id` 后缀);query 变体亦独立成 tab,与 keep-alive key 同口径。 +2. **缓存身份=组件名=路由名**:keep-alive include 按组件名匹配,而 script setup 文件名推断名(15 个 index.vue 全叫 "index";PascalCase≠kebab 路由名)永不命中——守门测试固化此约定。 +3. **同名多实例**(account/1 与 account/2):关闭其一缓存条目随名保留,最后一个同名 tab 关闭才真正释放(keep-alive 按名驱逐,有限驻留可接受)。 +4. **刷新不持久化**:工单未要求;刷新后仅重开当前页 tab(watch immediate 兜底),增强项留待运营反馈。 + +## 四、已知边界与挂账 + +- ComingSoon 占位页每次进入重挂载(无状态可丢,刻意不缓存)。 +- 标签不随刷新恢复(挂账增强项,非工单范围)。 +- 工单评论回贴:Gitea API 读已验免 token(http://192.168.5.27:24400),写需 token——待用户提供或自行回贴。 diff --git a/memory-bank/activeContext.md b/memory-bank/activeContext.md index 9f4467bc..36bea60d 100644 --- a/memory-bank/activeContext.md +++ b/memory-bank/activeContext.md @@ -10,7 +10,7 @@ - **⚠️ 流程补正在途(两项,不阻塞开工)**:①S2 用户本人走查(s2-walkthrough.sh D2~D5,AI 预走查 27 PASS);②S2 结算页+S3 利润页+S4 回调管理页+record/history 页浏览器走查(:5173,s2demo 登录[admin 角色])。 - **24h 稳定性门槛 ✅ 终判通过(11-14)**;S4 后建议 S5 前复核 dmesg+零重启。 - **真浏览器通道就位(2026-11-15)**:Google Chrome 157 + Playwright `channel:'chrome'`(`scripts/chrome-session.mjs`;单 page 会话铁律)。 -- **Issue#1 两轮交付均已入库(2026-11-15/16)**;工单评论仍待用户贴 Gitea(或给 token)。 +- **Issue#1 两轮交付均已入库(2026-11-15/16)**;**Issue#2 多标签导航+页签缓存已交付(2026-11-16 傍晚)**:TagsBar+tabs store+keep-alive(include=路由名,29 视图 defineOptions 守门)+vitest 165+verify-layout 23+Chrome 走查 17/17(状态保留实证);**Gitea API 读免 token=http://192.168.5.27:24400**(写评论仍需 token,待用户);verify-layout 凭据已 env 化(缺省 s2demo——admin 原密码不可知,admin123 已不可登录)。 - **六项裁决速查(S2 全闭环)**:R1/R6 换算只在 price.go / R2 事实源 D2 落账 / R3 双通道 D3 落地(ref_id 区分)/ R4 rebate_rate D5 落地(profit.go 现算不落档)/ R5 settle_ladder D4 落地。 - 归档仓(只读):/data/poc-archive/repos/go-sms.git。 - **【铁律】测试端口固定=5173**:Web 测试/联调/走查/对外验收口径**一律** `http://<服务器IP>:5173`(vite dev,`make web-dev`);**禁止**用 WEB_PORT 覆盖到其他端口、禁止 preview(4173 等)/临时容器端口(30099 等)作为验收与走查入口——一次性探测端口仅限本机调试且不入文档口径(2026-11-15 用户裁定)。 diff --git a/memory-bank/progress.md b/memory-bank/progress.md index d2070b53..93f48172 100644 --- a/memory-bank/progress.md +++ b/memory-bank/progress.md @@ -21,6 +21,7 @@ | S3 前端收尾 | 盘点修正:views 31 页已在位零残留;FE-D34 利润页(/stats/profit)+FE-6 四件(Mock 浏览器通道下线/五角色×33 菜单矩阵快照/拆包全 chunk gzip<500KB/ci.yml web job+Dockerfile nginx+NodePort 30081 备档);vitest 148 全绿;LCP 实测与 kind 两项环境受阻如实标注 | ✅ 2026-11-15 凌晨(s3-closeout.md;页面走查在途) | | S4-D1/D2 C1 回调推送+C2 拉黑 | callback_task(v21)+PushWorker(指数退避/死信/重派)+双挂点(report 终态 Consumer/PairService+uplink 消费)+GET /ops/callback 管理面+前端回调管理页;C2 等值词表可配拉黑+Redis 即时生效;真机全链六步实证;**死信可查/拒收即拉黑两项验收 ✅** | ✅ 2026-11-16(s4-d1d2-callback.md) | | S4-D3 分区+冷热 | v22 RANGE(id) 分区(热 5 天+缓冲 3+pmax)+archive 域(CH 表/归档 job count 校验零丢失)+/record/history 冷查 16ms+settle-check 热窗感知(DetailPartial 两方基线);真机 5 连坑全修;**冷查<1s 验收 ✅,S4 三项全过收官** | ✅ 2026-11-16 下午(s4-d3-partition-archive.md) | +| Issue#2 管理前端 | 多标签导航(TagsBar/tabs store:独立关闭+中键+关闭其他+全部关闭,home 固定)+keep-alive 页签缓存(include=路由名;29 视图 defineOptions name=路由名,守门 view-cache-name.spec;tab 身份=fullPath 参数页独立);vitest 165/verify-layout 23/Chrome 走查 17/17(内 Tab+筛选切走切回保留实证) | ✅ 2026-11-16 傍晚(issue2-frontend-tabs.md) | | 观察项 | 24h 稳定性门槛(11-13 17:55 起计;期内 21:33 宿主主动重启=已知事件不判失败)期满核验 11-14 17:55 | ✅ 2026-11-14 18:02 终判通过(dmesg 0/零重启/驻留+md5 一致;S5 压测前置确认,S1 完全闭环) | | S2~S5 | 结算域/前端收尾/C1C2+冷热/基线与灰度 | 🔄 S2✅S3✅**S4✅收官**(S5 见《Go-sms-重建计划.md》) | diff --git a/web/scripts/verify-layout.mjs b/web/scripts/verify-layout.mjs index 12718ec8..524bb6f6 100644 --- a/web/scripts/verify-layout.mjs +++ b/web/scripts/verify-layout.mjs @@ -3,14 +3,18 @@ import { chromium } from 'playwright' const BASE = process.env.SHOT_BASE ?? 'http://127.0.0.1:5173' +// 凭据 env 可传(勿硬编码,同 chrome-session.mjs 惯例):内置 admin 原密码首启 +// 仅打印一次已不可知,缺省走 S2 种子的 s2demo(role=admin,scripts/seed_settle_demo.sql)。 +const USER = process.env.SHOT_USER ?? 's2demo' +const PASS = process.env.SHOT_PASS ?? 'S2demo@2026' const fails = [] const ok = (cond, msg) => { console.log(`${cond ? '✓' : '✗'} ${msg}`); if (!cond) fails.push(msg) } const browser = await chromium.launch() const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }) await page.goto(BASE + '/login', { waitUntil: 'networkidle' }) -await page.getByTestId('login-username').fill('admin') -await page.getByTestId('login-password').fill('admin123') +await page.getByTestId('login-username').fill(USER) +await page.getByTestId('login-password').fill(PASS) await page.getByTestId('login-submit').click() await page.waitForURL('**/home', { timeout: 15000 }) @@ -48,6 +52,17 @@ ok(sw === 'none', `侧栏滚动区 scrollbar-width === none(实际 ${sw})`) const gs = await page.evaluate(() => getComputedStyle(document.documentElement).scrollbarWidth) ok(gs === 'thin', `html scrollbar-width === thin(实际 ${gs})`) +// I2 · Issue#2 多标签导航断言(桌面视口,先于移动端断点切换) +ok(await page.locator('.tags-bar').count() === 1, 'tags-bar 存在且唯一') +ok(await page.locator('.tags-bar .tag-chip').count() >= 1, `登录后至少 1 个 chip(home,实际 ${await page.locator('.tags-bar .tag-chip').count()})`) +ok(await page.locator('[data-testid="tag-home-close"]').count() === 0, '固定 home 无关闭按钮') +await page.getByTestId('menu-channel').click() +await page.waitForTimeout(500) +ok(await page.locator('.tags-bar .tag-chip').count() === 2, `点菜单开新标签 chip=2(实际 ${await page.locator('.tags-bar .tag-chip').count()})`) +await page.getByTestId('tag-channel-close').click() +await page.waitForTimeout(500) +ok(await page.locator('.tags-bar .tag-chip').count() === 1, `独立关闭生效并回退 home chip=1(实际 ${await page.locator('.tags-bar .tag-chip').count()})`) + // 6) 移动端汉堡抽屉(375×812) await page.setViewportSize({ width: 375, height: 812 }) await page.waitForTimeout(300) diff --git a/web/src/components/TagsBar.vue b/web/src/components/TagsBar.vue new file mode 100644 index 00000000..6391cf9b --- /dev/null +++ b/web/src/components/TagsBar.vue @@ -0,0 +1,93 @@ + + + + + diff --git a/web/src/layouts/MainLayout.vue b/web/src/layouts/MainLayout.vue index a7ba61d4..ffe969e9 100644 --- a/web/src/layouts/MainLayout.vue +++ b/web/src/layouts/MainLayout.vue @@ -54,12 +54,21 @@
+ +

{{ route.meta.title ?? '' }}

{{ pageSub }}
- + + + + + +
@@ -68,11 +77,14 @@ import { computed, ref, watch } from 'vue' import { useRoute, useRouter } from 'vue-router' import { useUserStore } from '@/stores/user' +import { useTabsStore } from '@/stores/tabs' import { accessibleRoutes } from '@/router/guard' +import TagsBar from '@/components/TagsBar.vue' const route = useRoute() const router = useRouter() const userStore = useUserStore() +const tabs = useTabsStore() // ===== 暗色模式(html.dark;demo data-theme 的项目语义映射) ===== const isDark = ref(document.documentElement.classList.contains('dark')) @@ -126,9 +138,18 @@ watch( { immediate: true }, ) +// Issue#2:路由到达即登记标签(tab 身份=fullPath;store 内过滤错误页/redirect; +// watch fullPath 而非 path——查询变体亦独立成 tab,与 keep-alive key 同口径) +watch( + () => route.fullPath, + () => tabs.addTab(route), + { immediate: true }, +) + function onCommand(cmd: string) { if (cmd === 'logout') { userStore.logout() + tabs.$reset() // Issue#2:标签与缓存随登出清空(防跨角色残留) router.push('/login') } } diff --git a/web/src/stores/tabs.ts b/web/src/stores/tabs.ts new file mode 100644 index 00000000..51a22315 --- /dev/null +++ b/web/src/stores/tabs.ts @@ -0,0 +1,81 @@ +// stores/tabs.ts — Issue#2 多标签导航(tags-view)状态。 +// +// 设计口径(tab 身份=route.fullPath,缓存身份=组件名=路由名): +// - keep-alive :include 按**组件名**匹配,而 script setup 的文件名推断名 +// (15 个 index.vue 全叫 "index";PascalCase 文件名 ≠ kebab 路由名)永不 +// 命中——各业务视图必须 defineOptions({ name: <路由名> }),守门测试 +// tests/view-cache-name.spec.ts 防新增页面漏写导致"缓存静默失效"。 +// - tab 身份用 fullPath:参数页(account/:id、channel/edit/:id?)每实例 +// 一 tab;query 变体亦独立成 tab(口径如此,验收单有记)。 +// - ComingSoon 占位页(11 条路由共用)**豁免缓存**:无本地状态可保, +// 不写 defineOptions → include 永不命中 → 每次进入重挂载,零副作用。 +// - 同名多实例(如 account/1 与 account/2)关闭其一时缓存条目随名保留, +// 最后一个同名 tab 关闭才真正释放(keep-alive 按名驱逐,有限驻留可接受)。 +import { defineStore } from 'pinia' +import type { RouteLocationNormalizedLoaded } from 'vue-router' + +export interface TabItem { + path: string // fullPath(tab 身份:去重锚+跳转目标) + name: string // 路由名(=组件名,keep-alive include 锚) + title: string // 标签文案(meta.title + 参数后缀) + affix?: boolean // 固定标签(home,不可关闭) +} + +/** 固定标签:运营总览(五角色可达;刷新后的最小恢复集)。 */ +const AFFIX_HOME: TabItem = { path: '/home', name: 'home', title: '运营总览', affix: true } + +/** 参数页标题后缀:账号详情 #12 / 通道编辑 #7(无 id 的新建态不加后缀)。 */ +function tabTitle(route: RouteLocationNormalizedLoaded): string { + const base = String(route.meta.title ?? '') + const id = route.params?.id + return id ? `${base} #${String(id)}` : base +} + +/** 开标签判据:业务页(有 title+group);错误页(403/500/404)无 group 不开, + * 登录页在布局外、redirect 路由永不成为 resolved 终路由,均天然排除。 */ +function isTabbed(route: RouteLocationNormalizedLoaded): boolean { + return typeof route.name === 'string' && !!route.meta.title && !!route.meta.group +} + +interface TabsState { + visited: TabItem[] +} + +export const useTabsStore = defineStore('tabs', { + state: (): TabsState => ({ visited: [{ ...AFFIX_HOME }] }), + getters: { + /** keep-alive include 列表:打开中的 tab 的路由名(=组件名,去重)。 */ + cachedNames: (s): string[] => [...new Set(s.visited.map((t) => t.name))], + }, + actions: { + /** 路由到达即登记(按 fullPath 去重;标题随参数刷新)。 */ + addTab(route: RouteLocationNormalizedLoaded) { + if (!isTabbed(route)) return + const exists = this.visited.find((t) => t.path === route.fullPath) + if (exists) { + exists.title = tabTitle(route) + return + } + this.visited.push({ path: route.fullPath, name: String(route.name), title: tabTitle(route) }) + }, + /** 关闭单个标签;若关的是当前页则返回应跳转的相邻 tab path + * (右邻优先,末位取左邻),否则返回 null(无需导航)。固定标签不可关。 */ + close(path: string, activePath: string): string | null { + const idx = this.visited.findIndex((t) => t.path === path) + if (idx < 0 || this.visited[idx]!.affix) return null + this.visited.splice(idx, 1) + if (path !== activePath) return null + const neighbor = this.visited[Math.min(idx, this.visited.length - 1)] + return neighbor ? neighbor.path : '/home' + }, + /** 关闭其他(固定标签与当前页保留)。 */ + closeOthers(keepPath: string) { + this.visited = this.visited.filter((t) => t.affix || t.path === keepPath) + }, + /** 全部关闭(仅固定标签保留);返回回退目标。 */ + closeAll(): string { + this.visited = this.visited.filter((t) => t.affix) + return this.visited[0]?.path ?? '/home' + }, + }, +}) diff --git a/web/src/views/account/AccountCreate.vue b/web/src/views/account/AccountCreate.vue index bc53b95c..e42aff81 100644 --- a/web/src/views/account/AccountCreate.vue +++ b/web/src/views/account/AccountCreate.vue @@ -33,6 +33,8 @@