Issue#2: 管理前端多标签导航+页签缓存(Gitea 工单:可独立关闭/一次全部关闭/切换后缓存)—— ①多标签导航=stores/tabs.ts(tab 身份=fullPath,参数页每实例一 tab 带 #id 后缀;home 固定不可关;登出 $reset 防跨角色残留;close 关当前回退相邻右邻优先/closeOthers/closeAll)+TagsBar.vue(纯原生元素守 G2 断言语义;✕独立关闭+中键关闭[auxclick button===1,@click.middle 对中键永不触发]+关闭其他+全部关闭;aurora token 风格 primary-soft 激活/圆角10px);②keep-alive 页签缓存=MainLayout router-view v-slot+include=cachedNames+key=fullPath;**29 个业务视图 defineOptions name=路由名**(28 新增+stats/profit 由 StatsProfitView 对齐——script setup 文件名推断名永不命中 include:15 个 index.vue 全叫 index/PascalCase≠kebab);ComingSoon(11 路由共用)刻意豁免(无本地状态,不缓存零副作用);③守门=view-cache-name.spec.ts 固化组件名=路由名约定(漏写=缓存静默失效,测试红而非线上)+verify-layout.mjs +5 项 tags-bar 断言(18→23)且凭据 env 化(SHOT_USER/SHOT_PASS 缺省 s2demo——admin 原密码首启打印一次不可知,硬编码 admin123 已不可登录 ISC:401);④门禁=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 切走切回均保留;截图 /tmp/issue2-*.png);验收单 issue2-frontend-tabs.md+CHANGELOG+memory-bank 回填
ci / test (push) Canceled after 0s
ci / web-test (push) Canceled after 0s
ci / build (push) Canceled after 0s
ci / deploy-dev (push) Canceled after 0s

This commit is contained in:
2026-11-16 12:35:42 +08:00
parent 01c8874831
commit eaecd83ab0
40 changed files with 561 additions and 5 deletions
+8
View File
@@ -2,6 +2,14 @@
> 本仓 CHANGELOG 自重建起记(POC 明细见归档仓 /data/poc-archive/repos/go-sms.git 的 CHANGELOG.md,已冻结)。 > 本仓 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 `<keep-alive :include="tabs.cachedNames">`+`: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 泳道收官(三项验收全过) ## 2026-11-16(下午)· S4-D3:明细按天分区+CH 冷热切换——S4 泳道收官(三项验收全过)
- **分区**:迁移 v22 `PARTITION BY RANGE (id)`(雪花时间位当天零点边界,主键即分区键零唯一键改造;热 5 天+未来 3 天+pmax 兜底;MySQL 守卫 sqlite 跳过)+EnsurePartitions 幂等滚动(archive/partition.go);真机 9 分区落地存量无损。 - **分区**:迁移 v22 `PARTITION BY RANGE (id)`(雪花时间位当天零点边界,主键即分区键零唯一键改造;热 5 天+未来 3 天+pmax 兜底;MySQL 守卫 sqlite 跳过)+EnsurePartitions 幂等滚动(archive/partition.go);真机 9 分区落地存量无损。
+40
View File
@@ -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` | `<router-view v-slot>`+`<keep-alive :include="tabs.cachedNames">`+`<component :key="viewRoute.fullPath">`;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——待用户提供或自行回贴。
+1 -1
View File
@@ -10,7 +10,7 @@
- **⚠️ 流程补正在途(两项,不阻塞开工)**:①S2 用户本人走查(s2-walkthrough.sh D2~D5,AI 预走查 27 PASS);②S2 结算页+S3 利润页+S4 回调管理页+record/history 页浏览器走查(:5173,s2demo 登录[admin 角色])。 - **⚠️ 流程补正在途(两项,不阻塞开工)**:①S2 用户本人走查(s2-walkthrough.sh D2~D5,AI 预走查 27 PASS);②S2 结算页+S3 利润页+S4 回调管理页+record/history 页浏览器走查(:5173,s2demo 登录[admin 角色])。
- **24h 稳定性门槛 ✅ 终判通过(11-14)**;S4 后建议 S5 前复核 dmesg+零重启。 - **24h 稳定性门槛 ✅ 终判通过(11-14)**;S4 后建议 S5 前复核 dmesg+零重启。
- **真浏览器通道就位(2026-11-15)**:Google Chrome 157 + Playwright `channel:'chrome'`(`scripts/chrome-session.mjs`;单 page 会话铁律)。 - **真浏览器通道就位(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 落地。 - **六项裁决速查(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。 - 归档仓(只读):/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 用户裁定)。 - **【铁律】测试端口固定=5173**:Web 测试/联调/走查/对外验收口径**一律** `http://<服务器IP>:5173`(vite dev,`make web-dev`);**禁止**用 WEB_PORT 覆盖到其他端口、禁止 preview(4173 等)/临时容器端口(30099 等)作为验收与走查入口——一次性探测端口仅限本机调试且不入文档口径(2026-11-15 用户裁定)。
+1
View File
@@ -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;页面走查在途) | | 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-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) | | 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 完全闭环) | | 观察项 | 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》) | | S2~S5 | 结算域/前端收尾/C1C2+冷热/基线与灰度 | 🔄 S2✅S3✅**S4✅收官**(S5 见《Go-sms-重建计划.md》) |
+17 -2
View File
@@ -3,14 +3,18 @@
import { chromium } from 'playwright' import { chromium } from 'playwright'
const BASE = process.env.SHOT_BASE ?? 'http://127.0.0.1:5173' 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 fails = []
const ok = (cond, msg) => { console.log(`${cond ? '✓' : '✗'} ${msg}`); if (!cond) fails.push(msg) } const ok = (cond, msg) => { console.log(`${cond ? '✓' : '✗'} ${msg}`); if (!cond) fails.push(msg) }
const browser = await chromium.launch() const browser = await chromium.launch()
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }) const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
await page.goto(BASE + '/login', { waitUntil: 'networkidle' }) await page.goto(BASE + '/login', { waitUntil: 'networkidle' })
await page.getByTestId('login-username').fill('admin') await page.getByTestId('login-username').fill(USER)
await page.getByTestId('login-password').fill('admin123') await page.getByTestId('login-password').fill(PASS)
await page.getByTestId('login-submit').click() await page.getByTestId('login-submit').click()
await page.waitForURL('**/home', { timeout: 15000 }) 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) const gs = await page.evaluate(() => getComputedStyle(document.documentElement).scrollbarWidth)
ok(gs === 'thin', `html scrollbar-width === thin(实际 ${gs})`) 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) // 6) 移动端汉堡抽屉(375×812)
await page.setViewportSize({ width: 375, height: 812 }) await page.setViewportSize({ width: 375, height: 812 })
await page.waitForTimeout(300) await page.waitForTimeout(300)
+93
View File
@@ -0,0 +1,93 @@
<template>
<!-- Issue#2:多标签导航条——独立关闭(✕/中键)+关闭其他+全部关闭。
纯原生元素(遵守 G2 断言语义:EP 导航壳不进布局壳);视觉对齐
aurora nav-item(primary-soft 激活底/圆角 10px/hover 过渡)。 -->
<nav class="tags-bar" data-testid="tags-bar" aria-label="已打开页面">
<div class="tags-scroll">
<button
v-for="t in tabs.visited" :key="t.path" type="button"
class="tag-chip" :class="{ active: t.path === route.fullPath }"
:data-testid="`tag-${t.name}`" :title="t.title"
@click="go(t.path)" @auxclick="onAuxClick(t, $event)"
>
<span class="tag-txt">{{ t.title }}</span>
<span
v-if="!t.affix" class="tag-close" role="button" :aria-label="`关闭 ${t.title}`"
:data-testid="`tag-${t.name}-close`" @click.stop="close(t)"
>✕</span>
</button>
</div>
<div class="tags-actions">
<button type="button" class="tag-act" data-testid="tags-close-others" @click="closeOthers">关闭其他</button>
<button type="button" class="tag-act" data-testid="tags-close-all" @click="closeAll">全部关闭</button>
</div>
</nav>
</template>
<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router'
import { useTabsStore, type TabItem } from '@/stores/tabs'
const route = useRoute()
const router = useRouter()
const tabs = useTabsStore()
function go(path: string) {
void router.push(path)
}
function close(t: Pick<TabItem, 'path'>) {
const next = tabs.close(t.path, route.fullPath)
if (next) void router.push(next)
}
function closeOthers() {
tabs.closeOthers(route.fullPath)
}
function closeAll() {
void router.push(tabs.closeAll())
}
// 中键关闭:中键不派发 click 事件,须挂 auxclick 并自判 button===1
// (Vue 的 @click.middle 编译为 click+button 守卫,对中键永不触发)。
function onAuxClick(t: TabItem, e: MouseEvent) {
if (e.button !== 1 || t.affix) return
e.preventDefault()
close(t)
}
</script>
<style scoped>
.tags-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; min-width: 0; }
.tags-scroll {
display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0;
overflow-x: auto; scrollbar-width: none; padding: 2px;
}
.tags-scroll::-webkit-scrollbar { display: none; }
.tag-chip {
display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
padding: 4px 10px; border-radius: 10px; border: 1px solid transparent;
background: var(--gosms-card-veil); color: var(--gosms-text);
font-size: 12px; line-height: 1.4; cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.tag-chip:hover { background: var(--gosms-card-hover); color: var(--gosms-text-bright); }
.tag-chip.active { background: var(--gosms-primary-soft); color: var(--gosms-primary); font-weight: 600; }
.tag-close {
display: inline-grid; place-items: center; width: 14px; height: 14px;
border-radius: 4px; font-size: 10px; color: var(--gosms-text-muted); transition: all 0.15s;
}
.tag-close:hover { color: var(--gosms-red); background: rgba(248, 113, 113, 0.12); }
.tags-actions { display: flex; gap: 6px; flex-shrink: 0; }
.tag-act {
font-size: 11px; color: var(--gosms-text-muted); background: none;
border: 1px solid var(--gosms-border); border-radius: 8px; padding: 4px 10px;
cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.tag-act:hover { color: var(--gosms-primary); border-color: var(--gosms-primary); }
@media (max-width: 900px) {
/* 移动端收紧:动作按钮保留,chip 区横向滚动已由 tags-scroll 承接 */
.tags-bar { gap: 6px; margin-bottom: 10px; }
.tag-act { padding: 4px 8px; }
}
</style>
+22 -1
View File
@@ -54,12 +54,21 @@
<!-- ===== 主区(demo main 原文) ===== --> <!-- ===== 主区(demo main 原文) ===== -->
<main class="main"> <main class="main">
<!-- Issue#2:多标签导航(独立关闭/关闭其他/全部关闭) -->
<TagsBar />
<div class="page-head"> <div class="page-head">
<h2>{{ route.meta.title ?? '' }}</h2> <h2>{{ route.meta.title ?? '' }}</h2>
<span v-if="pageSub" class="sub">{{ pageSub }}</span> <span v-if="pageSub" class="sub">{{ pageSub }}</span>
<span id="page-head-extra" class="page-head-extra"></span> <span id="page-head-extra" class="page-head-extra"></span>
</div> </div>
<router-view /> <!-- Issue#2:keep-alive 页签缓存——include=打开中 tab 的路由名(各视图
defineOptions name=路由名,守门 tests/view-cache-name.spec.ts);
key=fullPath:参数页/查询变体各自独立实例(tab 身份同口径)。 -->
<router-view v-slot="{ Component, route: viewRoute }">
<keep-alive :include="tabs.cachedNames">
<component :is="Component" :key="viewRoute.fullPath" />
</keep-alive>
</router-view>
</main> </main>
</div> </div>
</template> </template>
@@ -68,11 +77,14 @@
import { computed, ref, watch } from 'vue' import { computed, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { useTabsStore } from '@/stores/tabs'
import { accessibleRoutes } from '@/router/guard' import { accessibleRoutes } from '@/router/guard'
import TagsBar from '@/components/TagsBar.vue'
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
const userStore = useUserStore() const userStore = useUserStore()
const tabs = useTabsStore()
// ===== 暗色模式(html.dark;demo data-theme 的项目语义映射) ===== // ===== 暗色模式(html.dark;demo data-theme 的项目语义映射) =====
const isDark = ref(document.documentElement.classList.contains('dark')) const isDark = ref(document.documentElement.classList.contains('dark'))
@@ -126,9 +138,18 @@ watch(
{ immediate: true }, { 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) { function onCommand(cmd: string) {
if (cmd === 'logout') { if (cmd === 'logout') {
userStore.logout() userStore.logout()
tabs.$reset() // Issue#2:标签与缓存随登出清空(防跨角色残留)
router.push('/login') router.push('/login')
} }
} }
+81
View File
@@ -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'
},
},
})
+2
View File
@@ -33,6 +33,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'account-create' })
import { computed, reactive, ref } from 'vue' import { computed, reactive, ref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { ElMessage, type FormInstance, type FormRules } from 'element-plus' import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
+2
View File
@@ -138,6 +138,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'account-detail' })
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
+2
View File
@@ -51,6 +51,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'account-list' })
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import ProTable from '@/components/ProTable.vue' import ProTable from '@/components/ProTable.vue'
@@ -16,6 +16,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'account-recharge' })
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
+2
View File
@@ -17,6 +17,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'account-roles' })
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import { accountApi, type Role } from '@/api/account' import { accountApi, type Role } from '@/api/account'
+2
View File
@@ -20,6 +20,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'audit-login' })
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import { accountApi, type LoginAuditRow } from '@/api/account' import { accountApi, type LoginAuditRow } from '@/api/account'
+2
View File
@@ -86,6 +86,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'audit' })
// D21 审核中心:五类审核态 Tab 聚合+计数徽标(counts 端点)/批量通过拒绝(已审跳过幂等)/ // D21 审核中心:五类审核态 Tab 聚合+计数徽标(counts 端点)/批量通过拒绝(已审跳过幂等)/
// 48h 临期标红(待审剩 ≤12h)与超时行样式区分;操作后列表与徽标联动刷新。 // 48h 临期标红(待审剩 ≤12h)与超时行样式区分;操作后列表与徽标联动刷新。
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
+2
View File
@@ -319,6 +319,8 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'channel-edit' })
import { computed, onMounted, reactive, ref } from 'vue' import { computed, onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { ElMessage, ElMessageBox, type FormInstance } from 'element-plus' import { ElMessage, ElMessageBox, type FormInstance } from 'element-plus'
+2
View File
@@ -85,6 +85,8 @@
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'channel-group' })
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { channelApi, ROUTE_STEPS, type ChannelGroup, type Channel } from '@/api/channel' import { channelApi, ROUTE_STEPS, type ChannelGroup, type Channel } from '@/api/channel'
+2
View File
@@ -105,6 +105,8 @@
</el-drawer> </el-drawer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'channel' })
import { onBeforeUnmount, onMounted, reactive, ref } from 'vue' import { onBeforeUnmount, onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import ProTable from '@/components/ProTable.vue' import ProTable from '@/components/ProTable.vue'
+2
View File
@@ -35,6 +35,8 @@
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'channel-upstream' })
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus' import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
import ProTable from '@/components/ProTable.vue' import ProTable from '@/components/ProTable.vue'
+2
View File
@@ -158,6 +158,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'home' })
// P1 信息密度重构(2026-11-13):删除三处 demo 假数据(rateNow 随机速率/静态通道表/ // P1 信息密度重构(2026-11-13):删除三处 demo 假数据(rateNow 随机速率/静态通道表/
// 快捷卡死文案),拆三条独立加载管线;P2 图标统一 EP;P3 count-up + 走势 hover。 // 快捷卡死文案),拆三条独立加载管线;P2 图标统一 EP;P3 count-up + 走势 hover。
// 设计基线 demo-c-aurora 的 token/卡片/徽章体系不变。 // 设计基线 demo-c-aurora 的 token/卡片/徽章体系不变。
+2
View File
@@ -71,6 +71,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'ops-callback' })
/** 回调管理页(S4·C1):callback_task 列表 + 状态面板 + 死信重派。 /** 回调管理页(S4·C1):callback_task 列表 + 状态面板 + 死信重派。
* 口径:PushWorker 在 consumer 进程投递(2s 扫描/2^n 秒退避/10 次耗尽死信); * 口径:PushWorker 在 consumer 进程投递(2s 扫描/2^n 秒退避/10 次耗尽死信);
* 本页仅管理面——列表查询 + 死信重派(POST /ops/callback/:id/resend)。 */ * 本页仅管理面——列表查询 + 死信重派(POST /ops/callback/:id/resend)。 */
+2
View File
@@ -107,6 +107,8 @@
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'policy' })
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { policyApi, KEYWORD_LEVELS, type NumberList, type Keyword, type FrequencyPolicy, type BlockedCode } from '@/api/policy' import { policyApi, KEYWORD_LEVELS, type NumberList, type Keyword, type FrequencyPolicy, type BlockedCode } from '@/api/policy'
+2
View File
@@ -52,6 +52,8 @@
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'policy-report' })
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { policyApi, REPORT_TYPES, type Report } from '@/api/policy' import { policyApi, REPORT_TYPES, type Report } from '@/api/policy'
+2
View File
@@ -50,6 +50,8 @@
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'policy-route' })
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { policyApi, RULE_TYPES, type RouteRule } from '@/api/policy' import { policyApi, RULE_TYPES, type RouteRule } from '@/api/policy'
+2
View File
@@ -103,6 +103,8 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'record-down' })
// D24 下行批次记录(方案 A 开工,2026-09-13):筛选/进度占比/拦截号码下载。 // D24 下行批次记录(方案 A 开工,2026-09-13):筛选/进度占比/拦截号码下载。
// 契约先行——接口走 api/record.ts,msw fe4-handlers 承载,Day60 后端 // 契约先行——接口走 api/record.ts,msw fe4-handlers 承载,Day60 后端
// api/v1/record.go 就绪后切 real 模式联调(A-5.x 验收口径:分页 100/页流畅; // api/v1/record.go 就绪后切 real 模式联调(A-5.x 验收口径:分页 100/页流畅;
+2
View File
@@ -96,6 +96,8 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'record-history' })
// D26 历史记录(2026-09-13):>5 天全量冷数据查询+异步导出→下载中心。 // D26 历史记录(2026-09-13):>5 天全量冷数据查询+异步导出→下载中心。
// 契约先行——接口走 api/record.ts,msw fe4-handlers 承载,Day61 后端 // 契约先行——接口走 api/record.ts,msw fe4-handlers 承载,Day61 后端
// ClickHouse 历史域(冷热切换)+Day62 MinIO 异步下载落地后切 real 联调。 // ClickHouse 历史域(冷热切换)+Day62 MinIO 异步下载落地后切 real 联调。
+2
View File
@@ -147,6 +147,8 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'record-repush' })
// D28 回执工具(2026-09-14):回执重推(30 天窗口)+手动配对(四方式,3h 外)。 // D28 回执工具(2026-09-14):回执重推(30 天窗口)+手动配对(四方式,3h 外)。
// 契约先行——接口走 api/record.ts(fetchRepushReports/createRepush/ // 契约先行——接口走 api/record.ts(fetchRepushReports/createRepush/
// fetchPendingDetails/createManualPair),msw fe4RepushHandlers 承载; // fetchPendingDetails/createManualPair),msw fe4RepushHandlers 承载;
+2
View File
@@ -73,6 +73,8 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'record-up' })
// D27 上行记录(2026-09-14):码号/手机号查询+匹配态筛选+权限导出。 // D27 上行记录(2026-09-14):码号/手机号查询+匹配态筛选+权限导出。
// 契约先行——接口走 api/record.ts(fetchUplinkRecords/createUplinkExport), // 契约先行——接口走 api/record.ts(fetchUplinkRecords/createUplinkExport),
// msw fe4UplinkHandlers 承载;后端 message_uplink 查询域 Day60 record API // msw fe4UplinkHandlers 承载;后端 message_uplink 查询域 Day60 record API
+2
View File
@@ -182,6 +182,8 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'settle' })
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { import {
+2
View File
@@ -56,6 +56,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'sms-batch' })
import { computed, reactive, ref, watch } from 'vue' import { computed, reactive, ref, watch } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
@@ -120,6 +120,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'sms-downlink-detail' })
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { ArrowDown } from '@element-plus/icons-vue' import { ArrowDown } from '@element-plus/icons-vue'
+2
View File
@@ -76,6 +76,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'sms-home' })
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
const router = useRouter() const router = useRouter()
+2
View File
@@ -76,6 +76,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'sms-personal' })
import { computed, onMounted, ref } from 'vue' import { computed, onMounted, ref } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { smsApi, type PrecheckResp, type SmsTemplate } from '@/api/sms' import { smsApi, type PrecheckResp, type SmsTemplate } from '@/api/sms'
+2
View File
@@ -103,6 +103,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'sms-result' })
// D22 发送结果反馈页(Day 46):任务检索→汇总卡→逐号明细核对。 // D22 发送结果反馈页(Day 46):任务检索→汇总卡→逐号明细核对。
// 错误码 tooltip 中文走 ISC_CN 字典(codegen 与后端码表双向锁定); // 错误码 tooltip 中文走 ISC_CN 字典(codegen 与后端码表双向锁定);
// 通道原始码(非 ISC:)原样展示,tooltip 提示「通道原始码」。 // 通道原始码(非 ISC:)原样展示,tooltip 提示「通道原始码」。
+2
View File
@@ -87,6 +87,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'sms-template' })
import { computed, onMounted, reactive, ref } from 'vue' import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { smsApi, type SmsTemplate } from '@/api/sms' import { smsApi, type SmsTemplate } from '@/api/sms'
+2
View File
@@ -110,6 +110,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// Issue#2:keep-alive 缓存锚点——组件名必须=路由 name(守门 tests/view-cache-name.spec.ts)
defineOptions({ name: 'sms-timer' })
// D19 定时任务列表:状态 Tab/类型与审核态过滤/分页/取消/改期(仅定时待发可改期, // D19 定时任务列表:状态 Tab/类型与审核态过滤/分页/取消/改期(仅定时待发可改期,
// 仅待发可取消——后端原子状态机,冲突 ISC:038)。 // 仅待发可取消——后端原子状态机,冲突 ISC:038)。
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
+1 -1
View File
@@ -91,7 +91,7 @@ import { onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { settleApi, type UserProfitRow, type UserProfitSummary, type ChannelProfitRow } from '@/api/settle' import { settleApi, type UserProfitRow, type UserProfitSummary, type ChannelProfitRow } from '@/api/settle'
defineOptions({ name: 'StatsProfitView' }) defineOptions({ name: 'stats-profit' })
const tab = ref<'users' | 'channels'>('users') const tab = ref<'users' | 'channels'>('users')
const parentId = ref(0) const parentId = ref(0)
+89
View File
@@ -0,0 +1,89 @@
// tabs-store.spec.ts Issue#2:多标签导航状态机(登记去重/关闭导航语义/固定标签/缓存名去重)。
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { useTabsStore } from '@/stores/tabs'
/** 构造路由壳(测试专用,不依赖真 router 实例)。 */
function r(
fullPath: string,
name: string,
title: string,
group = '运营管理',
params: Record<string, string> = {},
): RouteLocationNormalizedLoaded {
return { fullPath, name, params, meta: { title, group } } as unknown as RouteLocationNormalizedLoaded
}
describe('tabs store(Issue#2 多标签导航)', () => {
beforeEach(() => {
setActivePinia(createPinia())
})
it('初始态:仅固定 home 标签(不可关)', () => {
const s = useTabsStore()
expect(s.visited).toHaveLength(1)
expect(s.visited[0]).toMatchObject({ path: '/home', name: 'home', affix: true })
expect(s.close('/home', '/home')).toBeNull()
expect(s.visited).toHaveLength(1)
})
it('addTab:登记 + 按 fullPath 去重 + 参数页标题带 #id 后缀', () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置', '通道与策略'))
s.addTab(r('/settle', 'settle', '结算管理', '统计结算'))
s.addTab(r('/settle', 'settle', '结算管理', '统计结算')) // 重复到达不去重登记
s.addTab(r('/account/12', 'account-detail', '账号详情', '运营管理', { id: '12' }))
expect(s.visited.map((t) => t.path)).toEqual(['/home', '/channel', '/settle', '/account/12'])
expect(s.visited[3]!.title).toBe('账号详情 #12')
})
it('addTab 过滤:错误页(无 group)/无 title/无名路由不进标签', () => {
const s = useTabsStore()
s.addTab({ fullPath: '/403', name: 'forbidden', params: {}, meta: { title: '无权限' } } as unknown as RouteLocationNormalizedLoaded)
s.addTab({ fullPath: '/x', name: 'x', params: {}, meta: { group: '运营管理' } } as unknown as RouteLocationNormalizedLoaded)
s.addTab({ fullPath: '/y', params: {}, meta: { title: 't', group: 'g' } } as unknown as RouteLocationNormalizedLoaded)
expect(s.visited).toHaveLength(1) // 仅初始 home
})
it('close:关后台 tab 返回 null 不导航;关当前 tab 返回右邻(末位取左邻)', () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置', '通道与策略'))
s.addTab(r('/settle', 'settle', '结算管理', '统计结算'))
s.addTab(r('/policy', 'policy', '规则策略', '通道与策略'))
// 关后台(settle 非当前)
expect(s.close('/settle', '/policy')).toBeNull()
expect(s.visited.map((t) => t.path)).toEqual(['/home', '/channel', '/policy'])
// 关当前且在末位 → 左邻
expect(s.close('/policy', '/policy')).toBe('/channel')
// 关当前在中间 → 右邻
s.addTab(r('/settle', 'settle', '结算管理', '统计结算'))
s.addTab(r('/policy', 'policy', '规则策略', '通道与策略')) // [home, channel, settle, policy]
expect(s.close('/settle', '/settle')).toBe('/policy')
expect(s.visited.map((t) => t.path)).toEqual(['/home', '/channel', '/policy'])
})
it('closeOthers:保固定标签与当前页', () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置', '通道与策略'))
s.addTab(r('/settle', 'settle', '结算管理', '统计结算'))
s.closeOthers('/channel')
expect(s.visited.map((t) => t.path)).toEqual(['/home', '/channel'])
})
it('closeAll:仅固定标签保留并返回回退目标', () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置', '通道与策略'))
s.addTab(r('/settle', 'settle', '结算管理', '统计结算'))
expect(s.closeAll()).toBe('/home')
expect(s.visited.map((t) => t.path)).toEqual(['/home'])
})
it('cachedNames:同名多实例(参数页)去重——keep-alive include 粒度=组件名', () => {
const s = useTabsStore()
s.addTab(r('/account/1', 'account-detail', '账号详情', '运营管理', { id: '1' }))
s.addTab(r('/account/2', 'account-detail', '账号详情', '运营管理', { id: '2' }))
s.addTab(r('/account/create', 'account-create', '开户'))
expect(s.cachedNames).toEqual(['home', 'account-detail', 'account-create'])
})
})
+97
View File
@@ -0,0 +1,97 @@
// tags-bar.spec.ts Issue#2:标签条组件(渲染/独立关闭/关闭导航/全部关闭/固定标签)。
// 惯例同 login-view.spec:vi.mock vue-router(useRoute 可变 fullPath + push mock)。
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createRouter, createWebHistory } from 'vue-router'
import TagsBar from '@/components/TagsBar.vue'
import { useTabsStore } from '@/stores/tabs'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
let currentPath = '/home'
const pushMock = vi.fn()
vi.mock('vue-router', async () => {
const actual = await vi.importActual<typeof import('vue-router')>('vue-router')
return {
...actual,
useRoute: () => ({ fullPath: currentPath }),
useRouter: () => ({ push: pushMock }),
}
})
function r(fullPath: string, name: string, title: string): RouteLocationNormalizedLoaded {
return { fullPath, name, params: {}, meta: { title, group: '运营管理' } } as unknown as RouteLocationNormalizedLoaded
}
function mountBar() {
const router = createRouter({ history: createWebHistory(), routes: [] })
return mount(TagsBar, { global: { plugins: [router] } })
}
describe('TagsBar(Issue#2 多标签导航条)', () => {
beforeEach(() => {
setActivePinia(createPinia())
pushMock.mockClear()
currentPath = '/home'
})
it('渲染:chips 来自 store,当前页 active,固定 home 无关闭按钮', () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置'))
s.addTab(r('/settle', 'settle', '结算管理'))
const w = mountBar()
expect(w.findAll('.tag-chip')).toHaveLength(3)
expect(w.get('[data-testid="tag-home"]').classes()).toContain('active')
expect(w.find('[data-testid="tag-home-close"]').exists()).toBe(false)
expect(w.find('[data-testid="tag-channel-close"]').exists()).toBe(true)
})
it('点击 chip 切换页面(push 该 fullPath)', async () => {
const s = useTabsStore()
s.addTab(r('/settle', 'settle', '结算管理'))
const w = mountBar()
await w.get('[data-testid="tag-settle"]').trigger('click')
expect(pushMock).toHaveBeenCalledWith('/settle')
})
it('独立关闭后台 tab:store 移除且不导航', async () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置'))
s.addTab(r('/settle', 'settle', '结算管理'))
const w = mountBar() // 当前= /home
await w.get('[data-testid="tag-settle-close"]').trigger('click')
expect(s.visited.map((t) => t.path)).toEqual(['/home', '/channel'])
expect(pushMock).not.toHaveBeenCalled()
})
it('独立关闭当前 tab:跳右邻(工单核心诉求:可独立关闭)', async () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置'))
s.addTab(r('/settle', 'settle', '结算管理'))
currentPath = '/channel'
const w = mountBar()
await w.get('[data-testid="tag-channel-close"]').trigger('click')
expect(pushMock).toHaveBeenCalledWith('/settle')
expect(s.visited.map((t) => t.path)).toEqual(['/home', '/settle'])
})
it('全部关闭:仅保 home 并回退(工单核心诉求:一次全部关闭)', async () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置'))
s.addTab(r('/settle', 'settle', '结算管理'))
const w = mountBar()
await w.get('[data-testid="tags-close-all"]').trigger('click')
expect(s.visited.map((t) => t.path)).toEqual(['/home'])
expect(pushMock).toHaveBeenCalledWith('/home')
})
it('关闭其他:保固定标签与当前页', async () => {
const s = useTabsStore()
s.addTab(r('/channel', 'channel', '通道配置'))
s.addTab(r('/settle', 'settle', '结算管理'))
currentPath = '/settle'
const w = mountBar()
await w.get('[data-testid="tags-close-others"]').trigger('click')
expect(s.visited.map((t) => t.path)).toEqual(['/home', '/settle'])
})
})
+55
View File
@@ -0,0 +1,55 @@
// view-cache-name.spec.ts Issue#2 守门:keep-alive :include 按**组件名**匹配,
// 组件名必须=路由 name——新增业务页漏写 defineOptions 会让缓存**静默失效**
// (页面照常工作,仅切 tab 丢状态),此类回归必须在本测试红,而不是线上被发现。
// 豁免:ComingSoon 占位页(11 条路由共用,无本地状态可保,刻意不缓存)。
import { readFileSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { asyncRoutes } from '@/router/routes'
const webRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
// 从 routes.ts 源码提取 路由名 → 视图文件 映射(name 与 component 动态 import
// 相邻的行内模式;redirect 路由天然无 component 不会入表)。
const routesSrc = readFileSync(join(webRoot, 'src/router/routes.ts'), 'utf8')
const viewFile = new Map<string, string>()
for (const m of routesSrc.matchAll(/name:\s*'([\w-]+)',\s*component:\s*\(\)\s*=>\s*import\('([^']+)'\)/g)) {
viewFile.set(m[1]!, m[2]!)
}
describe('Issue#2 视图缓存命名守门(组件名=路由名)', () => {
it('路由→文件映射提取成功(≥40,防正则/结构漂移静默跳检)', () => {
expect(viewFile.size).toBeGreaterThanOrEqual(40)
})
it('每个业务视图 SFC 含 defineOptions({ name: <路由名> })', () => {
const children = asyncRoutes[0]!.children!
const business = children.filter(
(c) => c.name && c.meta?.title && c.meta?.group && viewFile.has(String(c.name)),
)
expect(business.length).toBeGreaterThanOrEqual(40)
const missing: string[] = []
for (const c of business) {
const name = String(c.name)
const rel = viewFile.get(name)!
// 豁免:ComingSoon 占位页(共用组件,刻意不参与缓存)
if (rel.endsWith('ComingSoon.vue')) continue
const sfc = readFileSync(join(webRoot, rel.replace('@/', 'src/')), 'utf8')
if (!sfc.includes(`defineOptions({ name: '${name}' })`)) missing.push(`${name} → ${rel}`)
}
expect(missing, `缺缓存命名(keep-alive 会静默失效):\n${missing.join('\n')}`).toEqual([])
})
it('豁免口径固化:ComingSoon 不写 defineOptions(每次进入重挂载,零状态可丢)', () => {
const sfc = readFileSync(join(webRoot, 'src/views/coming/ComingSoon.vue'), 'utf8')
expect(sfc).not.toContain('defineOptions')
})
it('MainLayout 已挂 keep-alive(include=tabs.cachedNames,key=fullPath)', () => {
const sfc = readFileSync(join(webRoot, 'src/layouts/MainLayout.vue'), 'utf8')
expect(sfc).toContain(':include="tabs.cachedNames"')
expect(sfc).toContain(':key="viewRoute.fullPath"')
expect(sfc).toContain('<TagsBar />')
})
})