Compare commits
32
Commits
ddbfd5b399
...
7a6218faf4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a6218faf4 | ||
|
|
f699c4c5e2 | ||
|
|
7387d2cf64 | ||
|
|
42b39b5a34 | ||
|
|
d441cb32a2 | ||
|
|
53395007bb | ||
|
|
b3e6bcab5d | ||
|
|
82420a844c | ||
|
|
f2ffa0b81e | ||
|
|
c13920bc46 | ||
|
|
fb72eb1739 | ||
|
|
a020c8b3a3 | ||
|
|
74e785c91e | ||
|
|
0ae6a2c1d4 | ||
|
|
936fed5cac | ||
|
|
9afab52239 | ||
|
|
cba37cc031 | ||
|
|
daf0659d2c | ||
|
|
449531e3e4 | ||
|
|
30b0e0b62c | ||
|
|
2265483466 | ||
|
|
2cc027a1df | ||
|
|
1b276d73c6 | ||
|
|
a7fb129f15 | ||
|
|
931d477305 | ||
|
|
eda275944f | ||
|
|
52692f4628 | ||
|
|
5591a485ad | ||
|
|
cc99aac16f | ||
|
|
7d34130079 | ||
|
|
ed40942a4c | ||
|
|
5ce4562347 |
@@ -2,6 +2,73 @@
|
||||
|
||||
> 本仓 CHANGELOG 自重建起记(POC 明细见归档仓 /data/poc-archive/repos/go-sms.git 的 CHANGELOG.md,已冻结)。
|
||||
|
||||
## 2026-11-17(晚)· Issue#5:压测复盘报告归档(100 万条目标达成 +12.7%)
|
||||
|
||||
- **工单**:Gitea #5「压测:100万条」(11-16 16:23 提出,11-17 19:05 催报)——完整报告归档 `docs/acceptance/issue5-bench-report.md` 并回帖工单(Markdown)。
|
||||
- **三场实况**:①白日场 vcmppgw 模拟上家(预检 2×1k+S1 1 万+S2 6.5 万@限速 200/s,p50/p99=8.8/17.4ms 零失败;数据已按恢复 SOP 清理);②夜间长短信段 18:32 起(5.1 万任务×均 3 片=15.4 万计费条)+③主战场 23:00~11-17 01:52 真上家 5.16(提交 199.9 万/下发成功 99.97 万/签名拦截 99.99 万 ISC:004 即时退款)。**下发成功合计 ≈112.7 万条 ✅ 超 100 万目标 12.7%**;受理均 194/30s 窗峰 287.9 QPS 且 **slow>200ms=0**,lag 峰 476/均 88,慢查询 0,双进程零重启。
|
||||
- **计费三平 ✅ 分毫不差**:充值 10.0001 亿(2 笔)− 预扣 2,183,182 + 拦截退款 999,741 = 余额 998,826,559(基数 100 万);billing_consume_log/余额流水/明细计费三方一致;100 万级拦截即时退款零差错。账单/利润链路 11-14 S2 泳道已验收,压测数据未出账(出账四件套入下轮 SOP;推算毛利 ≈7.33 万/112.7 万条=时间线价演示口径)。
|
||||
- **问题 6 项**:①R1 余额对账差额 P0 告警 ×33 次(典型 ±120~791 条+1 次 10 亿充值瞬时窗口,reconciler 5min 自愈覆写,无资损)待根修预扣-落账时序;②主战场 50% 流量签名拦截=压测脚本口径(内容未带报备签名,平台行为正确);③channel_log deliver_fail 2,652 条终态去向待复核;④长短信挂起 1,326 条 72h 制 **11-19 reaper 到期核验**;⑤channel host 配置不热切换(17:07 恢复后存量连接仍走 vcmppgw,受审 75,191 vs CSV 77,000 差=切换窗口分流)→ runbook 增补;⑥主战场客户端 CSV 未留档 → SOP 强制。
|
||||
- **规划**:11-18 P0 整改(R1 根修或窗口豁免+告警分级/deliver_fail 复核/脚本签名对齐/host runbook)→ 11-19 正式场阶梯 200/500/1000 TPS×30min(长短信占比 30%/按通道 speed 扩连接/双通道);收尾四件套=出账→确认→结账+利润报表+settle-check EXIT=0+XLSX。
|
||||
|
||||
## 2026-11-16(晚六)· Issue#4:版本号 + 发布日志(侧栏红点 / 系统管理二级菜单 / 运营大白话 Markdown)
|
||||
|
||||
- **工单**:Gitea Issue#4「增加:版本号及发布日志」——①菜单底部折叠展开旁显示最新版本号,有更新红点闪烁;②系统管理新增二级菜单「发布日志」,功能迭代明细用运营能读懂的大白话 + Markdown。
|
||||
- **单一事实源**:`web/src/data/releases.ts`(版本列表最新在前,`APP_VERSION = RELEASE_NOTES[0].version`);`package.json` version 0.1.0→**1.5.0** 同步,**tests/releases.spec.ts 断言两侧一致防漂移**;版本线 v1.0.0(11-13 平台一期上线)→ v1.5.0(11-16 客户对接打通+充值修复+本功能),文案全部运营向大白话(不写实现细节/工单号)。
|
||||
- **侧栏版本 chip**:MainLayout sidebar-foot(折叠按钮旁)加 `router-link → /system/release`(data-testid=sidebar-version);**红点=浏览器本地"未读"语义**:localStorage `gosms_seen_ver` ≠ 当前版本即亮(CSS `gosms-ver-blink` 脉冲闪烁);首访无记录=亮(引导看一次发布日志);点击 chip / 进入发布日志页 `markSeen()` 即灭;发新版重新部署后全员自动再亮。折叠态(64px)chip 缩为无边框短版本(v1.5)纵向排布。
|
||||
- **发布日志页**:`views/system/ReleaseLog.vue`(`defineOptions name='system-release'` 守门)+ 路由 `system/release`(**全角色**,同 faq 口径——发布日志本质是面向所有用户的平台公告,用户拍板;icon=Memo;subtitle=平台功能迭代明细·大白话版);时间线卡片=版本徽章+日期+标签(新功能/优化/修复)+「当前版本」角标。
|
||||
- **迷你 Markdown 渲染器**(`utils/markdown.ts`,**零新依赖**):标题/无序有序列表(`1.` 与 `1、` 顿号中文习惯均支持)/粗体/行内代码(哨兵保护,code 内 `**` 不误判粗体)/围栏代码块/链接(**仅 http(s)**,javascript: 伪协议不渲染为 a);**先全量 HTML 转义再解析**——内容源虽是仓库静态数据仍按不可信文本处理,v-html 零注入面。
|
||||
- **守门**:tests/releases.spec.ts **+14**(数据一致性 4:单一事实源/降序/semver/日期标签白名单;渲染器 7:格式+转义+伪协议+哨兵;store 3:首访亮/markSeen 灭+刷新持久/新版再亮);guard.spec 菜单计数 33→**34** 显式更;role-menu-matrix 登记 `system-release: ALL`;verify-layout.mjs **+8 断言(23→31)**:chip 可见/文本 vN.N/首访红点/点击跳转/已读即灭/版本卡片≥3/Markdown 列表渲染/回 home。
|
||||
- **门禁**:eslint 0 警/vue-tsc 0/**vitest 179 全绿(165+14)**/build ✓/verify-layout 31/31 ✓(Chrome 实机)。
|
||||
- **口径诚实标注**:红点为本地"未读"(换浏览器/清缓存会重新提示一次,无服务端已读同步——单机后台语义够用);移动端 ≤900 sidebar-foot 沿用既有隐藏约定(版本号仅桌面侧栏可见);发布内容=仓库静态数据,**发版 SOP=releases.ts 头部插一条 + package.json version 同步**,部署后全员红点亮起。验收单 `docs/acceptance/issue4-release-notes.md`。
|
||||
|
||||
## 2026-11-16(晚五)· Issue#3 联调闭环:客户(192.168.5.210)登录+提交+回执全链打通
|
||||
|
||||
- **登录**:15:47:13 `cmpp_conn_ok{s2demo, 192.168.5.210, ver=0x20}`+抓包 `CONNECT_RESP 2.0(21B) status=0` 双证——**-1 问题终结**(协议修复全链生效)。
|
||||
- **首报"提交报错:0"定位**:4 次 `cmpp_submit_rejected 余额不足`(s2demo 余额=0,验证额度已还原所致);平台回 `MsgID=0+Result=10` → 客户端显示"0"。**充值 10000 条即恢复**。
|
||||
- **重提闭环实证(15:58)**:3 次提交 30s stats 无 rejected;任务 4/5/6(source=2/CMPP)全 `status=2` 终态、明细全 `DELIVRD 送达`、fee=1 条/条计费正常——**客户确认「成功发送,状态正常返回」**。
|
||||
- **抓包分析器已知限制(挂账)**:高频「心跳+提交」混合流 PDU 重组错位(重传/乱序容错分支拼接缺陷;本次 Submit 明细靠日志定论)——D30/P2 优化。
|
||||
- **运维口径**:抓包常驻(`scripts/cmpp-capture.sh`);联调余额 10000 条挂账 s2demo。
|
||||
|
||||
## 2026-11-16(晚四)· Issue#3 联调装备:CMPP 抓包分析能力 + 连接日志补盲
|
||||
|
||||
- **背景**:客户重测在即,-1 类问题需「数据说话」——Connect 成功零日志+无抓包能力导致此前排查吃力(且上轮公网归因教训:通道表第一条即上游 5.16:7890,内网双 7890 并存,客户地址指向待确认)。
|
||||
- **抓包**:`apt install tcpdump 4.99.5`(新机原未装);`scripts/cmpp-capture.sh`(start/stop/status/analyze;`-i any -s 0 -C 50 -W 6` 环形 300MB 防打爆;**坑留痕:tcpdump 4.x 写 pcap 默认降权 tcpdump 用户致 Permission denied,须 `-Z root`**;PID 用 pgrep 管理+启动失败即报 stderr)。
|
||||
- **分析器**:`scripts/cmpp-analyze.py`(**纯 python 标准库零依赖**):pcap 魔数/纳秒自适应→链路层自适应(SLL/SLL2/以太+VLAN/RAW)→TCP 按 seq 重组(容重传/重叠)→CMPP PDU 按 TotalLength 切分;输出按连接分组时间线(时:分:秒.毫秒),CONNECT(sp/ver/ts)/CONNECT_RESP(**布局自动判定 21B=2.0/18B=3.0**+status 语义)/SUBMIT(srcid/码数/result)/DELIVER/心跳;**status≠0/result≠0 自动 ⚠️**;`analyze all` 合并环形切片。
|
||||
- **日志补盲**:server.go `cmpp_conn_accepted{client_ip}`(TCP 到达即留痕)+`cmpp_conn_ok{source_addr,client_ip,ver}`(Connect 成功留痕)——与抓包时间戳毫秒级互证,「客户连没连上」从此可追溯。
|
||||
- **自测实证**:三场景探针(本机正确密码 status=0/错误密码 status=2 ⚠️/上游 5.16 status=3 ⚠️)抓包时间线与 gateway 日志**毫秒级对齐**;顺带抓到 4 条上游通道连接心跳(运维流量可见)。
|
||||
- **联调 SOP**:`cmpp-capture.sh start` → 客户连 → `stop`+`analyze` → 30 秒出结论(到达与否/卡在哪步/谁拒绝/布局版本是否匹配);与 `cmpp_conn_*` 日志双通道互证。
|
||||
|
||||
## 2026-11-16(晚三)· Issue#3 追报:客户连公网 7890 非 本平台 + CMPP 版本协商 + 弹窗防截断
|
||||
|
||||
- **「登录仍报 -1」根因(网络层,非协议)**:探针对照实证——**公网 121.46.230.53:7890 是另一个 CMPP 网关**(回 Status=3 拒绝,本平台码值从不返回 3),s2demo 在彼处不存在;**本平台 CMPP 服务在内网 192.168.5.18:7890**(同请求 Status=0 鉴权通过)且 gateway 日志零客户连接记录(请求未达)。**结论:客户交付的连接地址指向公网机上的第三方/旧平台网关;本平台无公网 CMPP 入口。**解法=公网机 nginx 加 TCP stream 反代(7890 已被占用须用新端口如 17890→192.168.5.18:7890,需运维执行,配置片段已交付);过渡期客户可内网直连 192.168.5.18:7890。
|
||||
- **CMPP 版本协商加固(Issue#3 加固)**:服务端按客户端 Connect.Version(包体 offset22)应答——≥0x30 回 **3.0 布局**(1B Status/18B 包体/ISMG 串按 1B 参与/version 回显 0x30),否则 2.0(4B Status/21B);`ConnectResp.ClientVersion` 字段+Marshal/AuthenticatorISMG 双分支。**ISMG 鉴权串规范修正**:server 侧新增可选接口 `ISMGSecretSource`(access 实现=账号 ApiSecret),AuthenticatorISMG=MD5(Status+clientAuth+**shared_secret**)按规范掺入真密钥(此前 Secret 恒空串,严格校验 ISMG 的客户端必判失败——潜在 -1 源)。真机探针实证:2.0(21B/4B)与 3.0(18B/1B)Status=0 且**严格客户端视角重算 ISMG 串均匹配**。
|
||||
- **系统配置弹窗防截断**:Chrome 实测本机 1280×720/1024×600 几何均在视口内(用户场景为小视口/缩放/长选项);防御性全覆盖——dialog `align-center`(垂直居中,实测 top=精确居中)+`append-to-body`(防布局层裁剪)+max-width 92vw+body max-height 62vh 内滚(footer 恒可见);el-select 选项改**两行模板**(key 等宽主行+中文说明副行,原单行拼接 label ≈520px>面板 396px 必然省略号截断)+选中已知键在下方显示生效说明(keyHint)。
|
||||
- **测试 +2**:TestServer_ConnectVersion30(裸 TCP 第三方视角:0x30→18B/1B/version 回显,0x20→21B/4B 回归)、TestConnectRespVersion30Layout(3.0 布局往返+ISMG 1B 口径);fakeHandler 实现 ISMGSecret。
|
||||
- **门禁**:vet 0/-race cmpp+access+sysconfig 三包绿(全量 42 包前轮已绿)/lint 0;eslint 0/vue-tsc 0/vitest 165;gateway 串行部署(md5 ✓)。
|
||||
|
||||
## 2026-11-16(晚二)· Issue#3 方案B:系统配置页 + 系统级默认接入码回退链
|
||||
|
||||
- **范围(用户拍板 A+B)**:「系统配置」占位页做实(system_config KV 管理面)+ SrcID 校验两级回退链(账号 ext_code 优先 → 系统默认 cmpp.default_ext_code 兜底 → 均空放行)。
|
||||
- **sysconfig 域**(新包):Get(30s TTL 读缓存+缺行空值缓存)/List(cfg_key 升序)/Set(uk UPSERT:值/备注/操作人/时间;**写即刻失效缓存——区别于账号 ext_code 的 30s accCache 窗口,管理页改完即生效**);DB 错误降级空串=放行口径与账号级缺省一致。
|
||||
- **回退链(access)**:`effectiveExtCode`(账号 ext_code 优先,空读系统默认;getter 未注入=行为不变);precheck 改返 (cfg,ext,result)——直发/长短信 submitFragment/SMPP SubmitSM 三路径统一用生效前缀(扩展码剥离口径一致);拒收日志加 from_system_default 辨识来源。
|
||||
- **端点**:GET /system/config(登录即可)/ PUT /system/config(system:write——admin 直通,同 error-codes 口径;AuditTrail 写方法自动留痕 updated_by)。与 error-codes 同口径未进 openapi.yaml paths。
|
||||
- **前端**:系统配置页 views/system(占位页转正:KV 表格+新增/编辑对话框,已知键下拉 cmpp.default_ext_code/uplink.blacklist.keywords 带运营提示,defineOptions name=system 守门);api/system.ts;路由 meta 加 subtitle;AccountDetail 两处文案改「未配置时回退系统默认接入码」。
|
||||
- **真机闭环实证**(第三方 2.0 探针四态矩阵):账号 ext 空+系统默认 SYSDEF:106 → SYSDEF:10699 过(10)/10690331 拒(9)=**系统级接管**;恢复账号 10690331 → 10690331 过(10)/SYSDEF:10699 拒(9)=**账号级优先不叠加**;GET/PUT/UPSERT(updated_by 留痕+created_at 保留首插)全链过。生产值已设 **cmpp.default_ext_code=10690331**(未配置账号开箱即校验;账号级可覆盖)。
|
||||
- **测试 +8**:sysconfig 4 件(缺行空串/UPSERT+缓存即刻失效(长 TTL 反证)/List 顺序/键值校验)+ access 回退 3 件(系统默认放行+拒/账号优先不叠加/双空放行回归)。
|
||||
- **门禁**:vet 0/**-race 42 包全绿**(+1 新包)/lint 0;eslint 0/vue-tsc 0/vitest **165**/build 9.91s;gateway 串行部署(md5 比对 ✓)。
|
||||
|
||||
## 2026-11-16(晚)· Issue#3:CMPP 服务端连接报 -1 + 充值无响应 + SrcID 核验口径
|
||||
|
||||
- **工单**:Gitea Issue#3「Bug:服务端CMPP链接-1」——s2demo 作服务端账号客户连接报 -1;页面充值点击无响应;通道号(接入码)SrcID(≤21位)是否需要核验。
|
||||
- **CMPP -1 根因**:`ConnectResp.Marshal` 把 Status 按 **1 字节**编码(18B 包体)= CMPP **3.0** 布局;而 **CMPP 2.0 规范 CMPP_CONNECT_RESP.Status 为 4 字节整数**(21B 包体;两版本恰与 SUBMIT_RESP.Result 互为镜像——2.0 Result=1B、3.0=4B,本项目 SubmitResp 按 2.0 实现且与真实上游联调通过,唯独 ConnectResp 误用 3.0 布局)。标准 2.0 客户端按 4B 大端解析读到 [status,MD5[0..2]] **恒非 0** → 客户端工具报 -1;自家客户端同按 1B 解析,自测格式对称掩盖缺陷(与 Day39 Submit 布局坑同构:模拟网关与实现同源同错)。
|
||||
- **修复(body.go)**:①`Marshal` Status 4B 大端(21B 包体);②`AuthenticatorISMG` 中 Status 以 4B 参与 MD5(2.0 规范);③`ParseConnectResp` 自适应双布局(≥20B 按 2.0 4B;17~19B 按 3.0 1B 兼容;短包取首字节)——自家客户端连真实上游 2.0 网关不再靠「status=0 时 b[0] 恰为零」侥幸,拒绝码也能正确读出。
|
||||
- **充值无响应根因(双重)**:①前端 `accountApi.recharge` 发 `{count,remark}`,后端 `rechargeReq` 要求 `{amount}`(`binding:"required,gt=0"`)→ 恒 400;②`AccountRecharge.vue` submit 无 catch,BizError 被静默吞掉 → 点击零反馈。修复:API 字段对齐 amount+mock 契约同步(msw handlers)+submit catch 提示(含 acc 未装载 warning 分支)。
|
||||
- **SrcID 核验口径(用户裁定:方案 C 前缀+动态扩展,行业惯例)**:CMPP 2.0 协议 Src_ID 定长 21 字节(协议层硬约束,parse 天然截断);平台核验=账号 ext_code 非空时前缀匹配(不匹配回 Result=9)。**s2demo 已配置 ext_code=10690331**(通道接入码即分配前缀):客户 SrcID 须以 10690331 开头,可追加自定义扩展位(总长 ≤21,扩展 ≤13 位)区分业务——纯下发填 10690331,带扩展填 10690331xxx。AccountDetail 两处文案(接入信息+交付文本)明确「定长 ≤21 位+ext_code 前缀规则」,动态显示账号 ext_code。
|
||||
- **方案 C 真机四场景实证**(第三方 2.0 探针,余额 0 零副作用):纯接入码 10690331→Result=10(过码校验,欠费拒);接入码+扩展 10690331001→Result=10(**前缀+动态扩展通过**);不匹配 10699999→Result=9;空 SrcID→Result=9。日志双事件留痕(cmpp_submit_src_prefix_mismatch/cmpp_submit_rejected)。**运营口径:ext_code 变更后受理热路径账号缓存 30s 内生效**(Day63 accCache TTL;真机首验踩到,等 30s 后四场景全中)。
|
||||
- **真机实证**:标准 2.0 客户端探针(纯标准库,4B 解析视角)——修复前 18B/Status=3222621(复现 -1);修复后(串行 build→kill→md5 部署)21B/Status=0 连接成功 ✓,错误密码 Status=2(标准语义码);充值 curl:count→ISC:400(复现被吞报错)/amount→ISC:000 余额 0→100 ✓,冒烟数据已还原。
|
||||
- **顺手修**:TestClient_LoginOK 时序竞争(网关 logins.Add 在 WritePacket 后,客户端握手完成与落账存在调度窗口,全量 -race 并行下偶发 0)→ 轮询 1s 吸收;全量复跑 **41 包全绿**。
|
||||
- **门禁**:vet 0/-race 41 包/lint 0;eslint 0/vue-tsc 0/vitest **165**/build 9.88s。
|
||||
|
||||
## 2026-11-16(傍晚)· Issue#2:管理前端多标签导航 + 页签缓存
|
||||
|
||||
- **工单**:Gitea Issue#2「优化:管理前端V1」——增加菜单 Tab 页(可独立关闭/一次全部关闭),切换后页面状态保留。
|
||||
|
||||
+21
-1
@@ -1,7 +1,7 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
title: go-sms API v1(阶段 2:账号与权限)
|
||||
version: 1.4.0
|
||||
version: 1.5.0
|
||||
description: |
|
||||
阶段 2(Day 21-30)交付的账号与权限域全部端点。
|
||||
统一响应 {code,msg,data}:code=ISC:000 成功;错误码三位制(ISC:4xx/5xx)。
|
||||
@@ -955,6 +955,26 @@ paths:
|
||||
summary: 删除档位(settle:write)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: ok}}
|
||||
/stats/biz:
|
||||
get:
|
||||
tags: [stats]
|
||||
summary: 业务类型分布(Issue#6 Dashboard donut;近 N 自然日,1~30 缺省 7)
|
||||
parameters:
|
||||
- {name: days, in: query, schema: {type: integer, default: 7, minimum: 1, maximum: 30}}
|
||||
responses:
|
||||
"200": {description: '{days,by_business:[{key:sms|video,count}],by_send_type:[{key:batch|personal|timer|file|other,count}]}'}
|
||||
/stats/realtime:
|
||||
get:
|
||||
tags: [stats]
|
||||
summary: 实时提交速率(Issue#6 Dashboard KPI;60s 窗口均值,覆盖索引 COUNT)
|
||||
responses:
|
||||
"200": {description: '{ts,window_s:60,global_submit_ps,top_accounts:[{account_id,name,submit_ps}]Top5(客户口径仅自己)}'}
|
||||
/ops/system/overview:
|
||||
get:
|
||||
tags: [ops]
|
||||
summary: 系统健康总览(Issue#6 Dashboard 系统健康卡;admin/ops,gateway 视角五子系统)
|
||||
responses:
|
||||
"200": {description: '{uptime_s,subsystems:[{name:gateway|consumer|mysql|redis|kafka,status:up|degraded|down|unknown,detail,latency_ms}]}'}
|
||||
/stats/profit/users:
|
||||
get:
|
||||
tags: [settle]
|
||||
|
||||
+24
-1
@@ -18,9 +18,9 @@ import (
|
||||
"go-sms/internal/pkg/metrics"
|
||||
"go-sms/internal/pkg/queue"
|
||||
"go-sms/internal/pkg/storage"
|
||||
chrepo "go-sms/internal/repository/clickhouse"
|
||||
cmppproto "go-sms/internal/protocol/cmpp"
|
||||
smppproto "go-sms/internal/protocol/smpp"
|
||||
chrepo "go-sms/internal/repository/clickhouse"
|
||||
"go-sms/internal/service/access"
|
||||
"go-sms/internal/service/account"
|
||||
"go-sms/internal/service/archive"
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"go-sms/internal/service/router"
|
||||
"go-sms/internal/service/send"
|
||||
"go-sms/internal/service/settle"
|
||||
"go-sms/internal/service/sysconfig"
|
||||
"go-sms/internal/service/template"
|
||||
"go-sms/internal/service/uplink"
|
||||
"go-sms/internal/util"
|
||||
@@ -101,6 +102,8 @@ func main() {
|
||||
// Day 48:全流程状态机——拦截链(Day42)+sms-submit 统一出口(ProducerSink,
|
||||
// 替代 openapi 自投,预扣/拦截退费/审核拒绝退费在 SubmitService 内闭环)。
|
||||
// Kafka 降级(producer=nil)不注入 sink:发送由 ReclaimScanner DB 认领兜底。
|
||||
// Issue#6·P2:系统健康探针(lagR 未就绪时为 nil=unknown)。
|
||||
var healthLag func(ctx context.Context) (int64, error)
|
||||
pipelineOpts := []send.SubmitOption{send.WithInterceptorChain(ichain)}
|
||||
if p := a.Producer(); p != nil {
|
||||
pipelineOpts = append(pipelineOpts,
|
||||
@@ -145,6 +148,10 @@ func main() {
|
||||
}
|
||||
}()
|
||||
a.OnShutdown(func() { stopLag(); _ = lagR.Close() })
|
||||
// Issue#6·P2:健康探针复用同一 LagReader(只读)。
|
||||
healthLag = func(ctx context.Context) (int64, error) {
|
||||
return lagR.Total(ctx, []string{lagTopic})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
a.Lg().Warn("submit_pipeline_kafka_disabled",
|
||||
@@ -230,6 +237,13 @@ func main() {
|
||||
}
|
||||
a.OnShutdown(func() { _ = chConn.Close() })
|
||||
}
|
||||
// Issue#3 方案B:系统参数配置服务(system_config KV;/system/config
|
||||
// 管理端点 + access 系统默认接入码回退源;30s 读缓存+写即刻失效)。
|
||||
sysCfgSvc := sysconfig.New(db, 30*time.Second)
|
||||
healthDeps := &v1.HealthDeps{
|
||||
DB: db, Redis: a.Redis(), Lag: healthLag,
|
||||
StartTime: time.Now(), HTTPAddr: cfg.Server.HTTP.Addr, RedisMode: cfg.Redis.Mode,
|
||||
}
|
||||
v1.Register(rg, v1.Deps{
|
||||
Account: svc,
|
||||
Warning: warnSvc,
|
||||
@@ -261,6 +275,11 @@ func main() {
|
||||
Callback: cbSvc,
|
||||
// S4·D3:/record/history 冷查(CH;nil=不注册)
|
||||
Archive: arcSvc,
|
||||
// Issue#3 方案B:系统参数配置(/system/config;access 系统默认
|
||||
// 接入码回退数据源)。30s 读缓存+写即刻失效。
|
||||
SysConfig: sysCfgSvc,
|
||||
// Issue#6·P2:系统健康总览
|
||||
Health: healthDeps,
|
||||
})
|
||||
// Day68:运营总览汇总刷新(回补 30 天+60s ticker 增量 UPSERT stats_daily;
|
||||
// 幂等多实例无害,详见 stats_handler.go StartStatsRefresher)。
|
||||
@@ -319,7 +338,11 @@ func main() {
|
||||
MaxConns: cfg.Server.CMPP.MaxConnsPerAccount,
|
||||
SubmitRate: cfg.Server.CMPP.SubmitRatePerConn,
|
||||
LongSmsWindow: cfg.Server.CMPP.LongSmsWindow, // Day 71:≤0 默认 72h
|
||||
LongSmsMaxGroup: cfg.Server.CMPP.LongSmsMaxGroup, // ≤0 默认 20 万(乱序容忍窗)
|
||||
})
|
||||
// Issue#3 方案B:系统配置源注入——账号 ext_code 为空时回退系统默认
|
||||
// 接入码 cmpp.default_ext_code(/system/config 可配)。
|
||||
accSvc.SetSystemConfig(sysCfgSvc)
|
||||
// Day 71:长短信挂起制——重启恢复+72h 到期扫描(不齐不发,LP 失败
|
||||
// 终态+UNDELIV 回执经 Kafka cmpp-deliver 回环推下家在线连接)。
|
||||
{
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# Issue#4 验收单:版本号 + 发布日志(2026-11-16)
|
||||
|
||||
> 工单:Gitea Tory/go-sms-V2#4「增加:版本号及发布日志」。**纯前端交付(后端零改动)**;门禁四件 + verify-layout 全绿。
|
||||
|
||||
## 一、需求与落点
|
||||
|
||||
| 需求原文 | 落点 | 状态 |
|
||||
|---|---|---|
|
||||
| ①菜单底部,折叠展开旁边增加最新版本号,有更新时增加红点闪烁提示 | `MainLayout.vue` sidebar-foot 折叠按钮旁版本 chip(`data-testid=sidebar-version`,点击进发布日志页);红点=未读时 `gosms-ver-blink` CSS 脉冲闪烁 | ✅ |
|
||||
| ②系统管理增加二级菜单「发布日志」,功能迭代明细,运营大白话,Markdown 格式 | 路由 `/system/release`(**全角色**,同 faq 口径,用户拍板);`ReleaseLog.vue` 时间线卡片;`utils/markdown.ts` 迷你渲染器 | ✅ |
|
||||
|
||||
## 二、交付清单
|
||||
|
||||
| 文件 | 说明 |
|
||||
|---|---|
|
||||
| `web/src/data/releases.ts` | **单一事实源**:版本列表(最新在前,6 个版本 v1.0.0~v1.5.0,运营大白话 Markdown);`APP_VERSION = RELEASE_NOTES[0].version`;文件头含发版 SOP |
|
||||
| `web/src/utils/markdown.ts` | 迷你 Markdown→HTML(**零新依赖**):标题/无序有序列表(`1.` 与 `1、` 均支持)/粗体/行内代码(哨兵保护)/围栏代码块/链接(仅 http(s));**先全量 HTML 转义再解析** |
|
||||
| `web/src/stores/release.ts` | pinia store:`hasUpdate`(localStorage `gosms_seen_ver` ≠ APP_VERSION)/`markSeen()` |
|
||||
| `web/src/views/system/ReleaseLog.vue` | 发布日志页(`defineOptions name='system-release'`):hero 当前版本 + 版本时间线卡片(版本徽章/日期/标签/当前版本角标)+ Markdown 渲染 |
|
||||
| `web/src/layouts/MainLayout.vue` + `styles/shell.scss` | sidebar-foot 版本 chip(红点闪烁动画/折叠态 64px 短版本纵向/暗亮主题 token) |
|
||||
| `web/src/router/routes.ts` | `system/release` 路由(系统管理组,全角色,icon=Memo) |
|
||||
| `web/package.json` | version 0.1.0 → **1.5.0**(与 APP_VERSION 同步,测试断言防漂移) |
|
||||
| `web/tests/releases.spec.ts` | **+14 用例**(数据一致性 4/渲染器 7/store 3) |
|
||||
| `web/tests/guard.spec.ts` `role-menu-matrix.spec.ts` `web/scripts/verify-layout.mjs` | 菜单计数 33→34 显式更;矩阵登记 `system-release: ALL`;布局断言 23→**31** |
|
||||
|
||||
## 三、设计口径
|
||||
|
||||
1. **单一事实源**:版本号只在 `releases.ts` 头条维护;`APP_VERSION` 自动取首条,`package.json` 同步(测试两侧一致断言)。发版 SOP:**releases.ts 头部插一条(minor=功能/patch=修复)+ package.json version 同步**,部署后全员红点自动亮起。
|
||||
2. **红点语义(本地未读)**:localStorage `gosms_seen_ver` 存"上次已看过的版本";≠ 当前版本即亮;首访无记录=亮(引导看一次);点击 chip / 进入发布日志页即 `markSeen()` 熄灭;发新版后全员再亮。
|
||||
3. **Markdown 安全**:内容源=仓库静态数据(非用户输入),渲染器仍按不可信文本处理——先全量 HTML 转义再解析,链接仅 http(s)(javascript: 伪协议不渲染为 `<a>`),v-html 零注入面。
|
||||
4. **折叠态适配**:64px 窄栏下 chip 缩为无边框短版本(v1.5.0 → v1.5),与折叠按钮纵向排布;hover title 提示完整版本与更新引导。
|
||||
|
||||
## 四、门禁
|
||||
|
||||
- eslint **0 警** / vue-tsc **0** / vitest **179 全绿**(165+14)/ build ✓(chunk 剖面不变)。
|
||||
- verify-layout **31/31**(Chrome 实机,:5173,s2demo 登录):新增 8 项=chip 可见、文本 `vN.N`、首访红点存在、点击进发布日志、已读红点即灭、版本卡片 ≥3、Markdown 列表渲染、回 home。
|
||||
- 浏览器实机走查截图:`/tmp/issue4-*.png`(红点态/已读态/折叠态/发布日志页)。
|
||||
|
||||
## 五、口径与边界(诚实标注)
|
||||
|
||||
1. **红点为浏览器本地"未读"语义**:换浏览器/清缓存会重新提示一次;无服务端已读同步(单机管理后台语义够用,如需全员强提醒再挂后端)。
|
||||
2. **移动端(≤900px)**:sidebar-foot 沿用既有 `display:none` 约定,版本号仅桌面侧栏可见(工单语境为桌面管理后台)。
|
||||
3. **发布内容为仓库静态数据**:运营改文案=编辑 `releases.ts`(TypeScript 文件,格式有测试守门);不提供后台在线编辑(无需求,且内容发布本就应走代码评审)。
|
||||
4. CHANGELOG.md(技术向,仓库根)与发布日志(运营向,前端)是**两份受众不同的内容**,发版时各自更新。
|
||||
|
||||
## 六、遗留与下一步
|
||||
|
||||
- Gitea 工单 #4 完成评论待用户贴(写评论需 token)。
|
||||
- 版本线 v1.0.0~v1.4.0 的日期/内容为按 CHANGELOG 重建的运营向回顾(口径:一期 11-13 上线为 v1.0.0),如与用户预期划分不同,改 `releases.ts` 即可(纯数据)。
|
||||
@@ -0,0 +1,131 @@
|
||||
# Issue#5 压测复盘报告(2026-11-16 · 目标 100 万条)
|
||||
|
||||
> 工单:Gitea Tory/go-sms-V2#5「压测:100万条」(2026-11-16 16:23 提出;11-17 19:05 催报)。
|
||||
> 链路口径:**下家 s2demo**(account 90001,CMPP 2.0 客户端 cmppbench)→ **平台**(gateway :8080/CMPP :7890 + consumer)→ **上家 331004**(通道 9102「Hw测试专用」)。
|
||||
> 总判定:**下发成功 ≈112.7 万条,超额达成 100 万目标(+12.7%);计费全程三平、分毫不差;零失败终态、零慢查询;账单/利润链路就绪,压测数据待出账(列入下一轮 SOP)**。
|
||||
|
||||
## 一、结论速览
|
||||
|
||||
| 维度 | 结果 | 证据 |
|
||||
|---|---|---|
|
||||
| 100 万条目标 | ✅ 下发成功 ≈1,127,383 条(+12.7%);累计提交 ≈213.8 万条 | billing_consume_log + bench CSV + channel_log |
|
||||
| 计费 | ✅ 三平对账成立:充值 10.0001 亿 − 预扣 2,183,182 + 拦截退款 999,741 = 余额 998,826,559(基数 100 万,分毫不差);拦截即时退款 99.97 万笔零差错 | account_balance_log |
|
||||
| 账单 | ⚠️ 出账/确认/结账/阶梯链路 11-14 已验收(S2 泳道),库内仅 seed 演示账单;**本轮 206 万条尚未出账** → 列入正式压测 SOP | settle_customer 仅 account 2(seed) |
|
||||
| 利润 | ⚠️ 利润/返点/三方对账引擎已验收(settle-check EXIT=0);本轮未出报表;按时间线价推算(售价 0.10/成本 0.035)毛利 ≈7.33 万元/112.7 万条(演示口径,未出正式报表) | /stats/profit 引擎 + 价格抽屉走查 |
|
||||
| 稳定性 | ✅ 受理 slow>200ms=0;Kafka lag 峰 476/均 88;慢查询 0;双进程零重启;磁盘 4%~9% | watch_1m.sh 2,719 样本 |
|
||||
| 遗留问题 | 6 项(R1 余额对账差额 P0 ×33 次/签名拦截口径/deliver_fail 复核/长短信挂起/host 不热切换/CSV 留档) | 见 §六 |
|
||||
|
||||
## 二、压测环境与拓扑
|
||||
|
||||
```text
|
||||
cmppbench(自研压测客户端,CMPH 2.0,links/concurrency/rate/expect-receipt 可参)
|
||||
│ CMPP 2.0(纯文本 fmt=0x0f)
|
||||
▼
|
||||
平台 gateway(CMPP :7890 / HTTP :8080)──受理:预扣余额+拦截链+落 task/detail
|
||||
│ Kafka(16 分区)削峰
|
||||
▼
|
||||
consumer ──下发──► 上家通道 9102「Hw测试专用」(331004)
|
||||
│ ├─ 白日场:vcmppgw 模拟网关 127.0.0.1:17890(50ms 回 DELIVRD,17:26 退出)
|
||||
│ └─ 夜间场:真上家 192.168.5.16:7890(单连接)
|
||||
▼
|
||||
回执配对→明细终态→DELIVRD 推回客户端;拦截(status=5+ISC 码)即时退款
|
||||
监控:watch_1m.sh 30s 采样(task/detail/fee/report/lag/MySQL 慢查询/磁盘)+ tcpdump 环形 300MB 抓包
|
||||
```
|
||||
|
||||
- 压测前准备:通道 9102 host 临时切 vcmppgw(`logs/issue5-restore.sql` 预写恢复语句);s2demo 充值 10 亿条(**压测余额预算=TPS×时长×均条×2 教训落地**);价格配置面真浏览器走查(s2demo 售价 0.1000 / 通道 9102 成本 0.0350,`scripts/issue5-price-walkthrough.mjs` PASS 3/3)。
|
||||
|
||||
## 三、三场压测明细
|
||||
|
||||
### 3.1 白日场(17:00~17:26,上家=vcmppgw 模拟网关,数据已清理)
|
||||
|
||||
| 批次 | 时间 | 提交 | 成功 | 失败 | 延迟 p50/p90/p99/max(ms) | TPS |
|
||||
|---|---|---|---|---|---|---|
|
||||
| 预检×2 | 17:00:38 / 17:05 | 2,000 | 2,000 | 0 | 2.7~4.5 | — |
|
||||
| S1 单条 1 万 | 17:09:06~17:09:55(49.0s) | 10,000 | 10,000 | 0 | 6.0 / 8.9 / 12.1 / 22.3 | 均 203.9(限速 200) |
|
||||
| S2 单条(36 万目标) | 17:11:15~17:16:40(5m24.8s,人工中止) | 65,000 | 65,000 | 0 | 8.8 / 12.7 / 17.4 / 37.5 | 均 200.1 / 峰 258 |
|
||||
|
||||
- vcmppgw 侧:受理 75,191 / 回执 75,191 / 拒绝 0(与客户端 CSV 77,000 差 1,809 = host 切换窗口期分流,见 §六-5);17:23~17:26 drain 复跑 0 流量(排空验证 ✅)。
|
||||
- S2 中止说明:该场验证目标(200/s 限速下受理/下发/回执/计费全链零差错)已达成,转入夜间真上家场;36 万未跑完不判失败。
|
||||
- 客户端逐条 CSV 留档:`logs/bench-precheck*.csv / bench-s1-1w.csv / bench-s2-36w.csv`(77,000 行)。
|
||||
|
||||
### 3.2 夜间场·长短信段+小批量(18:32~21:00,上家=真上家 5.16,数据保留)
|
||||
|
||||
| 批次 | 时间 | 提交(任务) | 计费条(均片) | 成功 | 挂起 | 拦截 |
|
||||
|---|---|---|---|---|---|---|
|
||||
| 长短信段 | 18:32~19:00 | 51,264 | 153,786(×3) | 50,083 | 1,177 | 0 |
|
||||
| 小批量 | 20:00~ | 9,862 | 29,586(×3) | 9,862 | 0 | 2 |
|
||||
|
||||
### 3.3 夜间场·主战场(23:00~11-17 01:52,2h52m,上家=真上家 5.16 单连接)
|
||||
|
||||
| 指标 | 数值 |
|
||||
|---|---|
|
||||
| 提交 | 1,999,469 |
|
||||
| 下发成功(DELIVRD 终态) | 999,736 |
|
||||
| 签名拦截(ISC:004,即时退款) | 999,894(≈50%) |
|
||||
| 受理 QPS(30s 窗) | 均值 193.7(=拦截 96.9 + 下发 96.8)/ 峰值 287.9 / **slow>200ms=0** |
|
||||
| 下发吞吐(单连接) | ≈97 条/s |
|
||||
| channel_log | connect=1,submit 1,121,986,deliver 1,119,334,deliver_fail 2,652(待复核) |
|
||||
|
||||
### 3.4 总账(11-16 18:00 起,权威=DB)
|
||||
|
||||
- 提交 **2,060,928**(billing_consume_log 175,078+1,885,850;与余额流水 submit 笔数分毫不差)
|
||||
- 计费条 **2,183,182**(=余额扣款条数;11-17 场单条=提交数,11-16 场含长短信 3 片)
|
||||
- 成功 **1,059,540**(billing)≈ detail 终态成功 1,059,534 ✅
|
||||
- 拦截退款 **999,741 笔 / 999,741 条**(与 send_block_log 999,894 差 153=零星+清理项)
|
||||
- **三平对账**:1,000,000(基数)+1,000,010,000(充值 2 笔)− 2,183,182 + 999,741 = **998,826,559 = 当前余额** ✅
|
||||
|
||||
## 四、计费 / 账单 / 利润核验(工单问题①)
|
||||
|
||||
| 链路 | 状态 | 本轮压测实证 |
|
||||
|---|---|---|
|
||||
| **计费**(实时预扣+拦截退款) | ✅ **完善,支持压测** | 三平对账分毫不差(§3.4);100 万级拦截即时退款 99.97 万笔零差错;日汇总引擎(billing_consume_log)与明细/流水三方一致 |
|
||||
| **账单**(出账/确认/结账/阶梯/XLSX) | ⚠️ 功能完善(11-14 S2 泳道真机验收:生成→确认→结账→SettleRecord→真 XLSX),**本轮压测数据未执行出账**(出账为 T+1 运营动作) | 库内仅 seed 演示账单(account 2:16,050 条/1,605.00 元);**已列入下一轮压测 SOP 必做项** |
|
||||
| **利润**(时间线价收入+成本分摊+返点) | ⚠️ 引擎就绪(11-14 D5 验收 settle-check EXIT=0;价格面走查 s2demo 售 0.10/9102 成本 0.035),**本轮未出报表** | 推算演示:112.7 万条 ×(0.10−0.035)≈ **7.33 万元毛利**(时间线价口径,正式数字以下一轮出账报表为准) |
|
||||
|
||||
## 五、性能与稳定性数据(工单问题②:上下家提交速度)
|
||||
|
||||
| 指标 | 白日场(限速 200/s) | 夜间主战场(不限速) |
|
||||
|---|---|---|
|
||||
| 下家受理 | 200/s 恒定,均值 203.9 | 均 193.7/s、30s 窗峰 287.9/s,**slow>200ms=0** |
|
||||
| 受理延迟(CMPP Submit→Resp) | p99=17.4ms / max=37.5ms | 服务端 avg_ms≈0(快路径) |
|
||||
| 上家下发 | 200/s(模拟网关) | ≈97 条/s(真上家单连接;提吞吐需按通道 speed 扩连接) |
|
||||
| 回执 | vcmppgw 50ms 全量回 | 1,119,334 / 2,652 fail(复核中) |
|
||||
| Kafka lag | 峰 326 | 峰 476 / 均 88 |
|
||||
| 在途明细(status=1)峰 | 4,168 | 2,478 |
|
||||
| MySQL 活跃线程峰 / 慢查询 | 4 / 0 | 13 / **0** |
|
||||
| 磁盘 / 进程 | 3% / 零重启 | 4%~9% / 零重启、零 OOM |
|
||||
|
||||
## 六、发现的问题与整改建议
|
||||
|
||||
1. **R1 余额对账差额 P0 告警 ×33 次**(11-16 23:57 起 firing):Redis 预扣与 MySQL 流水重算差典型 ±120~791 条(另 1 次 10 亿=充值写入与重算的瞬时窗口,outlier);reconciler 5min 自动以流水覆写 Redis(自愈,流水为唯一事实源,无资损)。**建议**:根修预扣 Lua 与流水落库的时序窗口(或对账窗口排除在途)+告警按差额绝对值分级降噪。
|
||||
2. **主战场 50% 流量被签名拦截(ISC:004)**:平台行为正确(无报备签名内容应拦,且拦截+即时退款零差错);暴露的是**压测脚本口径**——下一轮内容须带账号报备签名,或专设「免签名压测账号」并留配置留痕。
|
||||
3. **channel_log deliver_fail 2,652 条终态去向待复核**(billing fail=0 / detail 失败终态=0):疑为通道侧失败回执重试链路计数,需一次明细级核对。
|
||||
4. **长短信段 1,326 条挂起未终态**(status=1 残留):符合 72h 挂起制语义,**11-19 reaper 到期处理**,到期核验终态与零费口径。
|
||||
5. **channel host 配置不热切换**:17:07:27 恢复 host=5.16 后,consumer 存量连接仍指向 vcmppgw(S1/S2 7.5 万条走旧连接;vcmppgw 受理 75,191 vs CSV 77,000 差 1,809=切换窗口分流)。**运维 runbook 增补:改通道 host 必须断连/重启连接池后核对实际流向**。
|
||||
6. **主战场客户端侧 CSV 未留档**(仅服务端 DB/日志齐全):SOP 增补「压测客户端 -csv 参数强制落盘」;白日场数据已按恢复 SOP 清理。
|
||||
|
||||
## 七、下一轮正式压测规划(建议 11-18 整改 / 11-19 正式场)
|
||||
|
||||
**P0 前置整改(11-18)**:①R1 差额根修或对账窗口豁免+告警分级(§六-1);②deliver_fail 复核(§六-3);③压测脚本签名口径对齐(§六-2);④host 热切换 runbook(§六-5)。
|
||||
|
||||
**SOP 增补(压测收尾四件套)**:出账→确认→结账全流程演练 + 利润报表产出与人工核对 + `settle-check` EXIT=0 + XLSX 导出留档;客户端 CSV 强制留档。
|
||||
|
||||
**阶梯方案(每档 30min 稳态,验收判据同行)**:
|
||||
|
||||
| 档 | 受理 TPS | 内容构成 | 上家 | 通过判据 |
|
||||
|---|---|---|---|---|
|
||||
| L1 | 200 | 单条 100% | 真上家单连接 | 三平+P99<50ms+零慢查询 |
|
||||
| L2 | 500 | 单条 70%+长短信 30% | 按通道 speed 扩连接 | 同上+lag<1k |
|
||||
| L3 | 1000 | 同 L2 | 双通道并发 | 同上+出账四件套全过 |
|
||||
|
||||
**观察项**:长短信挂起 1,326 条 11-19 到期核验;R1 告警整改后复测窗口。
|
||||
|
||||
## 附录:证据文件
|
||||
|
||||
- 客户端 CSV:`logs/bench-precheck*.csv`(2×1,000)/`bench-s1-1w.csv`(10,000)/`bench-s2-36w.csv`(65,000)
|
||||
- 压测日志:`logs/bench-s1.log`/`bench-s2.log`(含摘要 JSON);模拟网关 `logs/vcmppgw.log`/`vcmppgw-drain.log`
|
||||
- 监控:`logs/1m-baseline.txt` + `logs/1m-watch.log`(2,719 样本);网关日志 `logs/app-2026-11-16T17-35-43.916.log.gz`(主战场窗口,cmpp_submit_stats QPS 序列+R1 告警)
|
||||
- 抓包:`logs/capture/cmpp-20261116-174359.pcap0~5`(环形 300MB)
|
||||
- 工具:`cmd/cmppbench`(下家客户端)/`cmd/vcmppgw`(模拟上家)/`scripts/issue5-price-walkthrough.mjs`(价格面走查)/`logs/issue5-restore.sql`(通道恢复)
|
||||
- DB 对账:billing_consume_log / account_balance_log / send_block_log / channel_log / settle_*(2026-11-16~17 窗口,本文 §3~§6 数字均出自只读查询)
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"go-sms/internal/service/router"
|
||||
"go-sms/internal/service/send"
|
||||
"go-sms/internal/service/settle"
|
||||
"go-sms/internal/service/sysconfig"
|
||||
"go-sms/internal/service/template"
|
||||
)
|
||||
|
||||
@@ -76,6 +77,11 @@ type Deps struct {
|
||||
// Archive S4·D3:明细冷热归档(/record/history 冷查走 ClickHouse;
|
||||
// nil=不注册 history 端点,前端 404 优于半可用)。
|
||||
Archive *archive.Service
|
||||
// SysConfig Issue#3 方案B:系统参数配置(/system/config GET/PUT;
|
||||
// access 系统默认接入码回退的数据源;nil=不注册)。
|
||||
SysConfig *sysconfig.Service
|
||||
// Health Issue#6·P2:系统健康总览(/ops/system/overview;nil=不注册)。
|
||||
Health *HealthDeps
|
||||
}
|
||||
|
||||
// Register 注册 v1 路由组。
|
||||
@@ -152,6 +158,8 @@ func Register(rg *gin.RouterGroup, deps Deps) {
|
||||
protected.POST("/accounts/:id/realname", h.submitRealname)
|
||||
protected.POST("/accounts/:id/realname/review",
|
||||
middleware.RequirePermission(deps.Perm, "account", "write"), h.reviewRealname)
|
||||
// Issue#5·P0-A:账号分时单价时间线(结算/出账售价事实源的配置面;account:write)
|
||||
registerAccountPriceRoutes(protected, deps.Perm, deps.Account)
|
||||
}
|
||||
// Day 27:余额预警配置(本人或 admin)
|
||||
if deps.Warning != nil {
|
||||
@@ -187,6 +195,10 @@ func Register(rg *gin.RouterGroup, deps Deps) {
|
||||
if deps.ErrorCode != nil {
|
||||
registerErrorCodeRoutes(protected, deps.Perm, deps.ErrorCode)
|
||||
}
|
||||
// Issue#3 方案B:系统参数配置(system_config KV 管理页数据源)。
|
||||
if deps.SysConfig != nil {
|
||||
registerSysConfigRoutes(protected, deps.Perm, deps.SysConfig)
|
||||
}
|
||||
// Day 53(runbook §6.4/§6.2 P0):前端错误上报(POST public/GET 排障)+
|
||||
// Alertmanager webhook 接收(AM 推送→日志留痕,告警通道验收抓手)。
|
||||
registerFeErrorRoutes(rg, protected, deps.DB, deps.Perm)
|
||||
@@ -208,6 +220,10 @@ func Register(rg *gin.RouterGroup, deps Deps) {
|
||||
if deps.Callback != nil {
|
||||
registerCallbackRoutes(protected, deps)
|
||||
}
|
||||
// Issue#6·P2:系统健康总览(Dashboard 系统健康卡)。
|
||||
if deps.Health != nil {
|
||||
registerOpsRoutes(protected, deps)
|
||||
}
|
||||
// 阶段5收尾(D28):回执重推域四端点(回执分页/重推受理/挂起明细/手动配对;
|
||||
// 服务依赖 Billing/PushSink,装配见 cmd/gateway)。
|
||||
if deps.Pair != nil {
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
// ops_handler.go Issue#6·P2:系统健康总览(GET /ops/system/overview)——Dashboard
|
||||
// 系统健康卡数据源(D10 元信息层,gateway 视角探测):
|
||||
// - gateway 本进程 uptime(装配时刻起算);
|
||||
// - consumer 独立进程无直接探针,以 submit 消费组 lag 间接观测(<10k=up);
|
||||
// - mysql sql.DB.Ping 计时;
|
||||
// - redis go-redis Ping 计时(nil=未启用降级 → down,诚实标注);
|
||||
// - kafka LagReader.Total(与 consumer 同源 lag)。
|
||||
//
|
||||
// 角色门:admin/ops(基础设施信息不放大,group/customer/service 403——与
|
||||
// /billing/orders 平台门同口径;service 属业务角色不见运维面)。
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-sms/internal/pkg/cache"
|
||||
"go-sms/internal/pkg/response"
|
||||
)
|
||||
|
||||
// HealthDeps 系统健康探测依赖(nil 字段=该子系统探针缺失,状态 unknown)。
|
||||
// Lag 为函数字段便于测试注入(生产闭包包 LagReader;ctx 来自请求)。
|
||||
type HealthDeps struct {
|
||||
DB *gorm.DB
|
||||
Redis *cache.Client
|
||||
Lag func(ctx context.Context) (int64, error)
|
||||
StartTime time.Time
|
||||
HTTPAddr string
|
||||
RedisMode string
|
||||
}
|
||||
|
||||
// subsystemDTO 子系统状态(up/degraded/down/unknown 三态+unknown,拒绝全绿作弊)。
|
||||
type subsystemDTO struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Detail string `json:"detail"`
|
||||
LatencyMs float64 `json:"latency_ms"`
|
||||
}
|
||||
|
||||
type opsHandler struct{ hd *HealthDeps }
|
||||
|
||||
func registerOpsRoutes(protected *gin.RouterGroup, deps Deps) {
|
||||
if deps.Health == nil {
|
||||
return
|
||||
}
|
||||
h := &opsHandler{hd: deps.Health}
|
||||
protected.GET("/ops/system/overview", h.overview)
|
||||
}
|
||||
|
||||
// opsAdminGate admin/ops 角色门(与 /billing/orders 平台门同口径)。
|
||||
func opsAdminGate(c *gin.Context) bool {
|
||||
claims := statsClaims(c)
|
||||
if claims == nil {
|
||||
return true // 无 claims 仅测试场景,放行
|
||||
}
|
||||
for _, r := range claims.Roles {
|
||||
if r == "admin" || r == "ops" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// overview GET /ops/system/overview:五子系统快照(单次请求全量探测,
|
||||
// 上位机 10s 轮询;各探针失败不互相影响,缺失=unknown)。
|
||||
func (h *opsHandler) overview(c *gin.Context) {
|
||||
if !opsAdminGate(c) {
|
||||
c.JSON(http.StatusForbidden, gin.H{"code": "ISC-403", "msg": "仅管理员可查看系统健康"})
|
||||
return
|
||||
}
|
||||
hd := h.hd
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 3*time.Second)
|
||||
defer cancel()
|
||||
subs := make([]subsystemDTO, 0, 5)
|
||||
|
||||
// gateway:本进程
|
||||
up := time.Since(hd.StartTime).Round(time.Second)
|
||||
subs = append(subs, subsystemDTO{
|
||||
Name: "gateway", Status: "up",
|
||||
Detail: fmt.Sprintf("UP %s · %s", opsHumane(up), opsOr(hd.HTTPAddr, ":8080")),
|
||||
})
|
||||
|
||||
// lag 采样(consumer/kafka 共源;失败=双 unknown,链路抖动不判死)。
|
||||
var lag int64 = -1
|
||||
var lagErr error
|
||||
if hd.Lag != nil {
|
||||
lag, lagErr = hd.Lag(ctx)
|
||||
}
|
||||
lagStatus := func() string {
|
||||
switch {
|
||||
case hd.Lag == nil || lagErr != nil:
|
||||
return "unknown"
|
||||
case lag >= 10000:
|
||||
return "degraded"
|
||||
default:
|
||||
return "up"
|
||||
}
|
||||
}
|
||||
lagDetail := func(prefix string) string {
|
||||
if hd.Lag == nil {
|
||||
return prefix + "探针未装配"
|
||||
}
|
||||
if lagErr != nil {
|
||||
return prefix + "采样失败"
|
||||
}
|
||||
return fmt.Sprintf("%slag %s", prefix, opsThousand(lag))
|
||||
}
|
||||
subs = append(subs, subsystemDTO{Name: "consumer", Status: lagStatus(), Detail: lagDetail("kafka ")})
|
||||
subs = append(subs, subsystemDTO{Name: "kafka", Status: lagStatus(), Detail: lagDetail("")})
|
||||
|
||||
// mysql
|
||||
if hd.DB != nil {
|
||||
t0 := time.Now()
|
||||
if sdb, err := hd.DB.DB(); err == nil {
|
||||
if perr := sdb.PingContext(ctx); perr != nil {
|
||||
subs = append(subs, subsystemDTO{Name: "mysql", Status: "down", Detail: perr.Error()})
|
||||
} else {
|
||||
subs = append(subs, subsystemDTO{Name: "mysql", Status: "up",
|
||||
Detail: "OK", LatencyMs: opsMs(time.Since(t0))})
|
||||
}
|
||||
} else {
|
||||
subs = append(subs, subsystemDTO{Name: "mysql", Status: "unknown", Detail: "句柄不可用"})
|
||||
}
|
||||
} else {
|
||||
subs = append(subs, subsystemDTO{Name: "mysql", Status: "unknown", Detail: "未装配"})
|
||||
}
|
||||
|
||||
// redis(nil=降级未启用,诚实标 down 而非假绿)
|
||||
if hd.Redis == nil {
|
||||
subs = append(subs, subsystemDTO{Name: "redis", Status: "down", Detail: "未启用(降级态)"})
|
||||
} else {
|
||||
t0 := time.Now()
|
||||
if perr := hd.Redis.Ping(ctx).Err(); perr != nil {
|
||||
subs = append(subs, subsystemDTO{Name: "redis", Status: "down", Detail: perr.Error()})
|
||||
} else {
|
||||
subs = append(subs, subsystemDTO{Name: "redis", Status: "up",
|
||||
Detail: opsOr(hd.RedisMode, "single"), LatencyMs: opsMs(time.Since(t0))})
|
||||
}
|
||||
}
|
||||
|
||||
response.Success(c, gin.H{"uptime_s": int64(time.Since(hd.StartTime).Seconds()), "subsystems": subs})
|
||||
}
|
||||
|
||||
func opsOr(s, def string) string {
|
||||
if strings.TrimSpace(s) == "" {
|
||||
return def
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func opsMs(d time.Duration) float64 { return math.Round(float64(d.Microseconds())/10) / 100 }
|
||||
|
||||
func opsThousand(v int64) string {
|
||||
s := fmt.Sprintf("%d", v)
|
||||
if len(s) <= 3 {
|
||||
return s
|
||||
}
|
||||
var b []byte
|
||||
for i, r := range []byte(s) {
|
||||
if i > 0 && (len(s)-i)%3 == 0 {
|
||||
b = append(b, ',')
|
||||
}
|
||||
b = append(b, r)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func opsHumane(d time.Duration) string {
|
||||
if d < time.Hour {
|
||||
return d.Round(time.Minute).String()
|
||||
}
|
||||
days := int(d.Hours()) / 24
|
||||
return fmt.Sprintf("%dd%dh", days, int(d.Hours())%24)
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package v1
|
||||
|
||||
// ops_handler_test.go Issue#6·P2:/stats/biz(两维分布+双口径)+/stats/realtime
|
||||
// (60s 窗口 Top5+名字)+/ops/system/overview(角色门+三态诚实)。sqlite 单测;
|
||||
// LagReader 以函数注入,Kafka/Redis 真链路在 dev 实机冒烟。
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-sms/internal/middleware"
|
||||
"go-sms/internal/model/entity"
|
||||
)
|
||||
|
||||
// newOpsRouter 种子:今日 task(账号1:sms×2[1 条 business=video]+template×1;
|
||||
// 账号100:sms×1);60s 内 detail 账号1×7+账号100×3(60s 外 2 条不计);
|
||||
// 账号名 1=admin/100=cust100。同时挂 stats 与 ops(Health) 路由。
|
||||
func newOpsRouter(t *testing.T, hd *HealthDeps) (*gin.Engine, *gorm.DB, func(*middleware.Claims)) {
|
||||
t.Helper()
|
||||
gin.SetMode(gin.TestMode)
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s, e := db.DB(); e == nil {
|
||||
s.SetMaxOpenConns(1)
|
||||
}
|
||||
if err := db.AutoMigrate(&entity.MessageTask{}, &entity.MessageDetail{}, &entity.AccountUser{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now()
|
||||
tasks := []entity.MessageTask{
|
||||
{ID: 1, TaskNo: "T1", AccountID: 1, Business: "sms", SendType: 1, CreatedAt: now},
|
||||
{ID: 2, TaskNo: "T2", AccountID: 1, Business: "sms", SendType: 1, CreatedAt: now},
|
||||
{ID: 3, TaskNo: "T3", AccountID: 1, Business: "video", SendType: 1, CreatedAt: now},
|
||||
{ID: 4, TaskNo: "T4", AccountID: 1, Business: "", SendType: 2, CreatedAt: now}, // 空 business→sms 兼容
|
||||
{ID: 5, TaskNo: "T5", AccountID: 100, Business: "sms", SendType: 1, CreatedAt: now},
|
||||
}
|
||||
if err := db.Create(&tasks).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mk := func(id, acc int64, created time.Time) entity.MessageDetail {
|
||||
return entity.MessageDetail{SnowflakeModel: entity.SnowflakeModel{ID: id, CreatedAt: created},
|
||||
TaskID: 1, AccountID: acc, ChannelID: 1, Mobile: "13000001111", Content: "t", Status: 2}
|
||||
}
|
||||
details := []entity.MessageDetail{
|
||||
mk(11, 1, now.Add(-10*time.Second)), mk(12, 1, now.Add(-20*time.Second)),
|
||||
mk(13, 1, now.Add(-30*time.Second)), mk(14, 1, now.Add(-40*time.Second)),
|
||||
mk(15, 1, now.Add(-50*time.Second)), mk(16, 1, now.Add(-55*time.Second)),
|
||||
mk(17, 1, now.Add(-58*time.Second)),
|
||||
mk(21, 100, now.Add(-10*time.Second)), mk(22, 100, now.Add(-20*time.Second)),
|
||||
mk(23, 100, now.Add(-30*time.Second)),
|
||||
mk(31, 1, now.Add(-5*time.Minute)), mk(32, 100, now.Add(-5*time.Minute)), // 窗外不计
|
||||
}
|
||||
if err := db.Create(&details).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
accts := []entity.AccountUser{
|
||||
{Model: entity.Model{ID: 1}, Username: "admin", Status: 1},
|
||||
{Model: entity.Model{ID: 100}, Username: "cust100", Status: 1},
|
||||
}
|
||||
if err := db.Create(&accts).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rg := gin.New()
|
||||
api := rg.Group("/api/v1")
|
||||
var claims *middleware.Claims
|
||||
api.Use(func(c *gin.Context) {
|
||||
if claims != nil {
|
||||
c.Set(middleware.ContextKeyClaims, claims)
|
||||
}
|
||||
})
|
||||
registerStatsRoutes(api, db)
|
||||
if hd != nil {
|
||||
hd.DB = db
|
||||
registerOpsRoutes(api, Deps{Health: hd})
|
||||
}
|
||||
setClaims := func(cl *middleware.Claims) { claims = cl }
|
||||
return rg, db, setClaims
|
||||
}
|
||||
|
||||
func TestStatsBiz_PlatformAndCustomer(t *testing.T) {
|
||||
rg, _, setClaims := newOpsRouter(t, nil)
|
||||
setClaims(&middleware.Claims{AccountID: 1, Roles: []string{"admin"}})
|
||||
w := httptest.NewRecorder()
|
||||
rg.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/stats/biz?days=7", nil))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("code=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
var res struct {
|
||||
Data statsBizDTO `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := map[string]int64{}
|
||||
for _, r := range res.Data.ByBusiness {
|
||||
got[r.Key] = r.Count
|
||||
}
|
||||
// 平台:sms=3(账号1×2+账号100)+video=1;空 business 归一为 sms。
|
||||
if got["sms"] != 4 || got["video"] != 1 {
|
||||
t.Errorf("by_business = %v, 期望 sms=3 video=1", got)
|
||||
}
|
||||
gotT := map[string]int64{}
|
||||
for _, r := range res.Data.BySendType {
|
||||
gotT[r.Key] = r.Count
|
||||
}
|
||||
if gotT["batch"] != 4 || gotT["personal"] != 1 {
|
||||
t.Errorf("by_send_type = %v, 期望 batch=4 personal=1", gotT)
|
||||
}
|
||||
// 客户口径仅自己(账号100:sms×1)。
|
||||
setClaims(&middleware.Claims{AccountID: 100, Roles: []string{"customer"}})
|
||||
w = httptest.NewRecorder()
|
||||
rg.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/stats/biz", nil))
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(res.Data.ByBusiness) != 1 || res.Data.ByBusiness[0].Key != "sms" || res.Data.ByBusiness[0].Count != 1 {
|
||||
t.Errorf("customer by_business = %+v, 期望仅 sms=1", res.Data.ByBusiness)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatsRealtime_TopAccounts(t *testing.T) {
|
||||
rg, _, setClaims := newOpsRouter(t, nil)
|
||||
setClaims(&middleware.Claims{AccountID: 1, Roles: []string{"ops"}})
|
||||
w := httptest.NewRecorder()
|
||||
rg.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/stats/realtime", nil))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("code=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
var res struct {
|
||||
Data statsRealtimeDTO `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// 窗内 10 条(账号1×7+账号100×3)/60s ≈ 0.17;Top1=账号1 名 admin。
|
||||
if res.Data.GlobalSubmitPs < 0.1 || res.Data.GlobalSubmitPs > 0.25 {
|
||||
t.Errorf("global_submit_ps = %v, 期望 ≈0.17", res.Data.GlobalSubmitPs)
|
||||
}
|
||||
if len(res.Data.TopAccounts) != 2 || res.Data.TopAccounts[0].AccountID != 1 ||
|
||||
res.Data.TopAccounts[0].Name != "admin" {
|
||||
t.Errorf("top_accounts = %+v, 期望首名 admin(账号1)", res.Data.TopAccounts)
|
||||
}
|
||||
// 客户口径:仅自己(账号100 3 条)。
|
||||
setClaims(&middleware.Claims{AccountID: 100, Roles: []string{"customer"}})
|
||||
w = httptest.NewRecorder()
|
||||
rg.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/stats/realtime", nil))
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Data.GlobalSubmitPs < 0.03 || res.Data.GlobalSubmitPs > 0.07 {
|
||||
t.Errorf("customer global = %v, 期望 ≈0.05", res.Data.GlobalSubmitPs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpsOverview_GatesAndSubsystems(t *testing.T) {
|
||||
hd := &HealthDeps{
|
||||
Redis: nil, // 降级未启用 → down
|
||||
Lag: func(ctx context.Context) (int64, error) { return 1204, nil },
|
||||
StartTime: time.Now().Add(-3 * time.Hour),
|
||||
HTTPAddr: ":8080",
|
||||
}
|
||||
rg, _, setClaims := newOpsRouter(t, hd)
|
||||
setClaims(&middleware.Claims{AccountID: 1, Roles: []string{"admin"}})
|
||||
w := httptest.NewRecorder()
|
||||
rg.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/ops/system/overview", nil))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("code=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
var res struct {
|
||||
Data struct {
|
||||
UptimeS int64 `json:"uptime_s"`
|
||||
Subsystems []subsystemDTO `json:"subsystems"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(res.Data.Subsystems) != 5 {
|
||||
t.Fatalf("subsystems = %d, 期望 5", len(res.Data.Subsystems))
|
||||
}
|
||||
st := map[string]subsystemDTO{}
|
||||
for _, s := range res.Data.Subsystems {
|
||||
st[s.Name] = s
|
||||
}
|
||||
if st["gateway"].Status != "up" || st["mysql"].Status != "up" {
|
||||
t.Errorf("gateway/mysql = %s/%s, 期望 up/up", st["gateway"].Status, st["mysql"].Status)
|
||||
}
|
||||
if st["consumer"].Status != "up" || st["kafka"].Detail != "lag 1,204" {
|
||||
t.Errorf("consumer/kafka = %+v/%+v, 期望 up 且 lag 千分位", st["consumer"], st["kafka"])
|
||||
}
|
||||
if st["redis"].Status != "down" {
|
||||
t.Errorf("redis(nil 降级) = %s, 期望 down(诚实标注)", st["redis"].Status)
|
||||
}
|
||||
// lag 超阈 → degraded。
|
||||
hd.Lag = func(ctx context.Context) (int64, error) { return 15000, nil }
|
||||
w = httptest.NewRecorder()
|
||||
rg.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/ops/system/overview", nil))
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, s := range res.Data.Subsystems {
|
||||
if s.Name == "kafka" && s.Status != "degraded" {
|
||||
t.Errorf("kafka lag=15000 → %s, 期望 degraded", s.Status)
|
||||
}
|
||||
}
|
||||
// 角色门:customer 403。
|
||||
setClaims(&middleware.Claims{AccountID: 100, Roles: []string{"customer"}})
|
||||
w = httptest.NewRecorder()
|
||||
rg.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/ops/system/overview", nil))
|
||||
if w.Code != http.StatusForbidden {
|
||||
t.Errorf("customer code=%d, 期望 403", w.Code)
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -46,6 +48,9 @@ func registerStatsRoutes(protected *gin.RouterGroup, db *gorm.DB) {
|
||||
h := &statsHandler{db: db}
|
||||
protected.GET("/stats/summary", h.summary)
|
||||
protected.GET("/stats/trend", h.trend)
|
||||
// Issue#6·P2:Dashboard 业务分布与实时速率(契约 v3.2.1)。
|
||||
protected.GET("/stats/biz", h.biz)
|
||||
protected.GET("/stats/realtime", h.realtime)
|
||||
}
|
||||
|
||||
// statsSummaryDTO 四指标卡(mock 契约逐字段)。
|
||||
@@ -303,3 +308,153 @@ func StartStatsRefresher(db *gorm.DB, log *zap.Logger) {
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// ---- Issue#6·P2:业务类型分布(/stats/biz)与实时速率(/stats/realtime) ----
|
||||
// 契约=docs/design/issue6/v3-2-tailwind.html(v3.2.1)业务分布 donut 与 KPI
|
||||
// 实时速率卡;两维分布均聚合 message_task(表量级远小于 detail,HDD 可控),
|
||||
// 实时速率走 message_detail 的 idx_detail_created 覆盖索引 60s 窗口 COUNT。
|
||||
|
||||
type bizCountDTO struct {
|
||||
Key string `json:"key"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
// statsBizDTO 业务分布(business=sms/video 业务线;send_type=发送方式)。
|
||||
// 注:biz_type(sms/template/sign/group)属审核域 audit_record 非 task 维度,
|
||||
// 契约 donut 的第二维以 send_type 呈现(群发/个性/定时/文件)更贴运营语义。
|
||||
type statsBizDTO struct {
|
||||
Days int `json:"days"`
|
||||
ByBusiness []bizCountDTO `json:"by_business"` // message_task.business(空=sms 兼容 Day48 旧载荷)
|
||||
BySendType []bizCountDTO `json:"by_send_type"` // message_task.send_type:batch/personal/timer/file/other
|
||||
}
|
||||
|
||||
// biz GET /stats/biz?days=7——近 N 自然日两维分布(平台全量/客户仅自己)。
|
||||
func (h *statsHandler) biz(c *gin.Context) {
|
||||
days, _ := strconv.Atoi(c.DefaultQuery("days", "7"))
|
||||
if days < 1 || days > statsTrendMaxDays {
|
||||
days = 7
|
||||
}
|
||||
now := time.Now()
|
||||
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).
|
||||
AddDate(0, 0, -(days - 1))
|
||||
type row struct {
|
||||
Key string
|
||||
Count int64
|
||||
}
|
||||
var rows []row
|
||||
if err := h.db.Model(&entity.MessageTask{}).
|
||||
Where("created_at >= ?", start).Scopes(statsTaskScope(c)).
|
||||
Select("COALESCE(NULLIF(business,''),'sms') AS `key`, COUNT(*) AS count").
|
||||
Group("`key`").Order("count DESC").Scan(&rows).Error; err != nil {
|
||||
bizResp(c, err)
|
||||
return
|
||||
}
|
||||
byBiz := make([]bizCountDTO, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
byBiz = append(byBiz, bizCountDTO(r))
|
||||
}
|
||||
rows = nil
|
||||
if err := h.db.Model(&entity.MessageTask{}).
|
||||
Where("created_at >= ?", start).Scopes(statsTaskScope(c)).
|
||||
Select("send_type AS `key`, COUNT(*) AS count").
|
||||
Group("`key`").Order("count DESC").Scan(&rows).Error; err != nil {
|
||||
bizResp(c, err)
|
||||
return
|
||||
}
|
||||
sendNames := map[string]string{"1": "batch", "2": "personal", "3": "timer", "4": "file"}
|
||||
bySend := make([]bizCountDTO, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
k, ok := sendNames[r.Key]
|
||||
if !ok {
|
||||
k = "other"
|
||||
}
|
||||
bySend = append(bySend, bizCountDTO{Key: k, Count: r.Count})
|
||||
}
|
||||
response.Success(c, statsBizDTO{Days: days, ByBusiness: byBiz, BySendType: bySend})
|
||||
}
|
||||
|
||||
// statsTaskScope 平台/客户口径收敛(admin/ops/service 全量;其余仅自己)。
|
||||
func statsTaskScope(c *gin.Context) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if !statsIsPlatform(c) {
|
||||
return db.Where("account_id = ?", statsClaims(c).AccountID)
|
||||
}
|
||||
return db
|
||||
}
|
||||
}
|
||||
|
||||
type rtAccountDTO struct {
|
||||
AccountID int64 `json:"account_id"`
|
||||
Name string `json:"name"`
|
||||
SubmitPs float64 `json:"submit_ps"`
|
||||
}
|
||||
|
||||
// statsRealtimeDTO 实时速率(60s 窗口均值;平台=全局+Top5 账号,客户=仅自己)。
|
||||
type statsRealtimeDTO struct {
|
||||
Ts int64 `json:"ts"`
|
||||
WindowS int `json:"window_s"`
|
||||
GlobalSubmitPs float64 `json:"global_submit_ps"`
|
||||
TopAccounts []rtAccountDTO `json:"top_accounts"`
|
||||
}
|
||||
|
||||
// realtime GET /stats/realtime——60s 窗口提交速率(idx_detail_created 覆盖
|
||||
// COUNT 零回表;账号名小表 IN 补齐,缺失=空串不阻塞)。
|
||||
func (h *statsHandler) realtime(c *gin.Context) {
|
||||
const win = 60
|
||||
now := time.Now()
|
||||
since := now.Add(-win * time.Second)
|
||||
var global int64
|
||||
type topRow struct {
|
||||
AccountID int64
|
||||
Count int64
|
||||
}
|
||||
var tops []topRow
|
||||
if statsIsPlatform(c) {
|
||||
if err := h.db.Model(&entity.MessageDetail{}).Where("created_at >= ?", since).
|
||||
Count(&global).Error; err != nil {
|
||||
bizResp(c, err)
|
||||
return
|
||||
}
|
||||
if err := h.db.Model(&entity.MessageDetail{}).Where("created_at >= ?", since).
|
||||
Select("account_id, COUNT(*) AS count").
|
||||
Group("account_id").Order("count DESC").Limit(5).Scan(&tops).Error; err != nil {
|
||||
bizResp(c, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
claims := statsClaims(c)
|
||||
if err := h.db.Model(&entity.MessageDetail{}).
|
||||
Where("created_at >= ? AND account_id = ?", since, claims.AccountID).
|
||||
Count(&global).Error; err != nil {
|
||||
bizResp(c, err)
|
||||
return
|
||||
}
|
||||
tops = []topRow{{AccountID: claims.AccountID, Count: global}}
|
||||
}
|
||||
names := make(map[int64]string, len(tops))
|
||||
if len(tops) > 0 {
|
||||
ids := make([]int64, 0, len(tops))
|
||||
for _, t := range tops {
|
||||
ids = append(ids, t.AccountID)
|
||||
}
|
||||
var accs []entity.AccountUser
|
||||
_ = h.db.Select("id", "username").Where("id IN ?", ids).Find(&accs).Error
|
||||
for _, a := range accs {
|
||||
names[a.ID] = a.Username
|
||||
}
|
||||
}
|
||||
list := make([]rtAccountDTO, 0, len(tops))
|
||||
for _, t := range tops {
|
||||
list = append(list, rtAccountDTO{
|
||||
AccountID: t.AccountID, Name: names[t.AccountID],
|
||||
SubmitPs: statsRound2(float64(t.Count) / float64(win)),
|
||||
})
|
||||
}
|
||||
response.Success(c, statsRealtimeDTO{
|
||||
Ts: now.Unix(), WindowS: win,
|
||||
GlobalSubmitPs: statsRound2(float64(global) / float64(win)),
|
||||
TopAccounts: list,
|
||||
})
|
||||
}
|
||||
|
||||
func statsRound2(f float64) float64 { return math.Round(f*100) / 100 }
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// sysconfig_handler.go Issue#3 方案B:系统参数配置端点(system_config KV 表)。
|
||||
// - GET /system/config 全量列表(登录即可,管理页数据源)
|
||||
// - PUT /system/config 新增/更新(system:write——admin 直通;UPSERT+缓存即刻失效)
|
||||
// 已知键:cmpp.default_ext_code(系统默认接入码前缀,账号 ext_code 空时回退,
|
||||
// 受理热路径 30s 读缓存)/uplink.blacklist.keywords(上行拉黑词表,uplink 域
|
||||
// 自刷新 60s 生效)。表结构无白名单约束,新键=新能力按需扩展。
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"go-sms/internal/middleware"
|
||||
"go-sms/internal/pkg/errors"
|
||||
"go-sms/internal/pkg/response"
|
||||
"go-sms/internal/service/sysconfig"
|
||||
)
|
||||
|
||||
type sysConfigHandler struct{ svc *sysconfig.Service }
|
||||
|
||||
func registerSysConfigRoutes(protected *gin.RouterGroup, perm middleware.PermissionChecker, svc *sysconfig.Service) {
|
||||
h := &sysConfigHandler{svc: svc}
|
||||
protected.GET("/system/config", h.list)
|
||||
protected.PUT("/system/config", middleware.RequirePermission(perm, "system", "write"), h.set)
|
||||
}
|
||||
|
||||
// list GET /system/config(全量,cfg_key 升序)。
|
||||
func (h *sysConfigHandler) list(c *gin.Context) {
|
||||
rows, err := h.svc.List(c.Request.Context())
|
||||
if err != nil {
|
||||
response.Error(c, errors.InternalError)
|
||||
return
|
||||
}
|
||||
response.Success(c, gin.H{"list": rows})
|
||||
}
|
||||
|
||||
// sysConfigReq PUT 请求体。
|
||||
type sysConfigReq struct {
|
||||
CfgKey string `json:"cfg_key" binding:"required"`
|
||||
CfgValue string `json:"cfg_value"` // 空串=合法值(清空语义)
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
// set PUT /system/config(cfg_key 唯一 UPSERT;审计由 AuditTrail 写方法自动留痕)。
|
||||
func (h *sysConfigHandler) set(c *gin.Context) {
|
||||
var req sysConfigReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWithMsg(c, errors.InvalidParam, "参数错误: "+err.Error())
|
||||
return
|
||||
}
|
||||
claims := operatorClaims(c)
|
||||
operator := ""
|
||||
if claims != nil {
|
||||
operator = claims.Username
|
||||
}
|
||||
row, err := h.svc.Set(c.Request.Context(), req.CfgKey, req.CfgValue, req.Remark, operator)
|
||||
if err != nil {
|
||||
if bizErr, ok := err.(*errors.Error); ok {
|
||||
response.Error(c, bizErr)
|
||||
return
|
||||
}
|
||||
c.Set("biz_error", err.Error())
|
||||
response.Error(c, errors.InternalError)
|
||||
return
|
||||
}
|
||||
response.Success(c, row)
|
||||
}
|
||||
@@ -92,37 +92,74 @@ func VerifyAuth(sourceAddr, secret string, ts uint32, authenticator []byte) bool
|
||||
return true
|
||||
}
|
||||
|
||||
// ConnectResp 包体(status 1B + authenticator_ISMG 16B + version 1B)。
|
||||
// ConnectResp 包体(CMPP 2.0 规范:Status 4B 大端 + authenticator_ISMG 16B + version 1B = 21B)。
|
||||
type ConnectResp struct {
|
||||
Status byte
|
||||
Secret string // 计算服务端鉴权串
|
||||
Secret string // 计算服务端鉴权串(shared_secret;server 侧应填账号密钥)
|
||||
AuthenticatorClient []byte // 客户端鉴权串(参与计算)
|
||||
// ClientVersion 客户端 Connect.Version 声明(Issue#3 加固):≥0x30 按 3.0
|
||||
// 布局应答(1B Status,18B 包体,ISMG 串 Status 以 1B 参与)——防严格 3.0
|
||||
// 客户端按 1B 校验 ISMG 串错位报 -1;0/0x20 按 2.0(4B Status,21B 包体)。
|
||||
ClientVersion byte
|
||||
}
|
||||
|
||||
// AuthenticatorISMG 计算服务端鉴权串:MD5(status + authenticatorSource + shared)。
|
||||
// Issue#3 修正:CMPP 2.0 规范中 Status 以 4 字节大端参与拼接(3.0 为 1 字节)。
|
||||
func (r *ConnectResp) AuthenticatorISMG() []byte {
|
||||
sum := md5.Sum(append(append([]byte{r.Status}, r.AuthenticatorClient...), []byte(r.Secret)...))
|
||||
buf := make([]byte, 0, 4+len(r.AuthenticatorClient)+len(r.Secret))
|
||||
if r.ClientVersion >= 0x30 { // 3.0:Status 1B 参与
|
||||
buf = append(buf, r.Status)
|
||||
} else { // 2.0:Status 4B 大端参与
|
||||
var st [4]byte
|
||||
binary.BigEndian.PutUint32(st[:], uint32(r.Status))
|
||||
buf = append(buf, st[:]...)
|
||||
}
|
||||
buf = append(buf, r.AuthenticatorClient...)
|
||||
buf = append(buf, r.Secret...)
|
||||
sum := md5.Sum(buf)
|
||||
return sum[:]
|
||||
}
|
||||
|
||||
// Marshal 编码 ConnectResp 包体。
|
||||
// Issue#3 根因修复:CMPP 2.0 规范 CMPP_CONNECT_RESP 的 Status 为 4 字节整数
|
||||
// (与 3.0 的 1 字节不同——而 2.0 的 SUBMIT_RESP Result 恰为 1 字节,两版本在该
|
||||
// 两字段上互为镜像,极易混淆)。此前按 1B 编码(18B 包体),标准 2.0 客户端按
|
||||
// 4B 大端解析 Status 时读到 [status,MD5[0..2]] 恒非 0,客户连接被误判失败
|
||||
// (客户端工具报 -1);自家客户端同按 1B 解析,自测格式对称掩盖了缺陷。
|
||||
// Issue#3 加固:按客户端 Connect.Version 协商——0x30 回 3.0 布局(18B)。
|
||||
func (r *ConnectResp) Marshal() []byte {
|
||||
if r.ClientVersion >= 0x30 {
|
||||
b := make([]byte, 1+16+1)
|
||||
b[0] = r.Status
|
||||
copy(b[1:17], r.AuthenticatorISMG())
|
||||
b[17] = 0x20
|
||||
b[17] = 0x30
|
||||
return b
|
||||
}
|
||||
b := make([]byte, 4+16+1)
|
||||
binary.BigEndian.PutUint32(b[0:4], uint32(r.Status))
|
||||
copy(b[4:20], r.AuthenticatorISMG())
|
||||
b[20] = 0x20
|
||||
return b
|
||||
}
|
||||
|
||||
// ParseConnectResp 解析 ConnectResp(客户端校验服务端身份用)。
|
||||
// 自适应两种规范布局(Issue#3):
|
||||
// - CMPP 2.0(≥20B):Status 4B 大端 + AuthenticatorISMG 16B(+Version 1B=21B)
|
||||
// - CMPP 3.0/兼容(17~19B):Status 1B + AuthenticatorISMG 16B(+Version 1B)
|
||||
// - 其余短包:取首字节(历史行为;主流网关均回完整包)。
|
||||
func ParseConnectResp(body []byte) (status byte, authenticatorISMG []byte, err error) {
|
||||
if len(body) < 1 {
|
||||
return 0, nil, errors.New("cmpp: connect_resp 包体为空")
|
||||
}
|
||||
if len(body) >= 17 {
|
||||
authenticatorISMG = body[1:17]
|
||||
if len(body) >= 20 { // CMPP 2.0 布局(4B Status)
|
||||
status = byte(binary.BigEndian.Uint32(body[0:4]))
|
||||
authenticatorISMG = body[4:20]
|
||||
return status, authenticatorISMG, nil
|
||||
}
|
||||
return body[0], authenticatorISMG, nil
|
||||
if len(body) >= 17 { // 3.0/兼容布局(1B Status)
|
||||
return body[0], body[1:17], nil
|
||||
}
|
||||
return body[0], nil, nil
|
||||
}
|
||||
|
||||
// ActiveTest 心跳包体(空)。
|
||||
|
||||
@@ -169,6 +169,12 @@ func TestClient_LoginOK(t *testing.T) {
|
||||
t.Fatalf("握手应成功: %v", err)
|
||||
}
|
||||
defer func() { _ = c.Close() }()
|
||||
// 网关侧 logins.Add 在 WritePacket 之后:客户端握手完成与计数落账存在
|
||||
// 调度窗口,全量 -race 并行下曾偶发 0(轮询吸收,免 flaky 阻塞门禁)。
|
||||
deadline := time.Now().Add(time.Second)
|
||||
for g.logins.Load() != 1 && time.Now().Before(deadline) {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
if g.logins.Load() != 1 {
|
||||
t.Fatalf("网关成功登录数 = %d", g.logins.Load())
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package cmpp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -66,6 +68,9 @@ func TestConnectRespAuth(t *testing.T) {
|
||||
clientAuth := c.Authenticator(ts)
|
||||
resp := &ConnectResp{Status: 0, Secret: "pw", AuthenticatorClient: clientAuth}
|
||||
body := resp.Marshal()
|
||||
if len(body) != 21 { // Issue#3:CMPP 2.0 布局 4B+16B+1B
|
||||
t.Fatalf("connect_resp 包体应为 21 字节: %d", len(body))
|
||||
}
|
||||
status, ismg, err := ParseConnectResp(body)
|
||||
if err != nil || status != 0 || len(ismg) != 16 {
|
||||
t.Fatalf("解析: status=%d err=%v", status, err)
|
||||
@@ -76,6 +81,71 @@ func TestConnectRespAuth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestConnectRespCmpp20StatusLayout Issue#3 回归:服务端 Status 必须按 CMPP 2.0
|
||||
// 规范编为 4 字节大端——此前 1B 编码(3.0 布局)致标准 2.0 客户端按 4B 解析读到
|
||||
// [status,MD5[0..2]] 恒非 0,客户连接被误判失败(客户端工具报 -1)。
|
||||
func TestConnectRespCmpp20StatusLayout(t *testing.T) {
|
||||
resp := &ConnectResp{Status: ConnectBadAuth, Secret: "pw",
|
||||
AuthenticatorClient: bytes.Repeat([]byte{0xAB}, 16)}
|
||||
body := resp.Marshal()
|
||||
if len(body) != 21 {
|
||||
t.Fatalf("CMPP 2.0 connect_resp 包体应为 21 字节(4+16+1): %d", len(body))
|
||||
}
|
||||
// 第三方标准 2.0 客户端视角:前 4 字节大端 uint32 即 Status
|
||||
if got := binary.BigEndian.Uint32(body[0:4]); got != uint32(ConnectBadAuth) {
|
||||
t.Fatalf("2.0 客户端按 4B 解析 Status=%d, 期望 %d", got, ConnectBadAuth)
|
||||
}
|
||||
// 成功路径:前 4 字节全零,任何布局客户端均读到 0
|
||||
ok := (&ConnectResp{Status: ConnectOK, Secret: "pw",
|
||||
AuthenticatorClient: bytes.Repeat([]byte{0x01}, 16)}).Marshal()
|
||||
if got := binary.BigEndian.Uint32(ok[0:4]); got != 0 {
|
||||
t.Fatalf("成功状态 4B 解析应全零: %d", got)
|
||||
}
|
||||
// 自家客户端自适应解析(21B → 2.0 布局)拒绝码同样正确
|
||||
status, ismg, err := ParseConnectResp(body)
|
||||
if err != nil || status != ConnectBadAuth || len(ismg) != 16 {
|
||||
t.Fatalf("自适应解析: status=%d ismg=%dB err=%v", status, len(ismg), err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseConnectRespAdaptive Issue#3:客户端自适应两种规范布局。
|
||||
// 2.0(21B/4B Status)与 3.0(18B/1B Status)网关均可正确读出状态码。
|
||||
func TestParseConnectRespAdaptive(t *testing.T) {
|
||||
// 3.0/兼容布局(1B status=3 + 16B auth + 1B ver)
|
||||
b18 := append([]byte{3}, bytes.Repeat([]byte{0x11}, 17)...)
|
||||
if st, ismg, err := ParseConnectResp(b18); err != nil || st != 3 || len(ismg) != 16 {
|
||||
t.Fatalf("18B 布局解析: st=%d ismg=%dB err=%v", st, len(ismg), err)
|
||||
}
|
||||
// 2.0 无 Version 变体(4B status + 16B = 20B)
|
||||
b20 := append([]byte{0, 0, 0, 4}, bytes.Repeat([]byte{0x22}, 16)...)
|
||||
if st, ismg, err := ParseConnectResp(b20); err != nil || st != 4 || len(ismg) != 16 {
|
||||
t.Fatalf("20B 布局解析: st=%d ismg=%dB err=%v", st, len(ismg), err)
|
||||
}
|
||||
// 空包拒绝
|
||||
if _, _, err := ParseConnectResp(nil); err == nil {
|
||||
t.Fatal("空包应拒绝")
|
||||
}
|
||||
}
|
||||
|
||||
// TestConnectRespVersion30Layout Issue#3 加固:3.0 布局(1B Status)往返 +
|
||||
// ISMG 串按 1B status 计算(严格 3.0 客户端校验口径)。
|
||||
func TestConnectRespVersion30Layout(t *testing.T) {
|
||||
clientAuth := bytes.Repeat([]byte{0x33}, 16)
|
||||
r := &ConnectResp{Status: 0, Secret: "pw", AuthenticatorClient: clientAuth, ClientVersion: 0x30}
|
||||
body := r.Marshal()
|
||||
if len(body) != 18 {
|
||||
t.Fatalf("3.0 包体应 18B: %d", len(body))
|
||||
}
|
||||
st, ismg, err := ParseConnectResp(body)
|
||||
if err != nil || st != 0 || len(ismg) != 16 {
|
||||
t.Fatalf("解析: st=%d err=%v", st, err)
|
||||
}
|
||||
want := md5.Sum(append(append([]byte{0}, clientAuth...), []byte("pw")...))
|
||||
if !bytes.Equal(want[:], ismg) {
|
||||
t.Fatal("3.0 ISMG 串应按 1B status 计算")
|
||||
}
|
||||
}
|
||||
|
||||
// TestPacketReadWrite 包读写往返(WritePacket 自动补 TotalLength)。
|
||||
func TestPacketReadWrite(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
@@ -68,6 +68,13 @@ type ConnLimiter interface {
|
||||
ConnLimit(sourceAddr string) int
|
||||
}
|
||||
|
||||
// ISMGSecretSource 可选接口(Issue#3 加固):提供账号共享密钥——ConnectResp 的
|
||||
// AuthenticatorISMG=MD5(Status+AuthenticatorSource+shared_secret) 按规范掺入;
|
||||
// 不实现=空串(旧口径,严格校验 ISMG 的客户端会判失败)。
|
||||
type ISMGSecretSource interface {
|
||||
ISMGSecret(sourceAddr string) string
|
||||
}
|
||||
|
||||
// SubmitRateLimiter 可选接口(Day 62):账号级单链提交限速 条/s(≤0=不限)。
|
||||
type SubmitRateLimiter interface {
|
||||
SubmitRateLimit(sourceAddr string) int
|
||||
@@ -272,6 +279,9 @@ func (s *Server) handleConn(ctx context.Context, conn net.Conn) {
|
||||
ss := &session{conn: conn}
|
||||
defer s.dropConn(conn, ss)
|
||||
ip := remoteIP(conn)
|
||||
// Issue#3 联调补盲:TCP 到达即留痕(此前 Connect 成功零日志,客户「连没连上」不可追溯;
|
||||
// 配合 scripts/cmpp-capture.sh 抓包分析双通道定位)。
|
||||
logger.L().Info("cmpp_conn_accepted", zap.String("client_ip", ip))
|
||||
|
||||
// ---- Connect 握手 ----
|
||||
_ = conn.SetReadDeadline(time.Now().Add(s.cfg.LoginTimeout))
|
||||
@@ -284,6 +294,17 @@ func (s *Server) handleConn(ctx context.Context, conn net.Conn) {
|
||||
if perr == nil {
|
||||
status = s.h.Connect(sourceAddr, ts, authenticator, ip)
|
||||
}
|
||||
// Issue#3 加固:按客户端 Connect.Version 协商应答布局(≥0x30 回 3.0 的
|
||||
// 1B Status/18B;否则 2.0 的 4B Status/21B)——版本字节在包体 offset 22。
|
||||
ver := byte(0x20)
|
||||
if len(body) >= 23 && body[22] >= 0x30 {
|
||||
ver = body[22]
|
||||
}
|
||||
// Issue#3 加固:ISMG 鉴权串按规范掺 shared_secret(可选接口;不实现=空串)。
|
||||
smsSecret := ""
|
||||
if ss, ok := s.h.(ISMGSecretSource); ok {
|
||||
smsSecret = ss.ISMGSecret(sourceAddr)
|
||||
}
|
||||
// Day 62:鉴权通过后先占会话名额(账号级连接数上限,可选接口;持锁原子
|
||||
// 检查+登记防并发超卖),超限回保留码 0x8 后断链。
|
||||
if status == ConnectOK {
|
||||
@@ -297,7 +318,8 @@ func (s *Server) handleConn(ctx context.Context, conn net.Conn) {
|
||||
status = ConnectTooMany
|
||||
}
|
||||
}
|
||||
resp := &ConnectResp{Status: status, Secret: "", AuthenticatorClient: authenticator}
|
||||
resp := &ConnectResp{Status: status, Secret: smsSecret,
|
||||
AuthenticatorClient: authenticator, ClientVersion: ver}
|
||||
if werr := WritePacket(conn, &Header{CommandID: CmdConnectResp, SequenceID: h.SequenceID}, resp.Marshal()); werr != nil {
|
||||
return
|
||||
}
|
||||
@@ -308,6 +330,10 @@ func (s *Server) handleConn(ctx context.Context, conn net.Conn) {
|
||||
if rl, ok := s.h.(SubmitRateLimiter); ok {
|
||||
ss.rate.limit = rl.SubmitRateLimit(sourceAddr)
|
||||
}
|
||||
// Issue#3 联调补盲:Connect 成功留痕(账号/IP/客户端声明版本——与抓包时间线互证)。
|
||||
logger.L().Info("cmpp_conn_ok",
|
||||
zap.String("source_addr", sourceAddr), zap.String("client_ip", ip),
|
||||
zap.Uint8("ver", ver))
|
||||
|
||||
// ---- 会话循环 ----
|
||||
for {
|
||||
|
||||
@@ -5,6 +5,8 @@ package cmpp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -36,6 +38,9 @@ func (h *fakeHandler) Connect(sourceAddr string, ts uint32, authenticator []byte
|
||||
return ConnectOK
|
||||
}
|
||||
|
||||
// ISMGSecret Issue#3 加固:ConnectResp 鉴权串掺入 shared_secret(fake=密钥本身)。
|
||||
func (h *fakeHandler) ISMGSecret(sourceAddr string) string { return h.secret }
|
||||
|
||||
func (h *fakeHandler) Submit(sourceAddr, srcID string, dest []string,
|
||||
content string, udh *UDHInfo, registeredDelivery uint8, msgFmt uint8) (uint64, byte) {
|
||||
if h.rejectAll {
|
||||
@@ -113,6 +118,50 @@ func TestServer_ConnectOKAndSubmit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestServer_ConnectVersion30 Issue#3 加固:按客户端 Connect.Version 协商应答——
|
||||
// 0x30 回 3.0 布局(18B/1B Status/version 回显 0x30);0x20 回 2.0(21B/4B)。
|
||||
// 裸 TCP 第三方视角(自家 client 固定发 0x20 测不到该分支)。
|
||||
func TestServer_ConnectVersion30(t *testing.T) {
|
||||
h := &fakeHandler{secret: "abc123", submits: make(chan *submitRecord, 1)}
|
||||
srv := startTestServer(t, h)
|
||||
|
||||
send := func(ver byte) []byte {
|
||||
t.Helper()
|
||||
conn, err := net.DialTimeout("tcp", srv.Addr(), 2*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = conn.Close() }()
|
||||
_ = conn.SetDeadline(time.Now().Add(3 * time.Second))
|
||||
req := &Connect{SourceAddr: "user1", Secret: "abc123", Version: ver}
|
||||
if err := WritePacket(conn, &Header{CommandID: CmdConnect, SequenceID: 7},
|
||||
req.Marshal(authTimestamp(time.Now()))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, body, err := ReadPacket(conn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
b30 := send(0x30)
|
||||
if len(b30) != 18 {
|
||||
t.Fatalf("3.0 客户端应答应 18B(1B Status): %d", len(b30))
|
||||
}
|
||||
if b30[0] != 0 {
|
||||
t.Fatalf("3.0 Status(1B)=%d 期望 0", b30[0])
|
||||
}
|
||||
if b30[17] != 0x30 {
|
||||
t.Fatalf("3.0 应答回显 version=0x30, got 0x%02x", b30[17])
|
||||
}
|
||||
|
||||
b20 := send(0x20)
|
||||
if len(b20) != 21 || binary.BigEndian.Uint32(b20[0:4]) != 0 {
|
||||
t.Fatalf("2.0 应答应 21B/Status=0: len=%d", len(b20))
|
||||
}
|
||||
}
|
||||
|
||||
// TestServer_PushDeliver Day 61(P0.5):Connect 注册会话→PushDeliver 下发状态报告
|
||||
// →客户端 OnDeliver 收到(含 MsgID/Stat 口径)→服务端吸收 Deliver_Resp。
|
||||
func TestServer_PushDeliver(t *testing.T) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"go-sms/internal/service/openapi"
|
||||
"go-sms/internal/service/report"
|
||||
"go-sms/internal/service/send"
|
||||
"go-sms/internal/service/sysconfig"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -80,8 +81,19 @@ type Service struct {
|
||||
// 长短信片聚合器(批次 2278141 修复):入向 UDH 拼接多片按组聚合,
|
||||
// 到齐合并为一条逻辑 task;超时逐片退化直发。见 longsms.go。
|
||||
grouper *longSmsGrouper
|
||||
// sysCfg Issue#3 方案B:系统配置源(账号 ext_code 空时回退系统默认接入码
|
||||
// cmpp.default_ext_code);nil=无系统回退(行为不变,测试/降级场景)。
|
||||
sysCfg SystemConfigGetter
|
||||
}
|
||||
|
||||
// SystemConfigGetter 系统配置读取接口(由 sysconfig.Service 实现;解耦包依赖)。
|
||||
type SystemConfigGetter interface {
|
||||
Get(ctx context.Context, key string) string
|
||||
}
|
||||
|
||||
// SetSystemConfig 注入系统配置源(可选;gateway 装配调用,nil=无系统回退)。
|
||||
func (s *Service) SetSystemConfig(g SystemConfigGetter) { s.sysCfg = g }
|
||||
|
||||
// accountCacheEntry 账号缓存条目(u/cfg nil=查无,负缓存防穿透)。
|
||||
type accountCacheEntry struct {
|
||||
u, cfg any // *entity.AccountUser | *entity.AccountConfig | nil
|
||||
@@ -263,6 +275,17 @@ func (s *Service) Connect(sourceAddr string, ts uint32, authenticator []byte, cl
|
||||
// Submit 实现 cmpp.ServerHandler:账号/通道号前缀校验→SendMass 受理。
|
||||
// 长短信片(udh 非 nil 且单目的码)改走聚合器:按组拼接合并为一条逻辑
|
||||
// 短信单次受理(批次 2278141 修复,决策①A/②A/③——详见 longsms.go);其余
|
||||
// ISMGSecret 实现 cmpp.ISMGSecretSource:ConnectResp 鉴权串的 shared_secret
|
||||
// (账号 ApiSecret;查无账号=空串——该场景应答本就 status≠0,客户端按状态码判)。
|
||||
// 与 Connect 同走 loadAccountDB 直查(握手期非热路径,口径一致)。
|
||||
func (s *Service) ISMGSecret(sourceAddr string) string {
|
||||
_, cfg := s.loadAccountDB(context.Background(), sourceAddr)
|
||||
if cfg == nil {
|
||||
return ""
|
||||
}
|
||||
return cfg.ApiSecret
|
||||
}
|
||||
|
||||
// (普通提交/多目的码片)走原直发路径不变。
|
||||
func (s *Service) Submit(sourceAddr, srcID string, dest []string,
|
||||
content string, udh *cmpp.UDHInfo, registeredDelivery uint8, msgFmt uint8) (uint64, byte) {
|
||||
@@ -271,31 +294,47 @@ func (s *Service) Submit(sourceAddr, srcID string, dest []string,
|
||||
defer func() { submitStats.record(time.Since(t0)) }()
|
||||
ctx := context.Background()
|
||||
if udh != nil && udh.Total > 1 && len(dest) == 1 {
|
||||
cfg, result := s.precheck(ctx, sourceAddr, srcID)
|
||||
cfg, ext, result := s.precheck(ctx, sourceAddr, srcID)
|
||||
if cfg == nil {
|
||||
return 0, result
|
||||
}
|
||||
return s.grouper.submitFragment(s.api, cfg, sourceAddr, srcID,
|
||||
return s.grouper.submitFragment(s.api, cfg, ext, sourceAddr, srcID,
|
||||
dest[0], content, udh, msgFmt == cmpp.MsgFmtUCS2)
|
||||
}
|
||||
return s.submitDirect(ctx, sourceAddr, srcID, dest, content, msgFmt)
|
||||
}
|
||||
|
||||
// precheck 账号加载+通道号前缀校验(cfg=nil 时返回值为 CMPP 拒绝码)。
|
||||
// precheck 账号加载+通道号校验(cfg=nil 时返回值为 CMPP 拒绝码)。
|
||||
// 直发与长短信聚合共用(聚合组以首片账号快照为准)。
|
||||
func (s *Service) precheck(ctx context.Context, sourceAddr, srcID string) (*entity.AccountConfig, byte) {
|
||||
// Issue#3 方案B:返回生效校验前缀 ext——账号 ext_code 优先,空则回退系统默认
|
||||
// cmpp.default_ext_code(账号级定制>系统级统一;两层均空=不校验)。
|
||||
func (s *Service) precheck(ctx context.Context, sourceAddr, srcID string) (*entity.AccountConfig, string, byte) {
|
||||
_, cfg := s.loadAccount(ctx, sourceAddr)
|
||||
if cfg == nil {
|
||||
return nil, cmpp.SubmitRejected
|
||||
return nil, "", cmpp.SubmitRejected
|
||||
}
|
||||
// 通道号前缀:账号 ext_code 非空时 SrcID 必须以其为前缀(UT:0012 语义)。
|
||||
if cfg.ExtCode != "" && !strings.HasPrefix(srcID, cfg.ExtCode) {
|
||||
ext := s.effectiveExtCode(ctx, cfg)
|
||||
// 通道号前缀:ext 非空时 SrcID 必须以其为前缀(UT:0012 语义;系统默认同)。
|
||||
if ext != "" && !strings.HasPrefix(srcID, ext) {
|
||||
logger.L().Warn("cmpp_submit_src_prefix_mismatch",
|
||||
zap.String("source_addr", sourceAddr), zap.String("src_id", srcID),
|
||||
zap.String("ext_code", cfg.ExtCode))
|
||||
return nil, cmpp.SubmitBadCode
|
||||
zap.String("ext_code", ext),
|
||||
zap.Bool("from_system_default", cfg.ExtCode == ""))
|
||||
return nil, "", cmpp.SubmitBadCode
|
||||
}
|
||||
return cfg, cmpp.SubmitOK
|
||||
return cfg, ext, cmpp.SubmitOK
|
||||
}
|
||||
|
||||
// effectiveExtCode 生效校验前缀:账号 ext_code 优先;空则回退系统默认
|
||||
// (Issue#3 方案B;sysCfg 未注入/系统键未配置=空=不校验)。
|
||||
func (s *Service) effectiveExtCode(ctx context.Context, cfg *entity.AccountConfig) string {
|
||||
if cfg.ExtCode != "" {
|
||||
return cfg.ExtCode
|
||||
}
|
||||
if s.sysCfg != nil {
|
||||
return s.sysCfg.Get(ctx, sysconfig.KeyDefaultExtCode)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// submitDirect 普通提交(原 Submit 主体):P0-1(Day 63)快路径受理。
|
||||
@@ -303,7 +342,7 @@ func (s *Service) precheck(ctx context.Context, sourceAddr, srcID string) (*enti
|
||||
func (s *Service) submitDirect(ctx context.Context, sourceAddr, srcID string,
|
||||
dest []string, content string, msgFmt uint8) (uint64, byte) {
|
||||
tAcc := time.Now()
|
||||
cfg, result := s.precheck(ctx, sourceAddr, srcID)
|
||||
cfg, ext, result := s.precheck(ctx, sourceAddr, srcID)
|
||||
tAccCost := time.Since(tAcc)
|
||||
if cfg == nil {
|
||||
return 0, result
|
||||
@@ -316,7 +355,7 @@ func (s *Service) submitDirect(ctx context.Context, sourceAddr, srcID string,
|
||||
PhoneList: dest,
|
||||
Content: content,
|
||||
SignName: "", // CMPP 内容自带【签名】,与 Day41 验收二变口径一致
|
||||
ExtCode: strings.TrimPrefix(srcID, cfg.ExtCode),
|
||||
ExtCode: strings.TrimPrefix(srcID, ext),
|
||||
// Day 70:按 MsgFmt 分流计费口径(UCS2=8:每码元 2B;fee≡上游真实片数)。
|
||||
ContentEncoding: ucs2Encoding(msgFmt == cmpp.MsgFmtUCS2),
|
||||
}, remoteIPPlaceholder)
|
||||
@@ -356,7 +395,8 @@ func (s *Service) Bind(systemID, password, clientIP string) smpp.Status {
|
||||
return smpp.StatusOK
|
||||
}
|
||||
|
||||
// SubmitSM 实现 smpp.ServerHandler:源地址前缀校验→SendMass 受理。
|
||||
// SubmitSM 实现 smpp.ServerHandler:源地址校验(账号 ext_code 优先,空回退系统
|
||||
// 默认接入码——Issue#3 方案B,与 CMPP precheck 同口径)→SendMass 受理。
|
||||
func (s *Service) SubmitSM(systemID, srcAddr, destAddr, content string,
|
||||
registeredDelivery uint8) (string, smpp.Status) {
|
||||
ctx := context.Background()
|
||||
@@ -364,7 +404,8 @@ func (s *Service) SubmitSM(systemID, srcAddr, destAddr, content string,
|
||||
if cfg == nil {
|
||||
return "", smpp.StatusSysErr
|
||||
}
|
||||
if cfg.ExtCode != "" && !strings.HasPrefix(srcAddr, cfg.ExtCode) {
|
||||
ext := s.effectiveExtCode(ctx, cfg)
|
||||
if ext != "" && !strings.HasPrefix(srcAddr, ext) {
|
||||
return "", smpp.StatusSysErr
|
||||
}
|
||||
resp := s.api.SendMass(ctx, &openapi.AuthContext{
|
||||
@@ -373,7 +414,7 @@ func (s *Service) SubmitSM(systemID, srcAddr, destAddr, content string,
|
||||
}, &openapi.MassReq{
|
||||
PhoneList: []string{destAddr},
|
||||
Content: content,
|
||||
ExtCode: strings.TrimPrefix(srcAddr, cfg.ExtCode),
|
||||
ExtCode: strings.TrimPrefix(srcAddr, ext),
|
||||
}, remoteIPPlaceholder)
|
||||
if resp.Code != openapi.CodeOK {
|
||||
return "", smpp.StatusSysErr
|
||||
|
||||
@@ -90,14 +90,16 @@ func longSmsKey(accountID int64, srcID, mobile string, ref uint8) string {
|
||||
}
|
||||
|
||||
// submitFragment 片提交:入组缓存(未齐回组ID 不发)/到齐合并单次受理。
|
||||
// precheck(账号+通道号前缀)已由调用方 Submit 完成,cfg 为验过快照。
|
||||
// precheck(账号+通道号校验)已由调用方 Submit 完成,cfg 为验过快照;
|
||||
// ext=生效校验前缀(账号 ext_code 或系统默认,Issue#3 方案B)——扩展码
|
||||
// 剥离口径与直发一致(TrimPrefix(srcID, ext))。
|
||||
func (g *longSmsGrouper) submitFragment(api longSmsAPI, cfg *entity.AccountConfig,
|
||||
sourceAddr, srcID, mobile, content string, udh *cmpp.UDHInfo, ucs2 bool) (uint64, byte) {
|
||||
ext, sourceAddr, srcID, mobile, content string, udh *cmpp.UDHInfo, ucs2 bool) (uint64, byte) {
|
||||
auth := &openapi.AuthContext{
|
||||
AccountID: cfg.AccountID, Username: sourceAddr, Config: cfg,
|
||||
Source: send.TaskSourceCMPP, // Day 60:受理来源打标(CMPP 接入)
|
||||
}
|
||||
ext := strings.TrimPrefix(srcID, cfg.ExtCode)
|
||||
extCode := strings.TrimPrefix(srcID, ext)
|
||||
key := longSmsKey(cfg.AccountID, srcID, mobile, udh.Ref)
|
||||
|
||||
isNew := false
|
||||
@@ -112,7 +114,7 @@ func (g *longSmsGrouper) submitFragment(api longSmsAPI, cfg *entity.AccountConfi
|
||||
zap.String("source_addr", sourceAddr), zap.String("mobile", mobile),
|
||||
zap.Uint8("ref", udh.Ref), zap.Uint8("group_total", grp.total),
|
||||
zap.Uint8("frag_total", udh.Total))
|
||||
return directSubmit(api, auth, mobile, ext, content, ucs2)
|
||||
return directSubmit(api, auth, mobile, extCode, content, ucs2)
|
||||
}
|
||||
if !ok {
|
||||
if len(g.groups) >= g.maxGroup {
|
||||
@@ -127,7 +129,7 @@ func (g *longSmsGrouper) submitFragment(api longSmsAPI, cfg *entity.AccountConfi
|
||||
}
|
||||
grp = &pendingLong{
|
||||
groupID: uint64(api.NextMsgID()),
|
||||
auth: auth, srcID: srcID, mobile: mobile, extCode: ext,
|
||||
auth: auth, srcID: srcID, mobile: mobile, extCode: extCode,
|
||||
total: udh.Total, ref: udh.Ref, ucs2: ucs2, frags: make(map[uint8]string),
|
||||
}
|
||||
g.groups[key] = grp
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// sysconfig_fallback_test.go Issue#3 方案B:SrcID 校验两级回退链——
|
||||
// 账号 ext_code 优先 > 系统默认 cmpp.default_ext_code > 均空放行。
|
||||
package access
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go-sms/internal/model/entity"
|
||||
"go-sms/internal/protocol/cmpp"
|
||||
)
|
||||
|
||||
// sysCfgStub 固定值系统配置桩。
|
||||
type sysCfgStub struct{ v string }
|
||||
|
||||
func (s sysCfgStub) Get(_ context.Context, _ string) string { return s.v }
|
||||
|
||||
// TestSubmit_SystemDefaultFallback 账号 ext_code 空 → 回退系统默认:
|
||||
// 匹配系统前缀受理、不匹配回 9、命中日志可辨识。
|
||||
func TestSubmit_SystemDefaultFallback(t *testing.T) {
|
||||
db := newAccessDB(t)
|
||||
u := entity.AccountUser{Username: "noext_user", Status: 1, Balance: 10000}
|
||||
if err := db.Create(&u).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := entity.AccountConfig{AccountID: u.ID, Business: "sms",
|
||||
ApiSecret: "shared-secret-32hex", AuditMode: 0} // ExtCode 留空
|
||||
if err := db.Create(&cfg).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, _ := newSvc(t, db)
|
||||
s.SetSystemConfig(sysCfgStub{v: "SYS:1069"})
|
||||
|
||||
// 系统前缀+扩展 → 过(方案C 动态扩展同口径)。
|
||||
if _, result := s.Submit("noext_user", "SYS:1069001",
|
||||
[]string{"13800138000"}, "【签名】你好", nil, 1, cmpp.MsgFmtGBK); result != cmpp.SubmitOK {
|
||||
t.Fatalf("系统默认前缀应放行: result=%d", result)
|
||||
}
|
||||
// 不匹配系统前缀 → 9。
|
||||
if _, result := s.Submit("noext_user", "XX:9999",
|
||||
[]string{"13800138000"}, "【签名】你好", nil, 1, cmpp.MsgFmtGBK); result != cmpp.SubmitBadCode {
|
||||
t.Fatalf("不匹配系统默认应拒: result=%d", result)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSubmit_AccountExtTakesPriority 账号 ext_code 非空时账号优先——系统默认
|
||||
// 不参与(系统前缀的 SrcID 也拒,证明两级不叠加)。
|
||||
func TestSubmit_AccountExtTakesPriority(t *testing.T) {
|
||||
db := newAccessDB(t)
|
||||
seedAccount(t, db) // ExtCode=UT:0012
|
||||
s, _ := newSvc(t, db)
|
||||
s.SetSystemConfig(sysCfgStub{v: "SYS:1069"})
|
||||
|
||||
if _, result := s.Submit("cmpp_user", "SYS:1069001",
|
||||
[]string{"13800138000"}, "【签名】你好", nil, 1, cmpp.MsgFmtGBK); result != cmpp.SubmitBadCode {
|
||||
t.Fatalf("账号 ext 优先:系统前缀应拒(不叠加放行), result=%d", result)
|
||||
}
|
||||
if _, result := s.Submit("cmpp_user", "UT:001299",
|
||||
[]string{"13800138000"}, "【签名】你好", nil, 1, cmpp.MsgFmtGBK); result != cmpp.SubmitOK {
|
||||
t.Fatalf("账号前缀应放行: result=%d", result)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSubmit_NoSysCfgNoExt 双空放行(getter 未注入/ext 空/系统键空=回归原行为)。
|
||||
func TestSubmit_NoSysCfgNoExt(t *testing.T) {
|
||||
db := newAccessDB(t)
|
||||
u := entity.AccountUser{Username: "noext_user", Status: 1, Balance: 10000}
|
||||
if err := db.Create(&u).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := entity.AccountConfig{AccountID: u.ID, Business: "sms",
|
||||
ApiSecret: "shared-secret-32hex", AuditMode: 0}
|
||||
if err := db.Create(&cfg).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, _ := newSvc(t, db) // 未注入 sysCfg
|
||||
if _, result := s.Submit("noext_user", "ANY:THING",
|
||||
[]string{"13800138000"}, "【签名】你好", nil, 1, cmpp.MsgFmtGBK); result != cmpp.SubmitOK {
|
||||
t.Fatalf("双空应放行(原行为): result=%d", result)
|
||||
}
|
||||
// 注入但系统键空值=同语义。
|
||||
s.SetSystemConfig(sysCfgStub{v: ""})
|
||||
if _, result := s.Submit("noext_user", "ANY:THING",
|
||||
[]string{"13800138000"}, "【签名】你好", nil, 1, cmpp.MsgFmtGBK); result != cmpp.SubmitOK {
|
||||
t.Fatalf("系统键空应放行: result=%d", result)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// Package sysconfig 系统参数配置域(Issue#3 方案B):system_config KV 表统一
|
||||
// 读(Get 带 TTL 缓存)/写(Set UPSERT+缓存即刻失效)/列(List)。
|
||||
// 消费方:access(系统默认接入码回退,见 KeyDefaultExtCode)、uplink 拉黑词表
|
||||
// (uplink.blacklist.keywords,该域自刷新不走本缓存,页面改后 60s 生效)。
|
||||
package sysconfig
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go-sms/internal/model/entity"
|
||||
"go-sms/internal/pkg/errors"
|
||||
"go-sms/internal/pkg/logger"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// KeyDefaultExtCode 系统默认接入码前缀(账号 ext_code 为空时回退;Issue#3 方案B:
|
||||
// 账号级优先、系统级兜底——新账号开箱即有码校验,无需逐账号配置)。
|
||||
const KeyDefaultExtCode = "cmpp.default_ext_code"
|
||||
|
||||
const defaultTTL = 30 * time.Second
|
||||
|
||||
type cacheEntry struct {
|
||||
value string
|
||||
expireAt time.Time
|
||||
}
|
||||
|
||||
// Service 系统配置服务。
|
||||
type Service struct {
|
||||
db *gorm.DB
|
||||
ttl time.Duration
|
||||
|
||||
mu sync.RWMutex
|
||||
cache map[string]cacheEntry
|
||||
}
|
||||
|
||||
// New 构造(ttl≤0=30s,与 access 账号缓存同量级;Set 主动失效兜底即刻生效)。
|
||||
func New(db *gorm.DB, ttl time.Duration) *Service {
|
||||
if ttl <= 0 {
|
||||
ttl = defaultTTL
|
||||
}
|
||||
return &Service{db: db, ttl: ttl, cache: map[string]cacheEntry{}}
|
||||
}
|
||||
|
||||
// Get 读配置(未配置/缺行=空串;DB 错误降级空串记日志且不缓存——校验语义=不拦,
|
||||
// 与账号级 ext_code 缺省放行口径一致)。
|
||||
func (s *Service) Get(ctx context.Context, key string) string {
|
||||
now := time.Now()
|
||||
s.mu.RLock()
|
||||
e, ok := s.cache[key]
|
||||
s.mu.RUnlock()
|
||||
if ok && now.Before(e.expireAt) {
|
||||
return e.value
|
||||
}
|
||||
var row entity.SystemConfig
|
||||
err := s.db.WithContext(ctx).Where("cfg_key = ?", key).First(&row).Error
|
||||
value := ""
|
||||
if err == nil {
|
||||
value = row.CfgValue
|
||||
} else if err != gorm.ErrRecordNotFound {
|
||||
logger.L().Warn("sysconfig_get_failed", zap.String("key", key), zap.Error(err))
|
||||
return ""
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.cache[key] = cacheEntry{value: value, expireAt: now.Add(s.ttl)}
|
||||
s.mu.Unlock()
|
||||
return value
|
||||
}
|
||||
|
||||
// List 全量(cfg_key 升序;管理页数据源)。
|
||||
func (s *Service) List(ctx context.Context) ([]entity.SystemConfig, error) {
|
||||
var rows []entity.SystemConfig
|
||||
err := s.db.WithContext(ctx).Order("cfg_key").Find(&rows).Error
|
||||
return rows, err
|
||||
}
|
||||
|
||||
// Set UPSERT(uk cfg_key 冲突→更新值/备注/操作人/时间)并即刻失效该键缓存
|
||||
// (改完即生效——区别于账号 ext_code 的 30s accCache 窗口,管理页操作即时可验)。
|
||||
func (s *Service) Set(ctx context.Context, key, value, remark, updatedBy string) (*entity.SystemConfig, error) {
|
||||
key = strings.TrimSpace(key)
|
||||
if key == "" || len(key) > 64 {
|
||||
return nil, errors.InvalidParam.WithMsg("cfg_key 须 1~64 字符")
|
||||
}
|
||||
if len(value) > 1024 {
|
||||
return nil, errors.InvalidParam.WithMsg("cfg_value 超 1024 字符")
|
||||
}
|
||||
if len(remark) > 255 {
|
||||
return nil, errors.InvalidParam.WithMsg("remark 超 255 字符")
|
||||
}
|
||||
row := &entity.SystemConfig{CfgKey: key, CfgValue: value, Remark: remark, UpdatedBy: updatedBy}
|
||||
if err := s.db.WithContext(ctx).Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "cfg_key"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"cfg_value", "remark", "updated_by", "updated_at"}),
|
||||
}).Create(row).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.mu.Lock()
|
||||
delete(s.cache, key)
|
||||
s.mu.Unlock()
|
||||
return row, nil
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// service_test.go Issue#3 方案B:system_config 读写/缓存失效/UPSERT/校验。
|
||||
package sysconfig
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-sms/internal/model/entity"
|
||||
)
|
||||
|
||||
func newDB(t *testing.T) *gorm.DB {
|
||||
t.Helper()
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Migrator().CreateTable(&entity.SystemConfig{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
// TestGet_MissingKeyIsEmpty 缺行=空串(=不校验语义),不报错。
|
||||
func TestGet_MissingKeyIsEmpty(t *testing.T) {
|
||||
s := New(newDB(t), 0)
|
||||
if v := s.Get(context.Background(), "no.such.key"); v != "" {
|
||||
t.Fatalf("缺行应空串, got %q", v)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetUpsertAndCacheInvalidation Set 后 Get 立即读到新值(写即刻失效缓存,
|
||||
// 不吃 30s TTL 窗口);同 key 二次 Set=更新不报错。
|
||||
func TestSetUpsertAndCacheInvalidation(t *testing.T) {
|
||||
db := newDB(t)
|
||||
s := New(db, time.Minute) // 长 TTL:若失效逻辑缺失本测试必红
|
||||
ctx := context.Background()
|
||||
if _, err := s.Set(ctx, KeyDefaultExtCode, "10690", "系统默认接入码", "admin"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v := s.Get(ctx, KeyDefaultExtCode); v != "10690" {
|
||||
t.Fatalf("Get=%q", v)
|
||||
}
|
||||
// 覆盖更新(UPSERT):缓存里已有旧值,Set 后必须立即新值。
|
||||
if _, err := s.Set(ctx, KeyDefaultExtCode, "1069033", "改", "admin2"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v := s.Get(ctx, KeyDefaultExtCode); v != "1069033" {
|
||||
t.Fatalf("Set 后缓存未失效: %q", v)
|
||||
}
|
||||
var rows []entity.SystemConfig
|
||||
if err := db.Find(&rows).Error; err != nil || len(rows) != 1 {
|
||||
t.Fatalf("UPSERT 应单行: rows=%d err=%v", len(rows), err)
|
||||
}
|
||||
if rows[0].UpdatedBy != "admin2" {
|
||||
t.Fatalf("updated_by 应更新: %q", rows[0].UpdatedBy)
|
||||
}
|
||||
}
|
||||
|
||||
// TestListOrdered 全量 cfg_key 升序。
|
||||
func TestListOrdered(t *testing.T) {
|
||||
s := New(newDB(t), 0)
|
||||
ctx := context.Background()
|
||||
for _, k := range []string{"b.key", "a.key"} {
|
||||
if _, err := s.Set(ctx, k, "v", "", "op"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
rows, err := s.List(ctx)
|
||||
if err != nil || len(rows) != 2 {
|
||||
t.Fatalf("rows=%d err=%v", len(rows), err)
|
||||
}
|
||||
if rows[0].CfgKey != "a.key" {
|
||||
t.Fatalf("应 cfg_key 升序: %s", rows[0].CfgKey)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetValidation 键空/超长、值超长拒绝。
|
||||
func TestSetValidation(t *testing.T) {
|
||||
s := New(newDB(t), 0)
|
||||
ctx := context.Background()
|
||||
if _, err := s.Set(ctx, " ", "v", "", "op"); err == nil {
|
||||
t.Fatal("空键应拒绝")
|
||||
}
|
||||
if _, err := s.Set(ctx, strings.Repeat("k", 65), "v", "", "op"); err == nil {
|
||||
t.Fatal("超长键应拒绝")
|
||||
}
|
||||
if _, err := s.Set(ctx, "k", strings.Repeat("v", 1025), "", "op"); err == nil {
|
||||
t.Fatal("超长值应拒绝")
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,80 @@
|
||||
# 当前工作上下文(最近更新:2026-11-16 下午)
|
||||
# 当前工作上下文(最近更新:2026-11-17 B2 收官,新会话从 B3 开工)
|
||||
|
||||
## 当前状态快照(2026-11-16,**S4 泳道收官,一期 18/27 计划日**)
|
||||
## 🔧 Issue#6 附加轮·下拉菜单视觉契约修复 F1~F4 已闭环(2026-11-17,3 commits 6e6f5caf/bfdaf901/1ecd5fd9+Gitea#6 评论 201)
|
||||
|
||||
- **F1 根因(P3 遗留漏网)**:ep-theme 漏 html.dark 双写→EP 官方 dark/css-vars 以特异性 0,1,1 覆盖 :root 颜色族→暗色下 EP 组件回退原生 #141414 与 slate token 割裂;修复=双写+--el-select-* 9 变量族;**惠及旧 web/ 全站 EP 组件暗色**。教训:DOM 断言必须含 EP 组件 computed 层。
|
||||
- **F2 契约桥**:选项 padding 10/16/选中=primary-soft 底+primary-600 字/hover 中性/弹层圆角 4→12/dropdown-item flex-start。
|
||||
- **F3 ScSelect 统一封装**(`web/src/components/ScSelect.vue`):options 数组模式 auto>5 自动 filterable(sub2api searchable=auto 同源);downlink 来源(4 项)/状态(6 项)正反示范;新代码下拉一律用它。
|
||||
- **F4 门禁资产**:`web/scripts/verify-select-contract.mjs`(npm run verify:select;双主题 10 项 10/10)+sc-select.spec 4 用例;vitest 186 全绿。
|
||||
- 注:此轮改动落在旧 web/(用户排查诉求针对现网观感);web-next 侧由并行 B 线推进,B1/B2 已收官。
|
||||
|
||||
## ✅ Issue#5 压测复盘已交付(2026-11-17 晚;报告 `docs/acceptance/issue5-bench-report.md` + 工单 #5 Markdown 回帖)
|
||||
|
||||
- **结论**:100 万条目标达成(下发成功 ≈112.7 万/累计提交 ≈213.8 万);计费三平分毫不差(充值 10.0001 亿−预扣 2,183,182+退款 999,741=余额 998,826,559);受理峰 287.9 QPS slow=0/lag 峰 476/零慢查询零重启。
|
||||
- **三场**:白日场 vcmppgw 7.7 万@200/s(已清理)/夜间长短信 5.1 万任务×3 片/主战场 23:00~01:52 提交 199.9 万(50% 签名拦截 ISC:004 即时退款)。
|
||||
- **挂账移交(下轮压测前清偿)**:①R1 余额对账差额 P0 ×33 次(典型 ±120~791,自愈无资损)根修预扣-落账时序;②deliver_fail 2,652 条去向复核;③长短信挂起 1,326 条 **11-19 reaper 到期核验**;④channel host 不热切换(改 host 须断连,runbook);⑤压测脚本签名对齐+客户端 CSV 强制留档;⑥正式场=11-18 整改→11-19 阶梯 200/500/1000 TPS,出账四件套入 SOP。
|
||||
- **证据**:logs/bench-*.csv+log / vcmppgw*.log / 1m-watch.log(2,719 样本)/ capture pcap / DB 只读对账(billing_consume_log/account_balance_log/send_block_log/channel_log)。
|
||||
|
||||
## ⭐ Issue#6 · B 方案执行中:B2 三契约页已收官,下一步 B3 33 视图分批实装
|
||||
|
||||
- **B2 已交付(commit 见 git log)**:三契约页 1:1 逐行直抄 v3-2-tailwind.html——#p-dash 运营总览(895-1005:横幅+stat 6+4+chart.js 趋势+donut+监控表+系统健康+动态+快捷+快照)/#p-acct 帐号管理(1006-1034:单卡一体筛选+8 列表+分页)/#p-chan 通道编辑(1035-1059:双卡表单+switch+操作条);全部真实数据,缺数据项显式 —。
|
||||
- **B2 连带根修**:①stats_handler.go 两处 `AS key` 撞 MySQL 8.0 保留字 → /stats/biz 500(P2 遗留 bug,反引号转义已修,单测绿);②网关旧二进制已重建重启(bin/gateway 现含 P2 三端点)。
|
||||
- **B2 验收**:vue-tsc 0/build ✓(dash chunk gzip 65KB)/冒烟 12/12/stat-card computed style 与 17890 双会话对拍一致(radius16/pad20/flex/gap16)。截图:/tmp/b2-dash|acct|chan|contract-dash.png。
|
||||
|
||||
## ✅ B3 首批·Select 自绘下拉组件已落地(2026-11-17 晚,用户拍板逐页指令制;commit 见 git log B3 Select 条)
|
||||
|
||||
- `web-next/src/components/common/Select.vue`(sub2api 契约直译):Teleport+首项搜索+auto>5+键盘+clearable+r12·10-16+选中底色式+dark 全跟随;适配留痕=去 i18n/Icon 内联/裁 creatable+remote/clear 回空串;selectedLabel 空值恒显 placeholder。
|
||||
- 3 页 7 处原生 select 已替换(账号/通道/下行明细);**此后新页下拉一律复用它**。
|
||||
- 验收 13 断言全 PASS(auto 正反例/键盘搜索/teal 选中底/dark slate-800);截图 /tmp/b3-*.png。
|
||||
- **交付节奏(用户拍板):剩余 ~28 页逐页指令制——用户点名一页,实装+四关验收(vue-tsc/build/Chrome 冒烟/commit)+用户 5174 复核,再下一页**。范式族:审核中心/记录中心/统计结算=表格族;开户/充值=表单族;账号详情=详情族。
|
||||
|
||||
## B3 任务清单(新会话直接执行)
|
||||
|
||||
1. 33 视图分批实装(占位 ComingSoon 逐个替换;routes.ts component 已就位待换):范式族=表格页(ProTable 语义+契约表格 class)/表单页(契约 chan 范式)/详情页;**每页 defineOptions({name:路由名})**。
|
||||
2. 范式族映射:审核中心/记录中心/统计结算=表格族;开户/充值=表单族;账号详情=详情族。
|
||||
3. 每批完成后冒烟+commit;B4 收口(切部署/旧 web 归档/verify 重建/统一验收单/CHANGELOG/Gitea#6)。
|
||||
4. **视觉规范(2026-11-17 用户拍板,覆盖契约蓝本)**:菜单内容页**不加 `h2.page-title`**——顶栏 AppHeader 的 h1#pageTitle 已显示 route.meta.title,内容页再放 h2 属重复;内容页 page-header 只留 page-description 副标题+右侧动作按钮。已交付 5 页(DashboardView/AccountList/ChannelEdit/ChannelList/DownlinkDetailView)已删,后续每批交付断言 views/ 无 page-title。
|
||||
|
||||
## B 方案决议留痕(2026-11-17 拍板)
|
||||
|
||||
- **决议(用户原话)**:执行 B 方案;**必须不要有旧前端的影子**;**新增前端工程目录**;A 方案(EP 换肤模拟)彻底废弃。
|
||||
- **开发蓝本(用户重申)**:**v3-2-tailwind.html 按这个来开发前端**——文件里有什么,页面就做成什么样,不自由发挥;class 串 1:1 直抄。
|
||||
- **根因留痕(P3 被否决)**:① 契约 v3-2-tailwind.html 内含 3 页蓝本,P1 只认知 Dashboard 页;② sub2api 无 EP,EP 模拟转译损耗结构性不可救。P3 六 commits 留档不回滚。
|
||||
- **零影子复用边界**:✅ 仅复制纯逻辑层;❌ 零复用:样式/视图/组件/EP。
|
||||
|
||||
## 环境要点(B3 沿用)
|
||||
|
||||
- web-next dev:`cd web-next && npx vite --host 0.0.0.0 --port 5174 --strictPort`(nohup);依赖已装齐;:5173 旧 web 并行不动。
|
||||
- 网关 :8080 已重建(含 P2 三端点);/stats/biz 保留字 bug 已修;**后端改动仅 stats_handler.go 一处**。
|
||||
- chrome 铁律:channel:'chrome'+独立 launch+单 page;**同 browser 二次跨域导航会 ERR_ABORTED(CPU 缺陷),对拍用双会话**(/tmp/duel-style.mjs 模式);playwright 用 web/node_modules。
|
||||
- 冒烟账号 s2demo/S2demo@2026;dev 库:账号 3+/通道 1(Hw测试专用)/近 7 日 206 万条。
|
||||
- 坑留痕(B2 实录):①editor 大文件必须分段 insert,数好 template/script 闭合(根 div 缺闭合=plugin-vue 报 missing end tag,vue-tsc 不查模板结构);②MySQL 8.0 `key` 是保留字,SQL 别名必须反引号;③网关二进制日期要核对(bin/gateway 可能落后 main);④curl 循环带 TOKEN 必须同一命令字符串(多条命令=独立 shell 变量丢);⑤17890 契约预览 python http.server 对 HEAD/快速二连可能 abort。
|
||||
- **Gitea API 已通**(账号 Tory):token 存 `/tmp/gitea_token`;写评论=POST /api/v1/repos/Tory/go-sms-V2/issues/{n}/comments。
|
||||
|
||||
|
||||
|
||||
|
||||
## P3 留痕(已被 B 方案取代,commits 不回滚)
|
||||
|
||||
- **P2 后端 3 端点已入库**(/ops/system/overview + /stats/biz + /stats/realtime,openapi 1.5.0);**人工验收挂起**,与 B2/B3 合并统一验收单(验收标准已定稿待执行:重启网关+admin JWT+逐端点断言)。
|
||||
- **P3 壳层= sub2api 契约落地于旧 EP 工程**(用户验收否决,详见顶部根因):C1 tokens(teal 16 阶+slate/gray+旧名兼容)/C2 shell(侧栏 256/折叠 72/顶栏 64 glass)/C3 MainLayout 重排+TagsBar/C4 ep-theme/C5 旧值清零;verify-layout 31/31+verify-p3-contract.mjs 30/30+vitest 182 全绿——**机器断言全绿仍被否,教训:断言范围≠用户感知范围,功能页范式没进断言集**。
|
||||
- **坑留痕(通用)**:①Vue template 整段替换防 dropdown 内层 </template> 截断;②契约断言脚本须归一起始主题;③#020617 hex→dec=rgb(2,6,23);④契约类 HTML 文档必须**全文件通读**(3 页蓝本漏读 2 页=本次翻车主因)。
|
||||
- 挂账(随 B4 清偿):channel flaky 测试/access 域 6 lint unused/工作区遗留 8 文件(先前会话半成品,未提交未回滚)。
|
||||
|
||||
## Issue#6 前端重构 · 视觉契约已锁定(2026-11-17,P1 收官)
|
||||
|
||||
- **契约 = `docs/design/issue6/v3-2-tailwind.html`(v3.2.1,Chrome 机器验收 23/23)**:sub2api(Wei-Shaw/sub2api,LGPL,仅取样式+内部不分发=无义务)源码级 1:1——CSS 775 行 sed 直拼(非手抄)+组件 class 串直抄(AppSidebar/AppHeader/QuickActions)+tailwind.config 直抄;**主色=sub2api 官方 teal 全阶(primary-500 #14b8a6),用户拍板替代 Issue#6 原「emerald 生命绿」口径**;Tailwind 本地运行时 docs/design/issue6/tailwind.js(451KB,无外网依赖)仅用于预览,不进工程。
|
||||
- **契约文档**:`alignment-report.md`(渲染取证基线→源码规格表→契约锁定→豁免清单全程留痕);`baseline-ins2ai.json`;预览服务 `http://192.168.5.18:17890/`(python http.server,docs/design/issue6;注意本机内网 IP=192.168.5.18,5.27 是 Gitea 机)。ins2ai(token.unimsc.com)=sub2api 部署实例,Chrome 登录调研账号 info@inscom.ltd(密码在用户处)。
|
||||
- **迭代过程存档**(全部留档 docs/design/issue6/):demo-c-aurora 原风格→v1 三案换色(用户否决「换汤不换药」)→v2 推倒范式×3(否决「太失望」,根因=完成度低+方向应回归现代 SaaS)→v3 现代 SaaS+侧栏+缓存Tab(用户要求保留)→v3.1.x 渲染取证对齐(多轮肉眼纠偏:字体/间距/灰阶/icon 20/logo 36/品牌18/折叠72/分组14)→**v3.2 Tailwind 零转译(根治转译损耗)+v3.1.3 数据模块合并=v3.2.1 锁定**。
|
||||
- **统一范围(P3)**:视觉层全面换契约——tokens.scss(teal16阶+slate暗色系+源码间距/圆角/shadow 规格)/shell.scss(侧栏256折叠72+glass顶栏64+TagsBar+page-head)/ep-theme.scss 重映射/MainLayout 重排/全站松密度;**不变**:EP 组件库(用户裁决)/路由与 RBAC/功能行为(TagsBar keep-alive、版本红点等 Issue#2/#4 资产)。
|
||||
- **P2~P5**:P2 后端 3 端点(`/ops/system/overview` `/stats/biz` `/stats/realtime`,通道实时复用现成 `/channels/monitor/ws`)→P3 壳层→P4 Dashboard 13 模块组件化(Hero/KPI6+4/双系列图/donut/通道实时/系统健康/动态流/快捷/快照)→P5 七件套门禁(verify-layout 断言全部重写)。
|
||||
|
||||
## 当前状态快照(2026-11-16,**Issue#3 三连修复+方案B 系统配置落地,S4 泳道收官,一期 18/27 计划日**)
|
||||
|
||||
- **Issue#4 版本号+发布日志已交付(2026-11-16 晚六)**:①侧栏底脚(折叠按钮旁)版本 chip `v1.5.0`,未读红点 CSS 脉冲闪烁(localStorage `gosms_seen_ver`≠APP_VERSION;首访=亮;点击/进发布日志页 markSeen 即灭;发新版全员再亮);②系统管理二级菜单「发布日志」/system/release(**全角色**,同 faq 口径用户拍板),时间线卡片渲染 Markdown。**单一事实源=web/src/data/releases.ts**(APP_VERSION=首条;package.json 1.5.0 同步,releases.spec 断言防漂移);渲染器 utils/markdown.ts **零新依赖**(先全量 HTML 转义+仅 http(s) 链接,v-html 零注入)。门禁:eslint0/vue-tsc0/**vitest 179**(+14)/build/verify-layout **31/31**(+8)/Chrome 走查 4 步+样式级复核(折叠态曾溢出 foot 55px>47px,修=去 v 短版本 1.5+10px+红点 badge 绝对定位)。**发版 SOP=releases.ts 头部插一条+package.json 同步**;红点=本地未读语义(换浏览器重提示,无服务端同步);移动端 ≤900 版本号随 sidebar-foot 既有约定隐藏。验收单 issue4-release-notes.md;Gitea #4 完成评论待用户(token)。
|
||||
- **Issue#3 联调闭环(2026-11-16 晚五)🎉**:客户 192.168.5.210 登录成功(cmpp_conn_ok+抓包双证,-1 终结);首报「提交报错:0」=余额不足(MsgID=0+Result=10,充值 10000 恢复);重提 3 条全链打通(任务 status=2/明细 DELIVRD/计费正常)——**Issue#3 三问题(CMPP -1/充值无响应/SrcID 核验)全部闭环**。挂账:①抓包分析器混合流重组错位(D30/P2);②联调余额 10000 条在 s2demo;③上游 5.16:7890=旧平台网关与公网 121.46.230.53 同源(客户历史地址疑指此,已不影响联调)。
|
||||
|
||||
- **Issue#3 三连修复(2026-11-16 晚)**:①CMPP 连接报 -1 根因=`ConnectResp` 误按 **3.0 的 1B Status** 编码(标准 2.0 客户端按 4B 大端解析恒非 0)→ 修复=Marshal 4B(21B 包体)+AuthenticatorISMG 4B 参与 MD5+`ParseConnectResp` 自适应双布局(≥20B/2.0,17~19B/3.0);标准 2.0 探针真机实证 18B/垃圾值→21B/Status=0,**教训:2.0 与 3.0 在 CONNECT_RESP.Status/SUBMIT_RESP.Result 上互为镜像(2.0=4B/1B),自家 client+server 同源对称自测掩盖协议错位——同 Day39 坑**;②充值无响应=前端发 `{count}` 后端要 `{amount}`+submit 无 catch 静默吞错 → API/mock/组件三处修复;③SrcID 核验**用户裁定方案 C(前缀+动态扩展,行业惯例)**——s2demo 已配 ext_code=10690331(通道码即前缀),客户 SrcID 须以 10690331 开头+可追加扩展(≤21 位);真机四场景实证(纯码→10 过/码+扩展→10 过/不匹配→9/空→9);**运营口径:ext_code 变更后 30s 缓存生效(Day63 accCache)**。顺手修 TestClient_LoginOK 时序竞争(轮询吸收);门禁 -race 41 包/vitest 165/build 全绿;gateway 已串行部署(md5 比对 ✓)。
|
||||
- **仓库**:main 已推 Gitea;每日 bundle+push 双轨。
|
||||
- **一期进度**:S0✅ S1✅ S2✅ / S3 ✅(11-15 凌晨)/ **S4 ✅ 收官(11-16,三项验收全过:死信可查/拒收即拉黑/冷查 16ms<1s)**——D1/D2=C1 回调推送引擎+ C2 上行自动拉黑(真机六步实证,验收单 s4-d1d2-callback.md);D3=明细按天 RANGE(id) 分区热 5 天(迁移 v22,9 分区)+CH 冷热归档 job(count 校验零丢失方向)+/record/history 冷查(settle-check 热窗感知 DetailPartial 两方基线;真机 5 连坑全修存档,验收单 s4-d3-partition-archive.md)。
|
||||
- **下一步=S5 基线与灰度(8 日,一期最后泳道)**:kind 安装+deploy/k8s manifests apply(NodePort 30081)→ 24h 稳定性复核(S4 动了大表结构,S5 压测前重跑一轮而非沿用 11-14 旧判)→ 压测基线 200QPS×30min(SSD 下重标 workers:4/55/s 等 HDD 数字)→ 消费参数重标定 → 灰度接管现网流量。**出口四项**:七件套全绿/P0+P1+结算覆盖矩阵全勾/SSD 基线报告入档/v2 承载 ≥1 周零 P0 事故+POC 转冷备。
|
||||
|
||||
@@ -22,6 +22,15 @@
|
||||
| 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) |
|
||||
| Issue#4 版本号+发布日志 | 侧栏底脚版本 chip(红点=本地未读 localStorage gosms_seen_ver,CSS 脉冲闪烁,点击/进页 markSeen 即灭;折叠态 64px 短版本 1.5+红点 badge 绝对定位)+系统管理二级菜单「发布日志」(/system/release 全角色同 faq;ReleaseLog 时间线卡片);releases.ts 单一事实源(APP_VERSION=首条,package.json 1.5.0 同步防漂移断言);utils/markdown.ts 迷你渲染器零新依赖(先全量转义+仅 http(s) 链接);vitest 179(+14)/verify-layout 31(+8)/Chrome 走查+样式级复核(chip 几何/动画名/暗亮可见);**发版 SOP=releases.ts 头部插一条+package.json 同步** | ✅ 2026-11-16 晚(issue4-release-notes.md) |
|
||||
| Issue#6·P2 Dashboard 后端 3 端点 | /ops/system/overview(gateway 视角五子系统,up/degraded/down/unknown 三态诚实+admin/ops 门,LagReader 复用闭包注入)+/stats/biz(business[sms/video]+send_type[batch/personal/timer/file] 两维;口径修正留痕:biz_type 属审核域 audit_record 非 task 维)+/stats/realtime(60s 窗覆盖索引 COUNT+Top5 账号+名字);openapi +3;新测试 3 组绿,api 域 lint 0,全量 -race 除 channel 存量 flaky(单跑×2 绿,挂账) | ✅ 2026-11-17(P1 视觉契约 v3.2.1 同日锁定) |
|
||||
| Issue#6·P3 壳层契约化 | tokens(teal16 阶+slate/gray+字阶 10~24+lh1.65+旧名兼容)+shell(侧栏 256/折叠 72 品牌区/顶栏 64 glass/card r16 实底/td14·py16px20/aurora 退役)+MainLayout 重排(brand→侧栏+版本徽章迁位+icon20)+TagsBar 契约化+ep-theme(teal/emerald 分离/表格密度桥/渐变桥退役)+全站旧值清零;verify-layout 31/31(类名锚点策略兑现,仅续 2 值断言)+verify-p3-contract.mjs 30/30 双主题 DOM 断言+vitest 182 全绿(Issue#2/#4 资产无伤);6 commits | ✅ 2026-11-17 |
|
||||
| Issue#6·P3 壳层改造(EP 路线) | **用户验收否决→B 方案(0 重构 web-next)拍板**:契约实含 3 页蓝本(dash/acct/chan)P1 只认知 1 页;sub2api 无 EP(实证),EP 模拟非 EP 转译损耗结构性不可救;P3 六 commits 留档不回滚;决议=新工程 web-next(Tailwind3.4+契约 CSS 直拼+零 EP+零旧影子,仅复制逻辑层清 EP 引用);B1 契约基座→B2 三契约页对拍→B3 33 视图→B4 收口 | ❌ 2026-11-17(教训:机器断言全绿≠用户感知范围,契约类文档必须全文件通读) |
|
||||
| Issue#6·B1 web-next 契约基座 | 新工程 web-next 落地(commit 96ab7b87):脚手架 7 件(:5174+proxy→8080,无 EP)+tailwind.css(sub2api 775 行直拷+契约 stat-card/folded 补充)+IconSprite(契约 24 symbol)+逻辑层复制 27 文件(EP 归零)+壳层 5 件(BasicLayout/AppSidebar/AppHeader/TagsBar/VersionBadge,Issue#2/#4 语义保留)+LoginView(sub2api 范式)+36 视图路由契约占位;**验收=vue-tsc 0/build ✓ gzip 68KB/冒烟 10/10/style 断言 8/8** | ✅ 2026-11-17(B2 三契约页 1:1 对拍为下一步) |
|
||||
| Issue#6·B2 三契约页实装 | **v3-2-tailwind.html 按页 1:1 直抄落地**:#p-dash 运营总览(横幅+stat 6+4+chart.js 双线趋势+动态 donut+监控表 5s 轮询+系统健康 10s 轮询+快捷+快照)/#p-acct 帐号管理(单卡一体筛选+8 列表+分页,真实账号)/#p-chan 通道编辑(双卡表单+switch,协议↔版本映射);api 层补 P2 三端点封装;**连带根修:/stats/biz 撞 MySQL 保留字 `key` 500(反引号已修)+网关旧二进制重建**;验收=冒烟 12/12+stat-card style 与 17890 对拍一致 | ✅ 2026-11-17(B3 33 视图分批为下一步) |
|
||||
| Issue#5 压测复盘(11-16 三场) | 白日场 vcmppgw 7.7 万@200/s(p99≤17.4ms 零失败,已清理)+夜间真上家长短信 5.1 万任务×3 片+主战场 23:00~01:52 提交 199.9 万/成功 99.97 万/拦截退款 99.99 万(ISC:004);**下发成功 ≈112.7 万 ✅ 目标 100 万 +12.7%**;计费三平(充值 10.0001 亿−扣 218.3 万+退 99.97 万=余额 998,826,559 分毫不差);受理峰 287.9 QPS slow=0/lag 峰 476/零慢查询零重启;遗留 6 项(R1 差额 P0×33/deliver_fail 2,652/挂起 1,326 条 11-19 到期/host 不热切换/CSV 留档/签名口径)→11-18 整改 11-19 正式阶梯场 | ✅ 2026-11-17(报告 issue5-bench-report.md+工单 #5 Markdown 回帖;账单/利润出账演练挂 SOP) |
|
||||
|
||||
|
||||
| 观察项 | 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》) |
|
||||
|
||||
|
||||
Executable
+258
@@ -0,0 +1,258 @@
|
||||
#!/usr/bin/env python3
|
||||
# cmpp-analyze.py — CMPP 联调 pcap 分析器(Issue#3 排查装备;纯标准库零依赖)
|
||||
#
|
||||
# 输入:tcpdump -i any 抓的 pcap(含环形切片);输出:按 TCP 连接分组的 CMPP 时间线
|
||||
# + 异常自动标记(status≠0/result≠0/RST/握手失败/未知命令)。
|
||||
# 用法:python3 cmpp-analyze.py <file.pcap> [--pkts]
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def fmt_ts(ts):
|
||||
t = time.localtime(ts)
|
||||
return "%02d:%02d:%02d.%03d" % (t.tm_hour, t.tm_min, t.tm_sec, int((ts % 1) * 1000))
|
||||
|
||||
# ---- CMPP 2.0 命令字 ----
|
||||
CMDS = {
|
||||
0x00000001: "CONNECT", 0x80000001: "CONNECT_RESP",
|
||||
0x00000002: "TERMINATE", 0x80000002: "TERMINATE_RESP",
|
||||
0x00000003: "SUBMIT", 0x80000003: "SUBMIT_RESP",
|
||||
0x00000004: "DELIVER", 0x80000004: "DELIVER_RESP",
|
||||
0x00000008: "ACTIVE_TEST", 0x80000008: "ACTIVE_TEST_RESP",
|
||||
}
|
||||
CONN_STATUS = {0: "成功", 1: "结构非法", 2: "账号密码错", 3: "版本/企业代码错",
|
||||
4: "IP白名单拒", 5: "账号停用", 8: "连接数超限"}
|
||||
SUBMIT_RESULT = {0: "成功", 1: "结构错", 8: "流量控制", 9: "通道号前缀不匹配", 10: "业务拒绝(余额/审核)"}
|
||||
|
||||
|
||||
def trim_zero(b):
|
||||
return b.rstrip(b"\x00").decode("utf-8", "replace")
|
||||
|
||||
|
||||
# ---- pcap 文件层(大小端/纳秒魔数自适应) ----
|
||||
def read_pcap(path):
|
||||
with open(path, "rb") as f:
|
||||
gh = f.read(24)
|
||||
if len(gh) < 24:
|
||||
raise SystemExit("pcap 头不足")
|
||||
magic = gh[:4]
|
||||
if magic == b"\xd4\xc3\xb2\xa1":
|
||||
end, nano = "<", False
|
||||
elif magic == b"\xa1\xb2\xc3\xd4":
|
||||
end, nano = ">", False
|
||||
elif magic == b"\x4d\x3c\xb2\xa1":
|
||||
end, nano = "<", True
|
||||
elif magic == b"\xa1\xb2\x3c\x4d":
|
||||
end, nano = ">", True
|
||||
else:
|
||||
raise SystemExit("非 pcap 文件(magic=%s)" % magic.hex())
|
||||
link = struct.unpack(end + "I", gh[20:24])[0]
|
||||
while True:
|
||||
rh = f.read(16)
|
||||
if len(rh) < 16:
|
||||
return
|
||||
ts_s, ts_f, incl, _orig = struct.unpack(end + "IIII", rh)
|
||||
data = f.read(incl)
|
||||
if len(data) < incl:
|
||||
return
|
||||
yield (ts_s + (ts_f / 1e9 if nano else ts_f / 1e6), link, data)
|
||||
|
||||
|
||||
# ---- 链路层 → IP(自适应 -i any 的 SLL/SLL2/以太+VLAN/RAW) ----
|
||||
def to_ip(link, data):
|
||||
if link == 1: # Ethernet(含 VLAN 堆叠)
|
||||
if len(data) < 14:
|
||||
return None
|
||||
eth, off = data[12:14], 14
|
||||
while eth == b"\x81\x00" and len(data) >= off + 4:
|
||||
eth, off = data[off + 2:off + 4], off + 4
|
||||
return data[off:] if eth == b"\x08\x00" else None
|
||||
if link == 101: # RAW IP
|
||||
return data
|
||||
if link == 113: # LINUX_SLL
|
||||
if len(data) < 16 or struct.unpack(">H", data[14:16])[0] != 0x0800:
|
||||
return None
|
||||
return data[16:]
|
||||
if link == 276: # LINUX_SLL2
|
||||
if len(data) < 20 or struct.unpack(">H", data[0:2])[0] != 0x0800:
|
||||
return None
|
||||
return data[20:]
|
||||
if link == 0: # NULL/LOOP
|
||||
return data[4:] if len(data) > 4 else None
|
||||
return None
|
||||
|
||||
|
||||
def parse_ip(data):
|
||||
if len(data) < 20 or (data[0] >> 4) != 4:
|
||||
return None
|
||||
ihl = (data[0] & 0xF) * 4
|
||||
if len(data) < ihl or data[9] != 6: # 仅 TCP
|
||||
return None
|
||||
src = ".".join(str(b) for b in data[12:16])
|
||||
dst = ".".join(str(b) for b in data[16:20])
|
||||
return src, dst, data[ihl:]
|
||||
|
||||
|
||||
def parse_tcp(data):
|
||||
if len(data) < 20:
|
||||
return None
|
||||
sport, dport, seq = struct.unpack(">HHI", data[0:8])
|
||||
off = (data[12] >> 4) * 4
|
||||
return sport, dport, seq, data[13], data[off:]
|
||||
|
||||
|
||||
# ---- 流重组:双向归并;载荷按 seq 排序去重拼接(容重传/重叠) ----
|
||||
def stream_key(src, sport, dst, dport):
|
||||
a, b = (src, sport), (dst, dport)
|
||||
return (a, b) if a <= b else (b, a)
|
||||
|
||||
|
||||
def reassemble(events):
|
||||
streams = {}
|
||||
for ts, key, d, seq, flags, payload in events:
|
||||
st = streams.setdefault(key, {"first": ts, "last": ts,
|
||||
"segs": [], "data": {0: [], 1: []}})
|
||||
st["last"] = ts
|
||||
st["segs"].append((ts, d, flags))
|
||||
if payload:
|
||||
st["data"][d].append((seq & 0xFFFFFFFF, payload))
|
||||
for st in streams.values():
|
||||
for d in (0, 1):
|
||||
buf, expect = bytearray(), None
|
||||
for seq, payload in sorted(st["data"][d], key=lambda x: x[0]):
|
||||
if expect is None or seq == expect:
|
||||
buf += payload
|
||||
elif seq < expect:
|
||||
skip = expect - seq
|
||||
if skip < len(payload):
|
||||
buf += payload[skip:]
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
buf += payload # 缺块乱序:尽力拼接
|
||||
expect = (seq + len(payload)) & 0xFFFFFFFF
|
||||
st["data"][d] = bytes(buf)
|
||||
return streams
|
||||
|
||||
|
||||
# ---- CMPP PDU 切分与解码 ----
|
||||
def split_pdus(buf):
|
||||
out, off = [], 0
|
||||
while off + 12 <= len(buf):
|
||||
total, cmd = struct.unpack(">II", buf[off:off + 8])
|
||||
# 帧头合法性:长度窗口 + 已知命令字;不合法则滑动 1B 扫描(重组边界漂移容错)
|
||||
if total < 13 or total > 65535 or cmd not in CMDS:
|
||||
off += 1
|
||||
continue
|
||||
if off + total > len(buf):
|
||||
break # 尾部截断(环形切片)
|
||||
out.append((cmd, struct.unpack(">I", buf[off + 8:off + 12])[0],
|
||||
buf[off + 12:off + total]))
|
||||
off += total
|
||||
return out, buf[off:]
|
||||
|
||||
|
||||
def dec_connect(body):
|
||||
return "sp=%s ver=0x%02x ts=%d" % (trim_zero(body[0:6]), body[22],
|
||||
struct.unpack(">I", body[23:27])[0])
|
||||
|
||||
|
||||
def dec_connect_resp(body):
|
||||
if len(body) >= 20:
|
||||
st, layout = struct.unpack(">I", body[0:4])[0], "2.0(4B)"
|
||||
ver = body[20] if len(body) > 20 else 0
|
||||
else:
|
||||
st, layout = (body[0] if body else -1), "3.0(1B)"
|
||||
ver = body[17] if len(body) > 17 else 0
|
||||
return "布局=%s(%dB) status=%d(%s) ver=0x%02x" % (
|
||||
layout, len(body), st, CONN_STATUS.get(st, "?"), ver), st
|
||||
|
||||
|
||||
def dec_pdu(cmd, body):
|
||||
name = CMDS.get(cmd, "UNKNOWN_0x%08x" % cmd)
|
||||
detail, bad = "", False
|
||||
if cmd == 0x00000001 and len(body) >= 27:
|
||||
detail = dec_connect(body)
|
||||
elif cmd == 0x80000001:
|
||||
detail, st = dec_connect_resp(body)
|
||||
bad = st != 0
|
||||
elif cmd == 0x00000003 and len(body) >= 140:
|
||||
n = body[116]
|
||||
ml = body[117 + 21 * n] if len(body) > 117 + 21 * n else -1
|
||||
detail = "srcid=%s %d码 %dB udhi=%d" % (trim_zero(body[95:116]), n, ml, body[45])
|
||||
elif cmd == 0x80000003 and len(body) >= 9:
|
||||
r = body[8]
|
||||
detail = "msgid=%d result=%d(%s)" % (struct.unpack(">Q", body[0:8])[0],
|
||||
r, SUBMIT_RESULT.get(r, "?"))
|
||||
bad = r != 0
|
||||
elif cmd == 0x00000004 and len(body) >= 65:
|
||||
detail = "src=%s report=%s" % (trim_zero(body[42:63]), "是" if body[63] == 1 else "否")
|
||||
return name, detail, bad
|
||||
|
||||
|
||||
def flags_str(f):
|
||||
s = ""
|
||||
if f & 0x02: s += "SYN "
|
||||
if f & 0x01: s += "FIN "
|
||||
if f & 0x04: s += "RST "
|
||||
return s.strip()
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
raise SystemExit("用法: cmpp-analyze.py <file.pcap> [--pkts]")
|
||||
show_pkts, path = "--pkts" in sys.argv, sys.argv[1]
|
||||
events, skipped = [], 0
|
||||
for ts, link, data in read_pcap(path):
|
||||
ip = to_ip(link, data)
|
||||
if not ip:
|
||||
continue
|
||||
pr = parse_ip(ip)
|
||||
if not pr:
|
||||
continue
|
||||
src, dst, tcp = pr
|
||||
tp = parse_tcp(tcp)
|
||||
if not tp:
|
||||
continue
|
||||
sport, dport, seq, flags, payload = tp
|
||||
if sport != 7890 and dport != 7890:
|
||||
skipped += 1
|
||||
continue
|
||||
key = stream_key(src, sport, dst, dport)
|
||||
events.append((ts, key, 0 if (src, sport) == key[0] else 1, seq, flags, payload))
|
||||
if not events:
|
||||
print("无 7890 端口流量(过滤非 7890 包 %d 个)——确认客户端目标地址/端口。" % skipped)
|
||||
return
|
||||
streams = reassemble(events)
|
||||
print("=" * 96)
|
||||
print("pcap=%s | 连接数=%d | %.3f ~ %.3f" % (path, len(streams),
|
||||
events[0][0], max(e[0] for e in events)))
|
||||
print("=" * 96)
|
||||
for i, (key, st) in enumerate(sorted(streams.items(), key=lambda x: x[1]["first"]), 1):
|
||||
(s1, p1), (s2, p2) = key
|
||||
print("\n[连接%d] %s:%d ⇄ %s:%d" % (i, s1, p1, s2, p2))
|
||||
for d in (0, 1):
|
||||
pdus, tail = split_pdus(st["data"][d])
|
||||
a = (s1, p1) if d == 0 else (s2, p2)
|
||||
b = (s2, p2) if d == 0 else (s1, p1)
|
||||
t0 = next((t for t, dd, _ in st["segs"] if dd == d), st["first"])
|
||||
for cmd, sq, body in pdus:
|
||||
name, detail, bad = dec_pdu(cmd, body)
|
||||
print(" %s %s:%d→%s:%d %-14s seq=%-6d %s%s" % (
|
||||
fmt_ts(t0), a[0], a[1], b[0], b[1], name, sq, detail, " ⚠️" if bad else ""))
|
||||
if len(tail) >= 4:
|
||||
print(" %s %s:%d→%s:%d (尾段 %dB 未成完整 PDU)" % (fmt_ts(t0), a[0], a[1], b[0], b[1], len(tail)))
|
||||
if show_pkts:
|
||||
for ts, d, fl in st["segs"]:
|
||||
fs = flags_str(fl)
|
||||
if fs:
|
||||
side = key[0] if d == 0 else key[1]
|
||||
print(" %s TCP %-10s %s:%d" % (fmt_ts(ts), fs, side[0], side[1]))
|
||||
print("\n" + "=" * 96)
|
||||
print("⚠️=拒绝/异常码;CONNECT_RESP 布局自动判定(2.0=21B/3.0=18B)。")
|
||||
print("客户端报-1:先看 CONNECT_RESP.status 及布局是否匹配其版本;无本机流量=地址/端口未指向本平台。")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Executable
+97
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env bash
|
||||
# cmpp-capture.sh — CMPP 联调抓包控制(Issue#3:客户连接报 -1 排查装备)
|
||||
#
|
||||
# 用法:
|
||||
# scripts/cmpp-capture.sh start [端口] # 后台抓包(默认 7890;可 'host x.x.x.x' 过滤)
|
||||
# scripts/cmpp-capture.sh stop # 停止
|
||||
# scripts/cmpp-capture.sh status # 运行状态/文件/当前 7890 连接
|
||||
# scripts/cmpp-capture.sh analyze [pcap] # 解析最新(或指定)pcap → CMPP 时间线
|
||||
#
|
||||
# 抓包口径:-i any(LINUX_SLL 链路层,分析器自适应)/ -s 0 全包(长短信 Submit ~3KB)
|
||||
# / -C 50 -W 6 环形 50MB×6 防打爆 / -tttt.n 微秒时间戳
|
||||
# 权限:sudo(sudoers NOPASSWD 已配);无 root 时提示降级方案(python 探针)。
|
||||
set -euo pipefail
|
||||
|
||||
CAP_DIR="/data/go-sms-v2/logs/capture"
|
||||
PID_FILE="$CAP_DIR/capture.pid"
|
||||
LOG_FILE="$CAP_DIR/tcpdump-stderr.log"
|
||||
|
||||
ensure_dir() { mkdir -p "$CAP_DIR"; }
|
||||
|
||||
running() { pgrep -x tcpdump >/dev/null 2>&1; }
|
||||
|
||||
cmd_start() {
|
||||
if running; then echo "已在运行(PID $(cat "$PID_FILE")),文件:"; ls -lh "$CAP_DIR"/*.pcap 2>/dev/null | tail -2; exit 0; fi
|
||||
ensure_dir
|
||||
local filter="${1:-7890}"
|
||||
local f="port ${filter}"
|
||||
# 传 host x.x.x.x 形式时原样作过滤器
|
||||
[[ "$filter" == *" "* ]] && f="$filter"
|
||||
local ts file
|
||||
ts=$(date +%Y%m%d-%H%M%S)
|
||||
file="$CAP_DIR/cmpp-$ts.pcap"
|
||||
if ! sudo -n true 2>/dev/null; then
|
||||
echo "ERROR: sudo 免密不可用,tcpdump 需 root(抓不了包;可用 python3 探针替代连通性探测)" >&2; exit 1
|
||||
fi
|
||||
# -Z root:tcpdump 4.x 写 pcap 默认降权 tcpdump 用户(目录无权→Permission denied)
|
||||
sudo -n nohup tcpdump -Z root -i any -s 0 -C 50 -W 6 -tttt -n -U -w "$file" "$f" > "$LOG_FILE" 2>&1 &
|
||||
sleep 1
|
||||
local pid
|
||||
pid=$(pgrep -x tcpdump | head -1 || true)
|
||||
if [[ -z "$pid" ]]; then
|
||||
echo "ERROR: tcpdump 启动失败:" >&2; cat "$LOG_FILE" >&2; exit 1
|
||||
fi
|
||||
echo "$pid" > "$PID_FILE"
|
||||
echo "抓包已启动: PID=$pid 过滤器='$f'"
|
||||
echo "文件: $file(环形 50MB×6)"
|
||||
echo "停止: scripts/cmpp-capture.sh stop ;分析: scripts/cmpp-capture.sh analyze"
|
||||
}
|
||||
|
||||
cmd_stop() {
|
||||
if ! running; then echo "未在运行"; rm -f "$PID_FILE"; exit 0; fi
|
||||
sudo -n pkill -x tcpdump 2>/dev/null || pkill -x tcpdump 2>/dev/null || true
|
||||
sleep 1
|
||||
rm -f "$PID_FILE"
|
||||
echo "已停止。最近文件:"
|
||||
ls -lht "$CAP_DIR"/*.pcap* 2>/dev/null | head -3
|
||||
echo "分析: scripts/cmpp-capture.sh analyze"
|
||||
}
|
||||
|
||||
cmd_status() {
|
||||
if running; then
|
||||
echo "运行中 PID=$(cat "$PID_FILE")"
|
||||
else
|
||||
echo "未在运行"
|
||||
fi
|
||||
ls -lht "$CAP_DIR"/*.pcap* 2>/dev/null | head -3 || echo "(无 pcap)"
|
||||
echo "--- 当前 7890 连接(含出向)---"
|
||||
ss -tn 2>/dev/null | grep ':7890' || echo "(无)"
|
||||
tail -3 "$LOG_FILE" 2>/dev/null || true
|
||||
}
|
||||
|
||||
cmd_analyze() {
|
||||
local mode="${1:-}"
|
||||
ensure_dir
|
||||
# 环形切片 .pcapN:默认分析最新单片;all=cat 全组(按编号序)到临时文件合并分析
|
||||
local f newest group
|
||||
f=$(ls -t "$CAP_DIR"/*.pcap* 2>/dev/null | head -1 || true)
|
||||
if [[ -z "$f" ]]; then echo "ERROR: 无 pcap 文件(先 start)" >&2; exit 1; fi
|
||||
if [[ "$mode" == "all" ]]; then
|
||||
group="${f%.pcap*}.pcap"
|
||||
local merged="/tmp/cmpp-merged-$$.pcap"
|
||||
cat "$group" "$group"[0-9]* 2>/dev/null > "$merged" || cat "$group"* > "$merged"
|
||||
echo "(合并 $(ls "$group"* 2>/dev/null | wc -l) 个切片 → $merged)"
|
||||
python3 /data/go-sms-v2/scripts/cmpp-analyze.py "$merged"
|
||||
rm -f "$merged"
|
||||
else
|
||||
python3 /data/go-sms-v2/scripts/cmpp-analyze.py "$f"
|
||||
fi
|
||||
}
|
||||
|
||||
case "${1:-status}" in
|
||||
start) shift || true; cmd_start "$@" ;;
|
||||
stop) cmd_stop ;;
|
||||
status) cmd_status ;;
|
||||
analyze) shift || true; cmd_analyze "$@" ;;
|
||||
*) echo "用法: $0 {start [端口|过滤式]|stop|status|analyze [pcap]}"; exit 1 ;;
|
||||
esac
|
||||
@@ -0,0 +1,51 @@
|
||||
// Issue#6 P3 契约值断言(chrome-session 惯例:独立 launch+单 page,channel:'chrome')
|
||||
import { chromium } from '/data/go-sms-v2/web/node_modules/playwright/index.mjs'
|
||||
const ARGS=['--no-sandbox','--disable-gpu','--disable-dev-shm-usage']
|
||||
const fails=[]; const ok=(c,m,v)=>{console.log((c?'✓':'✗')+' '+m+(v!==undefined?` = ${v}`:''));if(!c)fails.push(m)}
|
||||
const cs=async(s,prop,pseudo)=>{try{return await page.$eval(s,(el,[pr,ps])=>ps?getComputedStyle(el,ps)[pr]:getComputedStyle(el)[pr],[prop,pseudo??null])}catch(e){return 'ERR:'+e.message.slice(0,40)}}
|
||||
const browser=await chromium.launch({channel:'chrome',args:ARGS})
|
||||
const page=await browser.newPage({viewport:{width:1440,height:900}})
|
||||
await page.goto('http://127.0.0.1:5173/login',{waitUntil:'networkidle'})
|
||||
await page.getByTestId('login-username').fill('s2demo')
|
||||
await page.getByTestId('login-password').fill('S2demo@2026')
|
||||
await page.getByTestId('login-submit').click()
|
||||
await page.waitForURL('**/home',{timeout:15000})
|
||||
await page.waitForTimeout(800)
|
||||
// 归一起始主题:localStorage 残留暗色时先切亮(s2demo 会话偏好不可控)
|
||||
if (await page.evaluate(() => document.documentElement.classList.contains('dark'))) {
|
||||
await page.getByTestId('dark-toggle').click(); await page.waitForTimeout(500)
|
||||
}
|
||||
ok(!(await page.evaluate(() => document.documentElement.classList.contains('dark'))), '起始=亮色')
|
||||
console.log('--- 亮色 ---')
|
||||
ok((await cs('body','fontSize'))==='14px','body 14px',await cs('body','fontSize'))
|
||||
ok(Math.abs(parseFloat(await cs('body','lineHeight'))-23.1)<0.5,'body lh≈1.65(23.1px)',await cs('body','lineHeight'))
|
||||
ok((await cs('body','backgroundColor'))==='rgb(249, 250, 251)','亮页底 gray-50',await cs('body','backgroundColor'))
|
||||
ok(Math.round((await page.locator('aside.sidebar').boundingBox()).width)===256,'sidebar 256',Math.round((await page.locator('aside.sidebar').boundingBox()).width))
|
||||
ok((await cs('.topbar','height'))==='64px','topbar 64',await cs('.topbar','height'))
|
||||
ok((await cs('header.topbar','backdropFilter')).includes('blur'),'topbar glass blur',await cs('header.topbar','backdropFilter'))
|
||||
ok((await cs('.nav-item','fontSize'))==='14px','菜单 14px',await cs('.nav-item','fontSize'))
|
||||
ok((await cs('.nav-item .ic svg','width'))==='20px','菜单 icon 20',(await cs('.nav-item .ic svg','width')))
|
||||
ok((await cs('.page-head h2','fontSize'))==='24px','页标题 24',await cs('.page-head h2','fontSize'))
|
||||
ok((await cs('main.main','paddingTop'))==='32px','main padding 32',await cs('main.main','paddingTop'))
|
||||
ok((await cs('.card','borderRadius'))==='16px','card r16',await cs('.card','borderRadius'))
|
||||
ok((await cs('.card','boxShadow')).includes('rgba(0, 0, 0, 0.04)'),'card shadow-sm 双层',(await cs('.card','boxShadow')).slice(0,40))
|
||||
ok((await cs('.nav-item.active','backgroundColor'))==='rgb(240, 253, 250)','激活底 teal-50',await cs('.nav-item.active','backgroundColor'))
|
||||
const bm=await page.locator('.brand .brand-mark').boundingBox()
|
||||
ok(bm&&bm.width===36&&bm.height===36,'brand-mark 36×36',bm&&`${bm.width}×${bm.height}`)
|
||||
ok((await cs('.brand .brand-mark','borderRadius'))==='12px','logo r12',await cs('.brand .brand-mark','borderRadius'))
|
||||
ok((await cs('.brand-name','fontSize'))==='18px','品牌 18px',await cs('.brand-name','fontSize'))
|
||||
ok(await page.locator('.sidebar-header .ver-badge').count()===1,'版本徽章在品牌下方')
|
||||
ok((await cs('.top-title','fontSize'))==='16px','顶栏页标题 16px',await cs('.top-title','fontSize'))
|
||||
console.log('--- 暗色(切换) ---')
|
||||
await page.getByTestId('dark-toggle').click(); await page.waitForTimeout(500)
|
||||
ok((await cs('body','backgroundColor'))==='rgb(2, 6, 23)','暗页底 slate-950',await cs('body','backgroundColor'))
|
||||
ok((await cs('aside.sidebar','backgroundColor'))==='rgb(15, 23, 42)','侧栏 slate-900',await cs('aside.sidebar','backgroundColor'))
|
||||
ok((await cs('.card','backgroundColor'))==='rgb(30, 41, 59)','卡 slate-800',await cs('.card','backgroundColor'))
|
||||
ok((await cs('.nav-item.active','color')).includes('45, 212, 191'),'激活字 teal-400(暗)',await cs('.nav-item.active','color'))
|
||||
// 折叠 72
|
||||
await page.getByTestId('sidebar-collapse-btn').click(); await page.waitForTimeout(500)
|
||||
ok(Math.abs((await page.locator('aside.sidebar').boundingBox()).width-72)<2,'折叠 72',(await page.locator('aside.sidebar').boundingBox()).width)
|
||||
ok(await page.locator('.sidebar .brand-name:visible').count()===0,'折叠态品牌/徽章隐藏')
|
||||
await browser.close()
|
||||
console.log(fails.length?`\n✗ ${fails.length} 项失败`:'\n✓ P3 契约值断言全通过')
|
||||
process.exit(fails.length?1:0)
|
||||
@@ -0,0 +1 @@
|
||||
VITE_API_BASE_URL=/api/v1
|
||||
@@ -0,0 +1 @@
|
||||
VITE_API_BASE_URL=/api/v1
|
||||
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
dist
|
||||
*.local
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>go-sms 管理台</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+2893
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "hwsms-web-next",
|
||||
"private": true,
|
||||
"version": "1.5.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview",
|
||||
"typecheck": "vue-tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.20.0",
|
||||
"chart.js": "^4.4.1",
|
||||
"pinia": "^2.1.7",
|
||||
"vue": "^3.5.43",
|
||||
"vue-chartjs": "^5.3.0",
|
||||
"vue-router": "^4.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.5",
|
||||
"@vitejs/plugin-vue": "^5.2.3",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"postcss": "^8.4.32",
|
||||
"tailwindcss": "^3.4.0",
|
||||
"typescript": "~5.6.0",
|
||||
"vite": "^5.0.10",
|
||||
"vue-tsc": "^2.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<template>
|
||||
<IconSprite />
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 全站图标唯一来源:契约 v3-2-tailwind.html 的 SVG defs 直挂(25 symbol,零图标库)。
|
||||
import IconSprite from '@/components/IconSprite.vue'
|
||||
</script>
|
||||
@@ -0,0 +1,139 @@
|
||||
import { del, get, post, put } from './request'
|
||||
|
||||
/** 账号(与后端 account_user 对齐,FE 视图裁剪)。 */
|
||||
export interface Account {
|
||||
id: number
|
||||
username: string
|
||||
real_name: string
|
||||
role: string
|
||||
status: number
|
||||
business: number
|
||||
balance: number
|
||||
credit_balance: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface Paged<T> { list: T[]; total: number }
|
||||
|
||||
export interface BalanceLog {
|
||||
id: number
|
||||
account_id: number
|
||||
biz_type: string
|
||||
amount: number
|
||||
balance_after: number
|
||||
operator: string
|
||||
remark: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface Role { code: string; name: string; is_built_in: number; permissions: string[] }
|
||||
|
||||
/** 账号业务配置(与后端 entity.AccountConfig 对齐,FE 裁剪;Day46/W6 详情页接真数据)。 */
|
||||
export interface AccountConfig {
|
||||
account_id: number
|
||||
business: string // 业务线 code(如 sms),BUSINESS 有中文映射
|
||||
audit_mode: number // 0免审 1人工审核 2自动审核(黑词)
|
||||
sms_type?: string
|
||||
protocol: string
|
||||
ext_code?: string
|
||||
}
|
||||
|
||||
export interface LoginAuditRow {
|
||||
id: number
|
||||
username: string
|
||||
ip: string
|
||||
ok: number
|
||||
fail_reason?: string
|
||||
login_at: string
|
||||
}
|
||||
|
||||
/** Issue#5·P0-A:账号分时单价时间线(account_price;出账售价唯一事实源)。 */
|
||||
export interface AccountPriceEntry {
|
||||
id: number
|
||||
account_id: number
|
||||
business: string
|
||||
price: number
|
||||
effective_at: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
/** Day 62:外部 API 配置(GET /accounts/:id/api-config)。 */
|
||||
export interface ApiConfig {
|
||||
account_id: number
|
||||
business: string
|
||||
report_url: string
|
||||
uplink_url: string
|
||||
speed_limit: number
|
||||
ext_code: string
|
||||
secret_issued: boolean
|
||||
secret_fingerprint: string
|
||||
cmpp_password: string // CMPP 客户端直接填的密码(库值全量)
|
||||
cmpp_max_conns: number // 账号级原始值(0=系统默认)
|
||||
cmpp_speed: number
|
||||
cmpp_max_conns_effective: number // 生效值(回退系统默认后)
|
||||
cmpp_speed_effective: number
|
||||
cmpp_access?: { port: string; version: string; default_max_conns: number; default_speed: number }
|
||||
}
|
||||
|
||||
/** Day 62:外部 API 配置更新(PUT;0=不修改,-1=恢复系统默认)。 */
|
||||
export interface ApiConfigSaveReq {
|
||||
report_url?: string
|
||||
uplink_url?: string
|
||||
speed_limit?: number
|
||||
ext_code?: string
|
||||
reset_secret?: boolean
|
||||
custom_secret?: string
|
||||
cmpp_max_conns?: number
|
||||
cmpp_speed?: number
|
||||
}
|
||||
|
||||
/** Day 62:配置更新结果(secret=明文仅一次;cmpp_password=CMPP 客户端密码)。 */
|
||||
export interface ApiConfigSaveResult {
|
||||
secret: string
|
||||
cmpp_password: string
|
||||
}
|
||||
|
||||
// 业务线位掩码(与后端 account.Business* 一致)
|
||||
export const BUSINESS = [
|
||||
{ bit: 1, code: 'sms', label: '国内短信' },
|
||||
{ bit: 2, code: 'intl', label: '国际短信' },
|
||||
{ bit: 4, code: 'video', label: '视频短信' },
|
||||
{ bit: 8, code: 'csp', label: 'CSP 5G' },
|
||||
{ bit: 16, code: 'nullfilter', label: '空号过滤' },
|
||||
{ bit: 32, code: 'shortlink', label: '短链' },
|
||||
] as const
|
||||
|
||||
export interface AccountQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
username?: string
|
||||
role?: string
|
||||
status?: string
|
||||
}
|
||||
|
||||
export const accountApi = {
|
||||
detail: (id: number) => get<{ account: Account; configs: AccountConfig[] }>(`/accounts/${id}`),
|
||||
list: (q: AccountQuery) => get<Paged<Account>>('/accounts', q as unknown as Record<string, unknown>),
|
||||
create: (body: { username: string; password: string; real_name?: string; role: string; business: number; credit_balance?: number }) =>
|
||||
post<{ id: number; username: string }>('/accounts', body),
|
||||
update: (id: number, body: Partial<Account>) => put<Account>(`/accounts/${id}`, body),
|
||||
setStatus: (id: number, status: number) => put<Account>(`/accounts/${id}/status`, { status }),
|
||||
remove: (id: number) => del<{ id: number }>(`/accounts/${id}`),
|
||||
// Issue#3 修复:后端 rechargeReq 为 {amount, remark}(此前误发 count 致 400 被吞)。
|
||||
recharge: (id: number, amount: number, remark: string) =>
|
||||
post<{ balance: number }>(`/accounts/${id}/recharge`, { amount, remark }),
|
||||
balanceLogs: (id: number) => get<Paged<BalanceLog>>(`/accounts/${id}/balance_logs`),
|
||||
// Issue#5·P0-A:分时单价时间线(结算/出账售价唯一事实源 settle.PriceAtAccount)
|
||||
priceList: (id: number, business?: string) =>
|
||||
get<Paged<AccountPriceEntry>>(`/accounts/${id}/prices`, business ? { business } : undefined),
|
||||
priceSet: (id: number, body: { business?: string; price: number; effective_at?: string }) =>
|
||||
post<AccountPriceEntry>(`/accounts/${id}/prices`, body),
|
||||
priceRemove: (id: number, priceId: number) =>
|
||||
del<{ id: number; price_id: number; deleted: boolean }>(`/accounts/${id}/prices/${priceId}`),
|
||||
// Day 62:外部 API 配置(CMPP 密码/接入配额/交付块)
|
||||
getApiConfig: (id: number) => get<ApiConfig>(`/accounts/${id}/api-config`),
|
||||
setApiConfig: (id: number, body: ApiConfigSaveReq) =>
|
||||
put<ApiConfigSaveResult>(`/accounts/${id}/api-config`, body),
|
||||
roles: () => get<Paged<Role>>('/roles'),
|
||||
loginAudit: (username?: string) => get<Paged<LoginAuditRow>>('/audit/logins', username ? { username } : undefined),
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { post } from './request'
|
||||
import { LoginData } from './types'
|
||||
|
||||
/** 登录(Mock:admin/admin 或 customer/123456)。 */
|
||||
export function login(body: { username: string; password: string }) {
|
||||
return post<LoginData>('/auth/login', body)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/** 回调任务管理 API(S4·C1;openapi v1.4.0 契约)。 */
|
||||
import { get, post } from './request'
|
||||
|
||||
/** 回调任务(status: 0待推送 1已送达 2死信;type: 1回执终态 2上行)。 */
|
||||
export interface CallbackTask {
|
||||
id: number
|
||||
account_id: number
|
||||
type: number
|
||||
url: string
|
||||
payload: string
|
||||
status: number
|
||||
attempt: number
|
||||
next_retry_at: string
|
||||
last_code: number
|
||||
last_err: string
|
||||
sent_at: string | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 列表结果(含状态计数面板)。 */
|
||||
export interface CallbackListResult {
|
||||
total: number
|
||||
list: CallbackTask[]
|
||||
status_counts: { pending?: number; sent?: number; dead?: number }
|
||||
}
|
||||
|
||||
export const callbackApi = {
|
||||
list: (params: Record<string, unknown>) => get<CallbackListResult>('/ops/callback', params),
|
||||
resend: (id: number) => post<{ id: number; resent: boolean }>(`/ops/callback/${id}/resend`),
|
||||
}
|
||||
|
||||
/** 状态码值 → 中文标签。 */
|
||||
export const CALLBACK_STATUS: Record<number, string> = { 0: '待推送', 1: '已送达', 2: '死信' }
|
||||
export const CALLBACK_TYPE: Record<number, string> = { 1: '回执终态', 2: '上行消息' }
|
||||
@@ -0,0 +1,192 @@
|
||||
import { del, get, post, put } from './request'
|
||||
import type { Paged } from './account'
|
||||
|
||||
/** 上家(通道方)。 */
|
||||
export interface Upstream {
|
||||
id: number
|
||||
name: string
|
||||
contact: string
|
||||
phone: string
|
||||
category: string
|
||||
status: number
|
||||
remark: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 通道。 */
|
||||
export interface Channel {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
protocol: 'cmpp' | 'http' | 'sgip' | 'smpp'
|
||||
upstream_id: number
|
||||
upstream_name?: string
|
||||
host: string
|
||||
port: number
|
||||
username: string
|
||||
password?: string
|
||||
speed: number
|
||||
conn_count: number
|
||||
status: number
|
||||
is_default: number
|
||||
priority: number
|
||||
weight: number
|
||||
day_limit: number
|
||||
night_limit: number
|
||||
sign_mode: number
|
||||
ext_length: number
|
||||
black_keywords: string
|
||||
block_regions: string
|
||||
template_mode: number
|
||||
remark: string
|
||||
created_at: string
|
||||
// ---- Day 31 扩展:协议接入参数 ----
|
||||
sp_id?: string // 企业代码(CMPP SourceAddr ≤6B/SGIP CorpID)
|
||||
protocol_version?: number // cmpp:20|30 sgip:12 smpp:34
|
||||
heartbeat_interval?: number // 心跳周期(秒)
|
||||
reconnect_max?: number // 重连退避上限(秒)
|
||||
service_id?: string // 服务代码
|
||||
// ---- Day 31 扩展:运营属性 ----
|
||||
carrier?: string // 运营商逗号分隔 cmcc,cucc,ctcc
|
||||
billing_length?: number // 计费长度(字/条)
|
||||
payment_type?: string // prepay_monthly/postpaid_monthly/prepay_realtime
|
||||
billing_mode?: string // success_unknown/success/all
|
||||
price?: number // 元/条
|
||||
category?: string
|
||||
mo_forward_channel_id?: number // 上行组合通道(0=不转发)
|
||||
number_rule?: number // 0~3
|
||||
code_truncate?: number // 通道号截断位数
|
||||
ext_params?: string
|
||||
service_remark?: string
|
||||
}
|
||||
|
||||
/** 通道组成员(四步路由)。 */
|
||||
export interface GroupItem {
|
||||
id: number
|
||||
group_id: number
|
||||
channel_id: number
|
||||
channel_name?: string
|
||||
step: 1 | 2 | 3 | 4 // 1条件过滤 2优先 3权重 4兜底
|
||||
priority: number
|
||||
weight: number
|
||||
region: string
|
||||
carrier: string
|
||||
keyword: string
|
||||
}
|
||||
|
||||
/** 通道组。 */
|
||||
export interface ChannelGroup {
|
||||
id: number
|
||||
name: string
|
||||
remark: string
|
||||
status: number
|
||||
items?: GroupItem[]
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export const PROTOCOLS = [
|
||||
{ value: 'cmpp', label: 'CMPP' },
|
||||
{ value: 'http', label: 'HTTP' },
|
||||
{ value: 'sgip', label: 'SGIP' },
|
||||
{ value: 'smpp', label: 'SMPP' },
|
||||
] as const
|
||||
|
||||
export const ROUTE_STEPS = [
|
||||
{ value: 1, label: '条件过滤', desc: '黑白名单/关键字/签名/地区/频次' },
|
||||
{ value: 2, label: '优先通道', desc: '省网分流/关键字命中走优先通道' },
|
||||
{ value: 3, label: '权重分发', desc: '按权重比例随机分发' },
|
||||
{ value: 4, label: '默认兜底', desc: '以上均未命中时的兜底通道' },
|
||||
] as const
|
||||
|
||||
/** 常驻链路状态(Day 39)。 */
|
||||
export interface LinkStatus {
|
||||
channel_id: number
|
||||
running: boolean
|
||||
total: number
|
||||
healthy: number
|
||||
started_at?: string
|
||||
}
|
||||
|
||||
/** 回执/上行(Day 39;is_report=true 为状态报告 stat,false 为上行短信)。 */
|
||||
export interface Receipt {
|
||||
channel_id: number
|
||||
msg_id: string
|
||||
is_report: boolean
|
||||
stat?: string
|
||||
submit_time?: string
|
||||
done_time?: string
|
||||
dest?: string
|
||||
src?: string
|
||||
content?: string
|
||||
at: string
|
||||
}
|
||||
|
||||
/** 通道分时成本价时间线(Issue#5·P0-A 封装 Day38 端点;出账成本唯一事实源)。 */
|
||||
export interface ChannelPriceEntry {
|
||||
id: number
|
||||
channel_id: number
|
||||
price: number
|
||||
effective_at: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
/** 通道实时快照(Day 40:/channels/monitor,与 WS 帧同构;60s 窗口均值)。 */
|
||||
export interface ChannelSnapshot {
|
||||
channel_id: number
|
||||
name: string
|
||||
protocol: string
|
||||
status: number
|
||||
running: boolean
|
||||
total: number
|
||||
healthy: number
|
||||
submit_ps: number
|
||||
deliver_ps: number
|
||||
fail_rate: number
|
||||
latency_p50_ms: number
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export const channelApi = {
|
||||
// ---- 实时监控(Day 40:HTTP 快照,与 /channels/monitor/ws 帧同构) ----
|
||||
monitor: () => get<ChannelSnapshot[]>('/channels/monitor'),
|
||||
|
||||
// ---- 上家 ----
|
||||
upstreamList: (q?: { page: number; page_size: number; name?: string }) =>
|
||||
get<Paged<Upstream>>('/channels/upstreams', q as Record<string, unknown>),
|
||||
upstreamCreate: (body: Partial<Upstream>) => post<Upstream>('/channels/upstreams', body),
|
||||
upstreamUpdate: (id: number, body: Partial<Upstream>) => put<Upstream>(`/channels/upstreams/${id}`, body),
|
||||
upstreamRemove: (id: number) => del<{ id: number }>(`/channels/upstreams/${id}`),
|
||||
|
||||
// ---- 通道 ----
|
||||
list: (q: Record<string, unknown>) => get<Paged<Channel>>('/channels', q),
|
||||
get: (id: number) => get<Channel>(`/channels/${id}`),
|
||||
create: (body: Partial<Channel>) => post<Channel>('/channels', body),
|
||||
update: (id: number, body: Partial<Channel>) => put<Channel>(`/channels/${id}`, body),
|
||||
remove: (id: number) => del<{ id: number }>(`/channels/${id}`),
|
||||
test: (id: number, body: { mobile: string; content: string }) =>
|
||||
post<{ message_id: string; protocol: string; elapsed_ms: number; ok?: boolean; latency_ms?: number; message?: string }>(
|
||||
`/channels/${id}/test`, body,
|
||||
),
|
||||
// ---- Day 39:链路状态/回执复核 ----
|
||||
linkStatus: (id: number) => get<LinkStatus>(`/channels/${id}/link-status`),
|
||||
linkReceipts: (id: number, limit = 50) =>
|
||||
get<{ channel_id: number; total: number; list: Receipt[] }>(`/channels/${id}/receipts`, { limit }),
|
||||
|
||||
// ---- Issue#5·P0-A:分时成本价时间线(Day38 端点 FE 封装,出账成本事实源) ----
|
||||
priceList: (id: number) => get<Paged<ChannelPriceEntry>>(`/channels/${id}/prices`),
|
||||
priceSet: (id: number, body: { price: number; effective_at?: string }) =>
|
||||
post<ChannelPriceEntry>(`/channels/${id}/prices`, body),
|
||||
priceRemove: (id: number, priceId: number) =>
|
||||
del<{ id: number; price_id: number; deleted: boolean }>(`/channels/${id}/prices/${priceId}`),
|
||||
|
||||
// ---- 通道组(四步路由) ----
|
||||
groupList: () => get<Paged<ChannelGroup>>('/channel-groups'),
|
||||
groupCreate: (body: { name: string; remark?: string }) => post<ChannelGroup>('/channel-groups', body),
|
||||
groupRemove: (id: number) => del<{ id: number }>(`/channel-groups/${id}`),
|
||||
groupItems: (groupId: number) => get<Paged<GroupItem>>(`/channel-groups/${groupId}/items`),
|
||||
groupItemAdd: (groupId: number, body: Partial<GroupItem>) => post<GroupItem>(`/channel-groups/${groupId}/items`, body),
|
||||
groupItemUpdate: (groupId: number, itemId: number, body: Partial<GroupItem>) =>
|
||||
put<GroupItem>(`/channel-groups/${groupId}/items/${itemId}`, body),
|
||||
groupItemRemove: (groupId: number, itemId: number) =>
|
||||
del<{ id: number }>(`/channel-groups/${groupId}/items/${itemId}`),
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Codegen:由 tools/gen-dict 从 api/openapi.yaml x-isc-dict 生成,勿手改。
|
||||
// 源码级锁定:internal/pkg/errors/openapi_sync_test.go(后端 codes.go ↔ openapi 双向一致)。
|
||||
// 重新生成:go run ./tools/gen-dict
|
||||
|
||||
export const ISC_CN: Record<string, string> = {
|
||||
'ISC:000': '成功',
|
||||
'ISC:001': '网关错误',
|
||||
'ISC:002': '账号被禁用',
|
||||
'ISC:003': '签名被禁用',
|
||||
'ISC:004': '签名非法',
|
||||
'ISC:005': '通道非法',
|
||||
'ISC:006': '黑名单',
|
||||
'ISC:007': '欠费',
|
||||
'ISC:009': '短信网关内部错误',
|
||||
'ISC:010': '发送回执超时',
|
||||
'ISC:011': '用户不在线',
|
||||
'ISC:012': '用户停机',
|
||||
'ISC:013': '没有路由,携号转网',
|
||||
'ISC:014': '用户不在服务区',
|
||||
'ISC:015': '端口下线',
|
||||
'ISC:016': '等待5G消息终端响应超时',
|
||||
'ISC:017': '消息编码非法',
|
||||
'ISC:018': '用户未开通5G消息',
|
||||
'ISC:019': '彩信下发成功,下载超时',
|
||||
'ISC:020': '终端存储空间满',
|
||||
'ISC:021': '回落彩信延迟获取',
|
||||
'ISC:022': '不支持彩信',
|
||||
'ISC:023': '码号局数据错误',
|
||||
'ISC:024': '短信已下发,但是终端故障',
|
||||
'ISC:025': '找不到归属运营商,可能是新号段',
|
||||
'ISC:026': '无法识别彩信回执',
|
||||
'ISC:027': '空号',
|
||||
'ISC:029': '无通道路由',
|
||||
'ISC:030': '通道拒绝',
|
||||
'ISC:031': '内容不合规拦截',
|
||||
'ISC:032': '发送限制',
|
||||
'ISC:033': '超出账号设置的最大文本长度',
|
||||
'ISC:034': '超出账号每天发送量限制',
|
||||
'ISC:035': '超出账号授信额限制',
|
||||
'ISC:036': '地区屏蔽',
|
||||
'ISC:037': '审核状态冲突(非待审)',
|
||||
'ISC:038': '任务状态冲突(不可取消/改期)',
|
||||
'ISC:039': '订单状态冲突(非待确认)',
|
||||
'ISC:040': '夜间频控',
|
||||
'ISC:043': '5G消息拦截',
|
||||
'ISC:400': '参数错误',
|
||||
'ISC:401': '未认证',
|
||||
'ISC:402': 'Token 已过期',
|
||||
'ISC:403': '无权限',
|
||||
'ISC:404': '资源不存在',
|
||||
'ISC:405': '方法不允许',
|
||||
'ISC:429': '请求过于频繁',
|
||||
'ISC:500': '其他错误,需要人工核查',
|
||||
'ISC:501': '数据库错误',
|
||||
'ISC:502': '缓存错误',
|
||||
'ISC:503': '消息队列错误',
|
||||
'ISC:504': '服务暂不可用',
|
||||
}
|
||||
|
||||
/** ISC 错误码 → 中文;未知码原样返回(后端新增码未同步时降级展示)。 */
|
||||
export function iscText(code: string): string {
|
||||
return ISC_CN[code] ?? code
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
import { del, get, post, put } from './request'
|
||||
import type { Paged } from './account'
|
||||
|
||||
/** 黑/白名单。 */
|
||||
export interface NumberList {
|
||||
id: number
|
||||
mobile: string
|
||||
account_id: number
|
||||
source: number
|
||||
operator: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 关键字。 */
|
||||
export interface Keyword {
|
||||
id: number
|
||||
word: string
|
||||
level: 1 | 2 | 3 // 1一级黑 2二级黑 3白
|
||||
status: number
|
||||
operator: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 频次策略。 */
|
||||
export interface FrequencyPolicy {
|
||||
id: number
|
||||
account_id: number
|
||||
dim: 1 | 2 // 1同号码 2同内容
|
||||
window_unit: 1 | 2 // 1自然日 2滚动24h
|
||||
max_count: number
|
||||
status: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 屏蔽码号。 */
|
||||
export interface BlockedCode {
|
||||
id: number
|
||||
channel_id: number
|
||||
code: string
|
||||
remark: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 导流规则。 */
|
||||
export interface RouteRule {
|
||||
id: number
|
||||
account_id: number
|
||||
channel_id: number
|
||||
channel_name?: string
|
||||
rule_type: 'keyword' | 'region' | 'account' | 'content'
|
||||
rule_config: string
|
||||
priority: number
|
||||
status: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 签名/码号报备。 */
|
||||
export interface Report {
|
||||
id: number
|
||||
type: 'sign' | 'code'
|
||||
content: string
|
||||
account_id: number
|
||||
status: 0 | 1 | 2 // 0 待审 1 通过 2 驳回(可重提)
|
||||
operator: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export const REPORT_TYPES = [
|
||||
{ value: 'sign', label: '签名报备' },
|
||||
{ value: 'code', label: '码号报备' },
|
||||
] as const
|
||||
|
||||
export const policyApi = {
|
||||
// 黑名单
|
||||
blacklist: (q?: { page: number; page_size: number; mobile?: string }) =>
|
||||
get<Paged<NumberList>>('/policies/blacklist', q as Record<string, unknown>),
|
||||
blacklistAdd: (body: { mobile: string }) => post<NumberList>('/policies/blacklist', body),
|
||||
blacklistRemove: (id: number) => del<{ id: number }>(`/policies/blacklist/${id}`),
|
||||
blacklistImport: (body: { mobiles: string[] }) => post<{ imported: number }>('/policies/blacklist/import', body),
|
||||
|
||||
// 白名单
|
||||
whitelist: (q?: { page: number; page_size: number }) =>
|
||||
get<Paged<NumberList>>('/policies/whitelist', q as Record<string, unknown>),
|
||||
whitelistAdd: (body: { mobile: string }) => post<NumberList>('/policies/whitelist', body),
|
||||
whitelistRemove: (id: number) => del<{ id: number }>(`/policies/whitelist/${id}`),
|
||||
|
||||
// 关键字
|
||||
keywords: (q?: { page: number; page_size: number; level?: number }) =>
|
||||
get<Paged<Keyword>>('/policies/keywords', q as Record<string, unknown>),
|
||||
keywordAdd: (body: { word: string; level: number }) => post<Keyword>('/policies/keywords', body),
|
||||
keywordRemove: (id: number) => del<{ id: number }>(`/policies/keywords/${id}`),
|
||||
|
||||
// 频次策略
|
||||
frequencies: () => get<Paged<FrequencyPolicy>>('/policies/frequencies'),
|
||||
frequencyCreate: (body: Partial<FrequencyPolicy>) => post<FrequencyPolicy>('/policies/frequencies', body),
|
||||
frequencyUpdate: (id: number, body: Partial<FrequencyPolicy>) => put<FrequencyPolicy>(`/policies/frequencies/${id}`, body),
|
||||
|
||||
// 屏蔽码号
|
||||
blockedCodes: (q?: { page: number; page_size: number }) =>
|
||||
get<Paged<BlockedCode>>('/policies/blocked-codes', q as Record<string, unknown>),
|
||||
blockedCodeAdd: (body: { channel_id: number; code: string }) => post<BlockedCode>('/policies/blocked-codes', body),
|
||||
blockedCodeRemove: (id: number) => del<{ id: number }>(`/policies/blocked-codes/${id}`),
|
||||
|
||||
// 导流策略
|
||||
routeRules: () => get<Paged<RouteRule>>('/policies/route-rules'),
|
||||
routeRuleCreate: (body: Partial<RouteRule>) => post<RouteRule>('/policies/route-rules', body),
|
||||
routeRuleUpdate: (id: number, body: Partial<RouteRule>) => put<RouteRule>(`/policies/route-rules/${id}`, body),
|
||||
routeRuleRemove: (id: number) => del<{ id: number }>(`/policies/route-rules/${id}`),
|
||||
// 签名/码号报备(D16)
|
||||
reports: () => get<Paged<Report>>('/policies/reports'),
|
||||
reportCreate: (body: { type: 'sign' | 'code'; content: string }) => post<Report>('/policies/reports', body),
|
||||
reportReview: (id: number, approve: boolean) => post<Report>(`/policies/reports/${id}/review`, { approve }),
|
||||
reportResubmit: (id: number) => post<Report>(`/policies/reports/${id}/resubmit`, {}),
|
||||
}
|
||||
|
||||
export const KEYWORD_LEVELS = [
|
||||
{ value: 1, label: '一级黑', tag: 'danger', desc: '强制失败' },
|
||||
{ value: 2, label: '二级黑', tag: 'warning', desc: '免审模式专用' },
|
||||
{ value: 3, label: '白名单', tag: 'success', desc: '免审直通' },
|
||||
] as const
|
||||
|
||||
export const RULE_TYPES = [
|
||||
{ value: 'keyword', label: '关键字' },
|
||||
{ value: 'region', label: '地区' },
|
||||
{ value: 'account', label: '账号' },
|
||||
{ value: 'content', label: '内容' },
|
||||
] as const
|
||||
@@ -0,0 +1,15 @@
|
||||
// api/record-progress.ts D25:进度五段纯函数——从 record.ts 拆出(无 request.ts 依赖),
|
||||
// mock(fe4-handlers)可安全运行时引用而不触发 axios/router 模块初始化(否则测试
|
||||
// vi.mock('@/router') hoist 失效,D24 的 record-down.spec 同口径断言不变)。
|
||||
import type { DownRecord } from './record'
|
||||
|
||||
/** 进度占比三工具(页面与测试共用,聚合口径锁定:sending+四态=mobile_count)。 */
|
||||
export function progressOf(r: DownRecord): { key: string; label: string; n: number; color: string }[] {
|
||||
return [
|
||||
{ key: 'success', label: '成功', n: r.success_count, color: '#67c23a' },
|
||||
{ key: 'sending', label: '发送中', n: r.sending_count, color: '#409eff' },
|
||||
{ key: 'unknown', label: '未知', n: r.unknown_count, color: '#909399' },
|
||||
{ key: 'fail', label: '失败', n: r.fail_count, color: '#f56c6c' },
|
||||
{ key: 'intercepted', label: '拦截', n: r.intercepted_count, color: '#e6a23c' },
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
// api/record.ts Day 53(D24):下行批次记录接口(契约先行,Day60 record API 前由
|
||||
// msw mock 承载——FE 全程不被后端阻塞;后端实现须按本契约回填 api/v1/record.go)。
|
||||
import { get, post } from './request'
|
||||
|
||||
/** 下行批次行(message_task 聚合口径;进度四态+发送中=mobile_count)。
|
||||
* intercepted_count 为 message_detail status=5 聚合计数(后端 Day60 实现)。 */
|
||||
export interface DownRecord {
|
||||
id: number
|
||||
task_no: string
|
||||
send_type: number // 1群发 2个性 3定时 4文件
|
||||
sign: string
|
||||
content: string
|
||||
mobile_count: number
|
||||
success_count: number
|
||||
fail_count: number
|
||||
unknown_count: number
|
||||
intercepted_count: number
|
||||
sending_count: number // 待发+提交中(0待发1提交)
|
||||
fee_total: number
|
||||
audit_status: number // 0待 1过 2拒 3免审 4超时
|
||||
status: number // 0待发 1进行中 2完成 3失败 4已取消
|
||||
created_at: string
|
||||
finished_at: string | null
|
||||
}
|
||||
|
||||
/** 下行批次列表查询参数(分页 100/页为验收口径)。 */
|
||||
export interface DownQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
task_no?: string
|
||||
send_type?: number
|
||||
status?: number
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
}
|
||||
|
||||
export interface DownPage {
|
||||
list: DownRecord[]
|
||||
total: number
|
||||
}
|
||||
|
||||
/** 下行批次分页列表。 */
|
||||
export function fetchDownRecords(q: DownQuery): Promise<DownPage> {
|
||||
return get<DownPage>('/record/down', { ...q })
|
||||
}
|
||||
|
||||
/** 拦截号码下载(CSV:mobile,error_code,reason;无拦截时后端返回 404 业务码)。
|
||||
* 原生 fetch 直取(不走 axios XHR——jsdom XHR+blob 与 msw 拦截层不兼容,
|
||||
* 同 fe2 multipart 坑;真实浏览器两条路径等价)。失败时抛 BizError 同构 Error。 */
|
||||
export async function downloadIntercepted(taskId: number): Promise<Blob> {
|
||||
const base = import.meta.env.VITE_API_BASE_URL as string
|
||||
const resp = await fetch(`${base}/record/down/${taskId}/intercepted?format=csv`, {
|
||||
headers: { Accept: 'text/csv' },
|
||||
})
|
||||
const ct = resp.headers.get('content-type') ?? ''
|
||||
if (!resp.ok || ct.includes('application/json')) {
|
||||
// 404 业务码:{code,msg}(无拦截/任务不存在)
|
||||
const body = (await resp.json().catch(() => null)) as { code?: string; msg?: string } | null
|
||||
throw new Error(body?.msg ?? `下载失败 HTTP:${resp.status}`)
|
||||
}
|
||||
return resp.blob()
|
||||
}
|
||||
|
||||
/** 进度占比工具已拆至 record-progress.ts(无 request 依赖,mock 安全引用);此处 re-export 保持既有 import 兼容。 */
|
||||
export { progressOf } from './record-progress'
|
||||
|
||||
/** 拦截明细行(下载预览/测试断言用)。 */
|
||||
export interface InterceptedRow {
|
||||
mobile: string
|
||||
error_code: string
|
||||
reason: string
|
||||
}
|
||||
|
||||
// ---- D25 下行明细(号码级,5 天热数据;契约先行,mock 承载,Day60 后端回填) ----
|
||||
|
||||
/** 号码级明细行(message_detail 口径,与 D22 SendDetail 同构+task_no 冗余便于全局检索)。 */
|
||||
export interface DownDetail {
|
||||
id: number
|
||||
task_id: number
|
||||
task_no: string
|
||||
mobile: string
|
||||
province: string
|
||||
carrier: string // 移动/联通/电信
|
||||
status: number // 0待发 1已提交 2成功 3失败 4未知 5拦截
|
||||
error_code: string // ISC:xxx/通道原始码(空=成功)
|
||||
ext_code: string
|
||||
call_data: string
|
||||
fee: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 明细查询参数(5 天热数据窗口由后端保证;分页 100/页与批次口径一致)。 */
|
||||
export interface DownDetailQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
mobile?: string // 模糊(尾号匹配)
|
||||
task_no?: string // 精确(批次钻入预填)
|
||||
status?: number
|
||||
error_code?: string // 精确(ISC 码筛选联调)
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
}
|
||||
|
||||
export interface DownDetailPage {
|
||||
list: DownDetail[]
|
||||
total: number
|
||||
}
|
||||
|
||||
/** 号码级明细分页(D25)。 */
|
||||
export function fetchDownDetails(q: DownDetailQuery): Promise<DownDetailPage> {
|
||||
return get<DownDetailPage>('/record/down/details', { ...q })
|
||||
}
|
||||
|
||||
/** 通道侧交互记录(CMPP 钻入:channel_log 按 detail 检索)。 */
|
||||
export interface ChannelLogEntry {
|
||||
at: string
|
||||
kind: string // connect/submit/deliver/reclaim…
|
||||
level: number // 0 info/1 warn/2 error
|
||||
msg_id: string
|
||||
detail: string
|
||||
latency_ms: number
|
||||
}
|
||||
|
||||
/** CMPP/通道日志钻入(D25;拦截号未投通道→空列表)。 */
|
||||
export function fetchDetailChannelLogs(detailId: number): Promise<{ total: number; list: ChannelLogEntry[] }> {
|
||||
return get<{ total: number; list: ChannelLogEntry[] }>(`/record/down/details/${detailId}/channel-logs`)
|
||||
}
|
||||
|
||||
// ---- D26 历史记录(>5 天全量,ClickHouse 冷数据;契约先行,Day61 后端回填) ----
|
||||
|
||||
/** 历史明细行(冷数据口径:与 DownDetail 同构+终态锁定,无进行中态)。 */
|
||||
export interface HistoryRecord {
|
||||
id: number
|
||||
task_id: number
|
||||
task_no: string
|
||||
mobile: string
|
||||
province: string
|
||||
carrier: string
|
||||
status: number // 冷数据仅终态:2成功/3失败/4未知/5拦截
|
||||
error_code: string
|
||||
fee: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 历史查询参数(时间范围为冷数据主索引;后端 ClickHouse 分区裁剪,mock 同语义)。 */
|
||||
export interface HistoryQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
mobile?: string
|
||||
task_no?: string
|
||||
status?: number
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
}
|
||||
|
||||
export interface HistoryPage {
|
||||
list: HistoryRecord[]
|
||||
total: number
|
||||
}
|
||||
|
||||
/** 全量历史明细分页(D26;查询 <3s 验收)。 */
|
||||
export function fetchHistoryRecords(q: HistoryQuery): Promise<HistoryPage> {
|
||||
return get<HistoryPage>('/record/history', { ...q })
|
||||
}
|
||||
|
||||
/** 异步导出任务(D26;状态机 pending→ready/failed,完成后下载中心取件)。 */
|
||||
export interface ExportTask {
|
||||
id: number
|
||||
scope: string // 导出范围描述(筛选条件快照)
|
||||
status: 'pending' | 'ready' | 'failed'
|
||||
total: number // 匹配行数(ready 时)
|
||||
created_at: string
|
||||
expires_at: string // 下载链接有效期(默认 24h)
|
||||
}
|
||||
|
||||
/** 提交异步导出(当前筛选条件快照;返回任务号,轮询下载中心)。 */
|
||||
export function createHistoryExport(q: Omit<HistoryQuery, 'page' | 'page_size'>): Promise<{ id: number }> {
|
||||
return post<{ id: number }>('/record/history/export', { ...q })
|
||||
}
|
||||
|
||||
/** 下载中心:导出任务列表(D26;Day62 MinIO 落地后切真实下载)。 */
|
||||
export function fetchHistoryExports(): Promise<{ list: ExportTask[] }> {
|
||||
return get<{ list: ExportTask[] }>('/record/history/exports')
|
||||
}
|
||||
|
||||
// ---- D27 上行记录(message_uplink 口径;契约先行,mock 承载,Day60 后端回填) ----
|
||||
|
||||
/** 上行记录行(message_uplink:Deliver MO→码号分配→落库;Day49 后端已交付)。 */
|
||||
export interface UplinkRecord {
|
||||
id: number
|
||||
dest_code: string // 接入码号(归属分配依据:精确>前缀>admin 兜底)
|
||||
src_mobile: string // 上行来源手机号
|
||||
content: string
|
||||
account_id: number // 归属账号
|
||||
account_name: string // 冗余展示(mock 口径;真实联调由后端 join)
|
||||
channel_id: number
|
||||
recv_at: string
|
||||
match_task_id: number // 0=未匹配(15 天窗口外/无下行);>0=窗口内最近下行明细
|
||||
}
|
||||
|
||||
/** 上行查询参数(码号/手机号为主筛选;matched 三态筛选)。 */
|
||||
export interface UplinkQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
dest_code?: string // 精确/前缀(码号两级匹配同口径)
|
||||
src_mobile?: string // 模糊(尾号匹配)
|
||||
matched?: number // 0=未匹配 1=已匹配(缺省=全部)
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
}
|
||||
|
||||
export interface UplinkPage {
|
||||
list: UplinkRecord[]
|
||||
total: number
|
||||
}
|
||||
|
||||
/** 上行记录分页(D27;15 天匹配窗口由后端保证,前端提示口径)。 */
|
||||
export function fetchUplinkRecords(q: UplinkQuery): Promise<UplinkPage> {
|
||||
return get<UplinkPage>('/record/uplink', { ...q })
|
||||
}
|
||||
|
||||
/** 提交上行导出(权限:uplink:export;无权限后端 403,按钮前端隐藏为第一道闸)。
|
||||
* 复用 D26 异步导出任务模型(下载中心取件),scope 快照含上行筛选条件。 */
|
||||
export function createUplinkExport(q: Omit<UplinkQuery, 'page' | 'page_size'>): Promise<{ id: number }> {
|
||||
return post<{ id: number }>('/record/uplink/export', { ...q })
|
||||
}
|
||||
|
||||
// ---- D28 回执重推工具+手动配对(message_report 30 天窗口;契约先行,mock 承载,Day58 后端 repush 域回填) ----
|
||||
|
||||
/** 回执行(message_report 口径;Day56 消费者已落库,30 天重推窗口数据源)。 */
|
||||
export interface RepushReport {
|
||||
id: number
|
||||
detail_id: number
|
||||
task_no: string // 冗余便于检索(后端 join message_detail)
|
||||
mobile: string
|
||||
account_id: number
|
||||
status: 'SUCCESS' | 'FAILURE' | 'UNKNOWN' // Day55 三态
|
||||
raw_code: string // 通道原始码(DELIVRD/GB:0001…)
|
||||
error_code: string
|
||||
report_at: string
|
||||
push_status: number // 0未推 1已推 2推送失败(重推候选)
|
||||
pushed_at: string | null
|
||||
}
|
||||
|
||||
/** 回执查询参数(重推工具筛选)。 */
|
||||
export interface RepushQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
account_id?: number
|
||||
mobile?: string // 尾号模糊
|
||||
task_no?: string // 精确
|
||||
status?: 'SUCCESS' | 'FAILURE' | 'UNKNOWN'
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
}
|
||||
|
||||
/** 回执分页(D28)。 */
|
||||
export function fetchRepushReports(q: RepushQuery): Promise<{ list: RepushReport[]; total: number }> {
|
||||
return get<{ list: RepushReport[]; total: number }>('/record/repush', { ...q })
|
||||
}
|
||||
|
||||
/** 重推请求(时间窗必填;账号/手机号收窄;30 天窗口后端强校验=第二道闸)。 */
|
||||
export interface RepushRequest {
|
||||
account_id?: number
|
||||
mobiles?: string[]
|
||||
start_time: string
|
||||
end_time: string
|
||||
}
|
||||
|
||||
/** 重推受理结果(异步任务:count=窗口内匹配回执数,推送反馈同批挂账 Day60)。 */
|
||||
export interface RepushResult {
|
||||
task_id: number
|
||||
count: number
|
||||
}
|
||||
|
||||
/** 提交回执重推(30 天窗口校验:超窗后端 ISC:400 业务错)。 */
|
||||
export function createRepush(req: RepushRequest): Promise<RepushResult> {
|
||||
return post<RepushResult>('/record/repush', req)
|
||||
}
|
||||
|
||||
/** 手动配对四方式(实施计划 5.5:3h 外无状态明细手工指定终态)。 */
|
||||
export type PairMode = 'msg_mobile' | 'detail' | 'task_time' | 'time_mobile'
|
||||
|
||||
/** 配对请求(按 mode 取对应字段;target_status 指定终态,资金口径后端同 Day57)。 */
|
||||
export interface PairRequest {
|
||||
mode: PairMode
|
||||
msg_id?: string // msg_mobile:通道 msg_id+手机号精确
|
||||
mobile?: string // msg_mobile/time_mobile:手机号
|
||||
detail_id?: number // detail:明细雪花 ID 精确
|
||||
task_no?: string // task_time:任务号
|
||||
start_time?: string // task_time/time_mobile:时间窗
|
||||
end_time?: string
|
||||
target_status: 2 | 3 | 4 // 成功(不退费)/失败(退款)/未知(冻结释放)
|
||||
}
|
||||
|
||||
/** 配对结果(matched=圈中挂起明细;updated=回写终态;skipped=已终态跳过)。 */
|
||||
export interface PairResult {
|
||||
matched: number
|
||||
updated: number
|
||||
skipped: number
|
||||
}
|
||||
|
||||
/** 提交手动配对(结果回写挂起列表:updated 行离场)。 */
|
||||
export function createManualPair(req: PairRequest): Promise<PairResult> {
|
||||
return post<PairResult>('/record/repush/pair', req)
|
||||
}
|
||||
|
||||
/** 挂起明细行(手动配对数据源:3h 外仍 status=1 的明细)。 */
|
||||
export interface PendingDetail {
|
||||
detail_id: number
|
||||
task_no: string
|
||||
msg_id: string // 通道 msg_id(msg_mobile 配对键)
|
||||
mobile: string
|
||||
content: string
|
||||
sent_at: string
|
||||
age_hours: number // 挂起时长(>3 为可配对口径)
|
||||
}
|
||||
|
||||
/** 挂起明细分页(配对页列表;仅 3h 外)。 */
|
||||
export function fetchPendingDetails(
|
||||
q: { page: number; page_size: number; mobile?: string; task_no?: string },
|
||||
): Promise<{ list: PendingDetail[]; total: number }> {
|
||||
return get<{ list: PendingDetail[]; total: number }>('/record/repush/pending', { ...q })
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import axios, { AxiosError, type AxiosResponse, type InternalAxiosRequestConfig } from 'axios'
|
||||
import router from '@/router'
|
||||
import { getToken, clearToken } from '@/utils/auth'
|
||||
import { reportFeError } from '@/utils/error-reporter'
|
||||
import { ApiResp, ISC } from './types'
|
||||
|
||||
/** 业务错误(code 为 ISC 码或 HTTP:xxx)。 */
|
||||
export class BizError extends Error {
|
||||
readonly code: string
|
||||
constructor(code: string, msg: string) {
|
||||
super(msg)
|
||||
this.name = 'BizError'
|
||||
this.code = code
|
||||
}
|
||||
}
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL as string,
|
||||
timeout: 15000,
|
||||
})
|
||||
|
||||
function newTraceId(): string {
|
||||
if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
|
||||
return crypto.randomUUID().replaceAll('-', '')
|
||||
}
|
||||
return Date.now().toString(36) + Math.random().toString(36).slice(2, 10)
|
||||
}
|
||||
|
||||
service.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
||||
const token = getToken()
|
||||
if (token) config.headers.Authorization = `Bearer ${token}`
|
||||
config.headers['X-Trace-Id'] = newTraceId()
|
||||
return config
|
||||
})
|
||||
|
||||
service.interceptors.response.use(
|
||||
(resp: AxiosResponse) => {
|
||||
const body = resp.data as ApiResp
|
||||
// 非统一响应(文件流等)原样透出
|
||||
if (typeof body?.code !== 'string') return body as unknown as AxiosResponse
|
||||
if (body.code === ISC.OK) {
|
||||
// 成功:调用方直接拿到 data(后端约定 {code,msg,data})
|
||||
return (body.data ?? body) as unknown as AxiosResponse
|
||||
}
|
||||
// 业务失败:统一 BizError,由调用方或全局提示处理
|
||||
if (body.code === ISC.UNAUTHORIZED) {
|
||||
clearToken()
|
||||
router.push('/login')
|
||||
}
|
||||
return Promise.reject(new BizError(body.code, body.msg))
|
||||
},
|
||||
(err: AxiosError<ApiResp>) => {
|
||||
const status = err.response?.status
|
||||
const code = err.response?.data?.code ?? `HTTP:${status ?? 0}`
|
||||
const msg = err.response?.data?.msg ?? err.message ?? '网络异常'
|
||||
if (status === 401) {
|
||||
clearToken()
|
||||
router.push('/login')
|
||||
}
|
||||
// Day 53(runbook §6.4):HTTP 5xx/网络层错误上报后端落库(trace_id 关联日志链);
|
||||
// 401/4xx 属业务语义不上报;上报接口自身失败由 error-reporter 静默吞掉防递归。
|
||||
if ((status != null && status >= 500) || status == null) {
|
||||
const traceId = (err.config?.headers?.['X-Trace-Id'] as string) ?? ''
|
||||
reportFeError({
|
||||
kind: 'http',
|
||||
page_url: typeof window !== 'undefined' ? window.location.href : '',
|
||||
message: `${code} ${msg}`.slice(0, 1024),
|
||||
ua: typeof navigator !== 'undefined' ? navigator.userAgent : '',
|
||||
trace_id: traceId,
|
||||
})
|
||||
}
|
||||
return Promise.reject(new BizError(code, msg))
|
||||
},
|
||||
)
|
||||
|
||||
/** 泛型请求:成功直接返回 data。 */
|
||||
export function get<T>(url: string, params?: Record<string, unknown>): Promise<T> {
|
||||
return service.get(url, { params }) as Promise<T>
|
||||
}
|
||||
|
||||
/** multipart 表单上传(axios 自动识别 FormData 设 boundary)。 */
|
||||
export function postForm<T>(url: string, form: FormData): Promise<T> {
|
||||
return service.post(url, form) as Promise<T>
|
||||
}
|
||||
|
||||
export function post<T>(url: string, body?: unknown): Promise<T> {
|
||||
return service.post(url, body) as Promise<T>
|
||||
}
|
||||
|
||||
export function put<T>(url: string, body?: unknown): Promise<T> {
|
||||
return service.put(url, body) as Promise<T>
|
||||
}
|
||||
|
||||
export function del<T>(url: string): Promise<T> {
|
||||
return service.delete(url) as Promise<T>
|
||||
}
|
||||
|
||||
export default service
|
||||
@@ -0,0 +1,38 @@
|
||||
import { del, get, post, put } from './request'
|
||||
|
||||
/** 导流规则(Day 38 引擎;account 型=账号级定向通道)。 */
|
||||
export interface RouteRule {
|
||||
id: number
|
||||
account_id: number
|
||||
channel_id: number
|
||||
rule_type: 'account' | 'keyword' | string
|
||||
rule_config: string
|
||||
priority: number
|
||||
status: number
|
||||
}
|
||||
|
||||
/** 账号通道绑定快照(Day 63;rule_id=0=未绑定,走四步智能路由)。 */
|
||||
export interface AccountSteer {
|
||||
account_id: number
|
||||
rule_id: number
|
||||
channel_id: number
|
||||
channel_name: string
|
||||
channel_code: string
|
||||
channel_status: number
|
||||
}
|
||||
|
||||
export const routeApi = {
|
||||
/** 账号当前通道绑定(含通道名/状态快照)。 */
|
||||
accountSteer: (id: number) => get<AccountSteer>(`/accounts/${id}/channel-steer`),
|
||||
/** 绑定/原子切换(channel_id>0)/解绑(0=回退智能路由);保存即生效。 */
|
||||
setAccountSteer: (id: number, channelId: number) =>
|
||||
put<{ account_id: number; rule_id: number; channel_id?: number }>(
|
||||
`/accounts/${id}/channel-steer`,
|
||||
{ channel_id: channelId },
|
||||
),
|
||||
// ---- 导流规则 CRUD(后期独立管理页预留) ----
|
||||
list: () => get<{ total: number; list: RouteRule[] }>('/route-rules'),
|
||||
create: (body: Partial<RouteRule>) => post<RouteRule>('/route-rules', body),
|
||||
update: (id: number, fields: Record<string, unknown>) => put<{ id: number }>(`/route-rules/${id}`, fields),
|
||||
remove: (id: number) => del<{ id: number }>(`/route-rules/${id}`),
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/** 结算域 API(S2 验收版;real 模式直连网关,openapi v1.3.0 契约)。 */
|
||||
import { get, post, put, del } from './request'
|
||||
import { getToken } from '@/utils/auth'
|
||||
|
||||
/** 消耗日汇总行(账号×业务×天;fee_total 单位=条)。 */
|
||||
export interface ConsumeRow {
|
||||
id: number
|
||||
account_id: number
|
||||
business: string
|
||||
stat_date: string
|
||||
submit_count: number
|
||||
success_count: number
|
||||
fail_count: number
|
||||
unknown_count: number
|
||||
fee_total: number
|
||||
}
|
||||
|
||||
/** 充值订单(pay_status: 0待确认 1已到账 2失败;count=条,amount=元)。 */
|
||||
export interface BillingOrder {
|
||||
id: number
|
||||
order_no: string
|
||||
account_id: number
|
||||
amount: number
|
||||
count: number
|
||||
pay_type: string
|
||||
pay_status: number
|
||||
operator: string
|
||||
paid_at: string | null
|
||||
remark: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 下家月结单(status: 0草稿 1已确认 2已结账;amount 单位=元)。 */
|
||||
export interface SettleCustomerBill {
|
||||
id: number
|
||||
settle_no: string
|
||||
account_id: number
|
||||
period: string
|
||||
success_count: number
|
||||
amount: number
|
||||
status: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 账单按天明细行。 */
|
||||
export interface BillDayRow {
|
||||
day: string
|
||||
success_count: number
|
||||
amount: number
|
||||
}
|
||||
|
||||
/** 阶梯价档位。 */
|
||||
export interface SettleLadder {
|
||||
id: number
|
||||
owner_type: 'account' | 'upstream'
|
||||
owner_id: number
|
||||
tier_from: number
|
||||
price: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 生成/重算统计。 */
|
||||
export interface GenerateResult {
|
||||
generated: number
|
||||
recalculated: number
|
||||
skipped: number
|
||||
}
|
||||
|
||||
// ---- 利润分析(S2-D5;金额=元) ----
|
||||
|
||||
/** 用户利润行(revenue=时间线价收入;cost=通道成本占比分摊;rebate=直线下级返点 R4)。 */
|
||||
export interface UserProfitRow {
|
||||
account_id: number
|
||||
username: string
|
||||
role: string
|
||||
success_count: number
|
||||
revenue: number
|
||||
cost: number
|
||||
rebate: number
|
||||
profit: number
|
||||
}
|
||||
|
||||
/** 用户利润汇总(与列表同 scope)。 */
|
||||
export interface UserProfitSummary {
|
||||
count: number
|
||||
total_revenue: number
|
||||
total_cost: number
|
||||
total_rebate: number
|
||||
platform_profit: number
|
||||
}
|
||||
|
||||
/** 用户利润结果集。 */
|
||||
export interface UserProfitResult {
|
||||
list: UserProfitRow[]
|
||||
total: number
|
||||
summary: UserProfitSummary
|
||||
}
|
||||
|
||||
/** 通道利润行(revenue=全平台用户收入×通道成功占比分摊;cost=通道时间线价直算)。 */
|
||||
export interface ChannelProfitRow {
|
||||
channel_id: number
|
||||
name: string
|
||||
upstream_id: number
|
||||
success_count: number
|
||||
revenue: number
|
||||
cost: number
|
||||
profit: number
|
||||
}
|
||||
|
||||
interface Paged<T> { total: number; list: T[] }
|
||||
|
||||
export const settleApi = {
|
||||
// ---- 消耗日汇总(D2) ----
|
||||
consume: (params: Record<string, unknown>) => get<Paged<ConsumeRow>>('/billing/consume', params),
|
||||
aggregate: (date?: string) => post<{ day: string; account_rows: number; channel_rows: number }>('/ops/settle/aggregate', date ? { date } : {}),
|
||||
|
||||
// ---- 充值订单(D3) ----
|
||||
orders: (params: Record<string, unknown>) => get<Paged<BillingOrder>>('/billing/orders', params),
|
||||
createOrder: (body: { account_id: number; count: number; amount?: number; pay_type?: string; remark?: string }) =>
|
||||
post<BillingOrder>('/billing/orders', body),
|
||||
confirmOrder: (id: number) => post<{ order_no: string; balance: number; count: number }>(`/billing/orders/${id}/confirm`),
|
||||
rejectOrder: (id: number, remark?: string) => post<BillingOrder>(`/billing/orders/${id}/reject`, { remark }),
|
||||
|
||||
// ---- 下家月结(D4) ----
|
||||
customerBills: (params: Record<string, unknown>) => get<Paged<SettleCustomerBill>>('/settle/customer', params),
|
||||
generateCustomer: (period: string) => post<GenerateResult>('/settle/customer/generate', { period }),
|
||||
customerBillDetail: (id: number) => get<{ bill: SettleCustomerBill; days: BillDayRow[] }>(`/settle/customer/${id}`),
|
||||
confirmCustomerBill: (id: number) => post<null>(`/settle/customer/${id}/confirm`),
|
||||
settleCustomerBill: (id: number, pay_type?: string) => post<Record<string, unknown>>(`/settle/customer/${id}/settle`, { pay_type }),
|
||||
exportCustomerBill: (id: number) => `/settle/customer/${id}/export`,
|
||||
|
||||
// ---- 阶梯价(D4) ----
|
||||
ladders: (owner_type?: string, owner_id?: number) =>
|
||||
get<SettleLadder[]>('/settle/ladder', { ...(owner_type ? { owner_type } : {}), ...(owner_id ? { owner_id } : {}) }),
|
||||
createLadder: (body: { owner_type: string; owner_id: number; tier_from: number; price: number }) =>
|
||||
post<SettleLadder>('/settle/ladder', body),
|
||||
deleteLadder: (id: number) => del<null>(`/settle/ladder/${id}`),
|
||||
updateLadder: (id: number, body: { tier_from?: number; price?: number }) => put<null>(`/settle/ladder/${id}`, body),
|
||||
|
||||
// ---- 利润分析(D5;平台角色端点) ----
|
||||
profitUsers: (params: { date_from: string; date_to: string; parent_id?: number; page?: number; page_size?: number }) =>
|
||||
get<UserProfitResult>('/stats/profit/users', params),
|
||||
profitChannels: (params: { date_from: string; date_to: string; channel_id?: number; page?: number; page_size?: number }) =>
|
||||
get<{ list: ChannelProfitRow[]; total: number }>('/stats/profit/channels', params),
|
||||
}
|
||||
|
||||
/** 导出下载(文件流需带 Authorization,axios JSON 拦截器不适配,走 fetch+blob)。 */
|
||||
export async function downloadBill(url: string, filename: string): Promise<void> {
|
||||
const base = (import.meta.env.VITE_API_BASE_URL as string) ?? ''
|
||||
const resp = await fetch(base + url, {
|
||||
headers: { Authorization: `Bearer ${getToken() ?? ''}` },
|
||||
})
|
||||
if (!resp.ok) throw new Error(`下载失败 HTTP ${resp.status}`)
|
||||
const blob = await resp.blob()
|
||||
const a = document.createElement('a')
|
||||
a.href = URL.createObjectURL(blob)
|
||||
a.download = filename
|
||||
a.click()
|
||||
URL.revokeObjectURL(a.href)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
// api/sms.ts Day 41(D17):发送域接口——预估/模板。
|
||||
import { get, post, put, del, postForm } from './request'
|
||||
|
||||
/** 计费预估(Day 41 后端 /send/estimate;与 utils/sms smsLength 双保险)。 */
|
||||
export interface Estimate {
|
||||
valid_count: number
|
||||
chars: number
|
||||
segments: number
|
||||
total_fee: number
|
||||
}
|
||||
|
||||
/** 提交受理结果(Day 43 修复循环;/send/submit 最小提交链)。 */
|
||||
export interface SubmitResult {
|
||||
task_no: string
|
||||
task_id: number
|
||||
audit_status: number // 0待审 1过 2拒 3免审
|
||||
audit_hint: string
|
||||
valid_count: number
|
||||
segments: number
|
||||
total_fee: number
|
||||
schedule_at?: string // RFC3339(定时任务)
|
||||
}
|
||||
|
||||
/** 模板(Day 41;/templates CRUD)。 */
|
||||
export interface SmsTemplate {
|
||||
id: number
|
||||
account_id: number
|
||||
name: string
|
||||
content: string
|
||||
variables: string
|
||||
status: 0 | 1 | -1 // 0待审 1通过 -1拒绝
|
||||
audit_at: string | null
|
||||
reason: string
|
||||
}
|
||||
|
||||
/** 号码文件导入结果(Day 44;/files/numbers/import)。 */
|
||||
export interface ImportResult {
|
||||
total: number
|
||||
valid: number
|
||||
duplicated: number
|
||||
invalid: number
|
||||
header_skipped: boolean
|
||||
mobiles: string[] // 合格号码全量(≤10000;可直接进入 estimate/submit)
|
||||
preview: string[] // 前 50 预览
|
||||
object_key: string // MinIO 对象键
|
||||
}
|
||||
|
||||
/** 预检拦截项(Day 42;/send/precheck)。 */
|
||||
export interface BlockItem {
|
||||
mobile: string
|
||||
interceptor: 'blacklist' | 'frequency' | 'sign' | 'unsubscribe' | 'region'
|
||||
code: string
|
||||
msg: string
|
||||
}
|
||||
|
||||
/** 预检结果(Day 42)。 */
|
||||
export interface PrecheckResp {
|
||||
total: number
|
||||
passed: number
|
||||
blocked: BlockItem[]
|
||||
}
|
||||
|
||||
/** 发送任务(Day 43/D19;/send/tasks)。 */
|
||||
export interface SendTask {
|
||||
id: number
|
||||
task_no: string
|
||||
account_id: number
|
||||
send_type: number // 1群发 2个性 3定时 4文件
|
||||
content: string
|
||||
sign: string
|
||||
mobile_count: number
|
||||
success_count: number
|
||||
fail_count: number
|
||||
unknown_count?: number // Day51 回执三态归一化后回填;当前链路可能缺省
|
||||
fee_total: number
|
||||
audit_status: number // 0待审 1通过 2拒绝 3免审 4超时
|
||||
status: number // 0待发 1发送中 2完成 3已取消
|
||||
schedule_at: string | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 任务列表查询(D19)。 */
|
||||
export interface TaskQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
account_id?: number
|
||||
status?: number // -1 全部
|
||||
audit_status?: number // -1 全部
|
||||
send_type?: number // 0 全部
|
||||
}
|
||||
|
||||
/** 发送明细(Day 46/D22;/send/tasks/:id/details)。 */
|
||||
export interface SendDetail {
|
||||
id: number
|
||||
task_id: number
|
||||
account_id: number
|
||||
mobile: string
|
||||
content: string
|
||||
province: string
|
||||
carrier: string
|
||||
status: number // 0待发 1已提交 2成功 3失败 4未知 5拦截
|
||||
error_code: string // ISC:xxx/通道原始码
|
||||
ext_code: string // Day 46:扩展码透传
|
||||
call_data: string // Day 46:用户回传数据
|
||||
fee: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 明细分页查询(D22)。 */
|
||||
export interface DetailQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
status?: number // -1 全部
|
||||
error_code?: string
|
||||
}
|
||||
|
||||
export const smsApi = {
|
||||
estimate: (body: {
|
||||
mobiles: string[]
|
||||
content?: string
|
||||
template_id?: number
|
||||
variables?: Record<string, string>
|
||||
sign?: string
|
||||
send_type?: number
|
||||
send_at?: string
|
||||
}) => post<Estimate>('/send/estimate', body),
|
||||
/** 提交受理(Day 43 修复循环:最小提交链;限流/扣费/下发 Day45/46)。 */
|
||||
submit: (body: {
|
||||
task_no?: string // 幂等键,缺省服务端生成
|
||||
account_id?: number
|
||||
mobiles: string[]
|
||||
content?: string
|
||||
template_id?: number
|
||||
variables?: Record<string, string>
|
||||
sign?: string
|
||||
send_type?: number
|
||||
send_at?: string
|
||||
}) => post<SubmitResult>('/send/submit', body),
|
||||
/** 发送预检(Day 42;拦截器链 DryRun:黑名单三级/频次滑窗/签名/退订/地区)。 */
|
||||
precheck: (body: {
|
||||
mobiles: string[]
|
||||
content?: string
|
||||
template_id?: number
|
||||
variables?: Record<string, string>
|
||||
account_id?: number
|
||||
send_type?: number
|
||||
}) => post<PrecheckResp>('/send/precheck', body),
|
||||
templateList: (q?: { page: number; page_size: number; status?: number; name?: string; account_id?: number }) =>
|
||||
get<{ total: number; list: SmsTemplate[] }>('/templates', q as unknown as Record<string, unknown>),
|
||||
templateCreate: (body: { account_id: number; name: string; content: string }) =>
|
||||
post<SmsTemplate>('/templates', body),
|
||||
templateUpdate: (id: number, body: Partial<Pick<SmsTemplate, 'name' | 'content'>>) =>
|
||||
put<{ id: number }>(`/templates/${id}`, body),
|
||||
templateRemove: (id: number) => del<{ id: number }>(`/templates/${id}`),
|
||||
templateReview: (id: number, pass: boolean, reason?: string) =>
|
||||
put<{ id: number }>(`/templates/${id}/review`, { pass, reason }),
|
||||
/** 批量审核(Day 44/D20;已审跳过,ok=成功翻转数)。 */
|
||||
templateBatchReview: (ids: number[], pass: boolean, reason?: string) =>
|
||||
put<{ ok: number; total: number }>('/templates/batch-review', { ids, pass, reason }),
|
||||
|
||||
/** 号码文件导入(Day 44;TXT/CSV/XLSX→后端解析→MinIO)。 */
|
||||
fileImport: (file: File, accountId?: number) => {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
if (accountId) fd.append('account_id', String(accountId))
|
||||
return postForm<ImportResult>('/files/numbers/import', fd)
|
||||
},
|
||||
|
||||
/** 任务列表(D19;/send/tasks——定时任务列表数据源)。 */
|
||||
tasks: (q?: Partial<TaskQuery>) =>
|
||||
get<{ total: number; list: SendTask[] }>('/send/tasks', (q ?? {}) as unknown as Record<string, unknown>),
|
||||
/** 取消任务(仅 status=0 待发可取消;冲突 ISC:038)。 */
|
||||
taskCancel: (id: number) => post<SendTask>(`/send/tasks/${id}/cancel`, {}),
|
||||
/** 定时任务改期(仅 send_type=3 且待发;send_at "YYYY-MM-DD HH:mm" 未来时刻)。 */
|
||||
taskReschedule: (id: number, sendAt: string) => put<SendTask>(`/send/tasks/${id}/reschedule`, { send_at: sendAt }),
|
||||
/** 任务明细分页(Day 46/D22 结果反馈页;status/error_code 过滤;含 ext_code/call_data)。 */
|
||||
taskDetails: (id: number, q?: Partial<DetailQuery>) =>
|
||||
get<{ total: number; list: SendDetail[] }>(`/send/tasks/${id}/details`, (q ?? {}) as unknown as Record<string, unknown>),
|
||||
|
||||
/** 审核中心(Day 43;待审消息列表/通过/拒绝)。 */
|
||||
auditMessages: (q?: Partial<TaskQuery>) =>
|
||||
get<{ total: number; list: SendTask[] }>('/audits/messages', (q ?? {}) as unknown as Record<string, unknown>),
|
||||
auditApprove: (id: number, reason?: string) => post<unknown>(`/audits/messages/${id}/approve`, { reason: reason ?? '' }),
|
||||
auditReject: (id: number, reason: string) => post<unknown>(`/audits/messages/${id}/reject`, { reason }),
|
||||
/** 审核态计数(Day 45/D21 审核中心 Tab 徽标;by_status key 为审核态字符串)。 */
|
||||
auditCounts: () => get<AuditCounts>('/audits/messages/counts'),
|
||||
/** 批量审核(Day 45/D21;已审跳过幂等,拒绝原因必填)。 */
|
||||
auditBatchReview: (ids: number[], pass: boolean, reason?: string) =>
|
||||
post<{ ok: number; total: number }>('/audits/messages/batch-review', { ids, pass, reason }),
|
||||
}
|
||||
|
||||
/** 审核态计数(D21)。 */
|
||||
export interface AuditCounts {
|
||||
total: number
|
||||
by_status: Record<string, number> // "0"待审/"1"过/"2"拒/"3"免/"4"超时
|
||||
}
|
||||
|
||||
// ---- D24-25 重构(2026-09-14):短信下行明细 v2 契约(契约先行,msw fe4-handlers ----
|
||||
// smsDownlinkHandlers 承载;Day60 record API 回填按本契约实现)。数据口径:
|
||||
// message_detail(热 5 天) JOIN task/account/channel + message_report_seg 聚合
|
||||
// (raw_code 通道原始状态码/耗时);提交来源=task.source(1API 2CMPP 3SMPP 4WEB,
|
||||
// 后端迁移 v14 已随 Day60 回填落地);通道号码=channel.code+ext_code 拼接。
|
||||
|
||||
/** 提交来源枚举(task.source)。 */
|
||||
export const SOURCE_OPTIONS = [
|
||||
{ value: 1, label: 'API接口' },
|
||||
{ value: 2, label: 'CMPP接入' },
|
||||
{ value: 3, label: 'SMPP接入' },
|
||||
{ value: 4, label: 'Web控制台' },
|
||||
] as const
|
||||
|
||||
export function sourceText(s: number): string {
|
||||
return SOURCE_OPTIONS.find((o) => o.value === s)?.label ?? String(s)
|
||||
}
|
||||
|
||||
/** 省市两级静态数据(UI 级联;后端 province 仅省级生效——市级无库列,二期回填)。 */
|
||||
export const REGION_OPTIONS = [
|
||||
{ value: '北京', label: '北京', children: [{ value: '北京', label: '北京' }] },
|
||||
{ value: '上海', label: '上海', children: [{ value: '上海', label: '上海' }] },
|
||||
{ value: '广东', label: '广东', children: [{ value: '广州', label: '广州' }, { value: '深圳', label: '深圳' }, { value: '东莞', label: '东莞' }] },
|
||||
{ value: '江苏', label: '江苏', children: [{ value: '南京', label: '南京' }, { value: '苏州', label: '苏州' }] },
|
||||
{ value: '浙江', label: '浙江', children: [{ value: '杭州', label: '杭州' }, { value: '宁波', label: '宁波' }] },
|
||||
{ value: '四川', label: '四川', children: [{ value: '成都', label: '成都' }, { value: '绵阳', label: '绵阳' }] },
|
||||
{ value: '山东', label: '山东', children: [{ value: '济南', label: '济南' }, { value: '青岛', label: '青岛' }] },
|
||||
{ value: '河南', label: '河南', children: [{ value: '郑州', label: '郑州' }, { value: '洛阳', label: '洛阳' }] },
|
||||
{ value: '湖北', label: '湖北', children: [{ value: '武汉', label: '武汉' }] },
|
||||
{ value: '湖南', label: '湖南', children: [{ value: '长沙', label: '长沙' }] },
|
||||
{ value: '福建', label: '福建', children: [{ value: '福州', label: '福州' }, { value: '厦门', label: '厦门' }] },
|
||||
{ value: '陕西', label: '陕西', children: [{ value: '西安', label: '西安' }] },
|
||||
]
|
||||
|
||||
/** 明细状态筛选(0待发 1已提交 2成功 3失败 4未知 5拦截;"发送中"=0/1 两段)。 */
|
||||
export const DOWNLINK_STATUS_OPTIONS = [
|
||||
{ value: 0, label: '发送中(待发)' },
|
||||
{ value: 1, label: '发送中(已提交)' },
|
||||
{ value: 2, label: '成功' },
|
||||
{ value: 3, label: '失败' },
|
||||
{ value: 4, label: '未知' },
|
||||
{ value: 5, label: '拦截' },
|
||||
] as const
|
||||
|
||||
export function downlinkStatusText(s: number): string {
|
||||
return DOWNLINK_STATUS_OPTIONS.find((o) => o.value === s)?.label.replace(/\(.*\)/, '') ?? String(s)
|
||||
}
|
||||
|
||||
/** 号码级明细行(v2 富表格口径:账号主副/通道码号/三时间/条数耗时/原始码+转义码)。 */
|
||||
export interface DownlinkDetailRow {
|
||||
batch_id: number // =message_task.id(批次ID)
|
||||
task_no: string
|
||||
account_id: number
|
||||
account_name: string // 主账号(username/ID 串,如 264305)
|
||||
account_sub: string // 副标题(账号备注/公司线,如 广东移动-行业-壹通道)
|
||||
parent_account_id: number
|
||||
channel_id: number
|
||||
channel_code: string
|
||||
channel_name: string
|
||||
channel_number: string // code+ext_code 拼接(如 106903316108;10659* 前缀模糊)
|
||||
ext_code: string
|
||||
mobile: string
|
||||
carrier: string // 移动/联通/电信
|
||||
province: string
|
||||
content: string
|
||||
created_at: string // 提交
|
||||
send_at: string | null // 发送(拦截/待发为 null)
|
||||
report_at: string | null // 回执(未达为 null)
|
||||
fee: number // 计费条数(≠段数,Day52 定论)
|
||||
duration_s: number | null // 通道耗时=回执-发送(秒;筛选用)
|
||||
status: number
|
||||
raw_code: string // 通道原始状态码(DELIVRD/FD:047…;拦截/待发为空)
|
||||
error_code: string // 转义码(ISC:xxx/UT:xxx;成功为空)
|
||||
source: number
|
||||
call_data: string
|
||||
}
|
||||
|
||||
/** 查询参数(三行筛选+展开高级;分页默认 10/页;时间默认当天)。 */
|
||||
export interface DownlinkDetailQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
batch_id?: string // 精确(数字 id 或 task_no 双兼容——批次钻入链)
|
||||
account_id?: number
|
||||
parent_account_id?: number // 上级账号(后端按 path 子孙集展开)
|
||||
mobile?: string // 模糊
|
||||
content?: string // 模糊
|
||||
fee_op?: '>=' | '=' | '<='
|
||||
fee?: number
|
||||
source?: number
|
||||
carrier?: string
|
||||
province?: string
|
||||
city?: string // UI 占位(后端市级二期,mock 忽略)
|
||||
channel_id?: number
|
||||
status?: number
|
||||
channel_number?: string // 前缀模糊(10659* / 10659)
|
||||
call_data?: string
|
||||
raw_code?: string // 详细状态精确(如 FD:047)
|
||||
raw_codes?: string[] // 指定状态多值(逗号输入)
|
||||
duration_op?: '>='
|
||||
duration_s?: number
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
}
|
||||
|
||||
export interface DownlinkDetailPage {
|
||||
list: DownlinkDetailRow[]
|
||||
total: number
|
||||
}
|
||||
|
||||
/** 号码级明细分页(/sms/downlink-details)。 */
|
||||
export function fetchDownlinkDetails(q: DownlinkDetailQuery): Promise<DownlinkDetailPage> {
|
||||
return get<DownlinkDetailPage>('/sms/downlink-details', { ...q } as Record<string, unknown>)
|
||||
}
|
||||
|
||||
// ---- 纯工具(组件渲染与测试共用) ----
|
||||
|
||||
function ts(s: string): number {
|
||||
return new Date(s.replace(/-/g, '/')).getTime()
|
||||
}
|
||||
|
||||
/** 手机号脱敏展示(137****7863)。 */
|
||||
export function maskMobile(m: string): string {
|
||||
return m.length === 11 ? `${m.slice(0, 3)}****${m.slice(7)}` : m
|
||||
}
|
||||
|
||||
/** 状态列着色:DELIVRD/成功→绿,失败→红,未知/拦截→橙,发送中→蓝灰。 */
|
||||
export function rawCodeType(status: number, rawCode: string): 'success' | 'danger' | 'warning' | 'info' {
|
||||
if (status === 2 || rawCode === 'DELIVRD') return 'success'
|
||||
if (status === 3) return 'danger'
|
||||
if (status === 4 || status === 5) return 'warning'
|
||||
return 'info'
|
||||
}
|
||||
|
||||
/** 两段耗时「提交→发送 发送→回执」:如 "0s 4s" / "0s -"(无回执)。 */
|
||||
export function segmentDurations(row: Pick<DownlinkDetailRow, 'created_at' | 'send_at' | 'report_at'>): string {
|
||||
const seg = (from: string | null, to: string | null): string => {
|
||||
if (!from || !to) return '-'
|
||||
return `${Math.max(0, Math.round((ts(to) - ts(from)) / 1000))}s`
|
||||
}
|
||||
return `${seg(row.created_at, row.send_at)} ${seg(row.send_at, row.report_at)}`
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/** 工作台统计 API(FE-Design-Audit B1)。real 模式走网关;mock 由 msw handlers 提供。 */
|
||||
import { get } from './request'
|
||||
|
||||
/** 四指标卡。 */
|
||||
export interface StatsSummary {
|
||||
/** 今日提交量(条) */
|
||||
today_sent: number
|
||||
/** 昨日提交量,用于环比 */
|
||||
yesterday_sent: number
|
||||
/** 今日回执成功率(0~1) */
|
||||
success_rate: number
|
||||
/** 昨日成功率,用于环比(pp 差值,如 -0.004) */
|
||||
success_rate_delta: number
|
||||
/** 余额低于预警线的账号数 */
|
||||
balance_alert_count: number
|
||||
/** 待人工审核条数 */
|
||||
pending_audit_count: number
|
||||
}
|
||||
|
||||
/** 近 N 日发送趋势点。 */
|
||||
export interface TrendPoint {
|
||||
date: string // 'MM-DD'
|
||||
sent: number // 提交量
|
||||
success: number // 成功量
|
||||
}
|
||||
|
||||
export const statsApi = {
|
||||
// W1 修复:原写全路径 '/api/v1/...' 与 axios baseURL(VITE_API_BASE_URL=/api/v1)
|
||||
// 叠加成 /api/v1/api/v1/... → msw 不匹配 → proxy 404(Home 指标一直空数据)。
|
||||
summary: () => get<StatsSummary>('/stats/summary'),
|
||||
trend: (days = 7) => get<TrendPoint[]>('/stats/trend', { days }),
|
||||
// ---- Issue#6·P2 Dashboard 三端点(openapi 1.5.0) ----
|
||||
biz: (days = 7) => get<BizDist>('/stats/biz', { days }),
|
||||
realtime: () => get<RealtimeStat>('/stats/realtime'),
|
||||
}
|
||||
|
||||
/** 业务类型分布(P2:/stats/biz)。 */
|
||||
export interface BizDist {
|
||||
days: number
|
||||
by_business: { key: string; count: number }[]
|
||||
by_send_type: { key: string; count: number }[]
|
||||
}
|
||||
|
||||
/** 实时提交速率(P2:/stats/realtime,60s 窗口均值)。 */
|
||||
export interface RealtimeStat {
|
||||
ts: string
|
||||
window_s: number
|
||||
global_submit_ps: number
|
||||
top_accounts: { account_id: number; name: string; submit_ps: number }[]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { get, put } from './request'
|
||||
|
||||
/** Issue#3 方案B:系统参数配置(system_config KV;admin)。 */
|
||||
export interface SystemConfigRow {
|
||||
id: number
|
||||
cfg_key: string
|
||||
cfg_value: string
|
||||
remark: string
|
||||
updated_by: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface SystemConfigSaveReq {
|
||||
cfg_key: string
|
||||
cfg_value: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** 已知键说明(表结构无白名单,新键=新能力;此处仅运营提示)。 */
|
||||
export const KNOWN_CFG_KEYS: { key: string; label: string; hint: string }[] = [
|
||||
{
|
||||
key: 'cmpp.default_ext_code',
|
||||
label: '系统默认接入码前缀',
|
||||
hint: 'CMPP/SMPP 账号未配置扩展码(ext_code)时回退此值校验 SrcID 前缀;改后受理侧 ≤30s 生效',
|
||||
},
|
||||
{
|
||||
key: 'uplink.blacklist.keywords',
|
||||
label: '上行自动拉黑词表',
|
||||
hint: '逗号分隔等值匹配(如 R,TD,退订,拒收);空=内置默认词表;改后 ≤60s 生效',
|
||||
},
|
||||
]
|
||||
|
||||
export const systemApi = {
|
||||
// ---- Issue#6·P2:/ops/system/overview(admin/ops;gateway 视角五子系统三态) ----
|
||||
overview: () => get<SystemOverview>('/ops/system/overview'),
|
||||
list: () => get<{ list: SystemConfigRow[] }>('/system/config'),
|
||||
update: (body: SystemConfigSaveReq) => put<SystemConfigRow>('/system/config', body),
|
||||
}
|
||||
|
||||
/** 系统健康总览(P2:/ops/system/overview)。 */
|
||||
export interface SystemOverview {
|
||||
uptime_s: number
|
||||
subsystems: { name: string; status: 'up' | 'degraded' | 'down' | 'unknown'; detail: string; latency_ms: number }[]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/** 后端统一响应结构(ISC:xxx)。 */
|
||||
export interface ApiResp<T = unknown> {
|
||||
code: string
|
||||
msg: string
|
||||
data: T
|
||||
}
|
||||
|
||||
/** 登录用户信息。 */
|
||||
export interface UserInfo {
|
||||
account_id: number
|
||||
username: string
|
||||
roles: string[]
|
||||
permissions: string[]
|
||||
}
|
||||
|
||||
/** 登录响应 data。 */
|
||||
export interface LoginData {
|
||||
token: string
|
||||
user: UserInfo
|
||||
}
|
||||
|
||||
/** ISC 错误码常量(与后端 internal/pkg/errors 对齐,FE-6 接 codegen 自动生成)。 */
|
||||
export const ISC = {
|
||||
OK: 'ISC:000',
|
||||
UNAUTHORIZED: 'ISC:401',
|
||||
FORBIDDEN: 'ISC:403',
|
||||
INTERNAL: 'ISC:500',
|
||||
} as const
|
||||
@@ -0,0 +1,29 @@
|
||||
<template>
|
||||
<!-- 契约 v3-2-tailwind.html SVG defs 直挂:全站图标唯一来源(<use href="#i-*">),零图标库依赖 -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" style="position:absolute" aria-hidden="true"><defs>
|
||||
<symbol id="i-logo" viewBox="0 0 24 24"><path d="M3 15c2-6 4-6 6 0s4 6 6 0 4-6 6 0" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/></symbol>
|
||||
<symbol id="i-grid" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="3.5" width="7" height="7" rx="1.5"/><rect x="13.5" y="3.5" width="7" height="7" rx="1.5"/><rect x="3.5" y="13.5" width="7" height="7" rx="1.5"/><rect x="13.5" y="13.5" width="7" height="7" rx="1.5"/></symbol>
|
||||
<symbol id="i-bell" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 9a6 6 0 1 0-12 0c0 5-2 6.5-2 6.5h16S18 14 18 9"/><path d="M10.3 19a2 2 0 0 0 3.4 0"/></symbol>
|
||||
<symbol id="i-users" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="8" r="3.5"/><path d="M3.5 20c.6-3.3 2.8-5 5.5-5s4.9 1.7 5.5 5"/><path d="M16 5.5a3 3 0 0 1 0 5.6M17.5 15.4c1.7.7 2.7 2.2 3 4.6"/></symbol>
|
||||
<symbol id="i-stamp" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M8.5 12.2l2.4 2.3 4.6-4.9"/></symbol>
|
||||
<symbol id="i-sms" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a8 8 0 0 1-8 8H4l2.2-2.6A8 8 0 1 1 21 12z"/><path d="M8.5 11h7M8.5 14h4"/></symbol>
|
||||
<symbol id="i-send" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 3L10.5 13.5"/><path d="M21 3l-6.8 18-3.7-7.5L3 9.8 21 3z"/></symbol>
|
||||
<symbol id="i-layer" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3l9 5-9 5-9-5 9-5z"/><path d="M3 13l9 5 9-5"/><path d="M3 17.5l9 5 9-5"/></symbol>
|
||||
<symbol id="i-coin" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="6.5" rx="7.5" ry="3"/><path d="M4.5 6.5v5c0 1.7 3.4 3 7.5 3s7.5-1.3 7.5-3v-5"/><path d="M4.5 11.5v5c0 1.7 3.4 3 7.5 3s7.5-1.3 7.5-3v-5"/></symbol>
|
||||
<symbol id="i-chart" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M4 20V4"/><path d="M4 20h16"/><path d="M8 16v-5M13 16V8M18 16v-8"/></symbol>
|
||||
<symbol id="i-set" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19 12a7 7 0 0 0-.1-1.2l2-1.6-2-3.4-2.4 1a7 7 0 0 0-2-1.2L14 3h-4l-.4 2.6a7 7 0 0 0-2 1.2l-2.5-1-2 3.4 2 1.6A7 7 0 0 0 5 12c0 .4 0 .8.1 1.2l-2 1.6 2 3.4 2.4-1a7 7 0 0 0 2 1.2L10 21h4l.4-2.6a7 7 0 0 0 2-1.2l2.5 1 2-3.4-2-1.6c.1-.4.1-.8.1-1.2z"/></symbol>
|
||||
<symbol id="i-zap" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2L4.5 13.5H11L9.5 22 19 10h-6.5L13 2z"/></symbol>
|
||||
<symbol id="i-srv" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="4" width="17" height="6.5" rx="1.5"/><rect x="3.5" y="13.5" width="17" height="6.5" rx="1.5"/><path d="M7 7.2h.01M7 16.8h.01"/></symbol>
|
||||
<symbol id="i-db" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><ellipse cx="12" cy="5.5" rx="7.5" ry="2.8"/><path d="M4.5 5.5V18.5c0 1.5 3.4 2.8 7.5 2.8s7.5-1.3 7.5-2.8V5.5"/><path d="M4.5 12c0 1.5 3.4 2.8 7.5 2.8s7.5-1.3 7.5-2.8"/></symbol>
|
||||
<symbol id="i-clock" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 7v5l3.5 2"/></symbol>
|
||||
<symbol id="i-wallet" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="6" width="18" height="13" rx="2.5"/><path d="M3 10h18"/><path d="M16.5 14.5h.01"/></symbol>
|
||||
<symbol id="i-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 12.5l5 5 10-11"/></symbol>
|
||||
<symbol id="i-warn" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 4L2.5 20h19L12 4z"/><path d="M12 10v4M12 17.2v.3"/></symbol>
|
||||
<symbol id="i-refresh" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 11a8 8 0 1 0-.6 4"/><path d="M20 4v7h-7"/></symbol>
|
||||
<symbol id="i-moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 13.5A8 8 0 0 1 10.5 4 8 8 0 1 0 20 13.5z"/></symbol>
|
||||
<symbol id="i-x" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></symbol>
|
||||
<symbol id="i-chev-l" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 5.5L8 12l6.5 6.5"/></symbol>
|
||||
<symbol id="i-callback" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9V6.5A2.5 2.5 0 0 1 6.5 4H10"/><path d="M20 15v2.5a2.5 2.5 0 0 1-2.5 2.5H14"/><rect x="9" y="9" width="6" height="6" rx="1"/></symbol>
|
||||
<symbol id="i-route" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="6" cy="6" r="2.5"/><circle cx="18" cy="18" r="2.5"/><path d="M8.5 6H14a3.5 3.5 0 0 1 0 7h-4a3.5 3.5 0 0 0 0 7h5.5"/></symbol>
|
||||
</defs></svg>
|
||||
</template>
|
||||
@@ -0,0 +1,90 @@
|
||||
<template>
|
||||
<!-- Issue#2 多标签导航 · 契约范式重实现(884-891):chip 式 tab,激活=primary-100 底。
|
||||
语义保留:fullPath 身份去重/独立关闭+中键/关闭其他+全部关闭/home 固定。 -->
|
||||
<div class="border-b border-gray-200/50 bg-white/60 px-6 py-2 dark:border-dark-700/50 dark:bg-dark-800/60">
|
||||
<div class="flex items-center gap-1 overflow-x-auto">
|
||||
<template v-for="tab in tabs.visited" :key="tab.path">
|
||||
<span
|
||||
class="group flex cursor-pointer items-center gap-1 rounded-lg px-3 py-1 text-sm transition-colors"
|
||||
:class="
|
||||
tab.path === route.fullPath
|
||||
? 'bg-primary-100 font-medium text-primary-700 dark:bg-primary-900/30 dark:text-primary-400'
|
||||
: 'text-gray-600 hover:bg-gray-100 dark:text-dark-400 dark:hover:bg-dark-800'
|
||||
"
|
||||
@click="router.push(tab.path)"
|
||||
@click.middle.prevent="closeTab(tab.path)"
|
||||
@contextmenu.prevent="openMenu($event, tab.path)"
|
||||
>
|
||||
{{ tab.title }}
|
||||
<svg
|
||||
v-if="!tab.affix"
|
||||
class="h-3 w-3 rounded text-gray-400 opacity-0 transition-opacity hover:text-red-500 group-hover:opacity-100"
|
||||
@click.stop="closeTab(tab.path)"
|
||||
>
|
||||
<use href="#i-x" />
|
||||
</svg>
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- 右键菜单:关闭其他 / 全部关闭(home 固定保留) -->
|
||||
<div
|
||||
v-if="menu.show"
|
||||
class="fixed z-50 w-36 rounded-xl border border-gray-200 bg-white p-1 shadow-lg dark:border-dark-700 dark:bg-dark-800"
|
||||
:style="{ left: `${menu.x}px`, top: `${menu.y}px` }"
|
||||
>
|
||||
<button
|
||||
class="block w-full rounded-lg px-3 py-1.5 text-left text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-dark-700"
|
||||
@click="closeOthers"
|
||||
>
|
||||
关闭其他
|
||||
</button>
|
||||
<button
|
||||
class="block w-full rounded-lg px-3 py-1.5 text-left text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-dark-700"
|
||||
@click="closeAll"
|
||||
>
|
||||
全部关闭
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, reactive } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useTabsStore } from '@/stores/tabs'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const tabs = useTabsStore()
|
||||
|
||||
const menu = reactive({ show: false, x: 0, y: 0, target: '' })
|
||||
|
||||
onMounted(() => document.addEventListener('click', () => (menu.show = false)))
|
||||
onBeforeUnmount(() => document.removeEventListener('click', () => (menu.show = false)))
|
||||
|
||||
|
||||
function closeTab(path: string) {
|
||||
const next = tabs.close(path, route.fullPath)
|
||||
if (next) router.push(next)
|
||||
menu.show = false
|
||||
}
|
||||
|
||||
function openMenu(e: MouseEvent, path: string) {
|
||||
menu.show = true
|
||||
menu.x = e.clientX
|
||||
menu.y = e.clientY
|
||||
menu.target = path
|
||||
}
|
||||
|
||||
function closeOthers() {
|
||||
tabs.closeOthers(menu.target || route.fullPath)
|
||||
router.push(menu.target || route.fullPath)
|
||||
menu.show = false
|
||||
}
|
||||
|
||||
function closeAll() {
|
||||
router.push(tabs.closeAll())
|
||||
menu.show = false
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,30 @@
|
||||
<template>
|
||||
<!-- Issue#4 版本徽章:契约 chip 结构;红点=本地未读(localStorage gosms_seen_ver≠APP_VERSION),
|
||||
点击 markSeen 即灭 + 跳发布日志页。折叠态随 .sidebar-brand 隐藏(契约 folded 规则)。 -->
|
||||
<button
|
||||
class="mt-0.5 flex items-center gap-1.5 rounded-lg bg-gray-100 px-2 py-1 text-xs text-gray-600 dark:bg-dark-800 dark:text-dark-400"
|
||||
:title="release.hasUpdate ? '有新版本,点击查看' : '当前版本'"
|
||||
@click="onClick"
|
||||
>
|
||||
<span v-if="release.hasUpdate" class="relative flex h-2 w-2">
|
||||
<span class="absolute inline-flex h-full w-full animate-ping rounded-full bg-red-400 opacity-75"></span>
|
||||
<span class="relative inline-flex h-2 w-2 rounded-full bg-red-500"></span>
|
||||
</span>
|
||||
<span v-else class="relative inline-flex h-2 w-2 rounded-full bg-primary-500"></span>
|
||||
<span class="font-medium">{{ APP_VERSION }}</span>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useReleaseStore } from '@/stores/release'
|
||||
import { APP_VERSION } from '@/data/releases'
|
||||
|
||||
const router = useRouter()
|
||||
const release = useReleaseStore()
|
||||
|
||||
function onClick() {
|
||||
release.markSeen()
|
||||
router.push('/system/release')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,438 @@
|
||||
<!-- Select.vue Issue#6·B3:自绘下拉(sub2api common/Select.vue 契约直译,2026-11-17)
|
||||
形态:Teleport 面板+首项搜索输入(auto>5 自动可搜)+键盘 ↑↓/Enter/Esc/Tab+clearable
|
||||
+上下自适应+scroll/resize 跟随;trigger r12·px-4·py-2.5;选中=底色式 primary-50/600字。
|
||||
适配裁剪(留痕):①去 vue-i18n(文案中文硬编码) ②Icon 组件→内联 svg(lucide 同款)
|
||||
③裁 creatable/remote 远程搜索(本工程无场景,契约注释可溯源)。
|
||||
用法:<Select v-model='x' :options='[{value,label}]' placeholder='状态:全部' class='!w-32' /> -->
|
||||
<template>
|
||||
<div ref='containerRef' class='relative'>
|
||||
<button
|
||||
ref='triggerRef'
|
||||
type='button'
|
||||
:class="['select-trigger', isOpen && 'select-trigger-open', disabled && 'select-trigger-disabled']"
|
||||
:disabled='disabled'
|
||||
:aria-expanded='isOpen'
|
||||
aria-haspopup='listbox'
|
||||
@click='toggle'
|
||||
@keydown.down.prevent='onTriggerKeyDown'
|
||||
@keydown.up.prevent='onTriggerKeyDown'
|
||||
>
|
||||
<span class='select-value' :class="!hasValue && 'text-gray-400 dark:text-dark-400'">{{ selectedLabel }}</span>
|
||||
<span
|
||||
v-if='clearable && hasValue && !disabled'
|
||||
class='select-clear'
|
||||
role='button'
|
||||
tabindex='-1'
|
||||
aria-label='Clear selection'
|
||||
@click.stop='clearSelection'
|
||||
@mousedown.stop
|
||||
@keydown.enter.stop.prevent='clearSelection'
|
||||
>
|
||||
<svg class='h-3.5 w-3.5' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M18 6 6 18M6 6l12 12'/></svg>
|
||||
</span>
|
||||
<span class='select-icon'>
|
||||
<svg
|
||||
class='h-4 w-4 transition-transform duration-200'
|
||||
:class="isOpen && 'rotate-180'"
|
||||
viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'
|
||||
><path d='m6 9 6 6 6-6'/></svg>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<Teleport to='body'>
|
||||
<Transition name='select-dropdown'>
|
||||
<div
|
||||
v-if='isOpen'
|
||||
ref='dropdownRef'
|
||||
:class="['select-dropdown-portal', instanceId]"
|
||||
:style='dropdownStyle'
|
||||
role='listbox'
|
||||
tabindex='-1'
|
||||
@click.stop
|
||||
@mousedown.stop
|
||||
@keydown='onDropdownKeyDown'
|
||||
>
|
||||
<div v-if='isSearchable' class='select-search'>
|
||||
<svg class='h-4 w-4 text-gray-400' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>
|
||||
<input ref='searchInputRef' v-model='searchQuery' type='text' :placeholder='searchPlaceholderText' :aria-label='searchPlaceholderText' class='select-search-input' @click.stop />
|
||||
</div>
|
||||
<div ref='optionsListRef' class='select-options'>
|
||||
<div
|
||||
v-for='(option, index) in filteredOptions'
|
||||
:key='`${String(getOptionValue(option))}`'
|
||||
role='option'
|
||||
:aria-selected='isSelected(option)'
|
||||
:aria-disabled='isOptionDisabled(option)'
|
||||
:class="[
|
||||
'select-option',
|
||||
isSelected(option) && 'select-option-selected',
|
||||
isOptionDisabled(option) && 'select-option-disabled',
|
||||
focusedIndex === index && !isOptionDisabled(option) && 'select-option-focused'
|
||||
]"
|
||||
@click.stop='!isOptionDisabled(option) && selectOption(option)'
|
||||
@mouseenter='handleOptionMouseEnter(option, index)'
|
||||
>
|
||||
<span class='select-option-label'>{{ getOptionLabel(option) }}</span>
|
||||
<svg v-if='isSelected(option)' class='h-4 w-4 flex-shrink-0 text-primary-500' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 6 9 17l-5-5'/></svg>
|
||||
</div>
|
||||
<div v-if='filteredOptions.length === 0' class='select-empty'>{{ emptyTextDisplay }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang='ts'>
|
||||
import { ref, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'
|
||||
|
||||
defineOptions({ name: 'Select' })
|
||||
|
||||
const instanceId = `select-${Math.random().toString(36).substring(2, 9)}`
|
||||
|
||||
export interface SelectOption {
|
||||
value: string | number | boolean | null
|
||||
label: string
|
||||
disabled?: boolean
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
interface Props {
|
||||
modelValue: string | number | boolean | null | undefined
|
||||
options: SelectOption[] | Array<Record<string, unknown>>
|
||||
placeholder?: string
|
||||
disabled?: boolean
|
||||
searchable?: boolean | 'auto'
|
||||
searchPlaceholder?: string
|
||||
emptyText?: string
|
||||
valueKey?: string
|
||||
labelKey?: string
|
||||
clearable?: boolean
|
||||
/** 宽度:外层 class='!w-32' 控制(对齐 input 惯例),trigger w-full 撑满 */
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
disabled: false,
|
||||
searchable: 'auto',
|
||||
clearable: false,
|
||||
valueKey: 'value',
|
||||
labelKey: 'label',
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: string | number | boolean | null]
|
||||
change: [value: string | number | boolean | null, option: SelectOption | null]
|
||||
}>()
|
||||
|
||||
const isOpen = ref(false)
|
||||
const searchQuery = ref('')
|
||||
const focusedIndex = ref(-1)
|
||||
const containerRef = ref<HTMLElement | null>(null)
|
||||
const triggerRef = ref<HTMLButtonElement | null>(null)
|
||||
const searchInputRef = ref<HTMLInputElement | null>(null)
|
||||
const dropdownRef = ref<HTMLElement | null>(null)
|
||||
const optionsListRef = ref<HTMLElement | null>(null)
|
||||
const dropdownPosition = ref<'bottom' | 'top'>('bottom')
|
||||
const triggerRect = ref<DOMRect | null>(null)
|
||||
const dropdownViewportPadding = 8
|
||||
const dropdownMinimumWidth = 200
|
||||
|
||||
const placeholderText = computed(() => props.placeholder ?? '请选择')
|
||||
const searchPlaceholderText = computed(() => props.searchPlaceholder ?? '搜索…')
|
||||
const emptyTextDisplay = computed(() => props.emptyText ?? '无匹配项')
|
||||
|
||||
/** 契约核心:searchable='auto'(默认)且选项>5 → 面板首项出搜索输入(sub2api Select L210 同源) */
|
||||
const isSearchable = computed(() => {
|
||||
if (props.searchable === 'auto') return props.options.length > 5
|
||||
return props.searchable
|
||||
})
|
||||
|
||||
const dropdownStyle = computed(() => {
|
||||
if (!triggerRect.value) return {}
|
||||
const rect = triggerRect.value
|
||||
const viewportRight = Math.max(dropdownViewportPadding, window.innerWidth - dropdownViewportPadding)
|
||||
const left = Math.min(Math.max(dropdownViewportPadding, rect.left), viewportRight)
|
||||
const availableWidth = Math.max(0, viewportRight - left)
|
||||
const preferredMinWidth = Math.max(dropdownMinimumWidth, rect.width)
|
||||
const minWidth = Math.min(preferredMinWidth, availableWidth)
|
||||
const style: Record<string, string> = {
|
||||
position: 'fixed',
|
||||
left: `${left}px`,
|
||||
minWidth: `${minWidth}px`,
|
||||
maxWidth: `${availableWidth}px`,
|
||||
zIndex: '100000020',
|
||||
}
|
||||
if (dropdownPosition.value === 'top') {
|
||||
style.bottom = `${window.innerHeight - rect.top + 4}px`
|
||||
} else {
|
||||
style.top = `${rect.bottom + 4}px`
|
||||
}
|
||||
return style
|
||||
})
|
||||
|
||||
const getOptionValue = (option: any): any => {
|
||||
if (typeof option === 'object' && option !== null) return option[props.valueKey]
|
||||
return option
|
||||
}
|
||||
const getOptionLabel = (option: any): string => {
|
||||
if (typeof option === 'object' && option !== null) return String(option[props.labelKey] ?? '')
|
||||
return String(option ?? '')
|
||||
}
|
||||
const isOptionDisabled = (option: any): boolean => {
|
||||
if (typeof option === 'object' && option !== null) return !!option.disabled
|
||||
return false
|
||||
}
|
||||
const selectedOption = computed(() => props.options.find((opt: any) => getOptionValue(opt) === props.modelValue) || null)
|
||||
// 空串值=未选(含数组内 value:'' 的全部项):trigger 恒显 placeholder,与原生 select 选中空 option 一致
|
||||
const selectedLabel = computed(() => (hasValue.value && selectedOption.value ? getOptionLabel(selectedOption.value) : placeholderText.value))
|
||||
const hasValue = computed(() => props.modelValue !== null && props.modelValue !== undefined && props.modelValue !== '')
|
||||
|
||||
const filteredOptions = computed(() => {
|
||||
let opts = props.options as any[]
|
||||
if (isSearchable.value && searchQuery.value) {
|
||||
const query = searchQuery.value.toLowerCase()
|
||||
opts = opts.filter((opt) => getOptionLabel(opt).toLowerCase().includes(query))
|
||||
}
|
||||
return opts
|
||||
})
|
||||
|
||||
const isSelected = (option: any) => getOptionValue(option) === props.modelValue
|
||||
|
||||
const findNextEnabledIndex = (startIndex: number): number => {
|
||||
const opts = filteredOptions.value
|
||||
if (opts.length === 0) return -1
|
||||
for (let offset = 0; offset < opts.length; offset++) {
|
||||
const idx = (startIndex + offset) % opts.length
|
||||
if (!isOptionDisabled(opts[idx])) return idx
|
||||
}
|
||||
return -1
|
||||
}
|
||||
const findPrevEnabledIndex = (startIndex: number): number => {
|
||||
const opts = filteredOptions.value
|
||||
if (opts.length === 0) return -1
|
||||
for (let offset = 0; offset < opts.length; offset++) {
|
||||
const idx = (startIndex - offset + opts.length) % opts.length
|
||||
if (!isOptionDisabled(opts[idx])) return idx
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
watch(filteredOptions, () => {
|
||||
if (!isOpen.value) return
|
||||
focusedIndex.value = findNextEnabledIndex(0)
|
||||
if (focusedIndex.value >= 0) scrollToFocused()
|
||||
})
|
||||
|
||||
const handleOptionMouseEnter = (option: any, index: number) => {
|
||||
if (isOptionDisabled(option)) return
|
||||
focusedIndex.value = index
|
||||
}
|
||||
|
||||
const updateTriggerRect = () => {
|
||||
if (containerRef.value) triggerRect.value = containerRef.value.getBoundingClientRect()
|
||||
}
|
||||
|
||||
const calculateDropdownPosition = () => {
|
||||
if (!containerRef.value) return
|
||||
updateTriggerRect()
|
||||
nextTick(() => {
|
||||
if (!dropdownRef.value || !triggerRect.value) return
|
||||
const dropdownHeight = dropdownRef.value.offsetHeight || 240
|
||||
const spaceBelow = window.innerHeight - triggerRect.value.bottom
|
||||
const spaceAbove = triggerRect.value.top
|
||||
dropdownPosition.value = spaceBelow < dropdownHeight && spaceAbove > dropdownHeight ? 'top' : 'bottom'
|
||||
})
|
||||
}
|
||||
|
||||
const toggle = () => {
|
||||
if (props.disabled) return
|
||||
isOpen.value = !isOpen.value
|
||||
}
|
||||
|
||||
watch(() => props.disabled, (disabled) => { if (disabled) isOpen.value = false })
|
||||
|
||||
watch(isOpen, (open) => {
|
||||
if (open) {
|
||||
calculateDropdownPosition()
|
||||
if (filteredOptions.value.length === 0) {
|
||||
focusedIndex.value = -1
|
||||
} else {
|
||||
const selectedIdx = filteredOptions.value.findIndex(isSelected)
|
||||
const initialIdx = selectedIdx >= 0 ? selectedIdx : 0
|
||||
focusedIndex.value = isOptionDisabled(filteredOptions.value[initialIdx]) ? findNextEnabledIndex(initialIdx + 1) : initialIdx
|
||||
}
|
||||
if (isSearchable.value) nextTick(() => searchInputRef.value?.focus())
|
||||
else nextTick(() => dropdownRef.value?.focus())
|
||||
window.addEventListener('scroll', updateTriggerRect, { capture: true, passive: true })
|
||||
window.addEventListener('resize', calculateDropdownPosition)
|
||||
} else {
|
||||
searchQuery.value = ''
|
||||
focusedIndex.value = -1
|
||||
window.removeEventListener('scroll', updateTriggerRect, { capture: true } as any)
|
||||
window.removeEventListener('resize', calculateDropdownPosition)
|
||||
}
|
||||
})
|
||||
|
||||
const selectOption = (option: any) => {
|
||||
const value = getOptionValue(option) ?? null
|
||||
emit('update:modelValue', value)
|
||||
emit('change', value, option)
|
||||
isOpen.value = false
|
||||
triggerRef.value?.focus()
|
||||
}
|
||||
|
||||
const clearSelection = () => {
|
||||
if (props.disabled) return
|
||||
// web-next 适配:筛选值域全为 string,清空回空串(=不过滤)而非 null,与原生 select 行为一致
|
||||
emit('update:modelValue', '')
|
||||
emit('change', '', null)
|
||||
}
|
||||
|
||||
const onTriggerKeyDown = () => { if (!isOpen.value) isOpen.value = true }
|
||||
|
||||
const onDropdownKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.isComposing) return
|
||||
switch (e.key) {
|
||||
case 'ArrowDown':
|
||||
e.preventDefault()
|
||||
focusedIndex.value = findNextEnabledIndex(focusedIndex.value + 1)
|
||||
if (focusedIndex.value >= 0) scrollToFocused()
|
||||
break
|
||||
case 'ArrowUp':
|
||||
e.preventDefault()
|
||||
focusedIndex.value = findPrevEnabledIndex(focusedIndex.value - 1)
|
||||
if (focusedIndex.value >= 0) scrollToFocused()
|
||||
break
|
||||
case 'Enter':
|
||||
e.preventDefault()
|
||||
if (focusedIndex.value >= 0 && focusedIndex.value < filteredOptions.value.length) {
|
||||
const opt = filteredOptions.value[focusedIndex.value]
|
||||
if (!isOptionDisabled(opt)) selectOption(opt)
|
||||
}
|
||||
break
|
||||
case 'Escape':
|
||||
e.preventDefault()
|
||||
isOpen.value = false
|
||||
triggerRef.value?.focus()
|
||||
break
|
||||
case 'Tab':
|
||||
isOpen.value = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const scrollToFocused = () => {
|
||||
nextTick(() => {
|
||||
const list = optionsListRef.value
|
||||
if (!list) return
|
||||
const focusedEl = list.children[focusedIndex.value] as HTMLElement
|
||||
if (!focusedEl) return
|
||||
if (focusedEl.offsetTop < list.scrollTop) list.scrollTop = focusedEl.offsetTop
|
||||
else if (focusedEl.offsetTop + focusedEl.offsetHeight > list.scrollTop + list.offsetHeight) list.scrollTop = focusedEl.offsetTop + focusedEl.offsetHeight - list.offsetHeight
|
||||
})
|
||||
}
|
||||
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
const target = event.target as HTMLElement
|
||||
const isInDropdown = !!target.closest(`.${instanceId}`)
|
||||
const isInTrigger = containerRef.value?.contains(target)
|
||||
if (!isInDropdown && !isInTrigger && isOpen.value) isOpen.value = false
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener('click', handleClickOutside))
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('click', handleClickOutside)
|
||||
window.removeEventListener('scroll', updateTriggerRect, { capture: true } as any)
|
||||
window.removeEventListener('resize', calculateDropdownPosition)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.select-trigger {
|
||||
@apply flex w-full items-center justify-between gap-2;
|
||||
@apply rounded-xl px-4 py-2.5 text-sm;
|
||||
@apply bg-white dark:bg-dark-800;
|
||||
@apply border border-gray-200 dark:border-dark-600;
|
||||
@apply text-gray-900 dark:text-gray-100;
|
||||
@apply transition-all duration-200;
|
||||
@apply focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/30;
|
||||
@apply hover:border-gray-300 dark:hover:border-dark-500;
|
||||
@apply cursor-pointer;
|
||||
}
|
||||
.select-trigger-open {
|
||||
@apply border-primary-500 ring-2 ring-primary-500/30;
|
||||
}
|
||||
.select-trigger-disabled {
|
||||
@apply cursor-not-allowed bg-gray-100 opacity-60 dark:bg-dark-900;
|
||||
}
|
||||
.select-value {
|
||||
@apply flex-1 truncate text-left;
|
||||
}
|
||||
.select-icon {
|
||||
@apply flex-shrink-0 text-gray-400 dark:text-dark-400;
|
||||
}
|
||||
.select-clear {
|
||||
@apply flex flex-shrink-0 cursor-pointer items-center justify-center;
|
||||
@apply rounded text-gray-400 transition-colors;
|
||||
@apply hover:text-gray-600 dark:hover:text-gray-200;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
.select-dropdown-portal {
|
||||
@apply w-max min-w-[200px];
|
||||
@apply bg-white dark:bg-dark-800;
|
||||
@apply rounded-xl;
|
||||
@apply border border-gray-200 dark:border-dark-700;
|
||||
@apply shadow-lg shadow-black/10 dark:shadow-black/30;
|
||||
@apply overflow-hidden;
|
||||
pointer-events: auto !important;
|
||||
}
|
||||
.select-dropdown-portal .select-search {
|
||||
@apply flex items-center gap-2 px-3 py-2;
|
||||
@apply border-b border-gray-100 dark:border-dark-700;
|
||||
}
|
||||
.select-dropdown-portal .select-search-input {
|
||||
@apply flex-1 bg-transparent text-sm;
|
||||
@apply text-gray-900 dark:text-gray-100;
|
||||
@apply placeholder:text-gray-400 dark:placeholder:text-dark-400;
|
||||
@apply focus:outline-none;
|
||||
}
|
||||
.select-dropdown-portal .select-options {
|
||||
@apply max-h-80 overflow-y-auto py-1 outline-none;
|
||||
}
|
||||
.select-dropdown-portal .select-option {
|
||||
@apply flex items-center justify-between gap-2;
|
||||
@apply px-4 py-2.5 text-sm;
|
||||
@apply text-gray-700 dark:text-gray-300;
|
||||
@apply cursor-pointer transition-colors duration-150;
|
||||
@apply hover:bg-gray-50 dark:hover:bg-dark-700;
|
||||
pointer-events: auto !important;
|
||||
}
|
||||
.select-dropdown-portal .select-option-selected {
|
||||
@apply bg-primary-50 dark:bg-primary-900/20;
|
||||
@apply text-primary-700 dark:text-primary-300;
|
||||
}
|
||||
.select-dropdown-portal .select-option-focused {
|
||||
@apply bg-gray-100 dark:bg-dark-700;
|
||||
}
|
||||
.select-dropdown-portal .select-option-disabled {
|
||||
@apply cursor-not-allowed opacity-40;
|
||||
}
|
||||
.select-dropdown-portal .select-option-label {
|
||||
@apply flex-1 min-w-0 truncate text-left;
|
||||
}
|
||||
.select-dropdown-portal .select-empty {
|
||||
@apply px-4 py-8 text-center text-sm;
|
||||
@apply text-gray-500 dark:text-dark-400;
|
||||
}
|
||||
.select-dropdown-enter-active,
|
||||
.select-dropdown-leave-active {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
.select-dropdown-enter-from,
|
||||
.select-dropdown-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-8px);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,78 @@
|
||||
// data/releases.ts — Issue#4 版本号与发布日志(单一事实源)。
|
||||
//
|
||||
// 发版 SOP(每 次功能上线):
|
||||
// 1. 在 RELEASE_NOTES **头部**插入一条(最新在最前),version 沿语义化
|
||||
// 版本递增(major.minor.patch:功能=minor、修复/小改=patch);
|
||||
// 2. APP_VERSION 自动取首条 version;package.json 的 version 需手工同步
|
||||
// (tests/releases.spec.ts 断言两侧一致防漂移);
|
||||
// 3. 文案面向运营/客户的**大白话**(不写实现细节/工单号),Markdown 格式
|
||||
// (utils/markdown.ts 渲染:标题/有序无序列表/粗体/行内代码/代码块/链接)。
|
||||
// 4. 部署后所有用户侧栏底部亮红点,点击进入发布日志页即标记已读。
|
||||
|
||||
/** 一条发布日志。 */
|
||||
export interface ReleaseNote {
|
||||
version: string // 语义化版本 x.y.z(与 package.json 一致)
|
||||
date: string // 发布日期 YYYY-MM-DD
|
||||
tag: string // 标签:新功能 / 优化 / 修复
|
||||
markdown: string // 发布说明(大白话 Markdown)
|
||||
}
|
||||
|
||||
export const RELEASE_NOTES: ReleaseNote[] = [
|
||||
{
|
||||
version: '1.5.0',
|
||||
date: '2026-11-16',
|
||||
tag: '新功能',
|
||||
markdown: `### 客户对接全链打通
|
||||
- **客户软件直连平台**:客户用自己熟悉的短信软件(标准 CMPP 协议)即可连上平台,**登录、发短信、接收发送报告**全流程顺畅,之前"连接报错"的问题已彻底解决。
|
||||
- **充值修复**:给账号充值时偶尔"没反应"的问题已修复,现在充值成功后余额马上更新。
|
||||
- **版本号与发布日志上线**(就是您现在看的这个页面):左侧菜单底部显示当前版本号,平台有更新时会亮**红点**提醒,点开就能看这次更新了什么。`,
|
||||
},
|
||||
{
|
||||
version: '1.4.0',
|
||||
date: '2026-11-16',
|
||||
tag: '优化',
|
||||
markdown: `### 操作更顺手
|
||||
- **多标签页**:打开的功能页会变成顶部标签,像浏览器标签页一样——可单独关闭、一键关闭全部;切走再切回来,**之前填的筛选条件还在**,不用重新填。
|
||||
- **系统配置页上线**:平台级参数(默认接入码、上行拉黑词表等)有了专门的管理页面,改完**立即生效**,全部操作留痕。`,
|
||||
},
|
||||
{
|
||||
version: '1.3.0',
|
||||
date: '2026-11-16',
|
||||
tag: '新功能',
|
||||
markdown: `### 平台能力升级
|
||||
- **发送结果自动通知**:短信发出后(无论成功失败),平台可自动把结果**推送到客户自己的系统**,不用登录平台手动查。
|
||||
- **退订自动拉黑**:用户回复"退订 / R / 拒收"等关键词后,系统自动把该号码加入黑名单,以后不再给 TA 发短信,减少投诉风险。
|
||||
- **历史记录查询提速**:短信明细保留 5 天热数据,更早的自动转入历史库;查**几个月前的记录也在 1 秒内**出结果。`,
|
||||
},
|
||||
{
|
||||
version: '1.2.0',
|
||||
date: '2026-11-15',
|
||||
tag: '新功能',
|
||||
markdown: `### 经营看得清
|
||||
- **利润分析上线**:一眼看清**每个账号赚多少、每条通道花多少、平台整体净利多少**;支持按时间段筛选,口径说明常驻页面,数字怎么算的清清楚楚。
|
||||
- **通道页面焕新**:通道列表从 20 列精简为 8 列重点信息,不再眼花缭乱;编辑页按"基本信息 / 通道配置 / 优先级限额"分组,找配置更快。`,
|
||||
},
|
||||
{
|
||||
version: '1.1.0',
|
||||
date: '2026-11-14',
|
||||
tag: '新功能',
|
||||
markdown: `### 结算管理上线
|
||||
- **订单与账单**:给客户创建结算订单、按月生成账单、确认结账、导出 Excel 对账单,全流程在页面上完成。
|
||||
- **阶梯价**:支持"发得越多、单价越便宜"的阶梯计费,按月用量自动落档。
|
||||
- **对账保障**:平台内部三方数据自动核对,**金额分毫不差才允许结账**,保证账单准确。`,
|
||||
},
|
||||
{
|
||||
version: '1.0.0',
|
||||
date: '2026-11-13',
|
||||
tag: '新功能',
|
||||
markdown: `### 平台一期上线
|
||||
- **全新短信管理平台**重建完成,界面焕然一新。
|
||||
- **基础功能**:登录、运营总览(今日发送量 / 成功率一眼看)、账号管理(开户 / 充值 / 角色权限)。
|
||||
- **短信业务**:群发工作台、个性短信、定时任务、短信模板。
|
||||
- **记录中心**:下发记录、上行记录、失败重推——每条短信的来龙去脉都可查。
|
||||
- **多协议接入**:支持 **CMPP、SMPP、HTTP** 三种主流方式对接客户与通道。`,
|
||||
},
|
||||
]
|
||||
|
||||
/** 当前版本(=最新一条;侧栏版本号与红点判定的事实源)。 */
|
||||
export const APP_VERSION: string = RELEASE_NOTES[0]!.version
|
||||
@@ -0,0 +1,79 @@
|
||||
<template>
|
||||
<!-- 契约顶栏(873-883 范式):glass sticky 64;左页题/副题,右通知/主题/用户 -->
|
||||
<header class="glass sticky top-0 z-30 border-b border-gray-200/50 dark:border-dark-700/50">
|
||||
<div class="flex h-16 items-center justify-between gap-2 px-2 sm:px-4 md:px-6">
|
||||
<div class="flex shrink-0 items-center gap-2 sm:gap-4">
|
||||
<div class="hidden lg:block">
|
||||
<h1 id="pageTitle" class="text-lg font-semibold text-gray-900 dark:text-white">
|
||||
{{ route.meta.title ?? '' }}
|
||||
</h1>
|
||||
<p v-if="route.meta.subtitle" id="pageDesc" class="text-xs text-gray-500 dark:text-dark-400">
|
||||
{{ route.meta.subtitle }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex min-w-0 items-center gap-1 sm:gap-3">
|
||||
<button class="btn-ghost btn-icon relative" title="通知">
|
||||
<svg class="h-5 w-5"><use href="#i-bell" /></svg>
|
||||
<span class="absolute right-2 top-2 h-2 w-2 rounded-full bg-red-500"></span>
|
||||
</button>
|
||||
<button id="themeBtn" class="btn-ghost btn-icon" title="切换主题" @click="toggleTheme">
|
||||
<svg class="h-5 w-5"><use href="#i-moon" /></svg>
|
||||
</button>
|
||||
<div class="group relative">
|
||||
<button class="flex items-center gap-2 rounded-xl p-1.5 hover:bg-gray-100 dark:hover:bg-dark-800">
|
||||
<div
|
||||
class="flex h-8 w-8 items-center justify-center rounded-xl bg-gradient-to-br from-primary-500 to-primary-600 text-sm font-medium text-white shadow-sm"
|
||||
>
|
||||
{{ avatar }}
|
||||
</div>
|
||||
<div class="hidden text-left md:block">
|
||||
<div class="text-sm font-medium text-gray-900 dark:text-white">{{ user.user?.username ?? '未登录' }}</div>
|
||||
<div class="text-xs text-gray-500 dark:text-dark-400">{{ user.roles.join('/') }}</div>
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
class="invisible absolute right-0 top-full z-40 mt-1 w-40 rounded-xl border border-gray-200 bg-white p-1 opacity-0 shadow-lg transition-all group-hover:visible group-hover:opacity-100 dark:border-dark-700 dark:bg-dark-800"
|
||||
>
|
||||
<router-link
|
||||
to="/system/release"
|
||||
class="block rounded-lg px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-dark-700"
|
||||
>
|
||||
发布日志
|
||||
</router-link>
|
||||
<button
|
||||
class="block w-full rounded-lg px-3 py-2 text-left text-sm text-red-600 hover:bg-gray-100 dark:text-red-400 dark:hover:bg-dark-700"
|
||||
@click="onLogout"
|
||||
>
|
||||
退出登录
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const user = useUserStore()
|
||||
|
||||
const avatar = computed(() => (user.user?.username ?? '?').slice(0, 2).toUpperCase())
|
||||
|
||||
/** 主题口径同 sub2api:localStorage 'theme' 键(light/dark),html.dark class 切换。 */
|
||||
function toggleTheme() {
|
||||
const dark = !document.documentElement.classList.contains('dark')
|
||||
document.documentElement.classList.toggle('dark', dark)
|
||||
localStorage.setItem('theme', dark ? 'dark' : 'light')
|
||||
}
|
||||
|
||||
function onLogout() {
|
||||
user.logout()
|
||||
router.push('/login')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,82 @@
|
||||
<template>
|
||||
<!-- 契约侧栏(830-871 范式):header(logo+品牌+版本徽章)/ nav(RBAC 分组菜单)/ 底部折叠钮 -->
|
||||
<aside id="sidebar" class="sidebar w-64">
|
||||
<div class="sidebar-header">
|
||||
<div
|
||||
class="sidebar-logo flex h-9 w-9 items-center justify-center overflow-hidden rounded-xl shadow-glow bg-gradient-to-br from-primary-500 to-primary-600 text-white"
|
||||
>
|
||||
<svg class="h-5 w-5"><use href="#i-logo" /></svg>
|
||||
</div>
|
||||
<div class="sidebar-brand">
|
||||
<span class="sidebar-brand-title text-lg font-bold text-gray-900 dark:text-white">go-sms</span>
|
||||
<VersionBadge />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="sidebar-nav scrollbar-hide">
|
||||
<div v-for="group in menuGroups" :key="group.name" class="sidebar-section">
|
||||
<div class="sidebar-section-title">{{ group.name }}</div>
|
||||
<router-link
|
||||
v-for="item in group.items"
|
||||
:key="item.path"
|
||||
:to="item.path"
|
||||
class="sidebar-link"
|
||||
active-class="sidebar-link-active"
|
||||
>
|
||||
<svg class="h-5 w-5 flex-shrink-0"><use :href="`#${item.icon}`" /></svg>
|
||||
<span class="sidebar-label sidebar-label-flex"><span class="min-w-0 truncate">{{ item.title }}</span></span>
|
||||
</router-link>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="border-t border-gray-100 p-3 dark:border-dark-800">
|
||||
<button id="foldBtn" class="btn btn-ghost btn-icon w-full" title="折叠侧栏" @click="toggleFold">
|
||||
<svg class="h-5 w-5" :style="{ transform: folded ? 'rotate(0deg)' : 'rotate(180deg)' }"><use href="#i-chev-l" /></svg>
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { accessibleRoutes } from '@/router/guard'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import VersionBadge from '@/components/VersionBadge.vue'
|
||||
|
||||
const FOLD_KEY = 'gosms_sidebar_folded'
|
||||
const user = useUserStore()
|
||||
const folded = ref(localStorage.getItem(FOLD_KEY) === '1')
|
||||
|
||||
function toggleFold() {
|
||||
folded.value = !folded.value
|
||||
document.body.classList.toggle('folded', folded.value)
|
||||
localStorage.setItem(FOLD_KEY, folded.value ? '1' : '0')
|
||||
}
|
||||
|
||||
if (folded.value) document.body.classList.add('folded')
|
||||
|
||||
interface MenuItem {
|
||||
path: string
|
||||
title: string
|
||||
icon: string
|
||||
}
|
||||
|
||||
/** 菜单=按角色可访问路由中 meta.menu 的项,按 meta.group 出现顺序分桶(RBAC 口径与守卫同源)。 */
|
||||
const menuGroups = computed(() => {
|
||||
const children: RouteRecordRaw[] = accessibleRoutes(user.roles)[0]?.children ?? []
|
||||
const groups: { name: string; items: MenuItem[] }[] = []
|
||||
for (const r of children) {
|
||||
if (!r.meta?.menu || !r.meta.group || !r.path) continue
|
||||
const title = String(r.meta.title ?? '')
|
||||
const icon = String(r.meta.icon ?? 'i-grid')
|
||||
let bucket = groups.find((g) => g.name === r.meta!.group)
|
||||
if (!bucket) {
|
||||
bucket = { name: String(r.meta.group), items: [] }
|
||||
groups.push(bucket)
|
||||
}
|
||||
bucket.items.push({ path: `/${String(r.path)}`, title, icon })
|
||||
}
|
||||
return groups
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<!-- 契约壳层:mainWrap(flex min-h-screen lg:pl-64)> header(64 glass)> tags 条 > main -->
|
||||
<div id="mainWrap" class="flex min-h-screen flex-col lg:pl-64">
|
||||
<AppHeader />
|
||||
<TagsBar />
|
||||
<main class="flex-1 p-4 md:p-6 lg:p-8">
|
||||
<!-- Issue#2 keep-alive 资产:include=cachedNames(路由名=组件名);B2 实装页起各视图 defineOptions({name:路由名}) -->
|
||||
<router-view v-slot="{ Component }">
|
||||
<keep-alive :include="tabs.cachedNames">
|
||||
<component :is="Component" />
|
||||
</keep-alive>
|
||||
</router-view>
|
||||
</main>
|
||||
</div>
|
||||
<AppSidebar />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import AppHeader from './AppHeader.vue'
|
||||
import AppSidebar from './AppSidebar.vue'
|
||||
import TagsBar from '@/components/TagsBar.vue'
|
||||
import { useTabsStore } from '@/stores/tabs'
|
||||
|
||||
const route = useRoute()
|
||||
const tabs = useTabsStore()
|
||||
|
||||
// Issue#2 语义:路由到达即登记 tab(fullPath 身份去重,标题随参数刷新)
|
||||
watch(() => route.fullPath, () => tabs.addTab(route), { immediate: true })
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import { setupRouterGuard } from './router/guard'
|
||||
import './styles/tailwind.css'
|
||||
|
||||
/** 主题口径与契约一致:localStorage 'theme' 键,无记录跟随系统(sub2api 同款)。 */
|
||||
function initThemeClass() {
|
||||
const savedTheme = localStorage.getItem('theme')
|
||||
const shouldUseDark =
|
||||
savedTheme === 'dark' || (!savedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches)
|
||||
document.documentElement.classList.toggle('dark', shouldUseDark)
|
||||
}
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(router)
|
||||
setupRouterGuard(router)
|
||||
initThemeClass()
|
||||
app.mount('#app')
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { Router, RouteRecordRaw } from 'vue-router'
|
||||
import { asyncRoutes } from './routes'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
export const WHITE_LIST = ['/login']
|
||||
|
||||
/** 按角色过滤可访问路由(admin 直通)。
|
||||
* 采用浅拷贝重建(children 过滤)而非深克隆:component 为动态 import 函数,
|
||||
* structuredClone 会抛 DataCloneError,且保留引用可让路由懒加载正常工作。 */
|
||||
export function accessibleRoutes(roles: string[]): RouteRecordRaw[] {
|
||||
const isAdmin = roles.includes('admin')
|
||||
if (isAdmin) return asyncRoutes
|
||||
const filter = (routes: RouteRecordRaw[]): RouteRecordRaw[] =>
|
||||
routes
|
||||
.filter((r) => !r.meta?.roles || r.meta.roles.some((role) => roles.includes(role)))
|
||||
.map((r) => ({ ...r, children: r.children ? filter(r.children) : undefined }) as RouteRecordRaw)
|
||||
.filter((r) => !r.children || r.children.length > 0)
|
||||
return filter(asyncRoutes)
|
||||
}
|
||||
|
||||
/** 安装全局守卫:白名单放行;未登录重定向;登录后注入动态路由。 */
|
||||
export function setupRouterGuard(router: Router) {
|
||||
router.beforeEach((to) => {
|
||||
const user = useUserStore()
|
||||
if (WHITE_LIST.includes(to.path)) {
|
||||
if (user.isLoggedIn && to.path === '/login') return '/home'
|
||||
return true
|
||||
}
|
||||
if (!user.isLoggedIn) {
|
||||
return { path: '/login', query: { redirect: to.fullPath } }
|
||||
}
|
||||
if (!user.routesAdded) {
|
||||
accessibleRoutes(user.roles).forEach((r) => router.addRoute(r))
|
||||
user.routesAdded = true
|
||||
// 按路径重新解析:展开 {...to} 会携带 catch-all 先匹配出的 name/matched,
|
||||
// vue-router 按 name 优先解析 → 刷新时永远落 not-found(404)——已修复。
|
||||
return { path: to.fullPath, replace: true }
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { publicRoutes } from './routes'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: publicRoutes,
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,91 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
/** 常量:可访问路由的 meta 键约定(title/menu/roles/icon/group/subtitle)。
|
||||
* icon=契约 SVG symbol id(components/IconSprite.vue #i-*),替代旧 EP 图标名。 */
|
||||
export interface RouteMetaExt {
|
||||
title?: string
|
||||
icon?: string
|
||||
menu?: boolean
|
||||
roles?: string[]
|
||||
group?: string
|
||||
subtitle?: string
|
||||
}
|
||||
|
||||
declare module 'vue-router' {
|
||||
interface RouteMeta extends RouteMetaExt {}
|
||||
}
|
||||
|
||||
/** 公共路由(无需登录)。 */
|
||||
export const publicRoutes: RouteRecordRaw[] = [
|
||||
{ path: '/login', name: 'login', component: () => import('@/views/login/LoginView.vue') },
|
||||
{ path: '/:pathMatch(.*)*', name: 'not-found', component: () => import('@/views/error/NotFound.vue') },
|
||||
]
|
||||
|
||||
/** 业务路由(需登录,按 roles 过滤)。
|
||||
* B1 基座:name/title/group/roles/subtitle 与旧 web 路由完全对齐(36 视图契约),
|
||||
* component 统一 ComingSoon 占位——B2 三契约页(dash/acct/chan)与 B3 33 视图逐页实装替换。 */
|
||||
export const asyncRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layouts/BasicLayout.vue'),
|
||||
redirect: '/home',
|
||||
children: [
|
||||
{ path: 'home', name: 'home', component: () => import('@/views/home/DashboardView.vue'), meta: { title: '运营总览', icon: 'i-grid', menu: true, group: '工作台', subtitle: '今日平台运行概览 · 60s 自动刷新', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'notice', name: 'notice', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '预警公告', icon: 'i-bell', menu: true, group: '工作台', roles: ['admin', 'ops', 'service', 'group'] } },
|
||||
|
||||
{ path: 'account', name: 'account-list', component: () => import('@/views/account/AccountList.vue'), meta: { title: '帐号管理', icon: 'i-users', menu: true, group: '运营管理', roles: ['admin', 'ops'] } },
|
||||
{ path: 'account/create', name: 'account-create', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '开户', group: '运营管理', roles: ['admin', 'ops'] } },
|
||||
{ path: 'account/:id', name: 'account-detail', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '账号详情', group: '运营管理', roles: ['admin', 'ops'] } },
|
||||
{ path: 'account/:id/recharge', name: 'account-recharge', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '充值', group: '运营管理', roles: ['admin', 'ops'] } },
|
||||
{ path: 'account/roles', name: 'account-roles', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '角色权限', group: '运营管理', roles: ['admin'] } },
|
||||
{ path: 'audit', name: 'audit', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '审核中心', icon: 'i-stamp', menu: true, group: '运营管理', roles: ['admin', 'ops', 'service'] } },
|
||||
{ path: 'audit/login', name: 'audit-login', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '登录审计', group: '运营管理', roles: ['admin', 'ops'] } },
|
||||
|
||||
{ path: 'sms', name: 'sms', redirect: '/sms/home', meta: { title: '短信业务', group: '业务中心' } },
|
||||
{ path: 'sms/home', name: 'sms-home', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '短信聚合页', icon: 'i-sms', menu: true, group: '业务中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'sms/batch', name: 'sms-batch', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '群发工作台', icon: 'i-send', menu: true, group: '业务中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'sms/personal', name: 'sms-personal', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '个性短信', icon: 'i-send', menu: true, group: '业务中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'sms/timer', name: 'sms-timer', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '定时任务', icon: 'i-clock', menu: true, group: '业务中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'sms/result', name: 'sms-result', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '发送结果反馈', icon: 'i-check', menu: true, group: '业务中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'sms/template', name: 'sms-template', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '模板管理', icon: 'i-sms', menu: true, group: '业务中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'sms/downlink-detail', name: 'sms-downlink-detail', component: () => import('@/views/sms/DownlinkDetailView.vue'), meta: { title: '短信下行明细', icon: 'i-sms', menu: true, group: '记录中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'video', name: 'video', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '视频业务', icon: 'i-zap', menu: true, group: '业务中心', roles: ['admin', 'ops'] } },
|
||||
{ path: 'csp', name: 'csp', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: 'CSP业务', icon: 'i-sms', menu: true, group: '业务中心', roles: ['admin', 'ops'] } },
|
||||
{ path: 'nullfilter', name: 'nullfilter', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '空号业务', icon: 'i-warn', menu: true, group: '业务中心', roles: ['admin', 'ops'] } },
|
||||
{ path: 'shortlink', name: 'shortlink', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '短链业务', icon: 'i-route', menu: true, group: '业务中心', roles: ['admin', 'ops'] } },
|
||||
|
||||
// 记录中心(FE-4;record/detail 为兼容重定向,语义同旧)
|
||||
{ path: 'record/down', name: 'record-down', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '下行记录', icon: 'i-sms', menu: true, group: '记录中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'record/detail', name: 'record-detail', redirect: (to) => ({ path: '/sms/downlink-detail', query: { ...to.query, batch_id: (to.query.task_no ?? to.query.batch_id) as string | undefined } }), meta: { title: '下行明细', menu: false, group: '记录中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'record/up', name: 'record-up', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '上行记录', icon: 'i-callback', menu: true, group: '记录中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
{ path: 'record/repush', name: 'record-repush', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '回执工具', icon: 'i-refresh', menu: true, group: '记录中心', roles: ['admin', 'ops', 'service'] } },
|
||||
{ path: 'record/history', name: 'record-history', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '历史记录', menu: false, group: '记录中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
|
||||
{ path: 'channel', name: 'channel', component: () => import('@/views/channel/ChannelList.vue'), meta: { title: '通道配置', icon: 'i-layer', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
|
||||
{ path: 'channel/upstream', name: 'channel-upstream', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '上家管理', icon: 'i-srv', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
|
||||
{ path: 'channel/edit/:id?', name: 'channel-edit', component: () => import('@/views/channel/ChannelEdit.vue'), meta: { title: '通道编辑', group: '通道与策略', roles: ['admin', 'ops'] } },
|
||||
{ path: 'channel/group', name: 'channel-group', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '通道组路由', icon: 'i-route', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
|
||||
{ path: 'policy', name: 'policy', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '规则策略', icon: 'i-set', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
|
||||
{ path: 'policy/route', name: 'policy-route', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '导流策略', icon: 'i-route', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
|
||||
{ path: 'policy/report', name: 'policy-report', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '签名/码号报备', icon: 'i-stamp', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
|
||||
{ path: 'contacts', name: 'contacts', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '通讯录', icon: 'i-users', menu: true, group: '通道与策略', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
|
||||
{ path: 'stats/user', name: 'stats-user', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '用户统计', icon: 'i-chart', menu: true, group: '统计结算', roles: ['admin', 'ops', 'service'] } },
|
||||
{ path: 'stats/channel', name: 'stats-channel', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '通道统计', icon: 'i-chart', menu: true, group: '统计结算', roles: ['admin', 'ops'] } },
|
||||
{ path: 'stats/profit', name: 'stats-profit', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '利润分析', icon: 'i-chart', menu: true, group: '统计结算', roles: ['admin', 'ops', 'service'], subtitle: '用户利润(含下级返点)· 通道利润 · 平台净利' } },
|
||||
{ path: 'settle', name: 'settle', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '结算管理', icon: 'i-coin', menu: true, group: '统计结算', roles: ['admin', 'ops'] } },
|
||||
{ path: 'ops/callback', name: 'ops-callback', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '回调管理', icon: 'i-callback', menu: true, group: '系统管理', roles: ['admin', 'ops'], subtitle: '客户回调推送任务 · 指数退避 · 死信可查可重派' } },
|
||||
|
||||
{ path: 'logs', name: 'logs', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '日志报表', icon: 'i-db', menu: true, group: '系统管理', roles: ['admin', 'ops', 'service'] } },
|
||||
{ path: 'system', name: 'system', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '系统配置', icon: 'i-set', menu: true, group: '系统管理', roles: ['admin'], subtitle: '系统级参数 KV · 默认接入码 · 拉黑词表' } },
|
||||
// Issue#4 发布日志(全角色);版本单一事实源=src/data/releases.ts。
|
||||
{ path: 'system/release', name: 'system-release', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '发布日志', icon: 'i-clock', menu: true, group: '系统管理', roles: ['admin', 'ops', 'service', 'group', 'customer'], subtitle: '平台功能迭代明细 · 大白话版' } },
|
||||
{ path: 'faq', name: 'faq', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '常见问题', icon: 'i-warn', menu: true, group: '系统管理', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
|
||||
// 隐藏页(不在菜单)
|
||||
{ path: '403', name: 'forbidden', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '无权限' } },
|
||||
{ path: '500', name: 'server-error', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '服务异常' } },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// stores/release.ts — Issue#4 版本已读状态(侧栏红点判定)。
|
||||
//
|
||||
// 口径:localStorage 记"上次已看过的版本"(gosms_seen_ver),≠ 当前版本
|
||||
// APP_VERSION 即视为"有更新"(红点亮);首次访问无记录=有更新,引导用户
|
||||
// 看一次发布日志。红点为浏览器本地"未读"语义——换浏览器/清缓存会重新
|
||||
// 提示一次(验收单如实标注),平台侧不做服务端已读同步。
|
||||
import { defineStore } from 'pinia'
|
||||
import { APP_VERSION } from '@/data/releases'
|
||||
|
||||
const SEEN_KEY = 'gosms_seen_ver'
|
||||
|
||||
function loadSeen(): string {
|
||||
return localStorage.getItem(SEEN_KEY) ?? ''
|
||||
}
|
||||
|
||||
export const useReleaseStore = defineStore('release', {
|
||||
state: (): { seenVer: string } => ({ seenVer: loadSeen() }),
|
||||
getters: {
|
||||
/** 有未读新版本(侧栏版本号旁红点闪烁的判定源)。 */
|
||||
hasUpdate: (s): boolean => s.seenVer !== APP_VERSION,
|
||||
},
|
||||
actions: {
|
||||
/** 标记当前版本已读(点击版本号 / 进入发布日志页时调用)。 */
|
||||
markSeen() {
|
||||
this.seenVer = APP_VERSION
|
||||
localStorage.setItem(SEEN_KEY, APP_VERSION)
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -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'
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,49 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { login as apiLogin } from '@/api/auth'
|
||||
import { clearToken, getToken, getStoredUser, setStoredUser, setToken } from '@/utils/auth'
|
||||
import type { UserInfo } from '@/api/types'
|
||||
|
||||
interface UserState {
|
||||
token: string
|
||||
user: UserInfo | null
|
||||
routesAdded: boolean
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: (): UserState => ({ token: getToken(), user: getStoredUser<UserInfo>(), routesAdded: false }),
|
||||
getters: {
|
||||
isLoggedIn: (s) => s.token !== '' && !!s.user, // !!s.user:undefined 与 null 同判未登录(防语义坑)
|
||||
roles: (s) => s.user?.roles ?? [],
|
||||
},
|
||||
actions: {
|
||||
async login(username: string, password: string) {
|
||||
const data = await apiLogin({ username, password })
|
||||
this.token = data.token
|
||||
// 双契约适配:后端返回 user 对象为準;旧/精简响应(仅 username+role 单数)时就地构造,
|
||||
// 避免写入 undefined 引发路由全过滤 404 与 localStorage 脏数据。
|
||||
const user = data.user ?? {
|
||||
account_id: 0,
|
||||
username: (data as { username?: string }).username ?? username,
|
||||
roles: [(data as { role?: string }).role ?? 'customer'].filter(Boolean),
|
||||
permissions: [] as string[],
|
||||
}
|
||||
this.user = user
|
||||
setToken(data.token)
|
||||
setStoredUser(user)
|
||||
},
|
||||
hasRole(role: string) {
|
||||
return this.roles.includes('admin') || this.roles.includes(role)
|
||||
},
|
||||
hasPermission(code: string) {
|
||||
if (this.roles.includes('admin')) return true
|
||||
return (this.user?.permissions ?? []).includes(code)
|
||||
},
|
||||
logout() {
|
||||
this.$reset()
|
||||
this.token = ''
|
||||
this.user = null
|
||||
this.routesAdded = false
|
||||
clearToken()
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,862 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-gray-200 dark:border-dark-700;
|
||||
}
|
||||
|
||||
html {
|
||||
@apply scroll-smooth antialiased;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
.dark {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-gray-50 text-gray-900 dark:bg-dark-950 dark:text-gray-100;
|
||||
@apply min-h-screen;
|
||||
}
|
||||
|
||||
/* 自定义滚动条 - 仅针对 Firefox,避免 Chrome 取消 webkit 的全局定制 */
|
||||
@supports (-moz-appearance:none) {
|
||||
* {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: transparent transparent;
|
||||
}
|
||||
|
||||
*:hover,
|
||||
*:focus-within {
|
||||
scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
|
||||
}
|
||||
|
||||
.dark *:hover,
|
||||
.dark *:focus-within {
|
||||
scrollbar-color: rgba(75, 85, 99, 0.5) transparent;
|
||||
}
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
@apply h-2 w-2;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
@apply bg-transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
@apply rounded-full bg-transparent;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
*:hover::-webkit-scrollbar-thumb {
|
||||
@apply bg-gray-300/50 dark:bg-dark-600/50;
|
||||
}
|
||||
|
||||
*:hover::-webkit-scrollbar-thumb:hover {
|
||||
@apply bg-gray-400 dark:bg-dark-500;
|
||||
}
|
||||
|
||||
/* 选中文本样式 */
|
||||
::selection {
|
||||
@apply bg-primary-500/20 text-primary-900 dark:text-primary-100;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@layer components {
|
||||
/* ============ 按钮样式 ============ */
|
||||
.btn {
|
||||
@apply inline-flex items-center justify-center gap-2;
|
||||
@apply rounded-xl px-4 py-2.5 text-sm font-medium;
|
||||
@apply transition-all duration-200 ease-out;
|
||||
@apply focus:outline-none focus:ring-2 focus:ring-primary-500/50 focus:ring-offset-2;
|
||||
@apply disabled:transform-none disabled:cursor-not-allowed disabled:opacity-50;
|
||||
@apply active:scale-[0.98];
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
@apply bg-gradient-to-r from-primary-500 to-primary-600;
|
||||
@apply text-white shadow-md shadow-primary-500/25;
|
||||
@apply hover:from-primary-600 hover:to-primary-700 hover:shadow-lg hover:shadow-primary-500/30;
|
||||
@apply dark:shadow-primary-500/20;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
@apply bg-white dark:bg-dark-800;
|
||||
@apply text-gray-700 dark:text-gray-200;
|
||||
@apply border border-gray-200 dark:border-dark-600;
|
||||
@apply shadow-sm hover:bg-gray-50 dark:hover:bg-dark-700;
|
||||
@apply hover:border-gray-300 dark:hover:border-dark-500;
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
@apply bg-transparent text-gray-600 dark:text-gray-300;
|
||||
@apply hover:bg-gray-100 dark:hover:bg-dark-800;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
@apply bg-gradient-to-r from-red-500 to-red-600;
|
||||
@apply text-white shadow-md shadow-red-500/25;
|
||||
@apply hover:from-red-600 hover:to-red-700 hover:shadow-lg hover:shadow-red-500/30;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
@apply bg-gradient-to-r from-emerald-500 to-emerald-600;
|
||||
@apply text-white shadow-md shadow-emerald-500/25;
|
||||
@apply hover:from-emerald-600 hover:to-emerald-700 hover:shadow-lg hover:shadow-emerald-500/30;
|
||||
@apply dark:shadow-emerald-500/20;
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
@apply bg-gradient-to-r from-amber-500 to-amber-600;
|
||||
@apply text-white shadow-md shadow-amber-500/25;
|
||||
@apply hover:from-amber-600 hover:to-amber-700 hover:shadow-lg hover:shadow-amber-500/30;
|
||||
@apply dark:shadow-amber-500/20;
|
||||
}
|
||||
|
||||
.btn-stripe {
|
||||
@apply bg-[#635bff] text-white shadow-md shadow-[#635bff]/25;
|
||||
@apply hover:bg-[#5851ea] hover:shadow-lg hover:shadow-[#635bff]/30;
|
||||
@apply dark:bg-[#7a73ff] dark:shadow-[#7a73ff]/20;
|
||||
@apply dark:hover:bg-[#635bff];
|
||||
}
|
||||
|
||||
.btn-airwallex {
|
||||
@apply bg-[#14171A] text-white shadow-md shadow-emerald-500/20;
|
||||
@apply hover:bg-[#20252a] hover:shadow-lg hover:shadow-emerald-500/25;
|
||||
@apply dark:bg-[#7AF0C4] dark:text-gray-950 dark:shadow-emerald-500/20;
|
||||
@apply dark:hover:bg-[#62d9ad];
|
||||
}
|
||||
|
||||
.btn-alipay {
|
||||
@apply bg-[#00AEEF] text-white shadow-md shadow-[#00AEEF]/25;
|
||||
@apply hover:bg-[#009dd6] hover:shadow-lg hover:shadow-[#00AEEF]/30;
|
||||
@apply active:bg-[#008cbe];
|
||||
@apply dark:shadow-[#00AEEF]/20;
|
||||
}
|
||||
|
||||
.btn-wxpay {
|
||||
@apply bg-[#2BB741] text-white shadow-md shadow-[#2BB741]/25;
|
||||
@apply hover:bg-[#24a038] hover:shadow-lg hover:shadow-[#2BB741]/30;
|
||||
@apply active:bg-[#1d8a2f];
|
||||
@apply dark:shadow-[#2BB741]/20;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
@apply rounded-lg px-3 py-1.5 text-xs;
|
||||
}
|
||||
|
||||
.btn-md {
|
||||
@apply rounded-xl px-4 py-2 text-sm;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
@apply rounded-2xl px-6 py-3 text-base;
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
@apply rounded-xl p-2.5;
|
||||
}
|
||||
|
||||
/* ============ 输入框样式 ============ */
|
||||
.input {
|
||||
@apply w-full rounded-xl px-4 py-2.5 text-sm;
|
||||
@apply bg-white dark:bg-dark-800;
|
||||
@apply border border-gray-200 dark:border-dark-600;
|
||||
@apply text-gray-900 dark:text-gray-100;
|
||||
@apply placeholder:text-gray-400 dark:placeholder:text-dark-400;
|
||||
@apply transition-all duration-200;
|
||||
@apply focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/30;
|
||||
@apply disabled:cursor-not-allowed disabled:bg-gray-100 dark:disabled:bg-dark-900;
|
||||
}
|
||||
|
||||
.dark .input[type='date'],
|
||||
.dark .input[type='time'],
|
||||
.dark .input[type='datetime-local'],
|
||||
.dark .input[type='month'],
|
||||
.dark .input[type='week'] {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
.input-error {
|
||||
@apply border-red-500 focus:border-red-500 focus:ring-red-500/30;
|
||||
}
|
||||
|
||||
.input-label {
|
||||
@apply mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300;
|
||||
}
|
||||
|
||||
.input-hint {
|
||||
@apply mt-1 text-xs text-gray-500 dark:text-dark-400;
|
||||
}
|
||||
|
||||
.input-error-text {
|
||||
@apply mt-1 text-xs text-red-500;
|
||||
}
|
||||
|
||||
/* Hide number input spinner buttons for cleaner UI */
|
||||
input[type='number']::-webkit-inner-spin-button,
|
||||
input[type='number']::-webkit-outer-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
input[type='number'] {
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
/* ============ 玻璃效果 ============ */
|
||||
.glass {
|
||||
@apply bg-white/80 backdrop-blur-xl dark:bg-dark-800/80;
|
||||
}
|
||||
|
||||
.glass-card {
|
||||
@apply bg-white/70 dark:bg-dark-800/70;
|
||||
@apply backdrop-blur-xl;
|
||||
@apply rounded-2xl;
|
||||
@apply border border-white/20 dark:border-dark-700/50;
|
||||
@apply shadow-glass;
|
||||
@apply transition-all duration-300;
|
||||
}
|
||||
|
||||
/* ============ 卡片样式 ============ */
|
||||
.card {
|
||||
@apply bg-white dark:bg-dark-800/50;
|
||||
@apply rounded-2xl;
|
||||
@apply border border-gray-100 dark:border-dark-700/50;
|
||||
@apply shadow-card;
|
||||
@apply transition-all duration-300;
|
||||
}
|
||||
|
||||
.card-hover {
|
||||
@apply hover:-translate-y-0.5 hover:shadow-card-hover;
|
||||
@apply hover:border-gray-200 dark:hover:border-dark-600;
|
||||
}
|
||||
|
||||
.card-glass {
|
||||
@apply bg-white/70 dark:bg-dark-800/70;
|
||||
@apply backdrop-blur-xl;
|
||||
@apply border border-white/20 dark:border-dark-700/50;
|
||||
@apply shadow-glass;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
@apply border-b border-gray-100 dark:border-dark-700;
|
||||
@apply px-6 py-4;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
@apply p-6;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
@apply border-t border-gray-100 dark:border-dark-700;
|
||||
@apply px-6 py-4;
|
||||
}
|
||||
|
||||
/* ============ 统计卡片 ============ */
|
||||
.stat-card {
|
||||
@apply card p-5;
|
||||
@apply flex items-start gap-4;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
@apply h-12 w-12 rounded-xl;
|
||||
@apply flex items-center justify-center;
|
||||
@apply text-xl;
|
||||
}
|
||||
|
||||
.stat-icon-primary {
|
||||
@apply bg-primary-100 text-primary-600 dark:bg-primary-900/30 dark:text-primary-400;
|
||||
}
|
||||
|
||||
.stat-icon-success {
|
||||
@apply bg-emerald-100 text-emerald-600 dark:bg-emerald-900/30 dark:text-emerald-400;
|
||||
}
|
||||
|
||||
.stat-icon-warning {
|
||||
@apply bg-amber-100 text-amber-600 dark:bg-amber-900/30 dark:text-amber-400;
|
||||
}
|
||||
|
||||
.stat-icon-danger {
|
||||
@apply bg-red-100 text-red-600 dark:bg-red-900/30 dark:text-red-400;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
@apply text-2xl font-bold text-gray-900 dark:text-white truncate;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
@apply text-sm text-gray-500 dark:text-dark-400;
|
||||
}
|
||||
|
||||
.stat-trend {
|
||||
@apply mt-1 flex items-center gap-1 text-xs font-medium;
|
||||
}
|
||||
|
||||
.stat-trend-up {
|
||||
@apply text-emerald-600 dark:text-emerald-400;
|
||||
}
|
||||
|
||||
.stat-trend-down {
|
||||
@apply text-red-600 dark:text-red-400;
|
||||
}
|
||||
|
||||
/* ============ 表格样式 ============ */
|
||||
.table-container {
|
||||
@apply overflow-x-auto rounded-xl border border-gray-200 dark:border-dark-700;
|
||||
}
|
||||
|
||||
.table {
|
||||
@apply w-full text-sm;
|
||||
}
|
||||
|
||||
.table th {
|
||||
@apply px-4 py-3 text-left font-medium;
|
||||
@apply text-gray-600 dark:text-dark-300;
|
||||
@apply bg-gray-50 dark:bg-dark-800/50;
|
||||
@apply border-b border-gray-200 dark:border-dark-700;
|
||||
}
|
||||
|
||||
.table td {
|
||||
@apply px-4 py-3;
|
||||
@apply text-gray-700 dark:text-gray-300;
|
||||
@apply border-b border-gray-100 dark:border-dark-800;
|
||||
}
|
||||
|
||||
.table tr:last-child td {
|
||||
@apply border-b-0;
|
||||
}
|
||||
|
||||
.table tbody tr {
|
||||
@apply transition-colors duration-150;
|
||||
@apply hover:bg-gray-50 dark:hover:bg-dark-800/30;
|
||||
}
|
||||
|
||||
/* ============ 徽章样式 ============ */
|
||||
.badge {
|
||||
@apply inline-flex items-center gap-1;
|
||||
@apply rounded-full px-2.5 py-0.5 text-xs font-medium;
|
||||
}
|
||||
|
||||
.badge-primary {
|
||||
@apply bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-400;
|
||||
}
|
||||
|
||||
.badge-success {
|
||||
@apply bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400;
|
||||
}
|
||||
|
||||
.badge-warning {
|
||||
@apply bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400;
|
||||
}
|
||||
|
||||
.badge-danger {
|
||||
@apply bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400;
|
||||
}
|
||||
|
||||
.badge-gray {
|
||||
@apply bg-gray-100 text-gray-700 dark:bg-dark-700 dark:text-dark-300;
|
||||
}
|
||||
|
||||
.badge-purple {
|
||||
@apply bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400;
|
||||
}
|
||||
|
||||
/* ============ 下拉菜单 ============ */
|
||||
.dropdown {
|
||||
@apply absolute z-50;
|
||||
@apply bg-white dark:bg-dark-800;
|
||||
@apply rounded-xl;
|
||||
@apply border border-gray-200 dark:border-dark-700;
|
||||
@apply shadow-lg;
|
||||
@apply py-1;
|
||||
@apply origin-top-right animate-scale-in;
|
||||
}
|
||||
|
||||
.dropdown-item {
|
||||
@apply px-4 py-2 text-sm;
|
||||
@apply text-gray-700 dark:text-gray-300;
|
||||
@apply hover:bg-gray-100 dark:hover:bg-dark-700;
|
||||
@apply cursor-pointer transition-colors;
|
||||
@apply flex items-center gap-2;
|
||||
}
|
||||
|
||||
/* ============ 模态框 ============ */
|
||||
.modal-overlay {
|
||||
@apply fixed inset-0 z-50;
|
||||
@apply bg-black/50 backdrop-blur-sm;
|
||||
@apply flex items-center justify-center p-2 sm:p-4;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
@apply w-full;
|
||||
@apply max-h-[95vh] sm:max-h-[90vh];
|
||||
@apply bg-white dark:bg-dark-800;
|
||||
@apply rounded-2xl shadow-2xl;
|
||||
@apply border border-gray-200 dark:border-dark-700;
|
||||
@apply flex flex-col;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
@apply border-b border-gray-200 px-4 py-3 dark:border-dark-700;
|
||||
@apply sm:px-6 sm:py-4;
|
||||
@apply flex items-center justify-between;
|
||||
@apply flex-shrink-0;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
@apply text-lg font-semibold text-gray-900 dark:text-white;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
@apply px-4 py-3;
|
||||
@apply sm:px-6 sm:py-4;
|
||||
@apply flex-1 overflow-y-auto;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
@apply border-t border-gray-200 px-4 py-3 dark:border-dark-700;
|
||||
@apply sm:px-6 sm:py-4;
|
||||
@apply flex items-center justify-end gap-3;
|
||||
@apply flex-shrink-0;
|
||||
}
|
||||
|
||||
/* 防止body滚动的工具类 */
|
||||
body.modal-open {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.modal-enter-active {
|
||||
transition: opacity 250ms ease-out;
|
||||
}
|
||||
|
||||
.modal-leave-active {
|
||||
transition: opacity 200ms ease-in;
|
||||
}
|
||||
|
||||
.modal-enter-from,
|
||||
.modal-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.modal-enter-active .modal-content {
|
||||
transition: transform 250ms ease-out, opacity 250ms ease-out;
|
||||
}
|
||||
|
||||
.modal-leave-active .modal-content {
|
||||
transition: transform 200ms ease-in, opacity 200ms ease-in;
|
||||
}
|
||||
|
||||
.modal-enter-from .modal-content,
|
||||
.modal-leave-to .modal-content {
|
||||
transform: scale(0.95);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.modal-enter-to .modal-content,
|
||||
.modal-leave-from .modal-content {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.modal-enter-active,
|
||||
.modal-leave-active,
|
||||
.modal-enter-active .modal-content,
|
||||
.modal-leave-active .modal-content {
|
||||
transition-duration: 1ms;
|
||||
transition-delay: 0ms;
|
||||
}
|
||||
|
||||
.modal-enter-from .modal-content,
|
||||
.modal-leave-to .modal-content {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============ Dialog ============ */
|
||||
.dialog-overlay {
|
||||
@apply fixed inset-0 z-50;
|
||||
@apply bg-black/40 dark:bg-black/60;
|
||||
@apply flex items-center justify-center p-4;
|
||||
}
|
||||
|
||||
.dialog-container {
|
||||
@apply flex w-full flex-col;
|
||||
@apply max-h-[90vh];
|
||||
@apply rounded-2xl bg-white dark:bg-dark-800;
|
||||
@apply shadow-xl;
|
||||
}
|
||||
|
||||
.dialog-header {
|
||||
@apply border-b border-gray-100 px-6 py-4 dark:border-dark-700;
|
||||
@apply flex items-center justify-between;
|
||||
}
|
||||
|
||||
.dialog-body {
|
||||
@apply overflow-y-auto px-6 py-4;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@apply border-t border-gray-100 px-6 py-4 dark:border-dark-700;
|
||||
@apply bg-gray-50/60 dark:bg-dark-900/40;
|
||||
@apply flex items-center justify-end gap-3;
|
||||
}
|
||||
|
||||
/* ============ Toast 通知 ============ */
|
||||
.toast {
|
||||
@apply fixed right-4 top-4 z-[100];
|
||||
@apply min-w-[320px] max-w-md;
|
||||
@apply bg-white dark:bg-dark-800;
|
||||
@apply rounded-xl shadow-lg;
|
||||
@apply border-l-4;
|
||||
@apply p-4;
|
||||
@apply animate-slide-in-right;
|
||||
}
|
||||
|
||||
.toast-success {
|
||||
@apply border-l-emerald-500;
|
||||
}
|
||||
|
||||
.toast-error {
|
||||
@apply border-l-red-500;
|
||||
}
|
||||
|
||||
.toast-warning {
|
||||
@apply border-l-amber-500;
|
||||
}
|
||||
|
||||
.toast-info {
|
||||
@apply border-l-primary-500;
|
||||
}
|
||||
|
||||
/* ============ 侧边栏 ============ */
|
||||
.sidebar {
|
||||
@apply fixed inset-y-0 left-0 z-40;
|
||||
@apply w-64 bg-white dark:bg-dark-900;
|
||||
@apply border-r border-gray-200 dark:border-dark-800;
|
||||
@apply flex flex-col;
|
||||
@apply transition-transform duration-300;
|
||||
transition-property: width, transform;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
@apply h-16 px-6;
|
||||
@apply flex items-center gap-3;
|
||||
@apply border-b border-gray-100 dark:border-dark-800;
|
||||
transition:
|
||||
padding 0.2s ease,
|
||||
gap 0.2s ease;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
@apply flex-1 overflow-y-auto px-3 py-4;
|
||||
}
|
||||
|
||||
.sidebar-link {
|
||||
@apply flex items-center gap-3 rounded-xl py-2.5;
|
||||
@apply overflow-hidden;
|
||||
@apply text-sm font-medium;
|
||||
@apply text-gray-600 dark:text-dark-300;
|
||||
@apply transition-all duration-200;
|
||||
@apply hover:bg-gray-100 dark:hover:bg-dark-800;
|
||||
@apply hover:text-gray-900 dark:hover:text-white;
|
||||
padding-left: 1.0625rem;
|
||||
padding-right: 0.875rem;
|
||||
}
|
||||
|
||||
.sidebar-link-active {
|
||||
@apply bg-primary-50 dark:bg-primary-900/20;
|
||||
@apply text-primary-600 dark:text-primary-400;
|
||||
@apply hover:bg-primary-100 dark:hover:bg-primary-900/30;
|
||||
}
|
||||
|
||||
.sidebar-section {
|
||||
@apply mb-6;
|
||||
}
|
||||
|
||||
.sidebar-section-title {
|
||||
@apply mb-2 px-3;
|
||||
@apply text-xs font-semibold uppercase tracking-wider;
|
||||
@apply text-gray-400 dark:text-dark-500;
|
||||
}
|
||||
|
||||
/* ============ 页面头部 ============ */
|
||||
.page-header {
|
||||
@apply mb-6;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
@apply text-2xl font-bold text-gray-900 dark:text-white;
|
||||
}
|
||||
|
||||
.page-description {
|
||||
@apply mt-1 text-sm text-gray-500 dark:text-dark-400;
|
||||
}
|
||||
|
||||
/* ============ 空状态 ============ */
|
||||
.empty-state {
|
||||
@apply flex flex-col items-center justify-center px-4 py-12;
|
||||
@apply text-center;
|
||||
}
|
||||
|
||||
.empty-state-icon {
|
||||
@apply mb-4 h-16 w-16;
|
||||
@apply text-gray-300 dark:text-dark-600;
|
||||
}
|
||||
|
||||
.empty-state-title {
|
||||
@apply mb-1 text-lg font-medium text-gray-900 dark:text-white;
|
||||
}
|
||||
|
||||
.empty-state-description {
|
||||
@apply max-w-sm text-sm text-gray-500 dark:text-dark-400;
|
||||
}
|
||||
|
||||
/* ============ 加载状态 ============ */
|
||||
.spinner {
|
||||
@apply h-5 w-5 rounded-full border-2 border-current border-t-transparent;
|
||||
@apply animate-spin;
|
||||
}
|
||||
|
||||
.skeleton {
|
||||
@apply animate-pulse rounded bg-gray-200 dark:bg-dark-700;
|
||||
}
|
||||
|
||||
/* ============ 分隔线 ============ */
|
||||
.divider {
|
||||
@apply my-4 h-px bg-gray-200 dark:bg-dark-700;
|
||||
}
|
||||
|
||||
/* ============ 标签页 ============ */
|
||||
.tabs {
|
||||
@apply flex gap-1 p-1;
|
||||
@apply rounded-xl bg-gray-100 dark:bg-dark-800;
|
||||
}
|
||||
|
||||
.tab {
|
||||
@apply rounded-lg px-4 py-2 text-sm font-medium;
|
||||
@apply text-gray-600 dark:text-dark-400;
|
||||
@apply transition-all duration-200;
|
||||
@apply hover:text-gray-900 dark:hover:text-white;
|
||||
}
|
||||
|
||||
.tab-active {
|
||||
@apply bg-white dark:bg-dark-700;
|
||||
@apply text-gray-900 dark:text-white;
|
||||
@apply shadow-sm;
|
||||
}
|
||||
|
||||
/* ============ 进度条 ============ */
|
||||
.progress {
|
||||
@apply h-2 overflow-hidden rounded-full bg-gray-200 dark:bg-dark-700;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
@apply h-full bg-gradient-to-r from-primary-500 to-primary-400;
|
||||
@apply transition-all duration-300;
|
||||
}
|
||||
|
||||
/* ============ 开关 ============ */
|
||||
.switch {
|
||||
@apply relative h-6 w-11 cursor-pointer rounded-full;
|
||||
@apply bg-gray-300 dark:bg-dark-600;
|
||||
@apply transition-colors duration-200;
|
||||
}
|
||||
|
||||
.switch-active {
|
||||
@apply bg-primary-500;
|
||||
}
|
||||
|
||||
.switch-thumb {
|
||||
@apply absolute left-0.5 top-0.5 h-5 w-5 rounded-full;
|
||||
@apply bg-white shadow-sm;
|
||||
@apply transition-transform duration-200;
|
||||
}
|
||||
|
||||
.switch-active .switch-thumb {
|
||||
@apply translate-x-5;
|
||||
}
|
||||
|
||||
/* ============ 代码块 ============ */
|
||||
.code {
|
||||
@apply font-mono text-sm;
|
||||
@apply bg-gray-100 dark:bg-dark-800;
|
||||
@apply rounded px-1.5 py-0.5;
|
||||
@apply text-primary-600 dark:text-primary-400;
|
||||
}
|
||||
|
||||
.code-block {
|
||||
@apply font-mono text-sm;
|
||||
@apply bg-gray-900 text-gray-100;
|
||||
@apply overflow-x-auto rounded-xl p-4;
|
||||
}
|
||||
|
||||
/* ============ Tour Description ============ */
|
||||
.tour-step-description {
|
||||
@apply space-y-3 text-sm leading-relaxed text-gray-700 dark:text-gray-200;
|
||||
}
|
||||
|
||||
.tour-step-description ul {
|
||||
@apply list-disc pl-5;
|
||||
}
|
||||
|
||||
.tour-step-description ol {
|
||||
@apply list-decimal pl-5;
|
||||
}
|
||||
|
||||
.tour-step-description li + li {
|
||||
@apply mt-1;
|
||||
}
|
||||
|
||||
.tour-info-box {
|
||||
@apply rounded-md border-l-4 border-blue-500 bg-blue-50 px-3 py-2 text-xs text-blue-900;
|
||||
@apply dark:border-blue-400 dark:bg-blue-950/40 dark:text-blue-200;
|
||||
}
|
||||
|
||||
.tour-success-box {
|
||||
@apply rounded-md border-l-4 border-emerald-500 bg-emerald-50 px-3 py-2 text-xs text-emerald-900;
|
||||
@apply dark:border-emerald-400 dark:bg-emerald-950/40 dark:text-emerald-200;
|
||||
}
|
||||
|
||||
.tour-warning-box {
|
||||
@apply rounded-md border-l-4 border-amber-500 bg-amber-50 px-3 py-2 text-xs text-amber-900;
|
||||
@apply dark:border-amber-400 dark:bg-amber-950/40 dark:text-amber-200;
|
||||
}
|
||||
|
||||
.tour-error-box {
|
||||
@apply rounded-md border-l-4 border-red-500 bg-red-50 px-3 py-2 text-xs text-red-900;
|
||||
@apply dark:border-red-400 dark:bg-red-950/40 dark:text-red-200;
|
||||
}
|
||||
|
||||
/* ============ 表格页面布局优化 ============ */
|
||||
/* 表格容器 - 默认仅支持水平滚动 */
|
||||
.table-wrapper {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
/* 表头固定时添加底部阴影,增强视觉层次 */
|
||||
.table-wrapper thead.sticky {
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
@layer utilities {
|
||||
/* 文字渐变 */
|
||||
.text-gradient {
|
||||
@apply bg-gradient-to-r from-primary-500 to-accent-500 bg-clip-text text-transparent;
|
||||
}
|
||||
|
||||
/* 玻璃效果 */
|
||||
.glass {
|
||||
@apply bg-white/80 backdrop-blur-xl dark:bg-dark-800/80;
|
||||
}
|
||||
|
||||
/* 隐藏滚动条 */
|
||||
.scrollbar-hide {
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
.scrollbar-hide::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* 安全区域 */
|
||||
.safe-top {
|
||||
padding-top: env(safe-area-inset-top);
|
||||
}
|
||||
|
||||
.safe-bottom {
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* 以下为 go-sms 契约补充段(docs/design/issue6/v3-2-tailwind.html)
|
||||
* 1) stat-card 族:契约 components 层统计卡片(契约豁免①,sub2api 源无此类)
|
||||
* 2) body.folded 族:契约侧栏折叠态(72px)布局规则
|
||||
* ============================================================ */
|
||||
|
||||
/* ============ 统计卡片(契约 285-330 行直拷) ============ */
|
||||
.stat-card {
|
||||
@apply card p-5;
|
||||
@apply flex items-start gap-4;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
@apply h-12 w-12 rounded-xl;
|
||||
@apply flex items-center justify-center;
|
||||
@apply text-xl;
|
||||
}
|
||||
|
||||
.stat-icon-primary {
|
||||
@apply bg-primary-100 text-primary-600 dark:bg-primary-900/30 dark:text-primary-400;
|
||||
}
|
||||
|
||||
.stat-icon-success {
|
||||
@apply bg-emerald-100 text-emerald-600 dark:bg-emerald-900/30 dark:text-emerald-400;
|
||||
}
|
||||
|
||||
.stat-icon-warning {
|
||||
@apply bg-amber-100 text-amber-600 dark:bg-amber-900/30 dark:text-amber-400;
|
||||
}
|
||||
|
||||
.stat-icon-danger {
|
||||
@apply bg-red-100 text-red-600 dark:bg-red-900/30 dark:text-red-400;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
@apply text-2xl font-bold text-gray-900 dark:text-white truncate;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
@apply text-sm text-gray-500 dark:text-dark-400;
|
||||
}
|
||||
|
||||
.stat-trend {
|
||||
@apply mt-1 flex items-center gap-1 text-xs font-medium;
|
||||
}
|
||||
|
||||
.stat-trend-up {
|
||||
@apply text-emerald-600 dark:text-emerald-400;
|
||||
}
|
||||
|
||||
.stat-trend-down {
|
||||
@apply text-red-600 dark:text-red-400;
|
||||
}
|
||||
|
||||
/* ============ 侧栏折叠态(契约 1067-1071 行直拷) ============ */
|
||||
body.folded .sidebar {
|
||||
width: 72px;
|
||||
}
|
||||
body.folded .sidebar-header {
|
||||
gap: 0;
|
||||
padding-left: 1.125rem;
|
||||
padding-right: 1.125rem;
|
||||
}
|
||||
body.folded .sidebar-brand,
|
||||
body.folded .sidebar-label,
|
||||
body.folded .sidebar-section-title,
|
||||
body.folded .sidebar-link .ml-auto {
|
||||
display: none;
|
||||
}
|
||||
body.folded .sidebar-link {
|
||||
justify-content: center;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
body.folded #mainWrap {
|
||||
padding-left: 72px;
|
||||
}
|
||||
@media (min-width: 1024px) {
|
||||
body.folded #mainWrap {
|
||||
padding-left: 72px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
const TOKEN_KEY = 'gosms_token'
|
||||
const USER_KEY = 'gosms_user'
|
||||
|
||||
export function getToken(): string {
|
||||
return localStorage.getItem(TOKEN_KEY) ?? ''
|
||||
}
|
||||
|
||||
export function setToken(token: string) {
|
||||
localStorage.setItem(TOKEN_KEY, token)
|
||||
}
|
||||
|
||||
export function clearToken() {
|
||||
localStorage.removeItem(TOKEN_KEY)
|
||||
localStorage.removeItem(USER_KEY)
|
||||
}
|
||||
|
||||
export function getStoredUser<T>(): T | null {
|
||||
const raw = localStorage.getItem(USER_KEY)
|
||||
if (!raw) return null
|
||||
try {
|
||||
return JSON.parse(raw) as T
|
||||
} catch {
|
||||
// 脏数据自愈(如历史版本写入的 "undefined"):清除并视为未登录,不再白屏。
|
||||
localStorage.removeItem(USER_KEY)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function setStoredUser(user: unknown) {
|
||||
localStorage.setItem(USER_KEY, JSON.stringify(user))
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// error-reporter.ts Day 53(runbook §6.4 P0):前端错误上报。
|
||||
// 双路采集:①window error/unhandledrejection(JS 运行时);②request.ts 响应
|
||||
// 拦截器(HTTP 5xx/网络层,见 request.ts 调用点)。上报自身静默失败(尽力而为,
|
||||
// 绝不递归:上报接口的错误不再上报)。Day43 vite proxy 死端口案例的后端零感知补洞。
|
||||
const SUPPRESS = 'fe-errors'
|
||||
|
||||
export interface FeErrorPayload {
|
||||
kind: 'js' | 'http' | 'unhandled'
|
||||
page_url: string
|
||||
message: string
|
||||
stack?: string
|
||||
ua: string
|
||||
trace_id?: string
|
||||
}
|
||||
|
||||
let lastAt = 0
|
||||
let dedupeKey = ''
|
||||
|
||||
/** 上报单条(60s 同 message 去重,防错误风暴刷爆 fe_error_log)。 */
|
||||
export function reportFeError(p: FeErrorPayload): void {
|
||||
const now = Date.now()
|
||||
if (p.message === dedupeKey && now - lastAt < 60_000) return
|
||||
dedupeKey = p.message
|
||||
lastAt = now
|
||||
try {
|
||||
void fetch(`${import.meta.env.VITE_API_BASE_URL}/fe-errors`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(p),
|
||||
keepalive: true, // 页面卸载路径(白屏)也能送达
|
||||
}).catch(() => undefined) // 静默:上报失败不阻塞业务
|
||||
} catch {
|
||||
/* 同上 */
|
||||
}
|
||||
}
|
||||
|
||||
function pageUrl(): string {
|
||||
try {
|
||||
return window.location.href
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
/** 安装全局监听(main.ts 挂载一次)。 */
|
||||
export function installFeErrorReporter(): void {
|
||||
if (typeof window === 'undefined') return
|
||||
window.addEventListener('error', (ev) => {
|
||||
// 资源加载错误(ev.target 非 window)与脚本错误分流
|
||||
const target = ev.target as HTMLElement | null
|
||||
if (target && target !== (window as unknown as HTMLElement)) {
|
||||
reportFeError({
|
||||
kind: 'js',
|
||||
page_url: pageUrl(),
|
||||
message: `资源加载失败:${(target as HTMLImageElement).src || (target as HTMLScriptElement).src || target.tagName}`,
|
||||
ua: navigator.userAgent,
|
||||
})
|
||||
return
|
||||
}
|
||||
reportFeError({
|
||||
kind: 'js',
|
||||
page_url: pageUrl(),
|
||||
message: ev.message || 'unknown error',
|
||||
stack: ev.error?.stack,
|
||||
ua: navigator.userAgent,
|
||||
})
|
||||
})
|
||||
window.addEventListener('unhandledrejection', (ev) => {
|
||||
const reason = ev.reason
|
||||
// 上报通道自身的失败不再上报(防递归);BizError 属业务语义不刷表
|
||||
const url = typeof reason === 'object' && reason?.config?.url ? String(reason.config.url) : ''
|
||||
if (url.includes(SUPPRESS)) return
|
||||
reportFeError({
|
||||
kind: 'unhandled',
|
||||
page_url: pageUrl(),
|
||||
message: reason instanceof Error ? reason.message : String(reason),
|
||||
stack: reason instanceof Error ? reason.stack : undefined,
|
||||
ua: navigator.userAgent,
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// utils/markdown.ts — Issue#4 迷你 Markdown 渲染器(发布日志专用,零依赖)。
|
||||
//
|
||||
// 支持范围(够用即止,不求 GFM 全集):
|
||||
// 标题 #~####、无序列表(-/*)、有序列表(1. / 1、)、粗体 **x**、
|
||||
// 行内代码 \`x\`、围栏代码块 \`\`\`、链接 [t](https://…)(仅 http/https)、
|
||||
// 空行分段(段内换行 → <br>)。
|
||||
// 安全口径:**输入先整体 HTML 转义再解析**——内容源虽是仓库静态数据
|
||||
// (releases.ts),仍按不可信文本处理,任何标签/引号都不会进入 DOM;
|
||||
// 链接仅允许 http(s) 协议(javascript: 伪协议不命中即保持原样文本)。
|
||||
|
||||
/** HTML 全量转义(含引号,防属性注入)。 */
|
||||
function escapeHtml(s: string): string {
|
||||
return s
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
/** 行内格式:行内代码(哨兵保护,内部不做粗体/链接替换)→ 粗体 → 链接。 */
|
||||
const CODE_SENTINEL = '@@GOSMS_MD_CODE_'
|
||||
function inline(s: string): string {
|
||||
const codes: string[] = []
|
||||
let t = s.replace(/`([^`]+)`/g, (_m, c: string) => {
|
||||
codes.push(c)
|
||||
return `${CODE_SENTINEL}${codes.length - 1}@@`
|
||||
})
|
||||
t = t.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
||||
t = t.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>')
|
||||
return t.replace(new RegExp(`${CODE_SENTINEL}(\\d+)@@`, 'g'), (_m, i: string) => `<code>${codes[Number(i)]!}</code>`)
|
||||
}
|
||||
|
||||
/** 块级行判据(段落收集的截断条件):代码围栏 / 标题 / 列表。 */
|
||||
const BLOCK_START = /^(#{1,4}\s|\s*[-*]\s|\s*\d+(?:\.\s+|、\s*)|```)/
|
||||
/** 有序列表行:点号后须空格(英文习惯),顿号后空格可选(中文习惯)。 */
|
||||
const OL_LINE = /^\s*\d+(?:\.\s+|、\s*)/
|
||||
|
||||
/** Markdown → HTML(输入不可信,输出已全量转义;v-html 挂载)。 */
|
||||
export function renderMarkdown(src: string): string {
|
||||
const lines = escapeHtml(src.replace(/\r\n/g, '\n')).split('\n')
|
||||
const out: string[] = []
|
||||
let i = 0
|
||||
while (i < lines.length) {
|
||||
const line = lines[i]!
|
||||
// 围栏代码块:内容保持原样(不再做行内格式化)
|
||||
if (line.trim().startsWith('```')) {
|
||||
const buf: string[] = []
|
||||
i++
|
||||
while (i < lines.length && !lines[i]!.trim().startsWith('```')) buf.push(lines[i++]!)
|
||||
i++ // 跳过闭合围栏(缺闭合则吞到结尾)
|
||||
out.push(`<pre><code>${buf.join('\n')}</code></pre>`)
|
||||
continue
|
||||
}
|
||||
// 标题 # ~ ####
|
||||
const h = /^(#{1,4})\s+(.*)$/.exec(line)
|
||||
if (h) {
|
||||
const lv = h[1]!.length
|
||||
out.push(`<h${lv}>${inline(h[2]!)}</h${lv}>`)
|
||||
i++
|
||||
continue
|
||||
}
|
||||
// 无序列表
|
||||
if (/^\s*[-*]\s+/.test(line)) {
|
||||
const items: string[] = []
|
||||
while (i < lines.length && /^\s*[-*]\s+/.test(lines[i]!)) items.push(inline(lines[i++]!.replace(/^\s*[-*]\s+/, '')))
|
||||
out.push(`<ul>${items.map((x) => `<li>${x}</li>`).join('')}</ul>`)
|
||||
continue
|
||||
}
|
||||
// 有序列表(1. 或 1、)
|
||||
if (OL_LINE.test(line)) {
|
||||
const items: string[] = []
|
||||
while (i < lines.length && OL_LINE.test(lines[i]!)) items.push(inline(lines[i++]!.replace(OL_LINE, '')))
|
||||
out.push(`<ol>${items.map((x) => `<li>${x}</li>`).join('')}</ol>`)
|
||||
continue
|
||||
}
|
||||
// 空行
|
||||
if (line.trim() === '') {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
// 段落:连续普通行合并,行间 <br>
|
||||
const buf: string[] = [line]
|
||||
i++
|
||||
while (i < lines.length && lines[i]!.trim() !== '' && !BLOCK_START.test(lines[i]!)) buf.push(lines[i++]!)
|
||||
out.push(`<p>${buf.map(inline).join('<br>')}</p>`)
|
||||
}
|
||||
return out.join('\n')
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<template>
|
||||
<!-- 契约 #p-acct(v3-2-tailwind.html 1006-1034)1:1 直抄:单卡一体(筛选区 border-b+原生 table+分页条) -->
|
||||
<div>
|
||||
<div class="page-header flex items-end justify-between">
|
||||
<div>
|
||||
<p class="page-description">{{ total }} 个账号 · 全平台口径</p>
|
||||
</div>
|
||||
<router-link to="/account/create" class="btn btn-primary">+ 开户</router-link>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<!-- 筛选区 -->
|
||||
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
||||
<input v-model="filterUsername" class="input !w-56" placeholder="搜索账号名 / 手机号" @keyup.enter="search" />
|
||||
<Select v-model="filterStatus" :options="STATUS_OPTIONS" placeholder="状态:全部" clearable class="!w-32" />
|
||||
<Select v-model="filterRole" :options="ROLE_OPTIONS" placeholder="角色:全部" clearable class="!w-32" />
|
||||
<button class="btn btn-primary" @click="search">搜索</button>
|
||||
<button class="btn btn-secondary" @click="reset">重置</button>
|
||||
<span class="ml-auto text-xs text-gray-400">已选 {{ selected.size }} 项</span>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<div class="table-container m-4 mt-0 border-0">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><input type="checkbox" class="accent-primary-600" :checked="allChecked" @change="toggleAll" /></th>
|
||||
<th>账号</th><th>角色</th><th>手机号</th>
|
||||
<th class="text-right">余额(元)</th><th class="text-right">今日提交</th>
|
||||
<th>状态</th><th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="a in rows" :key="a.id" :class="selected.has(a.id) ? 'bg-gray-50 dark:bg-dark-800/30' : ''">
|
||||
<td><input type="checkbox" class="accent-primary-600" :checked="selected.has(a.id)" @change="toggle(a.id)" /></td>
|
||||
<td>
|
||||
<span class="flex items-center gap-2 font-medium" :class="a.status === 1 ? 'text-gray-900 dark:text-white' : 'text-gray-500'">
|
||||
<span class="flex h-7 w-7 items-center justify-center rounded-full text-xs font-medium" :class="avatarClass(a)">{{ a.username.slice(0, 1) }}</span>
|
||||
{{ a.username }} <span class="text-xs text-gray-400">{{ a.id }}</span>
|
||||
</span>
|
||||
</td>
|
||||
<td><span class="badge" :class="roleBadge(a.role)">{{ a.role }}</span></td>
|
||||
<td class="text-gray-500">—</td>
|
||||
<td class="text-right font-medium">{{ fmtMoney(a.balance) }}</td>
|
||||
<td class="text-right text-gray-400">—</td>
|
||||
<td><span class="badge" :class="a.status === 1 ? 'badge-success' : 'badge-gray'">{{ a.status === 1 ? '启用' : '停用' }}</span></td>
|
||||
<td class="text-right">
|
||||
<router-link :to="`/account/${a.id}`" class="cursor-pointer text-sm text-primary-600 hover:underline">编辑</router-link>
|
||||
<template v-if="a.status === 1 && (a.role === 'customer' || a.role === 'group')">
|
||||
<router-link :to="`/account/${a.id}/recharge`" class="cursor-pointer text-sm text-primary-600 hover:underline">充值</router-link>
|
||||
</template>
|
||||
<router-link :to="`/account/${a.id}`" class="cursor-pointer text-sm text-primary-600 hover:underline">明细</router-link>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!loading && rows.length === 0">
|
||||
<td colspan="8" class="py-10 text-center text-sm text-gray-400">无匹配账号</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 分页条 -->
|
||||
<div class="flex items-center justify-between border-t border-gray-100 px-4 py-3 text-sm text-gray-500 dark:border-dark-700">
|
||||
<span>共 {{ total }} 条记录</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<button class="rounded-xl px-3.5 py-2 text-sm text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800" :disabled="page <= 1" @click="goPage(page - 1)">◀</button>
|
||||
<button v-for="p in pageButtons" :key="p" class="rounded-xl px-3.5 py-2 text-sm" :class="p === page ? 'bg-primary-600 font-medium text-white' : 'text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800'" @click="goPage(p)">{{ p }}</button>
|
||||
<span v-if="showEllipsis" class="px-1 text-gray-400">…</span>
|
||||
<button class="rounded-xl px-3.5 py-2 text-sm text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800" :disabled="page >= lastPage" @click="goPage(page + 1)">▶</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import Select from '@/components/common/Select.vue'
|
||||
import { accountApi, type Account } from '@/api/account'
|
||||
|
||||
defineOptions({ name: 'account-list' })
|
||||
|
||||
const rows = ref<Account[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = 10
|
||||
const loading = ref(false)
|
||||
const selected = reactive(new Set<number>())
|
||||
|
||||
// 筛选下拉选项(Select 组件 auto>5 自动出搜索;角色 6 项含全部)
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: '1', label: '启用' },
|
||||
{ value: '0', label: '停用' },
|
||||
]
|
||||
const ROLE_OPTIONS = [
|
||||
{ value: '', label: '全部' },
|
||||
{ value: 'customer', label: 'customer' },
|
||||
{ value: 'group', label: 'group' },
|
||||
{ value: 'service', label: 'service' },
|
||||
{ value: 'ops', label: 'ops' },
|
||||
{ value: 'admin', label: 'admin' },
|
||||
]
|
||||
const filterUsername = ref('')
|
||||
const filterRole = ref('')
|
||||
const filterStatus = ref('')
|
||||
const query = reactive({ username: '', role: '', status: '' })
|
||||
|
||||
const lastPage = computed(() => Math.max(1, Math.ceil(total.value / pageSize)))
|
||||
const allChecked = computed(() => rows.value.length > 0 && rows.value.every((a) => selected.has(a.id)))
|
||||
const showEllipsis = computed(() => lastPage.value > 5)
|
||||
const pageButtons = computed(() => {
|
||||
const last = lastPage.value
|
||||
const btns: number[] = []
|
||||
const from = Math.max(1, Math.min(page.value - 1, last - 4))
|
||||
for (let p = from; p <= Math.min(last, from + 4); p++) btns.push(p)
|
||||
return btns
|
||||
})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await accountApi.list({
|
||||
page: page.value,
|
||||
page_size: pageSize,
|
||||
username: query.username || undefined,
|
||||
role: query.role || undefined,
|
||||
status: query.status || undefined,
|
||||
})
|
||||
rows.value = res.list
|
||||
total.value = res.total
|
||||
} catch {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function search() {
|
||||
query.username = filterUsername.value.trim()
|
||||
query.role = filterRole.value
|
||||
query.status = filterStatus.value
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function reset() {
|
||||
filterUsername.value = ''
|
||||
filterRole.value = ''
|
||||
filterStatus.value = ''
|
||||
search()
|
||||
}
|
||||
|
||||
function goPage(p: number) {
|
||||
if (p < 1 || p > lastPage.value) return
|
||||
page.value = p
|
||||
void load()
|
||||
}
|
||||
|
||||
function toggle(id: number) {
|
||||
if (selected.has(id)) selected.delete(id)
|
||||
else selected.add(id)
|
||||
}
|
||||
function toggleAll() {
|
||||
if (allChecked.value) rows.value.forEach((a) => selected.delete(a.id))
|
||||
else rows.value.forEach((a) => selected.add(a.id))
|
||||
}
|
||||
|
||||
// 契约头像色轮转:primary/emerald/amber/sky 循环
|
||||
const AVATAR = [
|
||||
'bg-primary-100 text-primary-700',
|
||||
'bg-emerald-100 text-emerald-700',
|
||||
'bg-amber-100 text-amber-700',
|
||||
'bg-sky-100 text-sky-700',
|
||||
]
|
||||
function avatarClass(a: Account): string {
|
||||
if (a.status !== 1) return 'bg-gray-100 text-gray-500'
|
||||
return AVATAR[a.id % AVATAR.length] ?? AVATAR[0]!
|
||||
}
|
||||
function roleBadge(role: string): string {
|
||||
return ({ customer: 'badge-gray', group: 'badge-purple', ops: 'badge-primary', service: 'badge-gray', admin: 'badge-danger' } as Record<string, string>)[role] ?? 'badge-gray'
|
||||
}
|
||||
function fmtMoney(v: number): string {
|
||||
return v.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
}
|
||||
|
||||
onMounted(() => void load())
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
<template>
|
||||
<!-- 契约 #p-chan(v3-2-tailwind.html 1035-1059)1:1 直抄:表单范式(基本参数+吞吐与风控+操作条) -->
|
||||
<div>
|
||||
<div class="page-header flex items-end justify-between">
|
||||
<div>
|
||||
<p class="page-description">{{ isEdit ? `编辑通道 #${chanId}` : '新建通道' }} · 保存后进入 5 分钟探测期</p>
|
||||
</div>
|
||||
<router-link to="/channel" class="btn btn-secondary">← 返回</router-link>
|
||||
</div>
|
||||
|
||||
<!-- 基本参数 -->
|
||||
<div class="mb-4 card">
|
||||
<div class="border-b border-gray-100 px-6 py-4 dark:border-dark-700">
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">基本参数</h2>
|
||||
<p class="text-xs text-gray-500">必填 4 项</p>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-x-6 p-6 md:grid-cols-2">
|
||||
<div class="mb-4">
|
||||
<label class="input-label">通道名称 <span class="text-red-500">*</span></label>
|
||||
<input v-model="form.name" class="input" placeholder="运营侧显示名" />
|
||||
<p class="input-hint">运营侧显示名,2~32 字符</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="input-label">协议类型 <span class="text-red-500">*</span></label>
|
||||
<select v-model="form.protocolKey" class="input" :disabled="isEdit">
|
||||
<option value="cmpp20">CMPP 2.0</option>
|
||||
<option value="cmpp30">CMPP 3.0</option>
|
||||
<option value="smpp">SMPP</option>
|
||||
<option value="sgip">SGIP</option>
|
||||
<option value="http">HTTP</option>
|
||||
</select>
|
||||
<p class="input-hint">决定连接器与心跳语义</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="input-label">接入地址 <span class="text-red-500">*</span></label>
|
||||
<input v-model="form.addr" class="input" placeholder="cmpp://host:port 或 host:port" />
|
||||
<p class="input-hint">支持域名,自动 DNS 解析</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="input-label">接入账号 <span class="text-red-500">*</span></label>
|
||||
<input v-model="form.username" class="input" />
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="input-label">接入密码 <span class="text-red-500">*</span></label>
|
||||
<input v-model="form.password" type="password" class="input" placeholder="留空=沿用原密码" />
|
||||
<p class="input-hint">AES 加密存储</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="input-label">扩展码 ext_code</label>
|
||||
<input v-model="form.code" class="input" />
|
||||
<p class="input-hint">客户 SrcID 须以该前缀开头(≤21 位)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 吞吐与风控 -->
|
||||
<div class="card">
|
||||
<div class="border-b border-gray-100 px-6 py-4 dark:border-dark-700">
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">吞吐与风控</h2>
|
||||
<p class="text-xs text-gray-500">新建通道建议保守配置</p>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-x-6 p-6 md:grid-cols-2">
|
||||
<div class="mb-4">
|
||||
<label class="input-label">速率上限(条/s)</label>
|
||||
<input v-model.number="form.speed" type="number" class="input" />
|
||||
<p class="input-hint">连接池令牌桶上限</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="input-label">连接数</label>
|
||||
<input v-model.number="form.conn_count" type="number" min="1" max="16" class="input" />
|
||||
<p class="input-hint">CMPP 长连接,1~16</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="input-label">失败率熔断阈值</label>
|
||||
<input class="input" value="5%" disabled />
|
||||
<p class="input-hint">预留项 · 后端字段未开放,暂不生效</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="input-label">心跳间隔(秒)</label>
|
||||
<input v-model.number="form.heartbeat_interval" type="number" class="input" />
|
||||
<p class="input-hint">3 次未响应判定断链重连</p>
|
||||
</div>
|
||||
<div class="mb-4 md:col-span-2">
|
||||
<label class="input-label">启用状态</label>
|
||||
<div class="flex items-center gap-3">
|
||||
<button type="button" class="relative h-6 w-11 rounded-full transition-colors" :class="form.status === 1 ? 'bg-primary-600' : 'bg-gray-300 dark:bg-dark-600'" @click="form.status = form.status === 1 ? 0 : 1">
|
||||
<span class="absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white shadow transition-transform" :class="form.status === 1 ? 'translate-x-5' : ''"></span>
|
||||
</button>
|
||||
<span class="text-sm text-gray-500">启用(保存后 30s 缓存生效)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-end gap-3 border-t border-gray-100 px-6 py-4 dark:border-dark-700">
|
||||
<span class="mr-auto text-xs text-gray-400">探测期内通道不参与路由</span>
|
||||
<span v-if="error" class="mr-auto text-xs text-red-600">{{ error }}</span>
|
||||
<router-link to="/channel" class="btn btn-secondary">取消</router-link>
|
||||
<button class="btn btn-primary" :disabled="saving" @click="save">{{ saving ? '保存中…' : '保存通道' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { channelApi } from '@/api/channel'
|
||||
|
||||
defineOptions({ name: 'channel-edit' })
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const chanId = route.params.id ? Number(route.params.id) : 0
|
||||
const isEdit = chanId > 0
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
const form = reactive({
|
||||
name: '',
|
||||
protocolKey: 'cmpp20',
|
||||
addr: '',
|
||||
username: '',
|
||||
password: '',
|
||||
code: '',
|
||||
speed: 200,
|
||||
conn_count: 4,
|
||||
heartbeat_interval: 30,
|
||||
status: 1,
|
||||
})
|
||||
|
||||
/** 协议键 ↔ 后端 protocol + protocol_version 映射。 */
|
||||
function decodeProtocol(protocol: string, version?: number): string {
|
||||
if (protocol === 'cmpp') return version === 30 ? 'cmpp30' : 'cmpp20'
|
||||
if (protocol === 'sgip') return 'sgip'
|
||||
if (protocol === 'smpp') return 'smpp'
|
||||
return 'http'
|
||||
}
|
||||
function encodeProtocol(key: string): { protocol: 'cmpp' | 'smpp' | 'sgip' | 'http'; protocol_version?: number } {
|
||||
if (key === 'cmpp20') return { protocol: 'cmpp', protocol_version: 20 }
|
||||
if (key === 'cmpp30') return { protocol: 'cmpp', protocol_version: 30 }
|
||||
if (key === 'sgip') return { protocol: 'sgip', protocol_version: 12 }
|
||||
if (key === 'smpp') return { protocol: 'smpp', protocol_version: 34 }
|
||||
return { protocol: 'http' }
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!isEdit) return
|
||||
try {
|
||||
const c = await channelApi.get(chanId)
|
||||
form.name = c.name
|
||||
form.protocolKey = decodeProtocol(c.protocol, c.protocol_version)
|
||||
form.addr = `${c.host}:${c.port}`
|
||||
form.username = c.username
|
||||
form.password = ''
|
||||
form.code = c.code
|
||||
form.speed = c.speed
|
||||
form.conn_count = c.conn_count
|
||||
form.heartbeat_interval = c.heartbeat_interval ?? 30
|
||||
form.status = c.status
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : '加载通道失败'
|
||||
}
|
||||
})
|
||||
|
||||
function validate(): string {
|
||||
if (form.name.trim().length < 2) return '通道名称至少 2 字符'
|
||||
if (!form.addr.trim()) return '接入地址必填'
|
||||
if (!form.username.trim()) return '接入账号必填'
|
||||
if (!isEdit && !form.password) return '接入密码必填'
|
||||
const m = form.addr.trim().match(/^(?:[a-z]+:\/\/)?([^/:]+)(?::(\d+))?$/i)
|
||||
if (!m) return '接入地址格式有误(示例 cmpp://192.168.5.16:7890)'
|
||||
return ''
|
||||
}
|
||||
|
||||
async function save() {
|
||||
const msg = validate()
|
||||
if (msg) {
|
||||
error.value = msg
|
||||
return
|
||||
}
|
||||
error.value = ''
|
||||
saving.value = true
|
||||
try {
|
||||
const m = form.addr.trim().match(/^(?:[a-z]+:\/\/)?([^/:]+)(?::(\d+))?$/i)!
|
||||
const proto = encodeProtocol(form.protocolKey)
|
||||
const body = {
|
||||
name: form.name.trim(),
|
||||
...proto,
|
||||
host: m[1],
|
||||
port: m[2] ? Number(m[2]) : 7890,
|
||||
username: form.username.trim(),
|
||||
...(form.password ? { password: form.password } : {}),
|
||||
code: form.code,
|
||||
speed: form.speed,
|
||||
conn_count: form.conn_count,
|
||||
heartbeat_interval: form.heartbeat_interval,
|
||||
status: form.status,
|
||||
}
|
||||
if (isEdit) await channelApi.update(chanId, body)
|
||||
else await channelApi.create(body)
|
||||
router.push('/channel')
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : '保存失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,260 @@
|
||||
<template>
|
||||
<!-- 契约表格范式(#p-acct 单卡一体 1:1):筛选区 border-b+原生 table+分页条;入口页,行内编辑接 /channel/edit -->
|
||||
<div>
|
||||
<div class="page-header flex items-end justify-between">
|
||||
<div>
|
||||
<p class="page-description">{{ total }} 条通道 · {{ runningHint }}</p>
|
||||
</div>
|
||||
<router-link to="/channel/edit" class="btn btn-primary">+ 新建通道</router-link>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<!-- 筛选区 -->
|
||||
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
||||
<input v-model="filterName" class="input !w-56" placeholder="搜索通道名称 / 接入码" @keyup.enter="search" />
|
||||
<Select v-model="filterProtocol" :options="PROTOCOL_OPTIONS" placeholder="协议:全部" clearable class="!w-32" />
|
||||
<Select v-model="filterStatus" :options="STATUS_OPTIONS" placeholder="状态:全部" clearable class="!w-32" />
|
||||
<button class="btn btn-primary" @click="search">搜索</button>
|
||||
<button class="btn btn-secondary" @click="reset">重置</button>
|
||||
<span class="ml-auto text-xs text-gray-400">已选 {{ selected.size }} 项</span>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<div class="table-container m-4 mt-0 border-0">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><input type="checkbox" class="accent-primary-600" :checked="allChecked" @change="toggleAll" /></th>
|
||||
<th>通道</th><th>协议</th><th>接入地址</th>
|
||||
<th class="text-right">速率 / 连接</th><th>上家</th>
|
||||
<th>状态</th><th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="c in rows" :key="c.id" :class="selected.has(c.id) ? 'bg-gray-50 dark:bg-dark-800/30' : ''">
|
||||
<td><input type="checkbox" class="accent-primary-600" :checked="selected.has(c.id)" @change="toggle(c.id)" /></td>
|
||||
<td>
|
||||
<span class="flex items-center gap-2 font-medium" :class="c.status === 1 ? 'text-gray-900 dark:text-white' : 'text-gray-500'">
|
||||
<span class="flex h-7 w-7 items-center justify-center rounded-lg text-xs font-bold" :class="badgeClass(c)">{{ protoShort(c.protocol) }}</span>
|
||||
{{ c.name }} <span class="text-xs text-gray-400">{{ c.id }}</span>
|
||||
</span>
|
||||
</td>
|
||||
<td><span class="badge badge-gray">{{ protoLabel(c) }}</span></td>
|
||||
<td><span class="font-mono text-xs text-gray-500">{{ c.host }}:{{ c.port }}</span></td>
|
||||
<td class="text-right font-medium">{{ c.speed }} 条/s <span class="text-xs text-gray-400">· {{ c.conn_count }} 连接</span></td>
|
||||
<td class="text-gray-500">{{ c.upstream_name || '—' }}</td>
|
||||
<td><span class="badge" :class="c.status === 1 ? 'badge-success' : 'badge-gray'">{{ c.status === 1 ? '在营' : '停用' }}</span></td>
|
||||
<td class="text-right">
|
||||
<router-link :to="`/channel/edit/${c.id}`" class="cursor-pointer text-sm text-primary-600 hover:underline">编辑</router-link>
|
||||
<button class="cursor-pointer text-sm text-primary-600 hover:underline" @click="openTest(c)">测试</button>
|
||||
<button class="cursor-pointer text-sm hover:underline" :class="c.status === 1 ? 'text-amber-600' : 'text-emerald-600'" @click="toggleStatus(c)">
|
||||
{{ c.status === 1 ? '停用' : '启用' }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!loading && rows.length === 0">
|
||||
<td colspan="8" class="py-10 text-center text-sm text-gray-400">无匹配通道</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 分页条 -->
|
||||
<div class="flex items-center justify-between border-t border-gray-100 px-4 py-3 text-sm text-gray-500 dark:border-dark-700">
|
||||
<span>共 {{ total }} 条记录</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<button class="rounded-xl px-3.5 py-2 text-sm text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800" :disabled="page <= 1" @click="goPage(page - 1)">◀</button>
|
||||
<button v-for="p in pageButtons" :key="p" class="rounded-xl px-3.5 py-2 text-sm" :class="p === page ? 'bg-primary-600 font-medium text-white' : 'text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800'" @click="goPage(p)">{{ p }}</button>
|
||||
<span v-if="showEllipsis" class="px-1 text-gray-400">…</span>
|
||||
<button class="rounded-xl px-3.5 py-2 text-sm text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800" :disabled="page >= lastPage" @click="goPage(page + 1)">▶</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 测试发送弹窗(契约 dialog 范式:dialog-overlay/container/header/body/footer) -->
|
||||
<div v-if="testTarget" class="dialog-overlay" @click.self="closeTest">
|
||||
<div class="dialog-container max-w-md">
|
||||
<div class="dialog-header">
|
||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">测试发送</h3>
|
||||
<button class="btn-ghost btn-icon" @click="closeTest"><svg class="h-5 w-5"><use href="#i-x" /></svg></button>
|
||||
</div>
|
||||
<div class="dialog-body space-y-4">
|
||||
<p class="text-xs text-gray-500">通道 {{ testTarget.name }} · {{ protoLabel(testTarget) }} · 真实下发一条测试短信</p>
|
||||
<div>
|
||||
<label class="input-label">接收手机号 <span class="text-red-500">*</span></label>
|
||||
<input v-model="testMobile" class="input" placeholder="13800138000" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="input-label">短信内容 <span class="text-red-500">*</span></label>
|
||||
<textarea v-model="testContent" rows="3" class="input" placeholder="【签名】测试内容"></textarea>
|
||||
</div>
|
||||
<div v-if="testResult" class="rounded-xl border-l-4 p-3 text-sm" :class="testResult.ok ? 'border-emerald-500 bg-emerald-50 text-emerald-700 dark:bg-emerald-950/40 dark:text-emerald-300' : 'border-red-500 bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-300'">
|
||||
{{ testResult.msg }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button class="btn btn-secondary" @click="closeTest">取消</button>
|
||||
<button class="btn btn-primary" :disabled="testing" @click="sendTest">{{ testing ? '发送中…' : '发送' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import Select from '@/components/common/Select.vue'
|
||||
import { channelApi, type Channel } from '@/api/channel'
|
||||
|
||||
// Issue#2 keep-alive 锚点:组件名=路由名
|
||||
defineOptions({ name: 'channel' })
|
||||
|
||||
const rows = ref<Channel[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = 10
|
||||
const loading = ref(false)
|
||||
const selected = reactive(new Set<number>())
|
||||
|
||||
const PROTOCOL_OPTIONS = [
|
||||
{ value: 'cmpp', label: 'CMPP' },
|
||||
{ value: 'smpp', label: 'SMPP' },
|
||||
{ value: 'sgip', label: 'SGIP' },
|
||||
{ value: 'http', label: 'HTTP' },
|
||||
]
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: '1', label: '在营' },
|
||||
{ value: '0', label: '停用' },
|
||||
]
|
||||
const filterName = ref('')
|
||||
const filterProtocol = ref('')
|
||||
const filterStatus = ref('')
|
||||
const query = reactive({ name: '', protocol: '', status: '' })
|
||||
|
||||
const lastPage = computed(() => Math.max(1, Math.ceil(total.value / pageSize)))
|
||||
const allChecked = computed(() => rows.value.length > 0 && rows.value.every((c) => selected.has(c.id)))
|
||||
const showEllipsis = computed(() => lastPage.value > 5)
|
||||
const pageButtons = computed(() => {
|
||||
const last = lastPage.value
|
||||
const btns: number[] = []
|
||||
const from = Math.max(1, Math.min(page.value - 1, last - 4))
|
||||
for (let p = from; p <= Math.min(last, from + 4); p++) btns.push(p)
|
||||
return btns
|
||||
})
|
||||
const runningHint = computed(() => `${rows.value.filter((c) => c.status === 1).length} 在营(本页)`)
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await channelApi.list({
|
||||
page: page.value,
|
||||
page_size: pageSize,
|
||||
...(query.name ? { name: query.name } : {}),
|
||||
...(query.protocol ? { protocol: query.protocol } : {}),
|
||||
...(query.status !== '' ? { status: query.status } : {}),
|
||||
})
|
||||
rows.value = res.list
|
||||
total.value = res.total
|
||||
} catch {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function search() {
|
||||
query.name = filterName.value.trim()
|
||||
query.protocol = filterProtocol.value
|
||||
query.status = filterStatus.value
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function reset() {
|
||||
filterName.value = ''
|
||||
filterProtocol.value = ''
|
||||
filterStatus.value = ''
|
||||
search()
|
||||
}
|
||||
|
||||
function goPage(p: number) {
|
||||
if (p < 1 || p > lastPage.value) return
|
||||
page.value = p
|
||||
void load()
|
||||
}
|
||||
|
||||
function toggle(id: number) {
|
||||
if (selected.has(id)) selected.delete(id)
|
||||
else selected.add(id)
|
||||
}
|
||||
function toggleAll() {
|
||||
if (allChecked.value) rows.value.forEach((c) => selected.delete(c.id))
|
||||
else rows.value.forEach((c) => selected.add(c.id))
|
||||
}
|
||||
|
||||
async function toggleStatus(c: Channel) {
|
||||
const next = c.status === 1 ? 0 : 1
|
||||
try {
|
||||
await channelApi.update(c.id, { status: next })
|
||||
c.status = next
|
||||
} catch (e) {
|
||||
testResult.value = { ok: false, msg: e instanceof Error ? e.message : '操作失败' }
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 测试发送弹窗 ----
|
||||
const testTarget = ref<Channel | null>(null)
|
||||
const testMobile = ref('')
|
||||
const testContent = ref('')
|
||||
const testing = ref(false)
|
||||
const testResult = ref<{ ok: boolean; msg: string } | null>(null)
|
||||
|
||||
function openTest(c: Channel) {
|
||||
testTarget.value = c
|
||||
testMobile.value = ''
|
||||
testContent.value = '【测试】通道连通性验证'
|
||||
testResult.value = null
|
||||
}
|
||||
function closeTest() {
|
||||
testTarget.value = null
|
||||
}
|
||||
async function sendTest() {
|
||||
if (!testTarget.value || !/^1\d{10}$/.test(testMobile.value.trim())) {
|
||||
testResult.value = { ok: false, msg: '请输入正确的 11 位手机号' }
|
||||
return
|
||||
}
|
||||
if (!testContent.value.trim()) {
|
||||
testResult.value = { ok: false, msg: '短信内容必填' }
|
||||
return
|
||||
}
|
||||
testing.value = true
|
||||
testResult.value = null
|
||||
try {
|
||||
const r = await channelApi.test(testTarget.value.id, { mobile: testMobile.value.trim(), content: testContent.value.trim() })
|
||||
testResult.value = { ok: true, msg: `已提交 · MsgID ${r.message_id} · 协议 ${r.protocol} · 耗时 ${r.elapsed_ms}ms` }
|
||||
} catch (e) {
|
||||
testResult.value = { ok: false, msg: e instanceof Error ? e.message : '发送失败' }
|
||||
} finally {
|
||||
testing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 展示工具 ----
|
||||
function protoShort(p: string): string {
|
||||
return ({ cmpp: 'CM', smpp: 'SM', http: 'HT', sgip: 'SG' } as Record<string, string>)[p] ?? p.slice(0, 2).toUpperCase()
|
||||
}
|
||||
function protoLabel(c: Channel): string {
|
||||
const ver = c.protocol === 'cmpp' ? (c.protocol_version === 30 ? ' 3.0' : ' 2.0') : c.protocol === 'sgip' ? ' 1.2' : ''
|
||||
return (c.protocol + ver).toUpperCase()
|
||||
}
|
||||
const BADGE = ['bg-primary-100 text-primary-700', 'bg-emerald-100 text-emerald-700', 'bg-amber-100 text-amber-700', 'bg-sky-100 text-sky-700']
|
||||
function badgeClass(c: Channel): string {
|
||||
if (c.status !== 1) return 'bg-gray-100 text-gray-500'
|
||||
return BADGE[c.id % BADGE.length] ?? BADGE[0]!
|
||||
}
|
||||
|
||||
onMounted(() => void load())
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<template>
|
||||
<!-- B1 占位页(B2 三契约页 / B3 33 视图逐页实装时替换路由 component)。
|
||||
契约 empty-state 范式;无 defineOptions=豁免 keep-alive(与 tabs.ts 口径一致)。 -->
|
||||
<div class="empty-state">
|
||||
<svg class="empty-state-icon"><use href="#i-clock" /></svg>
|
||||
<h3 class="empty-state-title">{{ route.meta.title ?? '页面' }}</h3>
|
||||
<p class="empty-state-description">该页面建设中,即将在新版管理台与您见面。</p>
|
||||
<router-link to="/home" class="btn btn-secondary mt-6">返回运营总览</router-link>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
const route = useRoute()
|
||||
</script>
|
||||
@@ -0,0 +1,8 @@
|
||||
<template>
|
||||
<div class="empty-state">
|
||||
<svg class="empty-state-icon"><use href="#i-warn" /></svg>
|
||||
<h3 class="empty-state-title">404</h3>
|
||||
<p class="empty-state-description">页面不存在或已被移除。</p>
|
||||
<router-link to="/home" class="btn btn-primary mt-6">返回首页</router-link>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,505 @@
|
||||
<template>
|
||||
<!-- 契约 #p-dash(v3-2-tailwind.html 895-1005)1:1 直抄;数据源=P2 三端点+monitor 快照 -->
|
||||
<div>
|
||||
<div class="page-header flex items-end justify-between">
|
||||
<div>
|
||||
<p class="page-description">全平台口径 · {{ acctCount }} 账号 / {{ chanCount }} 通道 · 更新于 <span>{{ clock }}</span></p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button class="btn btn-secondary" @click="refreshAll"><svg class="h-4 w-4"><use href="#i-refresh" /></svg>刷新</button>
|
||||
<button class="btn btn-primary">导出日报</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 平台状态横幅 -->
|
||||
<div class="card mb-6 flex flex-wrap items-center gap-4 p-4">
|
||||
<div class="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-primary-100 text-primary-600 dark:bg-primary-900/30 dark:text-primary-400">
|
||||
<svg class="h-5 w-5"><use href="#i-check" /></svg>
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="text-base font-semibold text-gray-900 dark:text-white">{{ bannerTitle }}</p>
|
||||
<p class="text-xs text-gray-500">成功率 {{ pct(summary?.success_rate) }}({{ deltaPt }}) · 今日提交 {{ num(summary?.today_sent) }}({{ sentTrend }}) · 待审核 {{ summary?.pending_audit_count ?? '—' }} · 余额预警 {{ summary?.balance_alert_count ?? '—' }}</p>
|
||||
</div>
|
||||
<div class="hidden items-center gap-2 md:flex">
|
||||
<span v-for="s in subsystems" :key="s.name" class="badge" :class="subBadge(s.status)">{{ s.name }}</span>
|
||||
</div>
|
||||
<span class="flex items-center gap-2 text-xs text-gray-500">
|
||||
<span class="flex items-center gap-1.5 rounded-full bg-primary-50 px-3 py-1 font-medium text-primary-700 dark:bg-primary-900/30 dark:text-primary-300">
|
||||
<span class="relative flex h-2 w-2"><span class="absolute inline-flex h-full w-full animate-ping rounded-full bg-primary-400 opacity-75"></span><span class="relative inline-flex h-2 w-2 rounded-full bg-primary-500"></span></span>实时
|
||||
</span>
|
||||
<span>{{ clock }}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- stat 行 1:六卡 -->
|
||||
<div class="mb-6 grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-primary"><svg class="h-6 w-6"><use href="#i-send" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">今日提交</div>
|
||||
<div class="stat-value">{{ num(summary?.today_sent) }}</div>
|
||||
<div class="stat-trend stat-trend-up">↑ {{ sentTrendPct }}% 较昨日</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-success"><svg class="h-6 w-6"><use href="#i-check" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">回执成功率</div>
|
||||
<div class="stat-value">{{ pct(summary?.success_rate) }}</div>
|
||||
<div class="stat-trend" :class="(summary?.success_rate_delta ?? 0) >= 0 ? 'stat-trend-up' : 'stat-trend-down'">{{ deltaPt }} 环比</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-primary"><svg class="h-6 w-6"><use href="#i-zap" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">实时速率</div>
|
||||
<div class="stat-value">{{ realtime?.global_submit_ps != null ? realtime.global_submit_ps.toFixed(1) : '—' }}<span class="text-base font-medium text-gray-500"> 条/s</span></div>
|
||||
<div class="stat-trend text-gray-500">● 60s 窗口</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-warning"><svg class="h-6 w-6"><use href="#i-stamp" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">待人工审核</div>
|
||||
<div class="stat-value text-amber-600">{{ summary?.pending_audit_count ?? '—' }}</div>
|
||||
<div class="stat-trend text-amber-600">↓ 建议今日处理</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-danger"><svg class="h-6 w-6"><use href="#i-wallet" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">余额预警</div>
|
||||
<div class="stat-value text-red-600">{{ summary?.balance_alert_count ?? '—' }}</div>
|
||||
<div class="stat-trend stat-trend-down">↓ 低于预警线</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-success"><svg class="h-6 w-6"><use href="#i-coin" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">今日收入</div>
|
||||
<div class="stat-value">—</div>
|
||||
<div class="stat-trend text-gray-500">— 缺数据(结算域待接)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- stat 行 2:四卡 -->
|
||||
<div class="mb-6 grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-primary"><svg class="h-6 w-6"><use href="#i-zap" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">提交速率 RPM</div>
|
||||
<div class="stat-value">{{ rpm }}</div>
|
||||
<div class="stat-trend stat-trend-up">● 实时</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-success"><svg class="h-6 w-6"><use href="#i-callback" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">回执速率 TPM</div>
|
||||
<div class="stat-value">{{ tpm }}</div>
|
||||
<div class="stat-trend text-gray-500">— 回执端点待接</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-primary"><svg class="h-6 w-6"><use href="#i-clock" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">平均时延 P50</div>
|
||||
<div class="stat-value">{{ p50 }}</div>
|
||||
<div class="stat-trend text-gray-500">在营通道均值</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-icon-warning"><svg class="h-6 w-6"><use href="#i-layer" /></svg></div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="stat-label">活跃通道</div>
|
||||
<div class="stat-value">{{ runningCount }}<span class="text-base font-medium text-gray-500"> / {{ chanCount }}</span></div>
|
||||
<div class="stat-trend text-gray-500">◐ 停机 {{ stoppedCount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 行 3:发送趋势 + 业务分布 -->
|
||||
<div class="mb-6 grid grid-cols-1 gap-4 xl:grid-cols-3">
|
||||
<div class="card xl:col-span-2">
|
||||
<div class="flex items-center gap-3 border-b border-gray-100 px-6 py-4 dark:border-dark-700">
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">发送趋势</h2>
|
||||
<span class="text-xs text-gray-500">提交 vs 成功 · 单位:万条</span>
|
||||
<div class="ml-auto flex items-center gap-1 rounded-xl bg-gray-100 p-1 dark:bg-dark-800">
|
||||
<button class="rounded-lg px-3 py-1 text-xs" :class="trendDays === 7 ? 'bg-white font-medium text-gray-900 shadow-sm dark:bg-dark-700 dark:text-white' : 'text-gray-600 dark:text-dark-400'" @click="setTrendDays(7)">近 7 天</button>
|
||||
<button class="rounded-lg px-3 py-1 text-xs" :class="trendDays === 30 ? 'bg-white font-medium text-gray-900 shadow-sm dark:bg-dark-700 dark:text-white' : 'text-gray-600 dark:text-dark-400'" @click="setTrendDays(30)">近 30 天</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<!-- 固定高度包裹容器:chart.js responsive 必须有确定尺寸的父级,
|
||||
否则 canvas↔父容器互相撑开形成 resize 死循环(曲线持续拉升+页面卡死) -->
|
||||
<div class="relative" style="height: 238px">
|
||||
<Line :data="chartData" :options="chartOptions" />
|
||||
</div>
|
||||
<div class="mt-2 flex items-center gap-4 px-2 text-xs text-gray-500">
|
||||
<span class="flex items-center gap-1.5"><i class="inline-block h-1 w-4 rounded bg-primary-500"></i>提交</span>
|
||||
<span class="flex items-center gap-1.5"><i class="inline-block h-1 w-4 rounded bg-sky-500"></i>成功</span>
|
||||
<span class="ml-auto">GET /stats/trend</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="flex items-center gap-3 border-b border-gray-100 px-6 py-4 dark:border-dark-700">
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">业务类型分布</h2>
|
||||
<span class="ml-auto text-xs text-gray-500">biz_type</span>
|
||||
</div>
|
||||
<div class="p-5">
|
||||
<div class="flex items-center justify-center py-2">
|
||||
<div class="relative h-32 w-32">
|
||||
<svg viewBox="0 0 128 128" class="h-32 w-32 -rotate-90">
|
||||
<circle cx="64" cy="64" r="50" fill="none" stroke="#f3f4f6" stroke-width="14" />
|
||||
<circle v-for="seg in donutSegs" :key="seg.key" cx="64" cy="64" r="50" fill="none" :stroke="seg.color" stroke-width="14" :stroke-dasharray="`${seg.len} 314`" :stroke-dashoffset="seg.offset" />
|
||||
</svg>
|
||||
<div class="absolute inset-0 flex flex-col items-center justify-center">
|
||||
<span class="text-xl font-bold text-gray-900 dark:text-white">{{ num(bizTotal) }}</span>
|
||||
<span class="text-xs text-gray-500">近 {{ biz?.days ?? 7 }} 日提交</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 space-y-2">
|
||||
<div v-for="seg in donutSegs" :key="seg.key" class="flex items-center gap-2 rounded-lg px-2 py-1.5 text-sm hover:bg-gray-50 dark:hover:bg-dark-800/50">
|
||||
<i class="h-2.5 w-2.5 rounded" :style="{ backgroundColor: seg.color }"></i>{{ seg.label }}<span class="ml-auto font-medium">{{ seg.percent }}%</span>
|
||||
</div>
|
||||
<p v-if="donutSegs.length === 0" class="px-2 text-xs text-gray-400">近 {{ biz?.days ?? 7 }} 日无提交数据</p>
|
||||
</div>
|
||||
<p class="mt-3 text-xs text-gray-400">GET /stats/biz · 点击图例跳明细</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 行 4:通道实时监控 + 系统健康 -->
|
||||
<div class="mb-6 grid grid-cols-1 gap-4 xl:grid-cols-3">
|
||||
<div class="card xl:col-span-2">
|
||||
<div class="flex items-center gap-3 border-b border-gray-100 px-6 py-4 dark:border-dark-700">
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">通道实时监控</h2>
|
||||
<span class="badge badge-success ml-1">● 5s 快照</span>
|
||||
<span class="ml-auto text-xs text-gray-500">{{ chanCount }} 条中 {{ runningCount }} 条在营</span>
|
||||
</div>
|
||||
<div class="table-container m-4 mt-0 border-0">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr><th>通道</th><th>协议</th><th class="text-right">速率(条/s)</th><th class="text-right">失败率</th><th>负载</th><th class="text-right">P50</th><th>状态</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="c in monitor" :key="c.channel_id">
|
||||
<td class="font-medium" :class="c.running ? 'text-gray-900 dark:text-white' : 'text-gray-500'">{{ c.name }}</td>
|
||||
<td class="text-gray-500">{{ c.protocol.toUpperCase() }}</td>
|
||||
<td class="text-right font-semibold" :class="c.submit_ps > 0 ? 'text-emerald-600' : 'text-gray-400'">{{ c.submit_ps > 0 ? c.submit_ps.toFixed(1) : '0.0' }}</td>
|
||||
<td class="text-right" :class="failClass(c)">{{ c.submit_ps > 0 ? (c.fail_rate * 100).toFixed(1) + '%' : '—' }}</td>
|
||||
<td>
|
||||
<div class="h-1.5 w-20 rounded-full bg-gray-200"><div class="h-full rounded-full" :class="loadColor(c)" :style="{ width: loadPct(c) + '%' }"></div></div>
|
||||
</td>
|
||||
<td class="text-right text-gray-500">{{ c.latency_p50_ms > 0 ? c.latency_p50_ms + 'ms' : '—' }}</td>
|
||||
<td><span class="badge" :class="c.running ? 'badge-success' : 'badge-gray'">{{ c.running ? '运行' : '停机' }}</span></td>
|
||||
</tr>
|
||||
<tr v-if="monitor.length === 0"><td colspan="7" class="text-center text-sm text-gray-400">暂无通道数据</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="flex items-center gap-3 border-b border-gray-100 px-6 py-4 dark:border-dark-700">
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">系统健康</h2>
|
||||
<span class="ml-auto text-xs"><span v-if="warnCount > 0" class="text-amber-600">{{ warnCount }} 警告</span> · {{ subsystems.length }} 服务</span>
|
||||
</div>
|
||||
<div class="space-y-2 p-4">
|
||||
<div v-for="s in subsystems" :key="s.name" class="group flex w-full items-center gap-4 rounded-xl bg-gray-50 p-4 dark:bg-dark-800/50">
|
||||
<div class="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-xl" :class="healthIcon(s).bg">
|
||||
<svg class="h-6 w-6" :class="healthIcon(s).text"><use :href="healthIcon(s).icon" /></svg>
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="text-sm font-medium text-gray-900 dark:text-white">{{ s.name }}</p>
|
||||
<p class="text-xs text-gray-500">{{ s.detail }}<template v-if="s.latency_ms > 0"> · {{ s.latency_ms }}ms</template></p>
|
||||
</div>
|
||||
<span class="badge" :class="subBadge(s.status)">{{ subLabel(s) }}</span>
|
||||
</div>
|
||||
<p class="px-2 text-xs text-gray-400">GET /ops/system/overview · 10s 轮询</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 行 5:最近动态 + 快捷操作/通道快照 -->
|
||||
<div class="grid grid-cols-1 gap-4 xl:grid-cols-2">
|
||||
<div class="card">
|
||||
<div class="flex items-center border-b border-gray-100 px-6 py-4 dark:border-dark-700">
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">最近动态</h2>
|
||||
<span class="ml-auto cursor-pointer text-sm text-primary-600 hover:underline">查看全部 →</span>
|
||||
</div>
|
||||
<div class="space-y-1 p-3">
|
||||
<p class="px-2 py-8 text-center text-sm text-gray-400">暂无动态 · 事件流待接入(诚实空态,不造假数据)</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="card">
|
||||
<div class="border-b border-gray-100 px-6 py-4 dark:border-dark-700"><h2 class="text-lg font-semibold text-gray-900 dark:text-white">快捷操作</h2></div>
|
||||
<div class="grid grid-cols-1 gap-3 p-4 md:grid-cols-2">
|
||||
<router-link to="/sms/batch" class="group flex w-full items-center gap-4 rounded-xl bg-gray-50 p-4 text-left transition-all duration-200 hover:bg-gray-100 dark:bg-dark-800/50 dark:hover:bg-dark-800">
|
||||
<div class="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-xl bg-primary-100 transition-transform group-hover:scale-105 dark:bg-primary-900/30"><svg class="h-6 w-6 text-primary-600 dark:text-primary-400"><use href="#i-send" /></svg></div>
|
||||
<div class="min-w-0 flex-1"><p class="text-sm font-medium text-gray-900 dark:text-white">新建群发</p><p class="text-xs text-gray-500">模板 / 个性 / 定时</p></div>
|
||||
<svg class="h-5 w-5 text-gray-400 transition-colors group-hover:text-primary-500"><use href="#i-chev-l" style="transform:rotate(180deg)" /></svg>
|
||||
</router-link>
|
||||
<router-link to="/account" class="group flex w-full items-center gap-4 rounded-xl bg-gray-50 p-4 text-left transition-all duration-200 hover:bg-gray-100 dark:bg-dark-800/50 dark:hover:bg-dark-800">
|
||||
<div class="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-xl bg-emerald-100 transition-transform group-hover:scale-105 dark:bg-emerald-900/30"><svg class="h-6 w-6 text-emerald-600 dark:text-emerald-400"><use href="#i-wallet" /></svg></div>
|
||||
<div class="min-w-0 flex-1"><p class="text-sm font-medium text-gray-900 dark:text-white">账号充值</p><p class="text-xs text-gray-500">双通道 · 审核流</p></div>
|
||||
<svg class="h-5 w-5 text-gray-400 transition-colors group-hover:text-emerald-500"><use href="#i-chev-l" style="transform:rotate(180deg)" /></svg>
|
||||
</router-link>
|
||||
<router-link to="/audit" class="group flex w-full items-center gap-4 rounded-xl bg-gray-50 p-4 text-left transition-all duration-200 hover:bg-gray-100 dark:bg-dark-800/50 dark:hover:bg-dark-800">
|
||||
<div class="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-xl bg-sky-100 transition-transform group-hover:scale-105 dark:bg-sky-900/30"><svg class="h-6 w-6 text-sky-600 dark:text-sky-400"><use href="#i-stamp" /></svg></div>
|
||||
<div class="min-w-0 flex-1"><p class="text-sm font-medium text-gray-900 dark:text-white">审核中心</p><p class="text-xs text-gray-500">{{ summary?.pending_audit_count ?? 0 }} 条待处理</p></div>
|
||||
<svg class="h-5 w-5 text-gray-400 transition-colors group-hover:text-sky-500"><use href="#i-chev-l" style="transform:rotate(180deg)" /></svg>
|
||||
</router-link>
|
||||
<router-link to="/channel" class="group flex w-full items-center gap-4 rounded-xl bg-gray-50 p-4 text-left transition-all duration-200 hover:bg-gray-100 dark:bg-dark-800/50 dark:hover:bg-dark-800">
|
||||
<div class="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-xl bg-amber-100 transition-transform group-hover:scale-105 dark:bg-amber-900/30"><svg class="h-6 w-6 text-amber-600 dark:text-amber-400"><use href="#i-layer" /></svg></div>
|
||||
<div class="min-w-0 flex-1"><p class="text-sm font-medium text-gray-900 dark:text-white">通道管理</p><p class="text-xs text-gray-500">{{ chanCount }} 条 · {{ runningCount }} 在营</p></div>
|
||||
<svg class="h-5 w-5 text-gray-400 transition-colors group-hover:text-amber-500"><use href="#i-chev-l" style="transform:rotate(180deg)" /></svg>
|
||||
</router-link>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="flex items-center border-b border-gray-100 px-6 py-4 dark:border-dark-700"><h2 class="text-lg font-semibold text-gray-900 dark:text-white">通道配置快照</h2><span class="ml-auto text-xs text-gray-500">配置域 · 点击进通道管理</span></div>
|
||||
<div class="space-y-3 p-4">
|
||||
<router-link v-for="c in chanSnapshot" :key="c.id" to="/channel" class="group flex w-full cursor-pointer items-center gap-4 rounded-xl bg-gray-50 p-4 transition-all duration-200 hover:bg-gray-100 dark:bg-dark-800/50 dark:hover:bg-dark-800">
|
||||
<div class="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-primary-100 text-xs font-bold text-primary-700 dark:bg-primary-900/30 dark:text-primary-400">{{ protoShort(c.protocol) }}</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="text-sm font-medium text-gray-900 dark:text-white">{{ c.name }} <span class="badge badge-gray ml-1">{{ protoLabel(c) }}</span></p>
|
||||
<p class="text-xs text-gray-500">{{ c.speed }} 条/s · {{ c.conn_count }} 连接</p>
|
||||
</div>
|
||||
<span class="badge" :class="c.status === 1 ? 'badge-success' : 'badge-gray'">{{ c.status === 1 ? '在营' : '停用' }}</span>
|
||||
</router-link>
|
||||
<p v-if="chanSnapshot.length === 0" class="py-4 text-center text-sm text-gray-400">暂无通道</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { Line } from 'vue-chartjs'
|
||||
import {
|
||||
CategoryScale, Chart, Filler, Legend, LinearScale, LineElement, PointElement, Tooltip,
|
||||
type ChartData, type ChartOptions,
|
||||
} from 'chart.js'
|
||||
import { statsApi, type BizDist, type RealtimeStat, type StatsSummary, type TrendPoint } from '@/api/stats'
|
||||
import { systemApi, type SystemOverview } from '@/api/system'
|
||||
import { channelApi, type Channel, type ChannelSnapshot } from '@/api/channel'
|
||||
import { accountApi } from '@/api/account'
|
||||
|
||||
defineOptions({ name: 'home' })
|
||||
|
||||
Chart.register(CategoryScale, LinearScale, LineElement, PointElement, Filler, Tooltip, Legend)
|
||||
|
||||
// ---- 状态 ----
|
||||
const clock = ref('--:--:--')
|
||||
const summary = ref<StatsSummary | null>(null)
|
||||
const realtime = ref<RealtimeStat | null>(null)
|
||||
const biz = ref<BizDist | null>(null)
|
||||
const overview = ref<SystemOverview | null>(null)
|
||||
const monitor = ref<ChannelSnapshot[]>([])
|
||||
const chanSnapshot = ref<Channel[]>([])
|
||||
const acctCount = ref<number | null>(null)
|
||||
const chanCount = ref<number | null>(null)
|
||||
const trendDays = ref(7)
|
||||
const trend = ref<TrendPoint[]>([])
|
||||
|
||||
let timers: number[] = []
|
||||
|
||||
// ---- 拉取(缺数据如实显示 —,不造假) ----
|
||||
async function loadSummary() { try { summary.value = await statsApi.summary() } catch { /* keep null */ } }
|
||||
async function loadRealtime() { try { realtime.value = await statsApi.realtime() } catch { /* keep null */ } }
|
||||
async function loadBiz() { try { biz.value = await statsApi.biz(7) } catch { /* keep null */ } }
|
||||
async function loadOverview() { try { overview.value = await systemApi.overview() } catch { /* keep null */ } }
|
||||
async function loadMonitor() { try { monitor.value = await channelApi.monitor() } catch { /* keep null */ } }
|
||||
async function loadTrend() { try { trend.value = await statsApi.trend(trendDays.value) } catch { /* keep null */ } }
|
||||
async function loadCounts() {
|
||||
try {
|
||||
const [ac, ch] = await Promise.all([
|
||||
accountApi.list({ page: 1, page_size: 1 }),
|
||||
channelApi.list({ page: 1, page_size: 5 }),
|
||||
])
|
||||
acctCount.value = ac.total
|
||||
chanCount.value = ch.total
|
||||
chanSnapshot.value = ch.list.slice(0, 3)
|
||||
} catch { /* keep null */ }
|
||||
}
|
||||
|
||||
function setTrendDays(d: 7 | 30) {
|
||||
trendDays.value = d
|
||||
void loadTrend()
|
||||
}
|
||||
|
||||
function refreshAll() {
|
||||
void loadSummary(); void loadRealtime(); void loadBiz(); void loadOverview(); void loadMonitor(); void loadCounts(); void loadTrend()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
refreshAll()
|
||||
const tick = () => { clock.value = new Date().toTimeString().slice(0, 8) }
|
||||
tick()
|
||||
timers.push(window.setInterval(tick, 1000))
|
||||
timers.push(window.setInterval(() => void loadRealtime(), 5000))
|
||||
timers.push(window.setInterval(() => void loadMonitor(), 5000))
|
||||
timers.push(window.setInterval(() => void loadOverview(), 10000))
|
||||
timers.push(window.setInterval(() => void loadSummary(), 60000))
|
||||
})
|
||||
onBeforeUnmount(() => { timers.forEach(clearInterval); timers = [] })
|
||||
|
||||
|
||||
// ---- 派生 ----
|
||||
const subsystems = computed(() => overview.value?.subsystems ?? [])
|
||||
const warnCount = computed(() => subsystems.value.filter((s) => s.status === 'degraded' || s.status === 'down').length)
|
||||
const bannerTitle = computed(() => {
|
||||
const down = subsystems.value.filter((s) => s.status === 'down').length
|
||||
const deg = subsystems.value.filter((s) => s.status === 'degraded').length
|
||||
if (down > 0) return `平台有 ${down} 个子系统故障 · 请立即处置`
|
||||
if (deg > 0) return `平台运行中 · ${deg} 个子系统降级`
|
||||
if (subsystems.value.length > 0) return '平台运行平稳 · 无待处置事项'
|
||||
return '平台状态加载中'
|
||||
})
|
||||
const runningCount = computed(() => monitor.value.filter((c) => c.running).length)
|
||||
const stoppedCount = computed(() => monitor.value.filter((c) => !c.running).length)
|
||||
const rpm = computed(() => {
|
||||
const ps = realtime.value?.global_submit_ps
|
||||
return ps != null ? Math.round(ps * 60).toLocaleString() : '—'
|
||||
})
|
||||
const tpm = computed(() => {
|
||||
const sum = monitor.value.reduce((s, c) => s + c.deliver_ps, 0)
|
||||
return sum > 0 ? Math.round(sum * 60).toLocaleString() : '—'
|
||||
})
|
||||
const p50 = computed(() => {
|
||||
const live = monitor.value.filter((c) => c.running && c.latency_p50_ms > 0)
|
||||
if (live.length === 0) return '—'
|
||||
return Math.round(live.reduce((s, c) => s + c.latency_p50_ms, 0) / live.length) + 'ms'
|
||||
})
|
||||
const sentTrendPct = computed(() => {
|
||||
const t = summary.value
|
||||
if (!t || !t.yesterday_sent) return '0'
|
||||
return (((t.today_sent - t.yesterday_sent) / t.yesterday_sent) * 100).toFixed(1)
|
||||
})
|
||||
const sentTrend = computed(() => (sentTrendPct.value === '0' ? '—' : `↑${sentTrendPct.value}%`))
|
||||
const deltaPt = computed(() => {
|
||||
const d = summary.value?.success_rate_delta
|
||||
return d != null ? `${d >= 0 ? '+' : ''}${(d * 100).toFixed(1)}pt` : '—'
|
||||
})
|
||||
|
||||
|
||||
const bizTotal = computed(() => biz.value?.by_business.reduce((s, x) => s + x.count, 0) ?? 0)
|
||||
const BIZ_META: Record<string, { label: string; color: string }> = {
|
||||
sms: { label: '普通短信', color: '#14b8a6' },
|
||||
video: { label: '视频短信', color: '#0ea5e9' },
|
||||
}
|
||||
const donutSegs = computed(() => {
|
||||
const total = bizTotal.value
|
||||
if (total === 0) return []
|
||||
let offset = 0
|
||||
return (biz.value?.by_business ?? []).map((x) => {
|
||||
const meta = BIZ_META[x.key] ?? { label: x.key, color: '#9ca3af' }
|
||||
const frac = x.count / total
|
||||
const seg = { key: x.key, label: meta.label, color: meta.color, len: Math.max(frac * 314 - 2, 0), offset: -offset, percent: (frac * 100).toFixed(0) }
|
||||
offset += frac * 314
|
||||
return seg
|
||||
})
|
||||
})
|
||||
|
||||
const chartData = computed<ChartData<'line'>>(() => ({
|
||||
labels: trend.value.map((p) => p.date),
|
||||
datasets: [
|
||||
{
|
||||
label: '提交',
|
||||
data: trend.value.map((p) => p.sent / 10000),
|
||||
borderColor: '#14b8a6',
|
||||
backgroundColor: (ctx) => {
|
||||
const { chart } = ctx
|
||||
const g = chart.ctx.createLinearGradient(0, 0, 0, chart.height)
|
||||
g.addColorStop(0, 'rgba(20,184,166,0.22)')
|
||||
g.addColorStop(1, 'rgba(20,184,166,0)')
|
||||
return g
|
||||
},
|
||||
fill: true, tension: 0.35, borderWidth: 2.5, pointRadius: 3, pointBackgroundColor: '#14b8a6',
|
||||
},
|
||||
{
|
||||
label: '成功',
|
||||
data: trend.value.map((p) => p.success / 10000),
|
||||
borderColor: '#0ea5e9',
|
||||
backgroundColor: (ctx) => {
|
||||
const { chart } = ctx
|
||||
const g = chart.ctx.createLinearGradient(0, 0, 0, chart.height)
|
||||
g.addColorStop(0, 'rgba(14,165,233,0.16)')
|
||||
g.addColorStop(1, 'rgba(14,165,233,0)')
|
||||
return g
|
||||
},
|
||||
fill: true, tension: 0.35, borderWidth: 2, pointRadius: 3, pointBackgroundColor: '#0ea5e9',
|
||||
},
|
||||
],
|
||||
}))
|
||||
|
||||
// ---- 工具 ----
|
||||
function num(v: number | null | undefined): string {
|
||||
return v != null ? v.toLocaleString() : '—'
|
||||
}
|
||||
function pct(v: number | null | undefined): string {
|
||||
return v != null ? (v * 100).toFixed(1) + '%' : '—'
|
||||
}
|
||||
function subBadge(status: string): string {
|
||||
return ({ up: 'badge-success', degraded: 'badge-warning', down: 'badge-danger', unknown: 'badge-gray' } as Record<string, string>)[status] ?? 'badge-gray'
|
||||
}
|
||||
function subLabel(s: { name: string; status: string }): string {
|
||||
if (s.status === 'up') return s.name === 'gateway' || s.name === 'consumer' ? 'UP' : 'OK'
|
||||
return ({ degraded: 'DEGRADED', down: 'DOWN', unknown: 'UNKNOWN' } as Record<string, string>)[s.status] ?? s.status.toUpperCase()
|
||||
}
|
||||
function healthIcon(s: { name: string; status: string }): { icon: string; bg: string; text: string } {
|
||||
const icon = ({ gateway: '#i-srv', consumer: '#i-zap', mysql: '#i-db', redis: '#i-zap', kafka: '#i-warn' } as Record<string, string>)[s.name] ?? '#i-srv'
|
||||
if (s.status === 'up') {
|
||||
const emerald = s.name === 'consumer' || s.name === 'redis'
|
||||
return {
|
||||
icon,
|
||||
bg: emerald ? 'bg-emerald-100 text-emerald-600 dark:bg-emerald-900/30 dark:text-emerald-400' : 'bg-primary-100 text-primary-600 dark:bg-primary-900/30 dark:text-primary-400',
|
||||
text: '',
|
||||
}
|
||||
}
|
||||
if (s.status === 'degraded') return { icon, bg: 'bg-amber-100 text-amber-600 dark:bg-amber-900/30 dark:text-amber-400', text: '' }
|
||||
if (s.status === 'down') return { icon, bg: 'bg-red-100 text-red-600 dark:bg-red-900/30 dark:text-red-400', text: '' }
|
||||
return { icon, bg: 'bg-gray-100 text-gray-500 dark:bg-dark-700 dark:text-dark-400', text: '' }
|
||||
}
|
||||
function failClass(c: ChannelSnapshot): string {
|
||||
if (c.submit_ps <= 0) return 'text-gray-400'
|
||||
return c.fail_rate > 0.02 ? 'text-red-600' : 'text-emerald-600'
|
||||
}
|
||||
function loadPct(c: ChannelSnapshot): number {
|
||||
return c.total ? Math.round((c.healthy / c.total) * 100) : 0
|
||||
}
|
||||
function loadColor(c: ChannelSnapshot): string {
|
||||
const p = loadPct(c)
|
||||
if (p >= 90) return 'bg-emerald-500'
|
||||
if (p >= 50) return 'bg-amber-500'
|
||||
return 'bg-red-500'
|
||||
}
|
||||
function protoShort(p: string): string {
|
||||
return ({ cmpp: 'CM', smpp: 'SM', http: 'HT', sgip: 'SG' } as Record<string, string>)[p] ?? p.slice(0, 2).toUpperCase()
|
||||
}
|
||||
function protoLabel(c: Channel): string {
|
||||
const ver = c.protocol === 'cmpp' ? (c.protocol_version === 30 ? ' 3.0' : ' 2.0') : c.protocol === 'sgip' ? ' 1.2' : ''
|
||||
return (c.protocol + ver).toUpperCase()
|
||||
}
|
||||
|
||||
const chartOptions: ChartOptions<'line'> = {
|
||||
responsive: true, maintainAspectRatio: false,
|
||||
animation: false, // 轮询期间避免动画叠加;趋势切换即时呈现
|
||||
interaction: { mode: 'index', intersect: false },
|
||||
plugins: { legend: { display: false } },
|
||||
scales: {
|
||||
x: { grid: { display: false }, ticks: { color: '#9ca3af', font: { size: 10 } } },
|
||||
y: { border: { display: false }, grid: { color: 'rgba(107,114,128,.12)' }, ticks: { color: '#9ca3af', font: { size: 10 } } },
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
<template>
|
||||
<!-- sub2api AuthLayout 范式:渐变背景+光斑 blur+网格纹理+品牌区+card-glass 登录卡(B 方案内联简化,无 OAuth/2FA) -->
|
||||
<div class="relative flex min-h-screen items-center justify-center overflow-hidden p-4">
|
||||
<div
|
||||
class="absolute inset-0 bg-gradient-to-br from-gray-50 via-primary-50/30 to-gray-100 dark:from-dark-950 dark:via-dark-900 dark:to-dark-950"
|
||||
></div>
|
||||
|
||||
<div class="pointer-events-none absolute inset-0 overflow-hidden">
|
||||
<div class="absolute -right-40 -top-40 h-80 w-80 rounded-full bg-primary-400/20 blur-3xl"></div>
|
||||
<div class="absolute -bottom-40 -left-40 h-80 w-80 rounded-full bg-primary-500/15 blur-3xl"></div>
|
||||
<div class="absolute left-1/2 top-1/2 h-96 w-96 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary-300/10 blur-3xl"></div>
|
||||
<div
|
||||
class="absolute inset-0 bg-[linear-gradient(rgba(20,184,166,0.03)_1px,transparent_1px),linear-gradient(90deg,rgba(20,184,166,0.03)_1px,transparent_1px)] bg-[size:64px_64px]"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<div class="relative z-10 w-full max-w-md">
|
||||
<div class="mb-8 text-center">
|
||||
<div
|
||||
class="mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-primary-500 to-primary-600 text-white shadow-lg shadow-primary-500/30"
|
||||
>
|
||||
<svg class="h-8 w-8"><use href="#i-logo" /></svg>
|
||||
</div>
|
||||
<h1 class="text-gradient mb-2 text-3xl font-bold">go-sms</h1>
|
||||
<p class="text-sm text-gray-500 dark:text-dark-400">汇网综合业务支撑平台</p>
|
||||
</div>
|
||||
|
||||
<div class="card-glass rounded-2xl p-8 shadow-glass">
|
||||
<div class="space-y-6">
|
||||
<div class="text-center">
|
||||
<h2 class="text-2xl font-bold text-gray-900 dark:text-white">欢迎回来</h2>
|
||||
<p class="mt-2 text-sm text-gray-500 dark:text-dark-400">登录管理台</p>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="errorMessage"
|
||||
class="flex items-start gap-2 rounded-xl border-l-4 border-red-500 bg-red-50 px-3 py-2.5 text-sm text-red-700 dark:border-red-400 dark:bg-red-950/40 dark:text-red-300"
|
||||
>
|
||||
<svg class="mt-0.5 h-4 w-4 flex-shrink-0"><use href="#i-warn" /></svg>
|
||||
<span>{{ errorMessage }}</span>
|
||||
</div>
|
||||
|
||||
<form class="space-y-5" @submit.prevent="handleLogin">
|
||||
<div>
|
||||
<label for="username" class="input-label">用户名</label>
|
||||
<div class="relative">
|
||||
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3.5">
|
||||
<svg class="h-4 w-4 text-gray-400 dark:text-dark-500"><use href="#i-users" /></svg>
|
||||
</div>
|
||||
<input
|
||||
id="username"
|
||||
v-model="username"
|
||||
type="text"
|
||||
required
|
||||
autofocus
|
||||
autocomplete="username"
|
||||
placeholder="请输入用户名"
|
||||
class="input pl-11"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="password" class="input-label">密码</label>
|
||||
<div class="relative">
|
||||
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3.5">
|
||||
<svg class="h-4 w-4 text-gray-400 dark:text-dark-500"><use href="#i-set" /></svg>
|
||||
</div>
|
||||
<input
|
||||
id="password"
|
||||
v-model="password"
|
||||
:type="showPassword ? 'text' : 'password'"
|
||||
required
|
||||
autocomplete="current-password"
|
||||
placeholder="请输入密码"
|
||||
class="input pl-11 pr-14"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="absolute inset-y-0 right-0 flex items-center pr-3.5 text-xs text-gray-400 transition-colors hover:text-gray-600 dark:hover:text-dark-300"
|
||||
@click="showPassword = !showPassword"
|
||||
>
|
||||
{{ showPassword ? '隐藏' : '显示' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-full" :disabled="loading">
|
||||
<svg v-if="loading" class="spinner -ml-1 mr-2 h-4 w-4 text-white" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none" />
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
||||
</svg>
|
||||
{{ loading ? '登录中…' : '登 录' }}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-8 text-center text-xs text-gray-400 dark:text-dark-500">
|
||||
© {{ year }} go-sms. All rights reserved.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const user = useUserStore()
|
||||
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const showPassword = ref(false)
|
||||
const loading = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const year = new Date().getFullYear()
|
||||
|
||||
async function handleLogin() {
|
||||
if (!username.value || !password.value) return
|
||||
loading.value = true
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
await user.login(username.value, password.value)
|
||||
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '/home'
|
||||
router.push(redirect)
|
||||
} catch (e) {
|
||||
errorMessage.value = e instanceof Error ? e.message : '登录失败,请稍后重试'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,199 @@
|
||||
<template>
|
||||
<!-- 契约表格范式(#p-acct 单卡一体):筛选区+原生 table+分页;批次钻入链(record/detail redirect 带 batch_id 进来)onMounted 预填 -->
|
||||
<div>
|
||||
<div class="page-header flex items-end justify-between">
|
||||
<div>
|
||||
<p class="page-description">号码级发送明细 · 共 {{ total }} 条</p>
|
||||
</div>
|
||||
<span v-if="drilledBatch" class="badge badge-primary">批次钻入 #{{ drilledBatch }}<button class="ml-1 cursor-pointer hover:text-red-500" @click="clearDrill">×</button></span>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<!-- 筛选区:常驻 5 控件 + 展开 5 控件 -->
|
||||
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
||||
<input v-model="filter.batch_id" class="input !w-36" placeholder="批次ID 精确" @keyup.enter="search" />
|
||||
<input v-model="filter.mobile" class="input !w-40" placeholder="手机号 模糊:135****0000" @keyup.enter="search" />
|
||||
<Select v-model="filter.status" :options="STATUS_SEL_OPTIONS" placeholder="状态:全部" clearable class="!w-36" @change="search" />
|
||||
<Select v-model="filter.channel_id" :options="channelSelOptions" placeholder="通道:全部" clearable class="!w-44" @change="search" />
|
||||
<button class="btn btn-primary" @click="search">搜索</button>
|
||||
<button class="btn btn-secondary" @click="reset">重置</button>
|
||||
<button class="cursor-pointer text-sm text-primary-600 hover:underline" @click="expanded = !expanded">{{ expanded ? '收起 ▴' : '展开 ▾' }}</button>
|
||||
</div>
|
||||
<div v-show="expanded" class="flex flex-wrap items-center gap-2 border-b border-gray-100 bg-gray-50/50 p-4 dark:border-dark-700 dark:bg-dark-800/30">
|
||||
<input v-model="filter.content" class="input !w-40" placeholder="发送内容 模糊:验证码" @keyup.enter="search" />
|
||||
<Select v-model="filter.carrier" :options="CARRIER_OPTIONS" placeholder="运营商:全部" clearable class="!w-28" @change="search" />
|
||||
<input v-model="filter.raw_code" class="input !w-32" placeholder="详细状态:DELIVRD" @keyup.enter="search" />
|
||||
<input v-model="filter.startTime" type="datetime-local" class="input !w-52" @change="search" />
|
||||
<span class="text-xs text-gray-400">至</span>
|
||||
<input v-model="filter.endTime" type="datetime-local" class="input !w-52" @change="search" />
|
||||
</div>
|
||||
|
||||
<!-- 表格 9 列 -->
|
||||
<div class="table-container m-4 mt-0 border-0">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>批次</th><th>账号</th><th>手机 / 通道</th><th>发送内容</th>
|
||||
<th>时间</th><th class="text-right">条数 · 耗时</th><th>状态</th><th>来源</th><th>CallData</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="r in rows" :key="`${r.batch_id}-${r.mobile}-${r.created_at}`">
|
||||
<td><span class="cursor-pointer font-mono text-xs text-primary-600 hover:underline" @click="drill(r.batch_id)">{{ r.batch_id }}</span></td>
|
||||
<td>
|
||||
<div class="text-sm text-gray-900 dark:text-white">{{ r.account_name }}</div>
|
||||
<div class="text-xs text-gray-400">{{ r.account_sub || '—' }}</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="font-mono text-xs">{{ maskMobile(r.mobile) }}</div>
|
||||
<div class="text-xs text-gray-400">{{ r.channel_name }} · {{ r.channel_number }}</div>
|
||||
</td>
|
||||
<td><div class="max-w-44 truncate text-sm text-gray-500" :title="r.content">{{ r.content }}</div></td>
|
||||
<td>
|
||||
<div class="text-xs">{{ fmt(r.created_at) }}</div>
|
||||
<div class="text-xs text-gray-400">{{ segmentDurations(r) }}</div>
|
||||
</td>
|
||||
<td class="text-right text-sm">{{ r.fee }} 条 <span class="text-xs text-gray-400">· {{ r.duration_s != null ? r.duration_s + 's' : '—' }}</span></td>
|
||||
<td><span class="badge" :class="statusClass(r)">{{ r.raw_code || downlinkStatusText(r.status) }}</span></td>
|
||||
<td><span class="text-xs text-gray-500">{{ sourceText(r.source) }}</span></td>
|
||||
<td><span class="font-mono text-xs text-gray-400">{{ r.call_data || '—' }}</span></td>
|
||||
</tr>
|
||||
<tr v-if="!loading && rows.length === 0">
|
||||
<td colspan="9" class="py-10 text-center text-sm text-gray-400">时间范围内无明细(默认当天)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 分页条 -->
|
||||
<div class="flex items-center justify-between border-t border-gray-100 px-4 py-3 text-sm text-gray-500 dark:border-dark-700">
|
||||
<span>共 {{ total }} 条记录</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<button class="rounded-xl px-3.5 py-2 text-sm text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800" :disabled="page <= 1" @click="goPage(page - 1)">◀</button>
|
||||
<button v-for="p in pageButtons" :key="p" class="rounded-xl px-3.5 py-2 text-sm" :class="p === page ? 'bg-primary-600 font-medium text-white' : 'text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800'" @click="goPage(p)">{{ p }}</button>
|
||||
<span v-if="lastPage > 5" class="px-1 text-gray-400">…</span>
|
||||
<button class="rounded-xl px-3.5 py-2 text-sm text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800" :disabled="page >= lastPage" @click="goPage(page + 1)">▶</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import {
|
||||
DOWNLINK_STATUS_OPTIONS, downlinkStatusText, fetchDownlinkDetails,
|
||||
segmentDurations, sourceText, type DownlinkDetailRow,
|
||||
} from '@/api/sms'
|
||||
import Select from '@/components/common/Select.vue'
|
||||
import { channelApi, type Channel } from '@/api/channel'
|
||||
|
||||
// Issue#2 keep-alive 锚点:组件名=路由名
|
||||
defineOptions({ name: 'sms-downlink-detail' })
|
||||
|
||||
const route = useRoute()
|
||||
const rows = ref<DownlinkDetailRow[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = 10
|
||||
const loading = ref(false)
|
||||
const expanded = ref(false)
|
||||
const drilledBatch = ref('')
|
||||
const channelOptions = ref<Channel[]>([])
|
||||
// Select 组件选项(值域统一 string 对齐原生前 select;状态 6 项>5 → auto 出搜索)
|
||||
const STATUS_SEL_OPTIONS = DOWNLINK_STATUS_OPTIONS.map((o) => ({ value: String(o.value), label: o.label }))
|
||||
const channelSelOptions = computed(() =>
|
||||
channelOptions.value.map((c) => ({ value: String(c.id), label: `${c.name}(${c.protocol.toUpperCase()})` }))
|
||||
)
|
||||
const CARRIER_OPTIONS = [
|
||||
{ value: '移动', label: '移动' },
|
||||
{ value: '联通', label: '联通' },
|
||||
{ value: '电信', label: '电信' },
|
||||
]
|
||||
|
||||
const filter = reactive({
|
||||
batch_id: '', mobile: '', status: '' as string | number, channel_id: '' as string | number,
|
||||
content: '', carrier: '', raw_code: '', startTime: '', endTime: '',
|
||||
})
|
||||
|
||||
const lastPage = computed(() => Math.max(1, Math.ceil(total.value / pageSize)))
|
||||
const pageButtons = computed(() => {
|
||||
const from = Math.max(1, Math.min(page.value - 1, lastPage.value - 4))
|
||||
return Array.from({ length: Math.min(5, lastPage.value) }, (_, i) => from + i).filter((p) => p <= lastPage.value)
|
||||
})
|
||||
|
||||
function buildQuery() {
|
||||
return {
|
||||
page: page.value,
|
||||
page_size: pageSize,
|
||||
...(filter.batch_id.trim() ? { batch_id: filter.batch_id.trim() } : {}),
|
||||
...(filter.mobile.trim() ? { mobile: filter.mobile.trim() } : {}),
|
||||
...(filter.status !== '' ? { status: Number(filter.status) } : {}),
|
||||
...(filter.channel_id !== '' ? { channel_id: Number(filter.channel_id) } : {}),
|
||||
...(filter.content.trim() ? { content: filter.content.trim() } : {}),
|
||||
...(filter.carrier ? { carrier: filter.carrier } : {}),
|
||||
...(filter.raw_code.trim() ? { raw_code: filter.raw_code.trim() } : {}),
|
||||
...(filter.startTime ? { start_time: filter.startTime.replace('T', ' ') + ':00' } : {}),
|
||||
...(filter.endTime ? { end_time: filter.endTime.replace('T', ' ') + ':00' } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchDownlinkDetails(buildQuery())
|
||||
rows.value = res.list
|
||||
total.value = res.total
|
||||
} catch {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function search() { page.value = 1; void load() }
|
||||
function reset() {
|
||||
filter.batch_id = ''; filter.mobile = ''; filter.status = ''; filter.channel_id = ''
|
||||
filter.content = ''; filter.carrier = ''; filter.raw_code = ''; filter.startTime = ''; filter.endTime = ''
|
||||
drilledBatch.value = ''
|
||||
search()
|
||||
}
|
||||
function goPage(p: number) {
|
||||
if (p < 1 || p > lastPage.value) return
|
||||
page.value = p
|
||||
void load()
|
||||
}
|
||||
|
||||
/** 批次钻入:表内批次ID 点击 → 收敛筛选(记录中心其他页跳入也走这里)。 */
|
||||
function drill(batchId: number) {
|
||||
drilledBatch.value = String(batchId)
|
||||
filter.batch_id = String(batchId)
|
||||
search()
|
||||
}
|
||||
function clearDrill() { filter.batch_id = ''; drilledBatch.value = ''; search() }
|
||||
|
||||
// ---- 展示工具 ----
|
||||
function maskMobile(m: string): string {
|
||||
return m.length >= 11 ? `${m.slice(0, 3)}****${m.slice(7)}` : m
|
||||
}
|
||||
function fmt(s: string): string {
|
||||
return s?.length >= 16 ? s.slice(5, 16) : s
|
||||
}
|
||||
function statusClass(r: DownlinkDetailRow): string {
|
||||
if (r.status === 2 && !r.error_code) return 'badge-success'
|
||||
if (r.status === 3) return 'badge-danger'
|
||||
if (r.status === 5) return 'badge-warning'
|
||||
return 'badge-gray'
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 批次钻入链:/record/detail redirect 会带 batch_id query 进来
|
||||
const q = route.query.batch_id as string | undefined
|
||||
if (q) { filter.batch_id = String(q); drilledBatch.value = String(q) }
|
||||
void load()
|
||||
void channelApi.list({ page: 1, page_size: 100 }).then((d) => { channelOptions.value = d.list }).catch(() => {})
|
||||
})
|
||||
</script>
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
const component: DefineComponent<Record<string, never>, Record<string, never>, unknown>
|
||||
export default component
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
|
||||
darkMode: 'class',
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
// 主色调 - Teal/Cyan 青色系
|
||||
primary: {
|
||||
50: '#f0fdfa',
|
||||
100: '#ccfbf1',
|
||||
200: '#99f6e4',
|
||||
300: '#5eead4',
|
||||
400: '#2dd4bf',
|
||||
500: '#14b8a6',
|
||||
600: '#0d9488',
|
||||
700: '#0f766e',
|
||||
800: '#115e59',
|
||||
900: '#134e4a',
|
||||
950: '#042f2e'
|
||||
},
|
||||
// 辅助色 - 深蓝灰
|
||||
accent: {
|
||||
50: '#f8fafc',
|
||||
100: '#f1f5f9',
|
||||
200: '#e2e8f0',
|
||||
300: '#cbd5e1',
|
||||
400: '#94a3b8',
|
||||
500: '#64748b',
|
||||
600: '#475569',
|
||||
700: '#334155',
|
||||
800: '#1e293b',
|
||||
900: '#0f172a',
|
||||
950: '#020617'
|
||||
},
|
||||
// 深色模式背景
|
||||
dark: {
|
||||
50: '#f8fafc',
|
||||
100: '#f1f5f9',
|
||||
200: '#e2e8f0',
|
||||
300: '#cbd5e1',
|
||||
400: '#94a3b8',
|
||||
500: '#64748b',
|
||||
600: '#475569',
|
||||
700: '#334155',
|
||||
800: '#1e293b',
|
||||
900: '#0f172a',
|
||||
950: '#020617'
|
||||
}
|
||||
},
|
||||
fontFamily: {
|
||||
sans: [
|
||||
'system-ui',
|
||||
'-apple-system',
|
||||
'BlinkMacSystemFont',
|
||||
'Segoe UI',
|
||||
'Roboto',
|
||||
'Helvetica Neue',
|
||||
'Arial',
|
||||
'PingFang SC',
|
||||
'Hiragino Sans GB',
|
||||
'Microsoft YaHei',
|
||||
'sans-serif'
|
||||
],
|
||||
mono: ['ui-monospace', 'SFMono-Regular', 'Menlo', 'Monaco', 'Consolas', 'monospace']
|
||||
},
|
||||
boxShadow: {
|
||||
glass: '0 8px 32px rgba(0, 0, 0, 0.08)',
|
||||
'glass-sm': '0 4px 16px rgba(0, 0, 0, 0.06)',
|
||||
glow: '0 0 20px rgba(20, 184, 166, 0.25)',
|
||||
'glow-lg': '0 0 40px rgba(20, 184, 166, 0.35)',
|
||||
card: '0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06)',
|
||||
'card-hover': '0 10px 40px rgba(0, 0, 0, 0.08)',
|
||||
'inner-glow': 'inset 0 1px 0 rgba(255, 255, 255, 0.1)'
|
||||
},
|
||||
backgroundImage: {
|
||||
'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
|
||||
'gradient-primary': 'linear-gradient(135deg, #14b8a6 0%, #0d9488 100%)',
|
||||
'gradient-dark': 'linear-gradient(135deg, #1e293b 0%, #0f172a 100%)',
|
||||
'gradient-glass':
|
||||
'linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%)',
|
||||
'mesh-gradient':
|
||||
'radial-gradient(at 40% 20%, rgba(20, 184, 166, 0.12) 0px, transparent 50%), radial-gradient(at 80% 0%, rgba(6, 182, 212, 0.08) 0px, transparent 50%), radial-gradient(at 0% 50%, rgba(20, 184, 166, 0.08) 0px, transparent 50%)'
|
||||
},
|
||||
animation: {
|
||||
'fade-in': 'fadeIn 0.3s ease-out',
|
||||
'slide-up': 'slideUp 0.3s ease-out',
|
||||
'slide-down': 'slideDown 0.3s ease-out',
|
||||
'slide-in-right': 'slideInRight 0.3s ease-out',
|
||||
'scale-in': 'scaleIn 0.2s ease-out',
|
||||
'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite',
|
||||
shimmer: 'shimmer 2s linear infinite',
|
||||
glow: 'glow 2s ease-in-out infinite alternate'
|
||||
},
|
||||
keyframes: {
|
||||
fadeIn: {
|
||||
'0%': { opacity: '0' },
|
||||
'100%': { opacity: '1' }
|
||||
},
|
||||
slideUp: {
|
||||
'0%': { opacity: '0', transform: 'translateY(10px)' },
|
||||
'100%': { opacity: '1', transform: 'translateY(0)' }
|
||||
},
|
||||
slideDown: {
|
||||
'0%': { opacity: '0', transform: 'translateY(-10px)' },
|
||||
'100%': { opacity: '1', transform: 'translateY(0)' }
|
||||
},
|
||||
slideInRight: {
|
||||
'0%': { opacity: '0', transform: 'translateX(20px)' },
|
||||
'100%': { opacity: '1', transform: 'translateX(0)' }
|
||||
},
|
||||
scaleIn: {
|
||||
'0%': { opacity: '0', transform: 'scale(0.95)' },
|
||||
'100%': { opacity: '1', transform: 'scale(1)' }
|
||||
},
|
||||
shimmer: {
|
||||
'0%': { backgroundPosition: '-200% 0' },
|
||||
'100%': { backgroundPosition: '200% 0' }
|
||||
},
|
||||
glow: {
|
||||
'0%': { boxShadow: '0 0 20px rgba(20, 184, 166, 0.25)' },
|
||||
'100%': { boxShadow: '0 0 30px rgba(20, 184, 166, 0.4)' }
|
||||
}
|
||||
},
|
||||
backdropBlur: {
|
||||
xs: '2px'
|
||||
},
|
||||
borderRadius: {
|
||||
'4xl': '2rem'
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: []
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2021",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2021", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
},
|
||||
"types": ["vite/client"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||
"exclude": ["src/**/__tests__/**", "src/**/*.spec.ts", "src/**/*.test.ts"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { resolve } from 'path'
|
||||
|
||||
// web-next · Issue#6 B 方案(0 重构):Tailwind3.4 + 契约 CSS 直拼 + 零 EP。
|
||||
// dev 口径::5174(与旧 web :5173 并行共存,切换期互不干扰)/api 反代网关 :8080。
|
||||
export default defineConfig(() => {
|
||||
return {
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, 'src'),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 5174,
|
||||
// sms.unimsc.com 外网域名通道(2026-11-17 需求:入口由旧 web :5173 切至 web-next :5174):
|
||||
// 经 nginx(192.168.5.20) 根路径反代(443→5174)访问,Host 头为域名;
|
||||
// vite5.4+ DNS-rebinding 防护默认只放行 localhost/内网 IP,须显式登记(口径同 web/vite.config.ts)。
|
||||
allowedHosts: ['sms.unimsc.com', 'sms.i7l.cn'],
|
||||
// HMR:不设 clientPort——同源端口直连(内网 http://ip:5174 → ws://ip:5174)。
|
||||
// 教训(2026-11-17):clientPort:443 曾致内网直连 HMR 连向 :443 失败循环刷新;
|
||||
// 域名通道 HMR 需 nginx 443 上线后再评估(届时走 wss 同源 443,勿再用 clientPort 硬编码)。
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: process.env.VITE_DEV_PROXY_TARGET || 'http://localhost:8080',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -438,11 +438,12 @@ export const handlers = [
|
||||
const id = Number(params.id)
|
||||
const acc = accountDB.find((a) => a.id === id)
|
||||
if (!acc) return fail('ISC:404', '资源不存在', 404)
|
||||
const body = (await request.json()) as { count: number; remark: string }
|
||||
if (!body.count || body.count <= 0) return fail('ISC:400', '充值条数必须大于 0')
|
||||
acc.balance += body.count
|
||||
// Issue#3:契约对齐真实后端 rechargeReq{amount, remark}(amount>0 必填)
|
||||
const body = (await request.json()) as { amount: number; remark: string }
|
||||
if (!body.amount || body.amount <= 0) return fail('ISC:400', '充值条数必须大于 0')
|
||||
acc.balance += body.amount
|
||||
balanceLogs.push({
|
||||
id: balanceLogs.length + 1, account_id: id, biz_type: 'recharge', amount: body.count,
|
||||
id: balanceLogs.length + 1, account_id: id, biz_type: 'recharge', amount: body.amount,
|
||||
balance_after: acc.balance, operator: 'admin', remark: body.remark || '后台充值',
|
||||
created_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
})
|
||||
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hwsms-web",
|
||||
"version": "0.1.0",
|
||||
"version": "1.5.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"packageManager": "pnpm@12.18.0",
|
||||
@@ -16,7 +16,8 @@
|
||||
"gen:dict": "cd .. && go run ./tools/gen-dict",
|
||||
"test:watch": "vitest",
|
||||
"shot": "node scripts/shot.mjs",
|
||||
"verify:layout": "node scripts/verify-layout.mjs"
|
||||
"verify:layout": "node scripts/verify-layout.mjs",
|
||||
"verify:select": "node scripts/verify-select-contract.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
|
||||
@@ -40,11 +40,11 @@ ok(await page.getByTestId('sidebar-collapse-btn').isVisible(), '桌面显示侧
|
||||
await page.getByTestId('sidebar-collapse-btn').click()
|
||||
await page.waitForTimeout(300)
|
||||
const wAfter = (await sidebar.boundingBox())?.width
|
||||
ok(wBefore === 224 && wAfter === 64, `收起 224→64(实际 ${wBefore}→${wAfter})`)
|
||||
ok(Math.round(wBefore) === 256 && Math.abs(wAfter - 72) < 2, `收起 256→72(实际 ${wBefore}→${wAfter})`)
|
||||
ok(await page.locator('.sidebar.collapsed').count() === 1, 'collapsed 类挂载')
|
||||
await page.getByTestId('sidebar-collapse-btn').click()
|
||||
await page.waitForTimeout(300)
|
||||
ok((await sidebar.boundingBox())?.width === 224, '再点展开恢复 224')
|
||||
ok(Math.abs(((await sidebar.boundingBox())?.width ?? 0) - 256) < 2, '再点展开恢复 256')
|
||||
// H2:侧栏滚动条视觉消除(滚动能力保留;W6 起滚动职责在 .nav-scroll,sidebar 本体 overflow:hidden)
|
||||
const sw = await page.evaluate(() => getComputedStyle(document.querySelector('aside.sidebar .nav-scroll')).scrollbarWidth)
|
||||
ok(sw === 'none', `侧栏滚动区 scrollbar-width === none(实际 ${sw})`)
|
||||
@@ -63,6 +63,21 @@ 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()})`)
|
||||
|
||||
// I4 · Issue#4 侧栏版本号 + 发布日志断言(桌面视口;全新会话 localStorage 空 → 红点亮)
|
||||
const verChip = page.getByTestId('sidebar-version')
|
||||
ok(await verChip.isVisible(), '侧栏底脚显示版本号 chip(折叠按钮旁)')
|
||||
const verText = ((await verChip.textContent()) ?? '').trim()
|
||||
ok(/^v\d+\.\d+/.test(verText), `版本号文本 vN.N(实际 ${verText})`)
|
||||
ok(await page.getByTestId('sidebar-version-dot').count() === 1, '首访未读 → 红点存在')
|
||||
await verChip.click()
|
||||
await page.waitForTimeout(500)
|
||||
ok(page.url().includes('/system/release'), '点击版本号进入发布日志页')
|
||||
ok(await page.getByTestId('sidebar-version-dot').count() === 0, '进入后红点消失(已读)')
|
||||
ok(await page.locator('.rn-item').count() >= 3, `发布日志版本卡片 ≥3(实际 ${await page.locator('.rn-item').count()})`)
|
||||
ok(await page.locator('.rn-md ul li').first().isVisible(), 'Markdown 列表已渲染')
|
||||
await page.getByTestId('menu-home').click()
|
||||
await page.waitForTimeout(300)
|
||||
|
||||
// 6) 移动端汉堡抽屉(375×812)
|
||||
await page.setViewportSize({ width: 375, height: 812 })
|
||||
await page.waitForTimeout(300)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// verify-select-contract.mjs Issue#6·F4:下拉契约断言(chrome-session 铁律:channel chrome+独立 launch+单 page)
|
||||
// 断言:F1 色调(trigger 底=token 系,暗=veil/亮=白;弹层底 slate-800/白;r12)/F2 密度与对齐(item 10/16+左)/选中底色式
|
||||
import { chromium } from '../node_modules/playwright/index.mjs'
|
||||
const sleep=(ms)=>new Promise(r=>setTimeout(r,ms))
|
||||
const fails=[]
|
||||
const ok=(c,m,v)=>{console.log((c?'✓ ':'✗ ')+m+(v!==undefined?` = ${v}`:''));if(!c)fails.push(m)}
|
||||
const browser = await chromium.launch({ channel:'chrome', args:['--no-sandbox','--disable-gpu','--disable-dev-shm-usage'] })
|
||||
const page = await browser.newPage({ viewport:{ width:1440, height:900 } })
|
||||
await page.goto('http://127.0.0.1:5173/login',{waitUntil:'domcontentloaded'})
|
||||
await page.getByTestId('login-username').fill(process.env.SHOT_USER ?? 's2demo')
|
||||
await page.getByTestId('login-password').fill(process.env.SHOT_PASS ?? 'S2demo@2026')
|
||||
await page.getByTestId('login-submit').click()
|
||||
await page.waitForURL('**/home',{timeout:15000}); await sleep(1500)
|
||||
async function probe(expect, label){
|
||||
await page.goto('http://127.0.0.1:5173/account',{waitUntil:'domcontentloaded'}); await sleep(2500)
|
||||
await page.locator('.el-select').first().click(); await sleep(1100)
|
||||
const r = await page.evaluate(() => {
|
||||
const trig=document.querySelector('.el-select__wrapper')
|
||||
const dd=document.querySelector('.el-select-dropdown')
|
||||
const pop=document.querySelector('.el-select__popper')
|
||||
const it=dd?.querySelector('.el-select-dropdown__item')
|
||||
const g=(e,k)=>e?getComputedStyle(e)[k]:'-'
|
||||
return { trig:g(trig,'backgroundColor'), popBg:g(pop,'backgroundColor'), popR:g(pop,'borderRadius'),
|
||||
pad:g(it,'padding'), align:g(it,'textAlign') }
|
||||
})
|
||||
ok(r.trig===expect.trig, `[${label}] trigger 底=token(${expect.trig})`, r.trig)
|
||||
ok(r.popBg===expect.pop, `[${label}] 弹层底`, r.popBg)
|
||||
ok(r.popR==='12px', `[${label}] 弹层圆角 12`, r.popR)
|
||||
ok(r.pad==='10px 16px', `[${label}] 选项密度 10/16(契约 px-4 py-2.5)`, r.pad)
|
||||
ok(r.align==='start', `[${label}] 选项左对齐`, r.align)
|
||||
await page.keyboard.press('Escape'); await sleep(350)
|
||||
}
|
||||
await probe({trig:'rgba(148, 163, 184, 0.06)',pop:'rgb(30, 41, 59)'},'暗')
|
||||
await page.getByTestId('dark-toggle').click(); await sleep(700)
|
||||
await probe({trig:'rgb(255, 255, 255)',pop:'rgb(255, 255, 255)'},'亮')
|
||||
await browser.close()
|
||||
if(fails.length){console.error(`\n✗ ${fails.length} 项失败`);process.exit(1)}
|
||||
console.log('\n✓ 下拉契约断言全通过')
|
||||
@@ -109,8 +109,9 @@ export const accountApi = {
|
||||
update: (id: number, body: Partial<Account>) => put<Account>(`/accounts/${id}`, body),
|
||||
setStatus: (id: number, status: number) => put<Account>(`/accounts/${id}/status`, { status }),
|
||||
remove: (id: number) => del<{ id: number }>(`/accounts/${id}`),
|
||||
recharge: (id: number, count: number, remark: string) =>
|
||||
post<{ balance: number }>(`/accounts/${id}/recharge`, { count, remark }),
|
||||
// Issue#3 修复:后端 rechargeReq 为 {amount, remark}(此前误发 count 致 400 被吞)。
|
||||
recharge: (id: number, amount: number, remark: string) =>
|
||||
post<{ balance: number }>(`/accounts/${id}/recharge`, { amount, remark }),
|
||||
balanceLogs: (id: number) => get<Paged<BalanceLog>>(`/accounts/${id}/balance_logs`),
|
||||
// Day 62:外部 API 配置(CMPP 密码/接入配额/交付块)
|
||||
getApiConfig: (id: number) => get<ApiConfig>(`/accounts/${id}/api-config`),
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { get, put } from './request'
|
||||
|
||||
/** Issue#3 方案B:系统参数配置(system_config KV;admin)。 */
|
||||
export interface SystemConfigRow {
|
||||
id: number
|
||||
cfg_key: string
|
||||
cfg_value: string
|
||||
remark: string
|
||||
updated_by: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface SystemConfigSaveReq {
|
||||
cfg_key: string
|
||||
cfg_value: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** 已知键说明(表结构无白名单,新键=新能力;此处仅运营提示)。 */
|
||||
export const KNOWN_CFG_KEYS: { key: string; label: string; hint: string }[] = [
|
||||
{
|
||||
key: 'cmpp.default_ext_code',
|
||||
label: '系统默认接入码前缀',
|
||||
hint: 'CMPP/SMPP 账号未配置扩展码(ext_code)时回退此值校验 SrcID 前缀;改后受理侧 ≤30s 生效',
|
||||
},
|
||||
{
|
||||
key: 'uplink.blacklist.keywords',
|
||||
label: '上行自动拉黑词表',
|
||||
hint: '逗号分隔等值匹配(如 R,TD,退订,拒收);空=内置默认词表;改后 ≤60s 生效',
|
||||
},
|
||||
]
|
||||
|
||||
export const systemApi = {
|
||||
list: () => get<{ list: SystemConfigRow[] }>('/system/config'),
|
||||
update: (body: SystemConfigSaveReq) => put<SystemConfigRow>('/system/config', body),
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<!-- ScSelect.vue Issue#6·F3:下拉统一封装(对齐 sub2api Select searchable=auto 语义)
|
||||
规则:options 数组模式下选项>5 自动 filterable(契约源 Select.vue L210:
|
||||
options.length > 5);slot 模式纯透传(调用方自控)。新代码下拉一律用本件;
|
||||
web-next 新工程将 1:1 直译 sub2api Select(面板首项=搜索输入的严格形态)。 -->
|
||||
<template>
|
||||
<el-select
|
||||
:model-value="modelValue"
|
||||
:filterable="autoFilter || filterable"
|
||||
:placeholder="placeholder"
|
||||
:clearable="clearable"
|
||||
:disabled="disabled"
|
||||
:size="size"
|
||||
@update:model-value="$emit('update:modelValue', $event)"
|
||||
>
|
||||
<slot>
|
||||
<el-option v-for="o in options" :key="String(o.value)" :value="o.value" :label="o.label" :disabled="o.disabled" />
|
||||
</slot>
|
||||
</el-select>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
defineOptions({ name: 'ScSelect', inheritAttrs: true })
|
||||
|
||||
export interface ScOption {
|
||||
value: string | number | boolean
|
||||
label: string
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: unknown
|
||||
/** 选项数组(推荐:驱动 auto>5 阈值);缺省走 slot */
|
||||
options?: ScOption[]
|
||||
placeholder?: string
|
||||
clearable?: boolean
|
||||
disabled?: boolean
|
||||
size?: 'large' | 'default' | 'small'
|
||||
/** 显式可搜(手写覆盖,等同 el-select filterable) */
|
||||
filterable?: boolean
|
||||
/** 契约 auto 阈值:'auto'(默认,>5 出搜索)|true|false;仅 options 数组模式生效 */
|
||||
searchable?: boolean | 'auto'
|
||||
}>(),
|
||||
{ clearable: true, searchable: 'auto' },
|
||||
)
|
||||
|
||||
defineEmits<{ 'update:modelValue': [value: unknown] }>()
|
||||
|
||||
const autoFilter = computed(() => {
|
||||
if (props.filterable || props.searchable === false) return false
|
||||
const n = props.options?.length ?? 0
|
||||
return props.searchable === true || n > 5
|
||||
})
|
||||
</script>
|
||||
@@ -59,7 +59,9 @@ function onAuxClick(t: TabItem, e: MouseEvent) {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tags-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; min-width: 0; }
|
||||
/* Issue#6 P3:sub2api 契约化——chip h32/r12/13px,激活 primary-soft 底
|
||||
primary 字(同 nav-item 激活语义);ghost 动作钮 12px。功能零动。 */
|
||||
.tags-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; 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;
|
||||
@@ -67,26 +69,26 @@ function onAuxClick(t: TabItem, e: MouseEvent) {
|
||||
.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;
|
||||
height: 32px; padding: 0 12px; border-radius: 12px; border: 1px solid transparent;
|
||||
background: var(--gosms-input-veil); color: var(--gosms-text-secondary);
|
||||
font-size: 13px; 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; }
|
||||
html:not(.dark) .tag-chip.active { background: var(--gosms-primary-50); color: var(--gosms-primary-600); }
|
||||
.tag-close {
|
||||
display: inline-grid; place-items: center; width: 14px; height: 14px;
|
||||
display: inline-grid; place-items: center; width: 16px; height: 16px;
|
||||
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); }
|
||||
.tag-close:hover { color: var(--gosms-red); background: rgba(239, 68, 68, 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;
|
||||
font-size: 12px; color: var(--gosms-text-secondary); background: none;
|
||||
border: 1px solid var(--gosms-border); border-radius: 8px; padding: 5px 10px;
|
||||
cursor: pointer; transition: all 0.2s; white-space: nowrap;
|
||||
}
|
||||
.tag-act:hover { color: var(--gosms-primary); border-color: var(--gosms-primary); }
|
||||
.tag-act:hover { color: var(--gosms-primary); border-color: var(--gosms-primary); background: var(--gosms-primary-soft); }
|
||||
@media (max-width: 900px) {
|
||||
/* 移动端收紧:动作按钮保留,chip 区横向滚动已由 tags-scroll 承接 */
|
||||
.tags-bar { gap: 6px; margin-bottom: 10px; }
|
||||
.tag-act { padding: 4px 8px; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// data/releases.ts — Issue#4 版本号与发布日志(单一事实源)。
|
||||
//
|
||||
// 发版 SOP(每 次功能上线):
|
||||
// 1. 在 RELEASE_NOTES **头部**插入一条(最新在最前),version 沿语义化
|
||||
// 版本递增(major.minor.patch:功能=minor、修复/小改=patch);
|
||||
// 2. APP_VERSION 自动取首条 version;package.json 的 version 需手工同步
|
||||
// (tests/releases.spec.ts 断言两侧一致防漂移);
|
||||
// 3. 文案面向运营/客户的**大白话**(不写实现细节/工单号),Markdown 格式
|
||||
// (utils/markdown.ts 渲染:标题/有序无序列表/粗体/行内代码/代码块/链接)。
|
||||
// 4. 部署后所有用户侧栏底部亮红点,点击进入发布日志页即标记已读。
|
||||
|
||||
/** 一条发布日志。 */
|
||||
export interface ReleaseNote {
|
||||
version: string // 语义化版本 x.y.z(与 package.json 一致)
|
||||
date: string // 发布日期 YYYY-MM-DD
|
||||
tag: string // 标签:新功能 / 优化 / 修复
|
||||
markdown: string // 发布说明(大白话 Markdown)
|
||||
}
|
||||
|
||||
export const RELEASE_NOTES: ReleaseNote[] = [
|
||||
{
|
||||
version: '1.5.0',
|
||||
date: '2026-11-16',
|
||||
tag: '新功能',
|
||||
markdown: `### 客户对接全链打通
|
||||
- **客户软件直连平台**:客户用自己熟悉的短信软件(标准 CMPP 协议)即可连上平台,**登录、发短信、接收发送报告**全流程顺畅,之前"连接报错"的问题已彻底解决。
|
||||
- **充值修复**:给账号充值时偶尔"没反应"的问题已修复,现在充值成功后余额马上更新。
|
||||
- **版本号与发布日志上线**(就是您现在看的这个页面):左侧菜单底部显示当前版本号,平台有更新时会亮**红点**提醒,点开就能看这次更新了什么。`,
|
||||
},
|
||||
{
|
||||
version: '1.4.0',
|
||||
date: '2026-11-16',
|
||||
tag: '优化',
|
||||
markdown: `### 操作更顺手
|
||||
- **多标签页**:打开的功能页会变成顶部标签,像浏览器标签页一样——可单独关闭、一键关闭全部;切走再切回来,**之前填的筛选条件还在**,不用重新填。
|
||||
- **系统配置页上线**:平台级参数(默认接入码、上行拉黑词表等)有了专门的管理页面,改完**立即生效**,全部操作留痕。`,
|
||||
},
|
||||
{
|
||||
version: '1.3.0',
|
||||
date: '2026-11-16',
|
||||
tag: '新功能',
|
||||
markdown: `### 平台能力升级
|
||||
- **发送结果自动通知**:短信发出后(无论成功失败),平台可自动把结果**推送到客户自己的系统**,不用登录平台手动查。
|
||||
- **退订自动拉黑**:用户回复"退订 / R / 拒收"等关键词后,系统自动把该号码加入黑名单,以后不再给 TA 发短信,减少投诉风险。
|
||||
- **历史记录查询提速**:短信明细保留 5 天热数据,更早的自动转入历史库;查**几个月前的记录也在 1 秒内**出结果。`,
|
||||
},
|
||||
{
|
||||
version: '1.2.0',
|
||||
date: '2026-11-15',
|
||||
tag: '新功能',
|
||||
markdown: `### 经营看得清
|
||||
- **利润分析上线**:一眼看清**每个账号赚多少、每条通道花多少、平台整体净利多少**;支持按时间段筛选,口径说明常驻页面,数字怎么算的清清楚楚。
|
||||
- **通道页面焕新**:通道列表从 20 列精简为 8 列重点信息,不再眼花缭乱;编辑页按"基本信息 / 通道配置 / 优先级限额"分组,找配置更快。`,
|
||||
},
|
||||
{
|
||||
version: '1.1.0',
|
||||
date: '2026-11-14',
|
||||
tag: '新功能',
|
||||
markdown: `### 结算管理上线
|
||||
- **订单与账单**:给客户创建结算订单、按月生成账单、确认结账、导出 Excel 对账单,全流程在页面上完成。
|
||||
- **阶梯价**:支持"发得越多、单价越便宜"的阶梯计费,按月用量自动落档。
|
||||
- **对账保障**:平台内部三方数据自动核对,**金额分毫不差才允许结账**,保证账单准确。`,
|
||||
},
|
||||
{
|
||||
version: '1.0.0',
|
||||
date: '2026-11-13',
|
||||
tag: '新功能',
|
||||
markdown: `### 平台一期上线
|
||||
- **全新短信管理平台**重建完成,界面焕然一新。
|
||||
- **基础功能**:登录、运营总览(今日发送量 / 成功率一眼看)、账号管理(开户 / 充值 / 角色权限)。
|
||||
- **短信业务**:群发工作台、个性短信、定时任务、短信模板。
|
||||
- **记录中心**:下发记录、上行记录、失败重推——每条短信的来龙去脉都可查。
|
||||
- **多协议接入**:支持 **CMPP、SMPP、HTTP** 三种主流方式对接客户与通道。`,
|
||||
},
|
||||
]
|
||||
|
||||
/** 当前版本(=最新一条;侧栏版本号与红点判定的事实源)。 */
|
||||
export const APP_VERSION: string = RELEASE_NOTES[0]!.version
|
||||
@@ -1,14 +1,9 @@
|
||||
<template>
|
||||
<!-- G2:demo-c-aurora.html body 结构 1:1 直译——aurora 光斑 + topbar + shell(sidebar/main)
|
||||
EP 导航壳(el-menu/el-scrollbar/el-drawer)全部退场,菜单= demo 原生 nav-item -->
|
||||
<div class="aurora"></div>
|
||||
|
||||
<!-- Issue#6 P3:sub2api 契约壳——顶栏 64 glass(页标题+动作)/侧栏 256·折叠 72
|
||||
(sidebar-header 品牌区+版本徽章=用户指令位)/main 32/keep-alive 不变 -->
|
||||
<header class="topbar">
|
||||
<button class="menu-btn" aria-label="打开导航菜单" data-testid="menu-drawer-btn" @click="navOpen = true">☰</button>
|
||||
<div class="brand">
|
||||
<div class="brand-mark">✦</div>
|
||||
<div><div class="brand-name">go-sms</div><div class="brand-sub">AURORA CONSOLE</div></div>
|
||||
</div>
|
||||
<h1 class="top-title" data-testid="top-title">{{ route.meta.title ?? '' }}</h1>
|
||||
<div class="top-actions">
|
||||
<button class="theme-btn" data-testid="dark-toggle" :aria-label="isDark ? '切换到亮色主题' : '切换到暗色主题'" @click="toggleTheme">
|
||||
{{ isDark ? '☀ 亮色' : '◑ 主题' }}
|
||||
@@ -29,9 +24,25 @@
|
||||
</header>
|
||||
|
||||
<div class="shell">
|
||||
<!-- ===== 侧栏(demo sidebar 原文结构;唯一菜单,无折叠/无 popup) ===== -->
|
||||
<!-- ===== 侧栏(sub2api AppSidebar 结构:header 品牌区+nav 滚动区+foot) ===== -->
|
||||
<aside class="sidebar" :class="{ open: navOpen, collapsed: collapsed && !navOpen }">
|
||||
<!-- W6:菜单滚动区(flex:1 承接滚动) + 底脚收起按钮(固定最下方) -->
|
||||
<router-link to="/" class="sidebar-header" @click="navOpen = false">
|
||||
<div class="brand">
|
||||
<div class="brand-mark">✦</div>
|
||||
<div>
|
||||
<div class="brand-name">go-sms</div>
|
||||
<!-- Issue#4 资产:版本徽章迁品牌下方(用户指令位);红点=本地未读,点击进发布日志 -->
|
||||
<span
|
||||
class="ver-badge" data-testid="sidebar-version"
|
||||
:title="release.hasUpdate ? `发现新版本 v${APP_VERSION},点击查看更新内容` : `当前版本 v${APP_VERSION}`"
|
||||
@click.stop.prevent="goRelease"
|
||||
>
|
||||
<span v-if="release.hasUpdate" class="ver-dot" data-testid="sidebar-version-dot"></span>
|
||||
<span class="ver-txt">v{{ APP_VERSION }}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</router-link>
|
||||
<div class="nav-scroll">
|
||||
<template v-for="(items, group) in menuGroups" :key="group">
|
||||
<div class="nav-group">{{ group }}</div>
|
||||
@@ -40,7 +51,7 @@
|
||||
class="nav-item" :class="{ active: isActive(m.path) }"
|
||||
:data-testid="`menu-${m.name}`" @click="navOpen = false"
|
||||
>
|
||||
<span class="ic"><el-icon :size="14"><component :is="m.icon" /></el-icon></span><span class="txt">{{ m.title }}</span>
|
||||
<span class="ic"><el-icon :size="20"><component :is="m.icon" /></el-icon></span><span class="txt">{{ m.title }}</span>
|
||||
</router-link>
|
||||
</template>
|
||||
</div>
|
||||
@@ -52,7 +63,7 @@
|
||||
</aside>
|
||||
<div v-if="navOpen" class="nav-scrim" @click="navOpen = false"></div>
|
||||
|
||||
<!-- ===== 主区(demo main 原文) ===== -->
|
||||
<!-- ===== 主区 ===== -->
|
||||
<main class="main">
|
||||
<!-- Issue#2:多标签导航(独立关闭/关闭其他/全部关闭) -->
|
||||
<TagsBar />
|
||||
@@ -78,15 +89,19 @@ import { computed, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { useTabsStore } from '@/stores/tabs'
|
||||
import { useReleaseStore } from '@/stores/release'
|
||||
import { accessibleRoutes } from '@/router/guard'
|
||||
import { APP_VERSION } from '@/data/releases'
|
||||
import TagsBar from '@/components/TagsBar.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
const tabs = useTabsStore()
|
||||
// Issue#4:版本已读状态(品牌区版本徽章红点判定)
|
||||
const release = useReleaseStore()
|
||||
|
||||
// ===== 暗色模式(html.dark;demo data-theme 的项目语义映射) =====
|
||||
// ===== 暗色模式(html.dark) =====
|
||||
const isDark = ref(document.documentElement.classList.contains('dark'))
|
||||
function toggleTheme() {
|
||||
isDark.value = !isDark.value
|
||||
@@ -94,23 +109,30 @@ function toggleTheme() {
|
||||
localStorage.setItem('gosms_dark', isDark.value ? '1' : '0')
|
||||
}
|
||||
|
||||
// ===== 移动端汉堡抽屉(<=900,demo 断点;CSS transform,无 EP) =====
|
||||
// ===== 移动端汉堡抽屉(<=900,CSS transform,无 EP) =====
|
||||
const navOpen = ref(false)
|
||||
|
||||
// ===== H1:桌面侧栏收起/展开(64px 图标态;localStorage 持久化) =====
|
||||
// ===== 侧栏收起/展开(72px 图标态;localStorage 持久化) =====
|
||||
const collapsed = ref(localStorage.getItem('gosms_sidebar') === '1')
|
||||
function toggleCollapse() {
|
||||
collapsed.value = !collapsed.value
|
||||
localStorage.setItem('gosms_sidebar', collapsed.value ? '1' : '0')
|
||||
}
|
||||
|
||||
// ===== 头像首字母(demo avatar:AD) =====
|
||||
// ===== 头像首字母 =====
|
||||
const initials = computed(() => (userStore.user?.username ?? '?').slice(0, 2).toUpperCase())
|
||||
|
||||
// page-head 副题(meta.subtitle 可选)
|
||||
const pageSub = computed(() => (route.meta as { subtitle?: string }).subtitle ?? '')
|
||||
|
||||
// ===== 菜单:可访问路由生成,按 group 分组(demo nav-item 数据源) =====
|
||||
// Issue#4→P3:版本徽章迁 sidebar-header 品牌下方;折叠态随品牌隐藏(契约同
|
||||
// sub2api),shortVersion 退役;点击徽章进发布日志并 markSeen。
|
||||
function goRelease() {
|
||||
release.markSeen()
|
||||
void router.push('/system/release')
|
||||
}
|
||||
|
||||
// ===== 菜单:可访问路由生成,按 group 分组 =====
|
||||
interface MenuItem { path: string; name: string; title: string; icon: string }
|
||||
const menuItems = computed<MenuItem[]>(() =>
|
||||
accessibleRoutes(userStore.roles)
|
||||
|
||||
@@ -75,7 +75,10 @@ export const asyncRoutes: RouteRecordRaw[] = [
|
||||
|
||||
|
||||
{ path: 'logs', name: 'logs', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '日志报表', icon: 'Document', menu: true, group: '系统管理', roles: ['admin', 'ops', 'service'] } },
|
||||
{ path: 'system', name: 'system', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '系统配置', icon: 'Setting', menu: true, group: '系统管理', roles: ['admin'] } },
|
||||
{ path: 'system', name: 'system', component: () => import('@/views/system/index.vue'), meta: { title: '系统配置', icon: 'Setting', menu: true, group: '系统管理', roles: ['admin'], subtitle: '系统级参数 KV · 默认接入码 · 拉黑词表' } },
|
||||
// Issue#4 发布日志:面向全体用户的平台更新公告(全角色,同 faq 口径);
|
||||
// 版本数据单一事实源=src/data/releases.ts(发版 SOP 见文件头注)。
|
||||
{ path: 'system/release', name: 'system-release', component: () => import('@/views/system/ReleaseLog.vue'), meta: { title: '发布日志', icon: 'Memo', menu: true, group: '系统管理', roles: ['admin', 'ops', 'service', 'group', 'customer'], subtitle: '平台功能迭代明细 · 大白话版' } },
|
||||
{ path: 'faq', name: 'faq', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '常见问题', icon: 'QuestionFilled', menu: true, group: '系统管理', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
|
||||
|
||||
// 隐藏页(不在菜单)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// stores/release.ts — Issue#4 版本已读状态(侧栏红点判定)。
|
||||
//
|
||||
// 口径:localStorage 记"上次已看过的版本"(gosms_seen_ver),≠ 当前版本
|
||||
// APP_VERSION 即视为"有更新"(红点亮);首次访问无记录=有更新,引导用户
|
||||
// 看一次发布日志。红点为浏览器本地"未读"语义——换浏览器/清缓存会重新
|
||||
// 提示一次(验收单如实标注),平台侧不做服务端已读同步。
|
||||
import { defineStore } from 'pinia'
|
||||
import { APP_VERSION } from '@/data/releases'
|
||||
|
||||
const SEEN_KEY = 'gosms_seen_ver'
|
||||
|
||||
function loadSeen(): string {
|
||||
return localStorage.getItem(SEEN_KEY) ?? ''
|
||||
}
|
||||
|
||||
export const useReleaseStore = defineStore('release', {
|
||||
state: (): { seenVer: string } => ({ seenVer: loadSeen() }),
|
||||
getters: {
|
||||
/** 有未读新版本(侧栏版本号旁红点闪烁的判定源)。 */
|
||||
hasUpdate: (s): boolean => s.seenVer !== APP_VERSION,
|
||||
},
|
||||
actions: {
|
||||
/** 标记当前版本已读(点击版本号 / 进入发布日志页时调用)。 */
|
||||
markSeen() {
|
||||
this.seenVer = APP_VERSION
|
||||
localStorage.setItem(SEEN_KEY, APP_VERSION)
|
||||
},
|
||||
},
|
||||
})
|
||||
+108
-58
@@ -1,31 +1,37 @@
|
||||
/* ============================================================
|
||||
* ep-theme.scss — W1:EP 官方 CSS 变量全量换肤(零元素补丁路线)
|
||||
* ep-theme.scss — Issue#6 P3 重写(sub2api 契约 v3.2.1)
|
||||
* 原则:只写 --el-* 变量声明,不碰 .el-* 元素选择器
|
||||
* (结构桥除外,见文末,每条注明"变量做不到"的理由)。
|
||||
* 优先级:本文件在 main.ts 中晚于 EP index.css + dark/css-vars.css
|
||||
* 引入;html.dark(0,1,1) > :root(0,1,0),映射稳定生效。
|
||||
* 色值一律引 tokens(--gosms-*),本文件零硬编码。
|
||||
* 契约口径:primary=teal(sub2api 官方);success=emerald(与主色分离,
|
||||
* 契约 KPI 值即 emerald-600);hover 底=gray-50/100(非主色化)。
|
||||
* ============================================================ */
|
||||
|
||||
/* ---- 暗色 = 默认(:root;tokens :root 即暗) ---- */
|
||||
:root {
|
||||
/* 主色族:demo teal;light-N 用半透明 teal 叠加(EP hover/disabled 语境) */
|
||||
--el-color-primary: var(--gosms-primary);
|
||||
/* ---- 暗色 = 默认(:root;tokens :root 即暗) ----
|
||||
* F1:html.dark 双写——EP 官方 dark/css-vars.css 的 html.dark(0,1,1)会覆盖
|
||||
* :root(0,1,0)的同名颜色变量,导致暗色下 EP 组件(trigger/弹层/输入底)回退
|
||||
* 原生 #141414 系与 slate token 割裂;本文件晚于其引入,同特异性按层叠序获胜。 */
|
||||
:root,
|
||||
html.dark {
|
||||
/* 主色族:teal 500;light-N 半透明阶(暗底 hover/disabled 语境) */
|
||||
--el-color-primary: var(--gosms-primary-500);
|
||||
--el-color-primary-light-3: rgba(45, 212, 191, 0.55);
|
||||
--el-color-primary-light-5: rgba(45, 212, 191, 0.35);
|
||||
--el-color-primary-light-7: rgba(45, 212, 191, 0.2);
|
||||
--el-color-primary-light-8: rgba(45, 212, 191, 0.14);
|
||||
--el-color-primary-light-9: rgba(45, 212, 191, 0.09);
|
||||
--el-color-primary-dark-2: var(--gosms-primary-strong);
|
||||
--el-color-primary-dark-2: var(--gosms-primary-600);
|
||||
|
||||
/* 状态族:demo 语义——成功=teal(badge.ok)/警告=amber/危险=red/信息=灰 */
|
||||
--el-color-success: var(--gosms-primary);
|
||||
--el-color-success-light-3: rgba(45, 212, 191, 0.55);
|
||||
--el-color-success-light-5: rgba(45, 212, 191, 0.35);
|
||||
--el-color-success-light-7: rgba(45, 212, 191, 0.2);
|
||||
--el-color-success-light-8: rgba(45, 212, 191, 0.14);
|
||||
--el-color-success-light-9: rgba(45, 212, 191, 0.09);
|
||||
--el-color-success-dark-2: var(--gosms-primary-strong);
|
||||
/* 状态族:成功=emerald(500/暗底亮化 400 档)/警告=amber/危险=red */
|
||||
--el-color-success: #10b981;
|
||||
--el-color-success-light-3: rgba(52, 211, 153, 0.55);
|
||||
--el-color-success-light-5: rgba(52, 211, 153, 0.35);
|
||||
--el-color-success-light-7: rgba(52, 211, 153, 0.2);
|
||||
--el-color-success-light-8: rgba(52, 211, 153, 0.14);
|
||||
--el-color-success-light-9: rgba(52, 211, 153, 0.09);
|
||||
--el-color-success-dark-2: #059669;
|
||||
--el-color-warning: var(--gosms-amber);
|
||||
--el-color-warning-light-9: rgba(251, 191, 36, 0.08);
|
||||
--el-color-warning-light-8: rgba(251, 191, 36, 0.12);
|
||||
@@ -45,45 +51,58 @@
|
||||
--el-color-info: var(--gosms-text-secondary);
|
||||
--el-color-info-light-9: var(--gosms-input-veil);
|
||||
|
||||
/* 文本族:demo --text/--text-dim/--text-bright */
|
||||
/* 文本族:slate 体系 */
|
||||
--el-text-color-primary: var(--gosms-text-bright);
|
||||
--el-text-color-regular: var(--gosms-text);
|
||||
--el-text-color-secondary: var(--gosms-text-secondary);
|
||||
--el-text-color-placeholder: var(--gosms-text-muted);
|
||||
--el-text-color-disabled: rgba(148, 163, 184, 0.35);
|
||||
|
||||
/* 边框族:demo --border 通透感 */
|
||||
/* 边框族:slate-700 基阶 */
|
||||
--el-border-color: var(--gosms-border);
|
||||
--el-border-color-light: rgba(148, 163, 184, 0.1);
|
||||
--el-border-color-lighter: rgba(148, 163, 184, 0.08);
|
||||
--el-border-color-extra-light: rgba(148, 163, 184, 0.06);
|
||||
--el-border-color-light: rgba(51, 65, 85, 0.8);
|
||||
--el-border-color-lighter: rgba(51, 65, 85, 0.6);
|
||||
--el-border-color-extra-light: rgba(51, 65, 85, 0.4);
|
||||
--el-border-color-dark: var(--gosms-border-strong);
|
||||
--el-border-color-darker: rgba(148, 163, 184, 0.4);
|
||||
--el-border-color-darker: rgba(71, 85, 105, 0.8);
|
||||
|
||||
/* 填充族:hover 底全部 teal-soft 化(demo quick-item/badge 审美) */
|
||||
--el-fill-color: var(--gosms-primary-soft);
|
||||
--el-fill-color-light: rgba(45, 212, 191, 0.07);
|
||||
/* 填充族:hover 底=中性 slate(sub2api hover=gray-100,非主色化) */
|
||||
--el-fill-color: rgba(148, 163, 184, 0.12);
|
||||
--el-fill-color-light: rgba(148, 163, 184, 0.08);
|
||||
--el-fill-color-lighter: var(--gosms-input-veil);
|
||||
--el-fill-color-extra-light: rgba(148, 163, 184, 0.05);
|
||||
--el-fill-color-dark: rgba(148, 163, 184, 0.16);
|
||||
--el-fill-color-darker: rgba(148, 163, 184, 0.24);
|
||||
--el-fill-color-blank: var(--gosms-input-veil); /* 输入框底=demo lf-input veil */
|
||||
--el-fill-color-blank: var(--gosms-input-veil);
|
||||
|
||||
/* 背景族:overlay(弹窗/下拉)需不透明实底 */
|
||||
/* 背景族:overlay(弹窗/下拉)=卡实底 */
|
||||
--el-bg-color: var(--gosms-card);
|
||||
--el-bg-color-page: var(--gosms-bg-page);
|
||||
--el-bg-color-overlay: var(--gosms-card);
|
||||
|
||||
/* 圆角族:demo lf-input/lf-btn=11 */
|
||||
/* 圆角族:契约 input/pagination=12 */
|
||||
--el-border-radius-small: 8px;
|
||||
--el-border-radius-base: 11px;
|
||||
--el-border-radius-base: 12px;
|
||||
--el-border-radius-round: 999px;
|
||||
|
||||
/* 字体/字号族:demo 紧凑控制台 */
|
||||
/* 字体/字号族:契约 14 基准/13 表格/12 辅助 */
|
||||
--el-font-family: var(--gosms-font);
|
||||
--el-font-size-extra-small: 12px;
|
||||
--el-font-size-small: var(--gosms-fs-base); /* 12.5 表格正文 */
|
||||
--el-font-size-base: var(--gosms-fs-body); /* 13.5 全局基准 */
|
||||
--el-font-size-small: 13px;
|
||||
--el-font-size-base: 14px;
|
||||
--el-font-size-medium: 14px;
|
||||
--el-font-size-large: 16px;
|
||||
|
||||
/* el-select 专属族(F1:EP 私有变量不跟 primary/border 主族,须显式挂接) */
|
||||
--el-select-border-color-hover: var(--gosms-primary-500);
|
||||
--el-select-input-focus-border-color: var(--gosms-primary-500);
|
||||
--el-select-input-color: var(--gosms-text);
|
||||
--el-select-multiple-input-color: var(--gosms-text);
|
||||
--el-select-close-hover-color: var(--gosms-primary-400);
|
||||
--el-select-disabled-color: rgba(148, 163, 184, 0.35);
|
||||
--el-select-disabled-border: var(--gosms-border);
|
||||
--el-select-font-size: 14px;
|
||||
--el-select-input-font-size: 14px;
|
||||
|
||||
/* 阴影/禁用 */
|
||||
--el-box-shadow: var(--gosms-shadow-card-hover);
|
||||
@@ -94,32 +113,33 @@
|
||||
--el-disabled-border-color: var(--gosms-border);
|
||||
}
|
||||
|
||||
/* ---- 亮色(html:not(.dark)):light-N 改混白系(EP 亮色语境) ---- */
|
||||
/* ---- 亮色(html:not(.dark)):混白阶(EP 亮色语境) ---- */
|
||||
html:not(.dark) {
|
||||
--el-color-primary: var(--gosms-primary); /* tokens 亮色=600 */
|
||||
--el-color-primary-light-3: #4dc3b5;
|
||||
--el-color-primary-light-5: #8ad8cd;
|
||||
--el-color-primary-light-7: #bce8e1;
|
||||
--el-color-primary-light-8: #d1f0eb;
|
||||
--el-color-primary-light-9: #e6f7f4;
|
||||
--el-color-primary-dark-2: var(--gosms-primary-strong);
|
||||
--el-color-success: var(--gosms-primary);
|
||||
--el-color-success-light-3: #4dc3b5;
|
||||
--el-color-success-light-5: #8ad8cd;
|
||||
--el-color-success-light-7: #bce8e1;
|
||||
--el-color-success-light-8: #d1f0eb;
|
||||
--el-color-success-light-9: #e6f7f4;
|
||||
--el-color-success-dark-2: var(--gosms-primary-strong);
|
||||
--el-color-primary: var(--gosms-primary-600); /* 亮底对比度取 600 */
|
||||
--el-color-primary-light-3: #5eb8ad;
|
||||
--el-color-primary-light-5: #96d3cb;
|
||||
--el-color-primary-light-7: #c3e8e3;
|
||||
--el-color-primary-light-8: #d7f1ee;
|
||||
--el-color-primary-light-9: #ebf8f6;
|
||||
--el-color-primary-dark-2: var(--gosms-primary-700);
|
||||
--el-color-success: #059669; /* 契约 KPI=emerald-600 */
|
||||
--el-color-success-light-3: #6ee7b7;
|
||||
--el-color-success-light-5: #a7f3d0;
|
||||
--el-color-success-light-7: #d1fae5;
|
||||
--el-color-success-light-8: #e6fbf1;
|
||||
--el-color-success-light-9: #ecfdf5;
|
||||
--el-color-success-dark-2: #047857;
|
||||
--el-color-warning-light-9: rgba(217, 119, 6, 0.08);
|
||||
--el-color-danger-light-9: rgba(220, 38, 38, 0.06);
|
||||
--el-color-error-light-9: rgba(220, 38, 38, 0.06);
|
||||
--el-fill-color: var(--gosms-primary-soft);
|
||||
--el-fill-color-light: rgba(13, 148, 136, 0.06);
|
||||
--el-fill-color: rgba(17, 24, 39, 0.08);
|
||||
--el-fill-color-light: rgba(17, 24, 39, 0.04);
|
||||
--el-fill-color-lighter: var(--gosms-input-veil);
|
||||
--el-fill-color-extra-light: rgba(36, 48, 59, 0.03);
|
||||
--el-fill-color-dark: rgba(36, 48, 59, 0.1);
|
||||
--el-fill-color-darker: rgba(36, 48, 59, 0.16);
|
||||
--el-text-color-disabled: rgba(130, 150, 166, 0.5);
|
||||
--el-fill-color-extra-light: rgba(17, 24, 39, 0.03);
|
||||
--el-fill-color-dark: rgba(17, 24, 39, 0.1);
|
||||
--el-fill-color-darker: rgba(17, 24, 39, 0.16);
|
||||
--el-fill-color-blank: #ffffff;
|
||||
--el-text-color-disabled: rgba(156, 163, 175, 0.5);
|
||||
--el-box-shadow: var(--gosms-shadow-card-hover);
|
||||
--el-box-shadow-light: var(--gosms-shadow-card);
|
||||
--el-box-shadow-lighter: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
@@ -127,19 +147,49 @@ html:not(.dark) {
|
||||
|
||||
/* ============================================================
|
||||
* 结构桥(每条注明"EP 变量做不到"的理由)
|
||||
* 1) el-table 无线化:EP 无"去竖线/透明底"变量族,须元素级
|
||||
* 2) el-card 玻璃面:demo .card 是半透明 veil,EP 无对应变量
|
||||
* 3) el-button primary 渐变底:demo .btn-primary 是 background-image,变量只支持纯色
|
||||
* 1) el-table 无线化:EP 无"去竖线/透明底"变量族,须元素级;
|
||||
* 表格密度(契约 td py16/px20/th 12/500)EP 无 padding 变量族
|
||||
* 2) el-card 实底+契约边:EP 无 gray-100 卡边变量
|
||||
* 3) el-input 高度 42:EP 组件尺寸无 CSS 变量(size=prop),以选择器统一
|
||||
* ============================================================ */
|
||||
.el-table {
|
||||
--el-table-border-color: transparent;
|
||||
--el-table-header-bg-color: transparent;
|
||||
--el-table-tr-bg-color: transparent;
|
||||
--el-table-row-hover-bg-color: var(--gosms-primary-soft);
|
||||
--el-table-row-hover-bg-color: var(--gosms-input-veil);
|
||||
background: transparent;
|
||||
}
|
||||
.el-table th.el-table__cell,
|
||||
.el-table td.el-table__cell { border-bottom: 1px solid var(--gosms-border); background-color: transparent; }
|
||||
.el-table th.el-table__cell { font-size: var(--gosms-fs-xs); color: var(--gosms-text-muted); letter-spacing: 0.1em; }
|
||||
.el-button--primary { background-image: var(--gosms-gradient); border: none; box-shadow: 0 4px 20px var(--gosms-glow); }
|
||||
.el-card { background: var(--gosms-card-veil); border: 1px solid var(--gosms-border); border-radius: var(--gosms-radius); }
|
||||
.el-table th.el-table__cell { font-size: 12px; font-weight: 500; color: var(--gosms-text-secondary); letter-spacing: 0.02em; }
|
||||
.el-table .cell { line-height: 20px; }
|
||||
.el-card { background: var(--gosms-card); border: 1px solid var(--gosms-border); border-radius: 16px; box-shadow: var(--gosms-shadow-card); }
|
||||
/* 契约 input h42(42=20px 行高+上下 padding;EP default 32)——统一 default 尺寸抬升 */
|
||||
.el-input .el-input__wrapper { padding: 4px 12px; }
|
||||
.el-input.el-input--default .el-input__inner { height: 34px; line-height: 34px; }
|
||||
|
||||
/* ============================================================
|
||||
* F2 下拉契约桥(Issue#6:对齐/色调/密度三统一,对齐 sub2api Select)
|
||||
* 4) 选项密度:EP 无 padding 变量族(0 32 20),契约=px-4 py-2.5(16/10)
|
||||
* 5) 选中底色式:EP is-selected 仅 primary+700 无底;契约=primary-50 底
|
||||
* +primary-700 字+右勾(勾为 EP 原生 :after,保留)
|
||||
* 6) 两族对齐:el-dropdown-menu__item 显式 flex-start(EP flex 无 justify,
|
||||
* 保险声明);hover 统一中性 fill(变量已映射,此处兜底 select 选项 hover)
|
||||
* ============================================================ */
|
||||
.el-select-dropdown__item { padding: 10px 16px; }
|
||||
.el-select-dropdown__item.is-selected {
|
||||
color: var(--gosms-primary-600);
|
||||
font-weight: 500;
|
||||
background-color: var(--gosms-primary-soft);
|
||||
}
|
||||
html:not(.dark) .el-select-dropdown__item.is-selected {
|
||||
color: var(--gosms-primary-600);
|
||||
background-color: var(--gosms-primary-50);
|
||||
}
|
||||
.el-select-dropdown__item.is-hovering { background-color: var(--gosms-input-veil); }
|
||||
.el-select-dropdown__list { padding: 4px 0; }
|
||||
.el-dropdown-menu__item { justify-content: flex-start; text-align: left; }
|
||||
.el-select__wrapper.is-hovering:not(.is-focused) { box-shadow: 0 0 0 1px var(--gosms-border-strong) inset; }
|
||||
.el-select__wrapper.is-focused { box-shadow: 0 0 0 1px var(--gosms-primary-500) inset; }
|
||||
/* 7) 弹层圆角:EP popper 缺省 4px(私有 --el-popper 不在 base 族),契约=r12 */
|
||||
.el-select__popper, .el-dropdown__popper, .el-popper.is-light { border-radius: 12px; }
|
||||
|
||||
+169
-176
@@ -1,259 +1,252 @@
|
||||
/* ============================================================
|
||||
* shell.scss — W1:布局壳(demo-c-aurora 原文直译,变量改引 tokens 单一来源)
|
||||
* 职责:极光背景/topbar/sidebar(H1 折叠+H2 滚动条)/page-head/main/
|
||||
* card/metrics/badge/delta/quick-item/lf-* 登录件/语义徽章/基础重置。
|
||||
* 变量:一律 var(--gosms-*)(tokens.scss);EP 控件走 ep-theme.scss 变量映射。
|
||||
* shell.scss — Issue#6 P3 重写(sub2api 契约 v3.2.1)
|
||||
* 职责:topbar(64 glass)/sidebar(256·折叠72,品牌头部)/page-head(24)/
|
||||
* main(32)/card(r16 实底 shadow-card)/metrics/badge/delta/quick-item/
|
||||
* ch-table(td 14·py16/px20)/版本 chip/基础重置/语义徽章/移动端抽屉。
|
||||
* 真值:sub2api style.css(.sidebar/.sidebar-link/.card/.glass)+alignment-report
|
||||
* 源码规格表;aurora 极光退役;类名锚点(.sidebar/.nav-item/...)全保留
|
||||
* 供 verify-layout 与 views 消费。变量一律 var(--gosms-*)。
|
||||
* ============================================================ */
|
||||
|
||||
body { font-family: var(--gosms-font); font-size: var(--gosms-fs-body); color: var(--gosms-text); background: var(--gosms-bg-page); }
|
||||
body {
|
||||
font-family: var(--gosms-font); font-size: var(--gosms-fs-body); line-height: var(--gosms-lh-body);
|
||||
color: var(--gosms-text); background: var(--gosms-bg-page);
|
||||
-webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
|
||||
}
|
||||
.num { font-variant-numeric: tabular-nums; }
|
||||
.num-glow { /* 退役兼容(sub2api 无数字 glow) */ }
|
||||
|
||||
/* ---- 极光背景:三层径向光斑(demo 原文) ---- */
|
||||
.aurora { position: fixed; inset: -20%; z-index: 0; pointer-events: none; filter: blur(90px); opacity: 0.55; }
|
||||
html:not(.dark) .aurora { opacity: 0.3; }
|
||||
.aurora::before, .aurora::after { content: ''; position: absolute; border-radius: 50%; }
|
||||
.aurora::before { width: 46vw; height: 46vw; left: -6vw; top: -10vh; background: radial-gradient(circle, rgba(45,212,191,0.5), transparent 65%); animation: drift1 20s ease-in-out infinite alternate; }
|
||||
.aurora::after { width: 40vw; height: 40vw; right: -8vw; top: 30vh; background: radial-gradient(circle, rgba(14,165,233,0.4), transparent 65%); animation: drift2 26s ease-in-out infinite alternate; }
|
||||
@keyframes drift1 { to { transform: translate(14vw, 10vh) scale(1.15); } }
|
||||
@keyframes drift2 { to { transform: translate(-10vw, -8vh) scale(0.9); } }
|
||||
@media (prefers-reduced-motion: reduce) { .aurora::before, .aurora::after { animation: none; } }
|
||||
.num { font-family: var(--gosms-font-num); font-variant-numeric: tabular-nums; }
|
||||
.num-glow { text-shadow: 0 0 22px var(--gosms-primary-soft); }
|
||||
|
||||
/* ---- 入场动画(W2:原 theme 层佚失类补回;登录卡/错误卡消费) ---- */
|
||||
@keyframes slide-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
|
||||
.animate-slide-up { animation: slide-up 0.45s ease-out both; }
|
||||
/* ---- 入场动画(sub2api fadeIn/slideUp 同族) ---- */
|
||||
@keyframes slide-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
|
||||
.animate-slide-up { animation: slide-up 0.3s ease-out both; }
|
||||
@media (prefers-reduced-motion: reduce) { .animate-slide-up { animation: none; } }
|
||||
|
||||
/* ---- 顶栏(demo 原文) ---- */
|
||||
/* ---- 顶栏(sub2api AppHeader:glass sticky h-64,左页标题右动作) ---- */
|
||||
.topbar {
|
||||
position: sticky; top: 0; z-index: 50; height: 54px; padding: 0 20px;
|
||||
position: sticky; top: 0; z-index: 50; height: 64px; padding: 0 24px;
|
||||
display: flex; align-items: center; gap: 16px;
|
||||
background: rgba(11, 16, 22, 0.72); backdrop-filter: blur(14px);
|
||||
border-bottom: 1px solid var(--gosms-border);
|
||||
background: var(--gosms-glass-header); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
|
||||
border-bottom: 1px solid var(--gosms-border-strong);
|
||||
}
|
||||
html:not(.dark) .topbar { background: rgba(255, 255, 255, 0.72); }
|
||||
.brand { display: flex; align-items: center; gap: 10px; }
|
||||
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--gosms-gradient); display: grid; place-items: center; font-size: 15px; box-shadow: 0 0 18px var(--gosms-glow); }
|
||||
.brand-name { font-weight: 700; font-size: 15px; color: var(--gosms-text-bright); letter-spacing: 0.02em; }
|
||||
.brand-sub { font-size: 10px; color: var(--gosms-text-muted); letter-spacing: 0.14em; }
|
||||
.top-title { font-size: var(--gosms-fs-lg); font-weight: 600; color: var(--gosms-text-bright); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
|
||||
.avatar-chip { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 5px; border-radius: 999px; border: 1px solid var(--gosms-border); cursor: pointer; transition: all 0.2s; }
|
||||
.avatar-chip:hover { border-color: var(--gosms-border-glow); box-shadow: 0 0 14px var(--gosms-primary-soft); }
|
||||
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--gosms-gradient); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
|
||||
.avatar-name { font-size: 12px; color: var(--gosms-text-bright); }
|
||||
.theme-btn { font-size: 12px; color: var(--gosms-text-muted); background: none; border: 1px solid var(--gosms-border); border-radius: 8px; padding: 5px 12px; cursor: pointer; transition: all 0.2s; }
|
||||
.theme-btn:hover { color: var(--gosms-primary); border-color: var(--gosms-primary); box-shadow: 0 0 12px var(--gosms-primary-soft); }
|
||||
/* 移动端汉堡(项目补充,demo 无;纯原生,不引入 EP) */
|
||||
.menu-btn { display: none; width: 34px; height: 34px; place-items: center; border: 1px solid var(--gosms-border); border-radius: 8px; background: none; color: var(--gosms-text-muted); cursor: pointer; font-size: 15px; }
|
||||
.avatar-chip {
|
||||
display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 5px; border-radius: var(--gosms-radius-base);
|
||||
border: 1px solid var(--gosms-border); cursor: pointer; transition: all 0.2s; background: none;
|
||||
}
|
||||
.avatar-chip:hover { background: var(--gosms-input-veil); border-color: var(--gosms-border-strong); }
|
||||
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--gosms-gradient); color: #fff; font-size: var(--gosms-fs-xs); font-weight: 700; display: grid; place-items: center; }
|
||||
.avatar-name { font-size: var(--gosms-fs-base); color: var(--gosms-text-bright); }
|
||||
.theme-btn {
|
||||
font-size: var(--gosms-fs-xs); color: var(--gosms-text-secondary); background: none;
|
||||
border: 1px solid var(--gosms-border); border-radius: var(--gosms-radius-base); padding: 6px 12px;
|
||||
cursor: pointer; transition: all 0.2s; white-space: nowrap;
|
||||
}
|
||||
.theme-btn:hover { color: var(--gosms-primary); border-color: var(--gosms-primary); background: var(--gosms-primary-soft); }
|
||||
/* 移动端汉堡(项目补充;纯原生,不引入 EP) */
|
||||
.menu-btn { display: none; width: 36px; height: 36px; place-items: center; border: 1px solid var(--gosms-border); border-radius: var(--gosms-radius-base); background: none; color: var(--gosms-text-secondary); cursor: pointer; font-size: 16px; }
|
||||
.menu-btn:hover { color: var(--gosms-primary); border-color: var(--gosms-primary); }
|
||||
|
||||
/* ---- 布局(demo 原文) ---- */
|
||||
/* ---- 布局 ---- */
|
||||
.shell { position: relative; z-index: 1; display: flex; min-height: 100vh; }
|
||||
.sidebar {
|
||||
width: 224px; flex-shrink: 0; position: sticky; top: 54px; height: calc(100vh - 54px);
|
||||
padding: 16px 12px; overflow: hidden;
|
||||
display: flex; flex-direction: column;
|
||||
background: rgba(255, 255, 255, 0.03); backdrop-filter: blur(14px); border-right: 1px solid var(--gosms-border);
|
||||
width: 256px; flex-shrink: 0; position: sticky; top: 64px; height: calc(100vh - 64px);
|
||||
overflow: hidden; display: flex; flex-direction: column;
|
||||
background: var(--gosms-bg-2); border-right: 1px solid var(--gosms-border);
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
/* W6:菜单滚动区(flex:1 承接)+底脚收起按钮固定最下方 */
|
||||
.nav-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; }
|
||||
/* 品牌头部(sub2api sidebar-header:h-64 px-24,logo 36 r12 glow+品牌 18/700+版本徽章) */
|
||||
.sidebar-header {
|
||||
flex-shrink: 0; height: 64px; padding: 0 24px; display: flex; align-items: center; gap: 12px;
|
||||
border-bottom: 1px solid var(--gosms-border); text-decoration: none;
|
||||
}
|
||||
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
|
||||
.brand-mark {
|
||||
flex-shrink: 0; width: 36px; height: 36px; border-radius: var(--gosms-radius-base);
|
||||
background: var(--gosms-gradient); display: grid; place-items: center;
|
||||
color: #fff; font-size: 17px; box-shadow: var(--gosms-shadow-glow); transition: opacity 0.2s;
|
||||
}
|
||||
.brand:hover .brand-mark { opacity: 0.85; }
|
||||
.brand-name { font-weight: 700; font-size: var(--gosms-fs-xl); color: var(--gosms-text-bright); letter-spacing: 0.01em; white-space: nowrap; }
|
||||
/* 版本徽章(sub2api VersionBadge:12px bg-gray-100 无边框;go-sms 置品牌下方=用户指令位) */
|
||||
.ver-badge {
|
||||
display: inline-flex; align-items: center; gap: 6px; margin-top: 2px;
|
||||
padding: 2px 8px; border-radius: var(--gosms-radius-sm);
|
||||
background: var(--gosms-input-veil); color: var(--gosms-text-secondary);
|
||||
font-size: var(--gosms-fs-xs); font-family: var(--gosms-font-num); white-space: nowrap;
|
||||
}
|
||||
/* 菜单滚动区(sub2api sidebar-nav:px-12 py-16) */
|
||||
.nav-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; padding: 16px 12px; }
|
||||
.nav-scroll::-webkit-scrollbar { display: none; }
|
||||
.sidebar-foot { flex-shrink: 0; display: flex; padding: 10px 0 0; margin-top: 8px; border-top: 1px solid var(--gosms-border); }
|
||||
.sidebar.collapsed .sidebar-foot { justify-content: center; }
|
||||
html:not(.dark) .sidebar { background: rgba(255, 255, 255, 0.55); }
|
||||
.nav-group { font-size: 10px; color: var(--gosms-text-muted); letter-spacing: 0.16em; padding: 16px 12px 6px; }
|
||||
.sidebar-foot { flex-shrink: 0; display: flex; align-items: center; justify-content: center; padding: 12px 0; border-top: 1px solid var(--gosms-border); }
|
||||
/* 分组标题(源码 12/600 uppercase;go-sms 覆盖 14px 对齐菜单=用户显式项) */
|
||||
.nav-group {
|
||||
font-size: var(--gosms-fs-base); font-weight: 600; color: var(--gosms-text-muted);
|
||||
letter-spacing: 0.05em; padding: 16px 12px 8px; white-space: nowrap;
|
||||
}
|
||||
/* 菜单项(sub2api sidebar-link:14/500 r12 py-10 pl-17 pr-14 gap-12;激活=primary-50 底+primary 字,无指示条) */
|
||||
.nav-item {
|
||||
display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px;
|
||||
color: var(--gosms-text); cursor: pointer; position: relative; transition: all 0.2s; margin-bottom: 2px;
|
||||
text-decoration: none;
|
||||
display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 17px;
|
||||
border-radius: var(--gosms-radius-base); margin-bottom: 4px;
|
||||
color: var(--gosms-text-secondary); font-size: var(--gosms-fs-base); font-weight: 500;
|
||||
cursor: pointer; text-decoration: none; white-space: nowrap; overflow: hidden;
|
||||
transition: background-color 0.2s, color 0.2s;
|
||||
}
|
||||
.nav-item .ic { width: 17px; text-align: center; font-size: 14px; opacity: 0.8; }
|
||||
.nav-item:hover { background: var(--gosms-card-hover); color: var(--gosms-text-bright); }
|
||||
.nav-item .ic { flex-shrink: 0; width: 20px; height: 20px; display: grid; place-items: center; }
|
||||
.nav-item:hover { background: var(--gosms-input-veil); color: var(--gosms-text-bright); }
|
||||
.nav-item.active { background: var(--gosms-primary-soft); color: var(--gosms-primary); font-weight: 600; }
|
||||
.nav-item.active::before {
|
||||
content: ''; position: absolute; left: -12px; top: 20%; bottom: 20%; width: 3px;
|
||||
border-radius: 3px; background: var(--gosms-gradient); box-shadow: 0 0 10px var(--gosms-glow);
|
||||
}
|
||||
.main { flex: 1; padding: 22px 26px; min-width: 0; }
|
||||
.page-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 16px; }
|
||||
.page-head h2 { font-size: 17px; font-weight: 700; color: var(--gosms-text-bright); margin: 0; }
|
||||
.page-head .sub { font-size: 11px; color: var(--gosms-text-muted); letter-spacing: 0.08em; }
|
||||
html:not(.dark) .nav-item.active { background: var(--gosms-primary-50); color: var(--gosms-primary-600); }
|
||||
/* 折叠态(w-72:图标居中/文字隐/分组隐;品牌缩 logo) */
|
||||
.sidebar.collapsed { width: 72px; }
|
||||
.sidebar.collapsed .sidebar-header { padding: 0; justify-content: center; }
|
||||
.sidebar.collapsed .brand-name, .sidebar.collapsed .ver-badge, .sidebar.collapsed .nav-item .txt,
|
||||
.sidebar.collapsed .nav-group { display: none; }
|
||||
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px 0; }
|
||||
.main { flex: 1; padding: 32px; min-width: 0; }
|
||||
|
||||
/* ---- 页头(sub2api page-header:mb-24;title 24/700) ---- */
|
||||
.page-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
|
||||
.page-head h2 { font-size: var(--gosms-fs-stat); font-weight: 700; color: var(--gosms-text-bright); margin: 0; }
|
||||
.page-head .sub { font-size: var(--gosms-fs-base); color: var(--gosms-text-secondary); }
|
||||
.page-head-extra { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
|
||||
.live-chip { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--gosms-primary); background: var(--gosms-primary-soft); padding: 4px 12px; border-radius: 999px; }
|
||||
.live-chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--gosms-primary); box-shadow: 0 0 8px var(--gosms-glow); animation: pulse 2s infinite; }
|
||||
.live-chip { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: var(--gosms-fs-xs); color: var(--gosms-primary); background: var(--gosms-primary-soft); padding: 4px 12px; border-radius: 999px; }
|
||||
.live-chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--gosms-primary); animation: pulse 2s infinite; }
|
||||
@keyframes pulse { 50% { opacity: 0.4; } }
|
||||
|
||||
/* ---- stagger 入场(demo 原文) ---- */
|
||||
.stagger > * { opacity: 0; animation: rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards; }
|
||||
.stagger > *:nth-child(1) { animation-delay: 0.05s; } .stagger > *:nth-child(2) { animation-delay: 0.13s; }
|
||||
.stagger > *:nth-child(3) { animation-delay: 0.21s; } .stagger > *:nth-child(4) { animation-delay: 0.29s; }
|
||||
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
|
||||
/* ---- stagger 入场 ---- */
|
||||
.stagger > * { opacity: 0; animation: rise 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards; }
|
||||
.stagger > *:nth-child(1) { animation-delay: 0.05s; } .stagger > *:nth-child(2) { animation-delay: 0.11s; }
|
||||
.stagger > *:nth-child(3) { animation-delay: 0.17s; } .stagger > *:nth-child(4) { animation-delay: 0.23s; }
|
||||
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
|
||||
@media (prefers-reduced-motion: reduce) { .stagger > * { animation: none; opacity: 1; } }
|
||||
|
||||
/* ---- 玻璃卡 + 渐变描边(demo 原文) ---- */
|
||||
/* ---- 卡片(sub2api .card:实底 r16 边 gray-100 shadow-card;p16=契约) ---- */
|
||||
.card {
|
||||
position: relative; border-radius: 16px; padding: 18px 20px;
|
||||
background: var(--gosms-card-veil); backdrop-filter: blur(12px);
|
||||
border: 1px solid var(--gosms-border); transition: all 0.25s;
|
||||
position: relative; border-radius: var(--gosms-radius); padding: 16px;
|
||||
background: var(--gosms-card); border: 1px solid var(--gosms-border);
|
||||
box-shadow: var(--gosms-shadow-card); transition: box-shadow 0.3s, border-color 0.3s;
|
||||
}
|
||||
.card::before {
|
||||
content: ''; position: absolute; inset: -1px; border-radius: 17px; padding: 1px;
|
||||
background: linear-gradient(135deg, rgba(45, 212, 191, 0.45), transparent 40%, transparent 60%, rgba(14, 165, 233, 0.3));
|
||||
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
|
||||
-webkit-mask-composite: xor; mask-composite: exclude;
|
||||
opacity: 0; transition: opacity 0.3s; pointer-events: none;
|
||||
}
|
||||
.card:hover { background: var(--gosms-card-hover); transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35); }
|
||||
.card:hover::before { opacity: 1; }
|
||||
html:not(.dark) .card:hover { box-shadow: 0 8px 28px rgba(13, 148, 136, 0.12); }
|
||||
.card:hover { box-shadow: var(--gosms-shadow-card-hover); }
|
||||
|
||||
/* ---- 指标卡(demo 原文) ---- */
|
||||
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
|
||||
.metric .label { font-size: 11px; color: var(--gosms-text-muted); display: flex; align-items: center; gap: 6px; }
|
||||
.metric .value { font-family: var(--gosms-font-num); font-size: 32px; font-weight: 600; color: var(--gosms-text-bright); margin: 10px 0 8px; line-height: 1; text-shadow: 0 0 22px var(--gosms-primary-soft); }
|
||||
.metric .value .unit { font-size: 14px; color: var(--gosms-text-muted); font-weight: 400; text-shadow: none; }
|
||||
.delta { font-size: 11.5px; display: inline-flex; gap: 5px; align-items: center; padding: 2px 9px; border-radius: 999px; }
|
||||
/* ---- 指标卡(KPI value 20/700 tabular;P4 Dashboard 组件化承载配色) ---- */
|
||||
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
|
||||
.metric .label { font-size: var(--gosms-fs-xs); color: var(--gosms-text-secondary); display: flex; align-items: center; gap: 6px; }
|
||||
.metric .value { font-size: var(--gosms-fs-hero); font-weight: 700; color: var(--gosms-text-bright); margin: 10px 0 8px; line-height: 1.2; font-variant-numeric: tabular-nums; }
|
||||
.metric .value .unit { font-size: var(--gosms-fs-base); color: var(--gosms-text-muted); font-weight: 400; }
|
||||
.delta { font-size: var(--gosms-fs-xs); display: inline-flex; gap: 5px; align-items: center; padding: 2px 9px; border-radius: 999px; }
|
||||
.delta.up { color: var(--gosms-primary); background: var(--gosms-primary-soft); }
|
||||
.delta.down { color: var(--gosms-red); background: rgba(248, 113, 113, 0.1); }
|
||||
.delta.warn { color: var(--gosms-amber); background: rgba(251, 191, 36, 0.1); }
|
||||
.delta.down { color: var(--gosms-red); background: rgba(239, 68, 68, 0.1); }
|
||||
.delta.warn { color: var(--gosms-amber); background: rgba(245, 158, 11, 0.1); }
|
||||
|
||||
/* ---- 图表 + 快捷(demo 原文) ---- */
|
||||
.duo { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-top: 14px; }
|
||||
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: var(--gosms-text-bright); }
|
||||
.card-head small { margin-left: auto; font-weight: 400; font-size: 10.5px; color: var(--gosms-text-muted); }
|
||||
/* ---- 图表 + 快捷 ---- */
|
||||
.duo { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-top: 16px; }
|
||||
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: var(--gosms-fs-base); font-weight: 600; color: var(--gosms-text-bright); }
|
||||
.card-head small { margin-left: auto; font-weight: 400; font-size: var(--gosms-fs-xs); color: var(--gosms-text-muted); }
|
||||
.trend-svg { width: 100%; height: auto; display: block; }
|
||||
.quick-item {
|
||||
display: flex; align-items: center; gap: 11px; padding: 10px; border-radius: 11px;
|
||||
cursor: pointer; transition: all 0.2s; border: 1px solid transparent;
|
||||
display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--gosms-radius-base);
|
||||
cursor: pointer; transition: background-color 0.2s; border: 1px solid transparent; text-decoration: none;
|
||||
}
|
||||
.quick-item:hover { background: var(--gosms-primary-soft); border-color: var(--gosms-border-glow); }
|
||||
.quick-item .qic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--gosms-primary-soft); font-size: 15px; }
|
||||
.quick-item .qt { font-size: 12.5px; color: var(--gosms-text-bright); }
|
||||
.quick-item .qd { font-size: 10.5px; color: var(--gosms-text-muted); margin-top: 2px; }
|
||||
.quick-item:hover { background: var(--gosms-input-veil); }
|
||||
.quick-item .qic { flex-shrink: 0; width: 48px; height: 48px; border-radius: var(--gosms-radius-base); display: grid; place-items: center; background: var(--gosms-primary-soft); color: var(--gosms-primary); font-size: var(--gosms-fs-xl); }
|
||||
.quick-item .qt { font-size: var(--gosms-fs-base); font-weight: 500; color: var(--gosms-text-bright); }
|
||||
.quick-item .qd { font-size: var(--gosms-fs-xs); color: var(--gosms-text-muted); margin-top: 2px; }
|
||||
.quick-item .arrow { margin-left: auto; color: var(--gosms-text-muted); transition: transform 0.2s; }
|
||||
.quick-item:hover .arrow { transform: translateX(3px); color: var(--gosms-primary); }
|
||||
|
||||
/* ---- 表格语义(demo 原文;页面内 el-table 由 EP-bridge 对齐) ---- */
|
||||
.ch-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
|
||||
.ch-table thead th { font-size: 10.5px; color: var(--gosms-text-muted); letter-spacing: 0.1em; text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--gosms-border); white-space: nowrap; font-weight: 600; }
|
||||
/* ---- 表格语义(契约 td:14/20 gray-700 py16/px20;th 12/500) ---- */
|
||||
.ch-table { width: 100%; border-collapse: collapse; font-size: var(--gosms-fs-base); }
|
||||
.ch-table thead th { font-size: var(--gosms-fs-xs); font-weight: 500; color: var(--gosms-text-secondary); letter-spacing: 0.02em; text-align: left; padding: 12px 20px; border-bottom: 1px solid var(--gosms-border); white-space: nowrap; }
|
||||
.ch-table thead th.r, .ch-table td.r { text-align: right; }
|
||||
.ch-table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--gosms-border); white-space: nowrap; }
|
||||
.ch-table tbody tr { transition: background 0.15s; }
|
||||
.ch-table tbody tr:hover { background: var(--gosms-primary-soft); }
|
||||
.ch-table tbody td { padding: 16px 20px; border-bottom: 1px solid var(--gosms-border); white-space: nowrap; color: var(--gosms-text); }
|
||||
.ch-table tbody tr { transition: background-color 0.15s; }
|
||||
.ch-table tbody tr:hover { background: var(--gosms-input-veil); }
|
||||
.mono { font-family: var(--gosms-font-num); color: var(--gosms-text-bright); }
|
||||
.badge { font-size: 10.5px; padding: 3px 10px; border-radius: 999px; border: 1px solid; font-weight: 500; display: inline-block; }
|
||||
.badge { font-size: var(--gosms-fs-xs); padding: 3px 10px; border-radius: 999px; border: 1px solid; font-weight: 500; display: inline-block; }
|
||||
.badge.ok { color: var(--gosms-primary); border-color: var(--gosms-border-glow); background: var(--gosms-primary-soft); }
|
||||
.badge.warn { color: var(--gosms-amber); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.08); }
|
||||
.badge.err { color: var(--gosms-red); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.08); }
|
||||
.badge.warn { color: var(--gosms-amber); border-color: rgba(245, 158, 11, 0.35); background: rgba(245, 158, 11, 0.08); }
|
||||
.badge.err { color: var(--gosms-red); border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.08); }
|
||||
.badge.violet { color: var(--gosms-violet); border-color: rgba(167, 139, 250, 0.35); background: rgba(167, 139, 250, 0.08); }
|
||||
.rate-bar { display: inline-flex; align-items: center; gap: 8px; }
|
||||
.rate-bar .rb { width: 54px; height: 4px; border-radius: 4px; background: var(--gosms-border); overflow: hidden; }
|
||||
.rate-bar .rb i { display: block; height: 100%; background: var(--gosms-gradient); border-radius: 4px; }
|
||||
|
||||
/* ---- 项目全局工具类(demo 语义补充;E 阶段 legacy 收编) ---- */
|
||||
.hint { font-size: 11px; color: var(--gosms-text-muted); }
|
||||
.page-stack { display: flex; flex-direction: column; gap: 14px; }
|
||||
.glass-card { position: relative; border-radius: 16px; padding: 18px 20px; background: var(--gosms-card-veil); backdrop-filter: blur(12px); border: 1px solid var(--gosms-border); }
|
||||
/* ---- 全局工具类 ---- */
|
||||
.hint { font-size: var(--gosms-fs-xs); color: var(--gosms-text-muted); line-height: 1.5; }
|
||||
.page-stack { display: flex; flex-direction: column; gap: 16px; }
|
||||
.glass-card { border-radius: var(--gosms-radius); padding: 16px; background: var(--gosms-card); border: 1px solid var(--gosms-border); box-shadow: var(--gosms-shadow-card); }
|
||||
.btn-gradient {
|
||||
background: var(--gosms-gradient); color: #fff; border: none; border-radius: 11px; padding: 11px 20px;
|
||||
font-size: 13.5px; font-weight: 700; cursor: pointer; letter-spacing: 0.04em;
|
||||
box-shadow: 0 4px 20px var(--gosms-glow); transition: all 0.2s;
|
||||
background: var(--gosms-gradient); color: #fff; border: none; border-radius: var(--gosms-radius-base); padding: 10px 20px;
|
||||
font-size: var(--gosms-fs-base); font-weight: 600; cursor: pointer;
|
||||
box-shadow: 0 2px 12px var(--gosms-glow); transition: all 0.2s;
|
||||
}
|
||||
.btn-gradient:hover { filter: brightness(1.1); box-shadow: 0 6px 28px var(--gosms-glow); transform: translateY(-1px); }
|
||||
.btn-gradient:hover { filter: brightness(1.08); box-shadow: 0 4px 20px var(--gosms-glow); }
|
||||
|
||||
/* ---- H1:侧栏收起/展开(64px 图标态;无 popup/无复制 logo,双菜单免疫) ---- */
|
||||
.collapse-btn { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--gosms-border); border-radius: 8px; background: none; color: var(--gosms-text-muted); cursor: pointer; font-size: 13px; transition: all 0.2s; }
|
||||
.collapse-btn:hover { color: var(--gosms-primary); border-color: var(--gosms-primary); }
|
||||
/* ---- 折叠钮 + 版本 chip(Issue#4 资产;折叠钮留 foot,版本徽章迁 brand 下) ---- */
|
||||
.collapse-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--gosms-border); border-radius: var(--gosms-radius-base); background: none; color: var(--gosms-text-secondary); cursor: pointer; font-size: 14px; transition: all 0.2s; }
|
||||
.collapse-btn:hover { color: var(--gosms-primary); border-color: var(--gosms-primary); background: var(--gosms-primary-soft); }
|
||||
.collapse-btn .cg { display: inline-block; transition: transform 0.25s; }
|
||||
.sidebar.collapsed { width: 64px; padding: 16px 8px; }
|
||||
.sidebar.collapsed .nav-item { justify-content: center; padding: 8px 0; }
|
||||
.sidebar.collapsed .nav-item .txt { display: none; }
|
||||
.sidebar.collapsed .nav-item.active::before { left: -8px; }
|
||||
.sidebar.collapsed .nav-group { color: transparent; padding: 12px 0 8px; position: relative; }
|
||||
.sidebar.collapsed .nav-group::after { content: ''; position: absolute; left: 24%; right: 24%; top: 50%; height: 1px; background: var(--gosms-border); }
|
||||
ver-chip { text-decoration: none; }
|
||||
.ver-badge { cursor: pointer; transition: color 0.2s; }
|
||||
.ver-badge:hover { color: var(--gosms-primary); }
|
||||
.ver-badge .ver-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: #ef4444; animation: gosms-ver-blink 1.1s ease-in-out infinite; }
|
||||
@keyframes gosms-ver-blink { 0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(245, 108, 108, 0.55); } 50% { opacity: 0.45; box-shadow: 0 0 0 5px rgba(245, 108, 108, 0); } }
|
||||
|
||||
/* ---- H2:滚动条——侧栏视觉消除(滚动能力保留,职责在 .nav-scroll),全局 demo 化细条 ---- */
|
||||
* { scrollbar-width: thin; scrollbar-color: var(--gosms-border) transparent; }
|
||||
/* ---- 滚动条(细条契约化) ---- */
|
||||
* { scrollbar-width: thin; scrollbar-color: var(--gosms-border-strong) transparent; }
|
||||
::-webkit-scrollbar { width: 6px; height: 6px; }
|
||||
::-webkit-scrollbar-track { background: transparent; }
|
||||
::-webkit-scrollbar-thumb { background: var(--gosms-border); border-radius: 3px; }
|
||||
::-webkit-scrollbar-thumb { background: var(--gosms-border-strong); border-radius: 3px; }
|
||||
::-webkit-scrollbar-thumb:hover { background: var(--gosms-primary-soft); }
|
||||
|
||||
/* ---- 移动端(demo 断点 900 + 项目汉堡抽屉补充) ---- */
|
||||
/* ---- 移动端(≤900 抽屉;顶栏 64) ---- */
|
||||
@media (max-width: 900px) {
|
||||
.sidebar { display: none; }
|
||||
.duo { grid-template-columns: 1fr; }
|
||||
.menu-btn { display: grid; }
|
||||
.sidebar.open {
|
||||
display: flex; flex-direction: column; position: fixed; top: 54px; left: 0; z-index: 60;
|
||||
height: calc(100vh - 54px); background: var(--gosms-bg-2);
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
|
||||
display: flex; flex-direction: column; position: fixed; top: 64px; left: 0; z-index: 60;
|
||||
height: calc(100vh - 64px); background: var(--gosms-bg-2);
|
||||
box-shadow: var(--gosms-shadow-glass);
|
||||
}
|
||||
.nav-scrim { position: fixed; inset: 54px 0 0 0; z-index: 55; background: rgba(0, 0, 0, 0.45); }
|
||||
.main { padding: 16px 14px; }
|
||||
.nav-scrim { position: fixed; inset: 64px 0 0 0; z-index: 55; background: rgba(0, 0, 0, 0.45); }
|
||||
.main { padding: 16px; }
|
||||
.collapse-btn, .sidebar-foot { display: none; }
|
||||
/* 抽屉态强制全宽+文字回归(collapsed 组合免疫) */
|
||||
.sidebar.open { width: 224px; padding: 16px 12px; }
|
||||
.sidebar.open .nav-item { justify-content: flex-start; padding: 8px 12px; }
|
||||
.sidebar.open { width: 256px; }
|
||||
.sidebar.open .nav-item { justify-content: flex-start; padding: 10px 14px 10px 17px; }
|
||||
.sidebar.open .nav-item .txt { display: inline; }
|
||||
.sidebar.open .nav-item.active::before { left: -12px; }
|
||||
.sidebar.open .nav-group { color: var(--gosms-text-muted); padding: 16px 12px 6px; }
|
||||
.sidebar.open .nav-group::after { display: none; }
|
||||
.sidebar.open .nav-group { padding: 16px 12px 8px; }
|
||||
}
|
||||
@media (min-width: 901px) { .nav-scrim { display: none; } }
|
||||
|
||||
/* ---- P3:全局键盘焦点可见性(只加强不重置;与 aurora 主色一致) ---- */
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--gosms-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
/* ---- 键盘焦点可见性 ---- */
|
||||
:focus-visible { outline: 2px solid var(--gosms-primary); outline-offset: 2px; }
|
||||
|
||||
/* ============================================================
|
||||
* 基础重置(原 index.scss 职责并入)
|
||||
* 基础重置
|
||||
* ============================================================ */
|
||||
* { box-sizing: border-box; }
|
||||
html, body, #app { height: 100%; margin: 0; padding: 0; }
|
||||
body { font-variant-numeric: tabular-nums; }
|
||||
table, .el-table { font-variant-numeric: tabular-nums; }
|
||||
::selection { background: var(--gosms-primary-soft); }
|
||||
|
||||
/* ============================================================
|
||||
* 语义徽章/趋势胶囊/说明文字(原 semantics.scss 职责并入)
|
||||
* 语义徽章/趋势胶囊
|
||||
* ============================================================ */
|
||||
.sem-badge {
|
||||
display: inline-flex; align-items: center; gap: 6px;
|
||||
padding: 2px 10px; border-radius: 999px;
|
||||
font-size: 12px; line-height: 18px;
|
||||
font-size: var(--gosms-fs-xs); line-height: 18px;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
.sem-badge::before {
|
||||
content: ''; width: 6px; height: 6px; border-radius: 50%;
|
||||
background: currentColor;
|
||||
}
|
||||
.sem-badge--ok {
|
||||
color: var(--el-color-success);
|
||||
background: var(--el-color-success-light-9);
|
||||
border-color: var(--el-color-success-light-7);
|
||||
}
|
||||
.sem-badge--fail {
|
||||
color: var(--el-color-danger);
|
||||
background: var(--el-color-danger-light-9);
|
||||
border-color: var(--el-color-danger-light-7);
|
||||
}
|
||||
.sem-badge--pending {
|
||||
color: var(--el-color-warning);
|
||||
background: var(--el-color-warning-light-9);
|
||||
border-color: var(--el-color-warning-light-7);
|
||||
}
|
||||
.sem-badge--off {
|
||||
color: var(--gosms-text-muted);
|
||||
background: var(--el-fill-color-light);
|
||||
border-color: var(--gosms-border);
|
||||
}
|
||||
.hint { font-size: var(--gosms-fs-xs); color: var(--gosms-text-muted); line-height: 1.5; }
|
||||
.sem-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
|
||||
.sem-badge--ok { color: var(--el-color-success); background: var(--el-color-success-light-9); border-color: var(--el-color-success-light-7); }
|
||||
.sem-badge--fail { color: var(--el-color-danger); background: var(--el-color-danger-light-9); border-color: var(--el-color-danger-light-7); }
|
||||
.sem-badge--pending { color: var(--el-color-warning); background: var(--el-color-warning-light-9); border-color: var(--el-color-warning-light-7); }
|
||||
.sem-badge--off { color: var(--gosms-text-muted); background: var(--el-fill-color-light); border-color: var(--gosms-border); }
|
||||
.trend-up, .trend-down, .trend-flat {
|
||||
display: inline-flex; align-items: center; gap: 3px;
|
||||
padding: 2px 9px; border-radius: 999px; font-size: var(--gosms-fs-sm);
|
||||
padding: 2px 9px; border-radius: 999px; font-size: var(--gosms-fs-xs);
|
||||
font-weight: 500; line-height: 16px; width: fit-content;
|
||||
}
|
||||
.trend-up { color: var(--el-color-success); background: var(--el-color-success-light-9); }
|
||||
|
||||
+103
-84
@@ -1,114 +1,133 @@
|
||||
/* ============================================================
|
||||
* go-sms Design Tokens — W1 重建(2026-09)
|
||||
* 唯一样式值来源;数值以 docs/design/demo-c-aurora.html 原文为准。
|
||||
* 主题语义与 demo 一致::root = 暗色(demo 原生),html:not(.dark) = 亮色。
|
||||
* go-sms Design Tokens — Issue#6 P3 重建(2026-11)
|
||||
* 唯一样式值来源;数值以 sub2api 源码真值为准:
|
||||
* tailwind.config.js(primary teal 全阶/dark=slate/shadow 族)+
|
||||
* alignment-report.md(v3.2.1 锁定规格表 + 4 项用户显式覆盖)。
|
||||
* 规则:任何层不得硬编码色值,一律 var(--gosms-*)。
|
||||
* 旧名(--gosms-*)全部保留,供 W4 渐进期 views 无缝消费。
|
||||
* 旧名(--gosms-primary 族等)全部保留映射新阶,供 views 渐进消费。
|
||||
* ============================================================ */
|
||||
:root {
|
||||
/* ---- 主色 teal 阶(demo:--teal/--teal-2/--teal-deep) ---- */
|
||||
--gosms-primary: #2dd4bf; /* demo --teal(暗色语境 400 亮化) */
|
||||
--gosms-primary-strong: #14b8a6; /* demo --teal-2 */
|
||||
--gosms-primary-deep: #0d9488; /* demo --teal-deep */
|
||||
--gosms-primary-light: #5eead4;
|
||||
--gosms-primary-pale: #99f6e4;
|
||||
--gosms-primary-soft: rgba(45, 212, 191, 0.12); /* demo --teal-soft 原值 */
|
||||
--gosms-primary-mist: rgba(45, 212, 191, 0.18);
|
||||
--gosms-glow: rgba(45, 212, 191, 0.45); /* demo --teal-glow 原值 */
|
||||
--gosms-glow-strong: rgba(45, 212, 191, 0.55);
|
||||
/* ---- 主色 teal 全阶(sub2api tailwind primary 官方原值) ---- */
|
||||
--gosms-primary-50: #f0fdfa;
|
||||
--gosms-primary-100: #ccfbf1;
|
||||
--gosms-primary-200: #99f6e4;
|
||||
--gosms-primary-300: #5eead4;
|
||||
--gosms-primary-400: #2dd4bf;
|
||||
--gosms-primary-500: #14b8a6;
|
||||
--gosms-primary-600: #0d9488;
|
||||
--gosms-primary-700: #0f766e;
|
||||
--gosms-primary-800: #115e59;
|
||||
--gosms-primary-900: #134e4a;
|
||||
--gosms-primary-950: #042f2e;
|
||||
|
||||
/* ---- 渐变/极光 ---- */
|
||||
--gosms-grad-from: #2dd4bf;
|
||||
--gosms-grad-to: #0ea5e9;
|
||||
/* ---- 旧主色名兼容映射(暗色语境=400 亮化,与 sub2api dark 下
|
||||
text-primary-400 同口径;亮色在 html:not(.dark) 覆写 600) ---- */
|
||||
--gosms-primary: var(--gosms-primary-400);
|
||||
--gosms-primary-strong: var(--gosms-primary-500);
|
||||
--gosms-primary-deep: var(--gosms-primary-600);
|
||||
--gosms-primary-light: var(--gosms-primary-300);
|
||||
--gosms-primary-pale: var(--gosms-primary-200);
|
||||
--gosms-primary-soft: rgba(20, 184, 166, 0.10); /* 激活底/选中底 */
|
||||
--gosms-primary-mist: rgba(20, 184, 166, 0.16); /* hover 加深档 */
|
||||
--gosms-glow: rgba(20, 184, 166, 0.25); /* 源码 shadow-glow 原值 */
|
||||
--gosms-glow-strong: rgba(20, 184, 166, 0.40);
|
||||
|
||||
/* ---- 品牌渐变(源码 background-image.gradient-primary 原值) ---- */
|
||||
--gosms-grad-from: var(--gosms-primary-500);
|
||||
--gosms-grad-to: var(--gosms-primary-600);
|
||||
--gosms-gradient: linear-gradient(135deg, var(--gosms-grad-from) 0%, var(--gosms-grad-to) 100%);
|
||||
--gosms-aurora-a: rgba(45, 212, 191, 0.5);
|
||||
--gosms-aurora-b: rgba(14, 165, 233, 0.4);
|
||||
--gosms-num-glow: 0 0 22px rgba(45, 212, 191, 0.3);
|
||||
--gosms-gap-card: 14px; /* demo 卡纵距 */
|
||||
--gosms-num-glow: none; /* sub2api 数字无 glow,置空兼容 */
|
||||
--gosms-gap-card: 16px; /* 契约:卡片 gap 16 */
|
||||
|
||||
/* ---- 状态色(demo 原生 --amber/--red/--violet) ---- */
|
||||
/* ---- 状态色(sub2api 语义:成功=emerald[KPI 契约 emerald-600]/警告=amber/危险=red) ---- */
|
||||
--gosms-emerald: #34d399;
|
||||
--gosms-success: #10b981;
|
||||
--gosms-amber: #fbbf24;
|
||||
--gosms-red: #f87171;
|
||||
--gosms-violet: #a78bfa;
|
||||
|
||||
/* ---- 中性(demo:--bg/--bg-2/--text 族) ---- */
|
||||
--gosms-bg-page: #0b1016; /* demo --bg */
|
||||
--gosms-bg-2: #0e141c; /* demo --bg-2 */
|
||||
--gosms-card: #0f172a; /* EP 弹窗/下拉实底(overlay 需不透明) */
|
||||
--gosms-card-veil: rgba(255, 255, 255, 0.035); /* demo --card 玻璃面(容器卡) */
|
||||
--gosms-card-hover: rgba(255, 255, 255, 0.06); /* demo --card-hover 原值 */
|
||||
--gosms-text: #d7e2ea; /* demo --text */
|
||||
--gosms-text-secondary: #94a3b8;
|
||||
--gosms-text-muted: #64748b; /* demo --text-dim */
|
||||
--gosms-text-bright: #f0f6fa; /* demo --text-bright */
|
||||
--gosms-border: rgba(148, 163, 184, 0.14); /* demo 原值(比旧值更通透) */
|
||||
--gosms-border-strong: rgba(148, 163, 184, 0.28);
|
||||
--gosms-border-glow: rgba(45, 212, 191, 0.4); /* demo --border-glow */
|
||||
/* ---- 中性·暗色(默认;slate 体系=源码 dark 阶:页 950/侧栏 900/卡 800/边 700) ---- */
|
||||
--gosms-bg-page: #020617; /* slate-950 */
|
||||
--gosms-bg-2: #0f172a; /* slate-900(侧栏) */
|
||||
--gosms-card: #1e293b; /* slate-800(EP overlay 实底) */
|
||||
--gosms-card-veil: #1e293b; /* 容器卡(旧 veil 语义并轨实底) */
|
||||
--gosms-card-hover: #273449; /* slate-800 提亮档(hover) */
|
||||
--gosms-text: #cbd5e1; /* slate-300 正文 */
|
||||
--gosms-text-secondary: #94a3b8; /* slate-400 */
|
||||
--gosms-text-muted: #64748b; /* slate-500 */
|
||||
--gosms-text-bright: #f8fafc; /* slate-50 标题/强调 */
|
||||
--gosms-border: #334155; /* slate-700 */
|
||||
--gosms-border-strong: #475569; /* slate-600 */
|
||||
--gosms-border-glow: rgba(20, 184, 166, 0.45);
|
||||
|
||||
/* ---- 玻璃面(顶栏/侧栏) ---- */
|
||||
/* ---- 玻璃面(顶栏 blur;sub2api dark 顶栏=slate-900 半透) ---- */
|
||||
--gosms-glass: rgba(15, 23, 42, 0.85);
|
||||
--gosms-glass-header: rgba(11, 16, 22, 0.72); /* demo topbar 原值 */
|
||||
--gosms-glass-thin: rgba(15, 23, 42, 0.5);
|
||||
--gosms-input-veil: rgba(148, 163, 184, 0.07); /* demo lf-input 底 */
|
||||
--gosms-glass-header: rgba(2, 6, 23, 0.75);
|
||||
--gosms-glass-thin: rgba(30, 41, 59, 0.5);
|
||||
--gosms-input-veil: rgba(148, 163, 184, 0.06); /* 输入底/次级底 */
|
||||
--gosms-scrim: rgba(2, 6, 23, 0.6);
|
||||
|
||||
/* ---- 字号阶(E:demo-c 紧凑控制台体系) ---- */
|
||||
--gosms-fs-2xs: 10px;
|
||||
--gosms-fs-xs: 10.5px;
|
||||
--gosms-fs-sm: 11px;
|
||||
--gosms-fs-base: 12.5px;
|
||||
--gosms-fs-md: 13px;
|
||||
--gosms-fs-body: 13.5px;
|
||||
--gosms-fs-lg: 15px;
|
||||
--gosms-fs-xl: 17px;
|
||||
--gosms-fs-hero: 22px;
|
||||
--gosms-fs-stat: 32px;
|
||||
/* ---- 字号阶(sub2api 机器可证集合 {10,12,14,16,18,20,24};
|
||||
正文行距 1.65 = 用户显式覆盖) ---- */
|
||||
--gosms-fs-2xs: 10px; /* 极小注脚/装饰 */
|
||||
--gosms-fs-xs: 12px; /* th/KPI label/徽章 */
|
||||
--gosms-fs-sm: 13px; /* 次要正文 */
|
||||
--gosms-fs-base: 14px; /* 菜单/表格/正文基准 */
|
||||
--gosms-fs-md: 14px;
|
||||
--gosms-fs-body: 14px;
|
||||
--gosms-fs-lg: 16px; /* 区块标题/按钮大 */
|
||||
--gosms-fs-xl: 18px; /* 品牌名 */
|
||||
--gosms-fs-hero: 20px; /* KPI 值(20/700) */
|
||||
--gosms-fs-stat: 24px; /* 页标题(text-2xl) */
|
||||
--gosms-lh-body: 1.65;
|
||||
|
||||
/* ---- 圆角/阴影/动效 ---- */
|
||||
/* ---- 圆角/阴影/动效(r: 卡 16/input 12/icon 12;shadow=源码 boxShadow 原值) ---- */
|
||||
--gosms-radius: 16px;
|
||||
--gosms-radius-sm: 8px;
|
||||
--gosms-shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3);
|
||||
--gosms-shadow-card-hover: 0 8px 32px rgba(0, 0, 0, 0.35); /* demo card:hover 原值 */
|
||||
--gosms-radius-base: 12px;
|
||||
--gosms-radius-lg: 24px;
|
||||
--gosms-shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
--gosms-shadow-card-hover: 0 10px 40px rgba(0, 0, 0, 0.08);
|
||||
--gosms-shadow-glow: 0 0 20px var(--gosms-glow);
|
||||
--gosms-shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.08);
|
||||
--gosms-dur-fast: 0.2s;
|
||||
--gosms-dur-base: 0.3s;
|
||||
|
||||
/* ---- 字体 ---- */
|
||||
--gosms-font: -apple-system, 'PingFang SC', 'Hiragino Sans GB',
|
||||
'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif; /* demo --sans 原序 */
|
||||
--gosms-font-num: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Monaco,
|
||||
Consolas, 'Liberation Mono', monospace;
|
||||
/* ---- 字体(源码 fontFamily.sans 原序;mono 同源码) ---- */
|
||||
--gosms-font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
||||
'Helvetica Neue', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
|
||||
--gosms-font-num: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
/* 亮色:html 无 .dark 即亮(demo html[data-theme="light"] 原值) */
|
||||
/* ---- 亮色(sub2api light:页 gray-50/边 gray-100/文 gray-900;主色 600 对比度) ---- */
|
||||
html:not(.dark) {
|
||||
--gosms-bg-page: #f4f7f9; /* demo 原值(旧 #f8fafc) */
|
||||
--gosms-bg-2: #ebf1f4;
|
||||
--gosms-primary: var(--gosms-primary-600);
|
||||
--gosms-primary-strong: var(--gosms-primary-700);
|
||||
--gosms-primary-deep: var(--gosms-primary-800);
|
||||
--gosms-primary-light: var(--gosms-primary-500);
|
||||
--gosms-primary-pale: var(--gosms-primary-400);
|
||||
--gosms-primary-soft: rgba(13, 148, 136, 0.08);
|
||||
--gosms-primary-mist: rgba(13, 148, 136, 0.14);
|
||||
--gosms-glow: rgba(13, 148, 136, 0.22);
|
||||
--gosms-glow-strong: rgba(13, 148, 136, 0.35);
|
||||
--gosms-emerald: #059669; /* 契约 KPI 值=emerald-600 */
|
||||
--gosms-amber: #d97706;
|
||||
--gosms-red: #dc2626;
|
||||
--gosms-bg-page: #f9fafb; /* gray-50(基线 body.bg 全等) */
|
||||
--gosms-bg-2: #f3f4f6; /* gray-100 */
|
||||
--gosms-card: #ffffff;
|
||||
--gosms-card-veil: rgba(255, 255, 255, 0.75);
|
||||
--gosms-card-hover: #ffffff;
|
||||
--gosms-primary: #14b8a6; /* 亮底对比度取 600(demo 未细分,项目沿用) */
|
||||
--gosms-primary-strong: #0d9488;
|
||||
--gosms-primary-deep: #0f766e;
|
||||
--gosms-primary-light: #2dd4bf;
|
||||
--gosms-primary-pale: #5eead4;
|
||||
--gosms-primary-soft: rgba(13, 148, 136, 0.09); /* demo light 原值 */
|
||||
--gosms-primary-mist: rgba(13, 148, 136, 0.15);
|
||||
--gosms-glow: rgba(13, 148, 136, 0.3); /* demo light 原值 */
|
||||
--gosms-glow-strong: rgba(13, 148, 136, 0.4);
|
||||
--gosms-num-glow: 0 0 22px rgba(13, 148, 136, 0.22);
|
||||
--gosms-text: #24303b; /* demo 原值 */
|
||||
--gosms-text-secondary: #64748b;
|
||||
--gosms-text-muted: #8296a6; /* demo light --text-dim 原值 */
|
||||
--gosms-text-bright: #0f1b26;
|
||||
--gosms-border: rgba(36, 48, 59, 0.1); /* demo 原值 */
|
||||
--gosms-border-strong: rgba(36, 48, 59, 0.2);
|
||||
--gosms-border-glow: rgba(13, 148, 136, 0.35); /* demo 原值 */
|
||||
--gosms-card-veil: #ffffff;
|
||||
--gosms-card-hover: #f9fafb;
|
||||
--gosms-text: #374151; /* gray-700(契约 td) */
|
||||
--gosms-text-secondary: #6b7280; /* gray-500 */
|
||||
--gosms-text-muted: #9ca3af; /* gray-400 */
|
||||
--gosms-text-bright: #111827; /* gray-900 */
|
||||
--gosms-border: #f3f4f6; /* gray-100(契约卡边) */
|
||||
--gosms-border-strong: #e5e7eb; /* gray-200 */
|
||||
--gosms-border-glow: rgba(13, 148, 136, 0.4);
|
||||
--gosms-glass: rgba(255, 255, 255, 0.85);
|
||||
--gosms-glass-header: rgba(255, 255, 255, 0.72); /* demo 原值 */
|
||||
--gosms-glass-header: rgba(255, 255, 255, 0.8);
|
||||
--gosms-glass-thin: rgba(255, 255, 255, 0.5);
|
||||
--gosms-input-veil: rgba(36, 48, 59, 0.04);
|
||||
--gosms-input-veil: rgba(17, 24, 39, 0.04);
|
||||
--gosms-scrim: rgba(15, 23, 42, 0.45);
|
||||
--gosms-shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
--gosms-shadow-card-hover: 0 10px 40px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// utils/markdown.ts — Issue#4 迷你 Markdown 渲染器(发布日志专用,零依赖)。
|
||||
//
|
||||
// 支持范围(够用即止,不求 GFM 全集):
|
||||
// 标题 #~####、无序列表(-/*)、有序列表(1. / 1、)、粗体 **x**、
|
||||
// 行内代码 \`x\`、围栏代码块 \`\`\`、链接 [t](https://…)(仅 http/https)、
|
||||
// 空行分段(段内换行 → <br>)。
|
||||
// 安全口径:**输入先整体 HTML 转义再解析**——内容源虽是仓库静态数据
|
||||
// (releases.ts),仍按不可信文本处理,任何标签/引号都不会进入 DOM;
|
||||
// 链接仅允许 http(s) 协议(javascript: 伪协议不命中即保持原样文本)。
|
||||
|
||||
/** HTML 全量转义(含引号,防属性注入)。 */
|
||||
function escapeHtml(s: string): string {
|
||||
return s
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
/** 行内格式:行内代码(哨兵保护,内部不做粗体/链接替换)→ 粗体 → 链接。 */
|
||||
const CODE_SENTINEL = '@@GOSMS_MD_CODE_'
|
||||
function inline(s: string): string {
|
||||
const codes: string[] = []
|
||||
let t = s.replace(/`([^`]+)`/g, (_m, c: string) => {
|
||||
codes.push(c)
|
||||
return `${CODE_SENTINEL}${codes.length - 1}@@`
|
||||
})
|
||||
t = t.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
||||
t = t.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>')
|
||||
return t.replace(new RegExp(`${CODE_SENTINEL}(\\d+)@@`, 'g'), (_m, i: string) => `<code>${codes[Number(i)]!}</code>`)
|
||||
}
|
||||
|
||||
/** 块级行判据(段落收集的截断条件):代码围栏 / 标题 / 列表。 */
|
||||
const BLOCK_START = /^(#{1,4}\s|\s*[-*]\s|\s*\d+(?:\.\s+|、\s*)|```)/
|
||||
/** 有序列表行:点号后须空格(英文习惯),顿号后空格可选(中文习惯)。 */
|
||||
const OL_LINE = /^\s*\d+(?:\.\s+|、\s*)/
|
||||
|
||||
/** Markdown → HTML(输入不可信,输出已全量转义;v-html 挂载)。 */
|
||||
export function renderMarkdown(src: string): string {
|
||||
const lines = escapeHtml(src.replace(/\r\n/g, '\n')).split('\n')
|
||||
const out: string[] = []
|
||||
let i = 0
|
||||
while (i < lines.length) {
|
||||
const line = lines[i]!
|
||||
// 围栏代码块:内容保持原样(不再做行内格式化)
|
||||
if (line.trim().startsWith('```')) {
|
||||
const buf: string[] = []
|
||||
i++
|
||||
while (i < lines.length && !lines[i]!.trim().startsWith('```')) buf.push(lines[i++]!)
|
||||
i++ // 跳过闭合围栏(缺闭合则吞到结尾)
|
||||
out.push(`<pre><code>${buf.join('\n')}</code></pre>`)
|
||||
continue
|
||||
}
|
||||
// 标题 # ~ ####
|
||||
const h = /^(#{1,4})\s+(.*)$/.exec(line)
|
||||
if (h) {
|
||||
const lv = h[1]!.length
|
||||
out.push(`<h${lv}>${inline(h[2]!)}</h${lv}>`)
|
||||
i++
|
||||
continue
|
||||
}
|
||||
// 无序列表
|
||||
if (/^\s*[-*]\s+/.test(line)) {
|
||||
const items: string[] = []
|
||||
while (i < lines.length && /^\s*[-*]\s+/.test(lines[i]!)) items.push(inline(lines[i++]!.replace(/^\s*[-*]\s+/, '')))
|
||||
out.push(`<ul>${items.map((x) => `<li>${x}</li>`).join('')}</ul>`)
|
||||
continue
|
||||
}
|
||||
// 有序列表(1. 或 1、)
|
||||
if (OL_LINE.test(line)) {
|
||||
const items: string[] = []
|
||||
while (i < lines.length && OL_LINE.test(lines[i]!)) items.push(inline(lines[i++]!.replace(OL_LINE, '')))
|
||||
out.push(`<ol>${items.map((x) => `<li>${x}</li>`).join('')}</ol>`)
|
||||
continue
|
||||
}
|
||||
// 空行
|
||||
if (line.trim() === '') {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
// 段落:连续普通行合并,行间 <br>
|
||||
const buf: string[] = [line]
|
||||
i++
|
||||
while (i < lines.length && lines[i]!.trim() !== '' && !BLOCK_START.test(lines[i]!)) buf.push(lines[i++]!)
|
||||
out.push(`<p>${buf.map(inline).join('<br>')}</p>`)
|
||||
}
|
||||
return out.join('\n')
|
||||
}
|
||||
@@ -46,7 +46,9 @@
|
||||
<el-button link type="primary" style="margin-left: 8px" @click="showPwd = !showPwd">{{ showPwd ? '隐藏' : '显示' }}</el-button>
|
||||
<el-button link type="primary" :disabled="!apiCfg.cmpp_password" @click="copyText(apiCfg.cmpp_password, 'CMPP密码')">复制</el-button>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="通道号(接入码)">提交时 SrcID 自带(≤21位)</el-descriptions-item>
|
||||
<el-descriptions-item label="通道号(接入码)">
|
||||
提交时 SrcID 自带(CMPP 2.0 协议定长 ≤21 位){{ apiCfg.ext_code ? `;须以 ${apiCfg.ext_code} 为前缀,不匹配拒收(Result=9)` : ';未配置时回退系统默认接入码(系统配置→cmpp.default_ext_code)' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="最大连接数">
|
||||
{{ apiCfg.cmpp_max_conns_effective }}{{ apiCfg.cmpp_max_conns ? '' : '(系统默认)' }}
|
||||
</el-descriptions-item>
|
||||
@@ -267,7 +269,7 @@ function deliveryText(): string {
|
||||
`连接端口:${c.cmpp_access?.port ?? '-'}`,
|
||||
`企业ID:${acc.value?.username ?? '-'}`,
|
||||
`CMPP密码:${c.cmpp_password}`,
|
||||
'通道号(接入码):提交时 SrcID 自带(≤21位)',
|
||||
`通道号(接入码):提交时 SrcID 自带(CMPP 2.0 定长 ≤21 位${c.ext_code ? `;须以 ${c.ext_code} 为前缀` : ';未配置时回退系统默认接入码'})`,
|
||||
`单链接速度:${c.cmpp_speed_effective} 条/秒`,
|
||||
`最大连接数:${c.cmpp_max_conns_effective}`,
|
||||
`协议版本:${c.cmpp_access?.version ?? 'CMPP 2.0'}`,
|
||||
|
||||
@@ -36,12 +36,18 @@ onMounted(async () => {
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!acc.value) return
|
||||
// Issue#3 修复:账号未装载/接口报错此前静默吞掉,页面表现为「点击无响应」。
|
||||
if (!acc.value) {
|
||||
ElMessage.warning('账号信息未加载,请刷新后重试')
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await accountApi.recharge(acc.value.id, count.value, remark.value)
|
||||
acc.value.balance = r.balance
|
||||
ElMessage.success(`充值成功,当前余额 ${r.balance}`)
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? `充值失败:${e.message}` : '充值失败,请稍后重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ watch(trend, () => { hoverIdx.value = -1 })
|
||||
background: var(--gosms-primary-soft); color: var(--gosms-primary);
|
||||
}
|
||||
.hero--warn .hero-ic { background: rgba(251, 191, 36, 0.1); color: var(--gosms-amber); }
|
||||
.hero--err .hero-ic { background: rgba(248, 113, 113, 0.1); color: var(--gosms-red); }
|
||||
.hero--err .hero-ic { background: rgba(239, 68, 68, 0.1); color: var(--gosms-red); }
|
||||
.hero--dim .hero-ic { background: var(--gosms-input-veil); color: var(--gosms-text-muted); }
|
||||
.hero-body { min-width: 0; flex: 1; }
|
||||
.hero-text { margin: 0; font-size: 14.5px; font-weight: 600; color: var(--gosms-text-bright); }
|
||||
@@ -459,7 +459,7 @@ watch(trend, () => { hoverIdx.value = -1 })
|
||||
.qic--hot { background: rgba(251, 191, 36, 0.1); color: var(--gosms-amber); }
|
||||
|
||||
/* ---- 走势:teal 光晕描边 + P3 hover 十字线/气泡 ---- */
|
||||
.trend-line { filter: drop-shadow(0 0 6px rgba(45, 212, 191, 0.4)); }
|
||||
.trend-line { filter: drop-shadow(0 0 6px var(--gosms-glow)); }
|
||||
.trend-cursor { stroke: var(--gosms-primary); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.7; }
|
||||
.trend-tip rect { fill: var(--gosms-glass); stroke: var(--gosms-border); }
|
||||
.trend-tip text { fill: var(--gosms-text); font-size: 11px; font-family: var(--gosms-font); }
|
||||
@@ -470,8 +470,8 @@ watch(trend, () => { hoverIdx.value = -1 })
|
||||
.live-chip { border: none; cursor: pointer; font-family: inherit; }
|
||||
.live-chip.stale { color: var(--gosms-amber); background: rgba(251, 191, 36, 0.1); }
|
||||
.live-chip.stale i { background: var(--gosms-amber); box-shadow: 0 0 8px rgba(251, 191, 36, 0.45); }
|
||||
.live-chip.dead { color: var(--gosms-red); background: rgba(248, 113, 113, 0.1); }
|
||||
.live-chip.dead i { background: var(--gosms-red); box-shadow: 0 0 8px rgba(248, 113, 113, 0.45); animation: none; }
|
||||
.live-chip.dead { color: var(--gosms-red); background: rgba(239, 68, 68, 0.1); }
|
||||
.live-chip.dead i { background: var(--gosms-red); box-shadow: 0 0 8px rgba(239, 68, 68, 0.45); animation: none; }
|
||||
|
||||
/* ---- 通道表(配置域快照) ---- */
|
||||
.ch-scroll { overflow-x: auto; }
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<!-- G3:光斑用 demo .aurora 原文(替代已删 theme-aurora 的 aurora-bg);登录页恒定深色 -->
|
||||
<div class="aurora login-aurora"></div>
|
||||
<!-- Issue#6 P3:极光退役(sub2api 契约);登录页恒定深色(slate-950 实底) -->
|
||||
<div class="login-wrap">
|
||||
<div class="login-inner">
|
||||
<!-- D 阶段:>md 双栏 hero(极光品牌区,<md 隐藏保持单栏) -->
|
||||
@@ -83,21 +82,20 @@ async function submit() {
|
||||
|
||||
<style scoped lang="scss">
|
||||
/* G3:登录页光斑恒定暗色亮度(登录恒深底,不受 dark 切换的 0.3 淡化影响) */
|
||||
.aurora.login-aurora { opacity: 0.55; }
|
||||
/* AuthLayout 复刻 + D 阶段极光化:极夜底 + 光斑氛围 + >md 双栏 hero */
|
||||
.login-wrap {
|
||||
/* W2:登录页恒暗语境——局部冻结暗色 token,全局切亮色时本页文字/卡面不退化 */
|
||||
--gosms-text-secondary: #94a3b8;
|
||||
--gosms-text: #d7e2ea;
|
||||
--gosms-text-bright: #f0f6fa;
|
||||
--gosms-text: #cbd5e1;
|
||||
--gosms-text-bright: #f8fafc;
|
||||
--gosms-text-muted: #64748b;
|
||||
--gosms-card-veil: rgba(255, 255, 255, 0.035);
|
||||
--gosms-border: rgba(148, 163, 184, 0.14);
|
||||
--gosms-card-veil: #1e293b;
|
||||
--gosms-border: #334155;
|
||||
--gosms-primary: #2dd4bf;
|
||||
--gosms-glow: rgba(45, 212, 191, 0.45);
|
||||
--gosms-glow: rgba(20, 184, 166, 0.4);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
min-height: 100vh;
|
||||
background: #0b1016; /* 极夜蓝黑(与暗色 token 同源,登录页恒定深色) */
|
||||
background: #020617; /* slate-950(契约暗色页底,登录页恒定深色) */
|
||||
position: relative;
|
||||
}
|
||||
.login-inner { width: 100%; max-width: 420px; padding: 16px; position: relative; }
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user