分销后台前端对接与结算明细接口

- 新增 GET /admin/distribution/settlement-batches/:id/items 明细查询
- distribution-admin 重构为 react-router 多页面:仪表盘/网站/规则(启停)/订单(筛选分页)/结算(创建/明细/结算)/支付通道(绑定解绑)/账号展示(上下架)
- axios 统一 401 提示,引导回主站后台登录;金额统一整数分格式化
- npm run build(tsc 严格模式) 通过
This commit is contained in:
yml2213
2026-09-05 11:17:43 +08:00
parent ac777f5b16
commit 3162d15425
15 changed files with 1006 additions and 38 deletions
+97
View File
@@ -0,0 +1,97 @@
import { useEffect, useState } from 'react'
import { Card, Table, Typography, Space, Select, Tag, message } from 'antd'
import { listRules, listSites, updateRuleStatus, type Rule, type Site } from '../api'
const MODE_LABELS: Record<string, string> = {
two_party_distributor_receive: '两方-分销收号',
two_party_platform_receive: '两方-分销卖出',
three_party: '三方',
}
export default function Rules() {
const [sites, setSites] = useState<Site[]>([])
const [siteID, setSiteID] = useState<number | undefined>(undefined)
const [rules, setRules] = useState<Rule[]>([])
const [loading, setLoading] = useState(false)
async function load(site?: number) {
setLoading(true)
try {
setRules(await listRules(site))
} catch {
message.error('规则加载失败')
} finally {
setLoading(false)
}
}
useEffect(() => {
listSites().then(setSites).catch(() => message.error('站点加载失败'))
void load(undefined)
}, [])
async function toggleStatus(rule: Rule) {
const next = rule.status === 'active' ? 'disabled' : 'active'
try {
await updateRuleStatus(rule.id, next)
message.success(`规则已${next === 'active' ? '启用' : '停用'}`)
void load(siteID)
} catch {
message.error('状态更新失败')
}
}
return (
<Space direction="vertical" className="page">
<Typography.Title level={3}>比例与税费规则</Typography.Title>
<Space>
<Select
allowClear
placeholder="分销网站"
style={{ width: 200 }}
options={sites.map((site) => ({ label: site.site_name, value: site.id }))}
onChange={(value) => {
setSiteID(value)
void load(value)
}}
/>
</Space>
<Card>
<Table
rowKey="id"
loading={loading}
dataSource={rules}
pagination={false}
columns={[
{ title: '模式', dataIndex: 'mode', render: (v: string) => MODE_LABELS[v] ?? v },
{ title: '版本', dataIndex: 'version' },
{ title: '状态', dataIndex: 'status', render: (v: string) => <Tag color={v === 'active' ? 'green' : 'default'}>{v}</Tag> },
{
title: '比例',
render: (_: unknown, r: Rule) => {
const parts: string[] = []
if (r.distributor_receive_ratio > 0) parts.push(`分销收 ${r.distributor_receive_ratio}`)
if (r.platform_sell_ratio > 0) parts.push(`主站卖 ${r.platform_sell_ratio}`)
if (r.distributor_sell_ratio > 0) parts.push(`分销卖 ${r.distributor_sell_ratio}`)
if (r.platform_receive_ratio > 0) parts.push(`主站收 ${r.platform_receive_ratio}`)
if (r.distributor_a_ratio > 0) parts.push(`分销A ${r.distributor_a_ratio}`)
if (r.distributor_b_ratio > 0) parts.push(`分销B ${r.distributor_b_ratio}`)
return parts.join(' / ') || '-'
},
},
{ title: '服务费', render: (_: unknown, r: Rule) => `${r.service_fee_value} (${r.service_fee_unit})` },
{ title: '手续费', dataIndex: 'payment_fee_bps', render: (v: number) => `${v / 100}%` },
{ title: '税费', render: (_: unknown, r: Rule) => (r.tax_enabled ? `${r.tax_rate_bps / 100}%` : '关闭') },
{ title: '生效时间', dataIndex: 'effective_from' },
{
title: '操作',
render: (_: unknown, r: Rule) => (
<a onClick={() => toggleStatus(r)}>{r.status === 'active' ? '停用' : '启用'}</a>
),
},
]}
/>
</Card>
</Space>
)
}