Files
go-sms-V2/web-next/src/api/channel.ts
T
Tory 0ae6a2c1d4 Issue#6·B2: 三契约页 1:1 实装(v3-2-tailwind.html 逐行直抄,真实数据)—— ①#p-dash 运营总览(895-1005):状态横幅(五子系统 badge+summary 指标串)+stat 双行 6+4 卡+chart.js 发送趋势(teal/sky 双线渐变填充,近7/30 切换)+业务分布动态 donut(SVG dasharray)+通道实时监控表(monitor 快照 5s 轮询,负载条/失败率/P50)+系统健康(overview 10s 轮询,up/degraded/down 三态 badge)+最近动态(诚实空态)+快捷操作 4+通道配置快照;缺数据项显式 —(今日收入/TPM);②#p-acct 帐号管理(1006-1034):单卡一体筛选区(input!w-56+双 select+搜索/重置+已选N)+8 列原生 table(彩色首字圆徽轮转/角色 badge/余额右对齐/停用灰)+分页条(共N条+页码窗口),/accounts 真实分页;③#p-chan 通道编辑(1035-1059):双卡表单(基本参数 6 字段必填 4*+吞吐风控 5 字段+启用 switch)+操作条(探测期提示/取消/保存),协议键↔protocol+version 映射,编辑回填 host:port 合并;④api 层补 P2 三端点封装(statsApi.biz/realtime+systemApi.overview+channelApi.monitor+三类型);⑤后端根修:stats_handler.go 两处 AS key 撞 MySQL 8.0 保留字致 /stats/biz 500(反引号转义,P2 遗留 bug B2 首次消费暴露);⑥验收:vue-tsc 0/build ✓(dash 懒加载 chunk gzip 65KB)/Chrome 冒烟 12/12(横幅真实判定/健康 5 徽章/acct 真实账号 3 行/chan 双卡)/stat-card computed style 双会话对拍一致(radius16/pad20/flex/gap16/shadow 同 17890);网关重建重启(11-16 旧二进制→含 P2 端点)
2026-11-18 10:58:18 +08:00

193 lines
6.4 KiB
TypeScript

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}`),
}