123 lines
4.1 KiB
TypeScript
123 lines
4.1 KiB
TypeScript
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
|
|
}
|
|
|
|
/** 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`),
|
|
// 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),
|
|
}
|