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

- 新增 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
+105
View File
@@ -0,0 +1,105 @@
import { useEffect, useState } from 'react'
import { Card, Table, Typography, Space, Select, Tag, message } from 'antd'
import { listAccountDisplays, listSites, updateAccountDisplay, type AccountDisplay, type Site } from '../api'
const STATUS_LABELS: Record<string, string> = {
enabled: '展示中',
disabled: '已下架',
sold: '已售出',
offline: '已离线',
}
export default function Accounts() {
const [sites, setSites] = useState<Site[]>([])
const [siteID, setSiteID] = useState<number>()
const [status, setStatus] = useState<string>('')
const [items, setItems] = useState<AccountDisplay[]>([])
const [loading, setLoading] = useState(false)
async function load(site?: number, statusFilter?: string) {
if (!site) return
setLoading(true)
try {
setItems(await listAccountDisplays(site, statusFilter))
} catch {
message.error('账号展示加载失败')
} finally {
setLoading(false)
}
}
useEffect(() => {
listSites()
.then((rows) => {
setSites(rows)
if (rows.length > 0) {
setSiteID(rows[0].id)
void load(rows[0].id)
}
})
.catch(() => message.error('站点加载失败'))
}, [])
async function toggle(item: AccountDisplay) {
const next = item.display_status === 'enabled' ? 'disabled' : 'enabled'
try {
await updateAccountDisplay(item.id, next)
message.success(next === 'enabled' ? '已恢复展示' : '已下架')
if (siteID) void load(siteID, status)
} catch (error: unknown) {
const respMessage = (error as { response?: { data?: { message?: string } } })?.response?.data?.message
message.error(respMessage ?? '状态更新失败')
}
}
return (
<Space direction="vertical" className="page">
<Typography.Title level={3}>账号展示</Typography.Title>
<Space>
<Select
placeholder="分销网站"
style={{ width: 200 }}
value={siteID}
options={sites.map((site) => ({ label: site.site_name, value: site.id }))}
onChange={(value) => {
setSiteID(value)
void load(value, status)
}}
/>
<Select
allowClear
placeholder="展示状态"
style={{ width: 140 }}
options={Object.entries(STATUS_LABELS).map(([value, label]) => ({ label, value }))}
onChange={(value) => {
setStatus(value ?? '')
void load(siteID, value ?? '')
}}
/>
</Space>
<Card>
<Table
rowKey="id"
loading={loading}
dataSource={items}
pagination={{ pageSize: 20 }}
columns={[
{ title: '账号 ID', dataIndex: 'account_id' },
{ title: '商品 ID', dataIndex: 'listing_id' },
{
title: '展示状态',
dataIndex: 'display_status',
render: (v: string) => <Tag color={v === 'enabled' ? 'green' : 'default'}>{STATUS_LABELS[v] ?? v}</Tag>,
},
{
title: '操作',
render: (_: unknown, row: AccountDisplay) => (
<a onClick={() => toggle(row)}>{row.display_status === 'enabled' ? '下架' : '恢复展示'}</a>
),
},
]}
/>
</Card>
</Space>
)
}