import { useState } from 'react'; import { Button, Descriptions, Drawer, Form, Input, Select, Table, Tag, Typography } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import { request } from '../lib/api'; import { fmtTime } from '../lib/constants'; import { THIRD_PARTY_PROVIDER_LABELS, THIRD_PARTY_SCENE_LABELS, THIRD_PARTY_STATUS_LABELS, formatRef, zhLabel, } from '../lib/display-labels'; import { useAdminList } from '../lib/useAdminList'; import { useAdminListColumns } from '../lib/useAdminListColumns'; import { AdminListHeader } from '../components/AdminListHeader'; import { AdminPrimaryLink } from '../components/AdminPrimaryLink'; type Row = { id: string; provider: string; scene: string; refType: string | null; refId: string | null; requestUrl?: string | null; requestBody?: Record | null; responseBody?: Record | null; externalNo?: string | null; amount?: string | null; status: string; errorMessage?: string | null; createdAt: string; }; const PROVIDER_OPTIONS = [ { value: 'WECHAT_AUTH', label: '微信授权' }, { value: 'WECHAT_PAY', label: '微信支付' }, { value: 'WECHAT_MAP', label: '微信/腾讯地图' }, { value: 'ALIYUN_OSS', label: '阿里云 OSS' }, { value: 'ALIYUN_SMS', label: '阿里云短信' }, { value: 'MOCK_SMS', label: 'Mock 短信' }, { value: 'XFX', label: '小飞侠' }, { value: 'LOGISTICS', label: '物流快递' }, ]; const STATUS_COLOR: Record = { SUCCESS: 'success', FAILED: 'error', PENDING: 'processing', }; function summarizeJson(json: Record | null | undefined) { if (!json || Object.keys(json).length === 0) return '—'; const text = JSON.stringify(json); return text.length > 60 ? `${text.slice(0, 60)}…` : text; } function JsonBlock({ value }: { value: unknown }) { if (value == null) return ; return (
      {JSON.stringify(value, null, 2)}
    
); } export default function ThirdPartyLogsPage() { const [filters, setFilters] = useState>({}); const { data, loading, page, pageSize, setPage, setPageSize } = useAdminList( '/common/third-party-logs', () => { const qs = new URLSearchParams(); if (filters.provider) qs.set('provider', filters.provider); if (filters.scene) qs.set('scene', filters.scene); if (filters.refId) qs.set('refId', filters.refId); return qs; }, [filters], ); const [detail, setDetail] = useState | null>(null); const [drawerOpen, setDrawerOpen] = useState(false); const baseColumns: ColumnsType = [ { title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime }, { title: '渠道', dataIndex: 'provider', width: 120, render: (v: string) => zhLabel(THIRD_PARTY_PROVIDER_LABELS, v) }, { title: '场景', dataIndex: 'scene', width: 140, render: (v: string) => zhLabel(THIRD_PARTY_SCENE_LABELS, v) }, { title: '关联', width: 120, render: (_, r) => formatRef(r.refType, r.refId), }, { title: '状态', dataIndex: 'status', width: 90, render: (v: string) => {zhLabel(THIRD_PARTY_STATUS_LABELS, v)}, }, { title: '错误信息', dataIndex: 'errorMessage', render: (v: string | null | undefined) => v || '—', }, { title: '请求摘要', render: (_, r) => summarizeJson(r.requestBody), }, { title: '外部单号', dataIndex: 'externalNo', width: 140, render: (v, row) => ( { setDetail(await request(`/common/third-party-logs/${row.id}`)); setDrawerOpen(true); }} > {v} ), }, { title: '操作', width: 80, render: (_, row) => ( ), }, ]; const { columns, settingsButton, settingsModal } = useAdminListColumns('logs-third-party', baseColumns, { page, pageSize, }); return (
{settingsModal}
{ setFilters(v); setPage(1); }} >
{ setPage(p); setPageSize(ps); }, }} /> setDrawerOpen(false)}> {detail && ( {String(detail.id)} {zhLabel(THIRD_PARTY_PROVIDER_LABELS, String(detail.provider))} {zhLabel(THIRD_PARTY_SCENE_LABELS, String(detail.scene))} {zhLabel(THIRD_PARTY_STATUS_LABELS, String(detail.status))} {formatRef(detail.refType ? String(detail.refType) : null, detail.refId ? String(detail.refId) : null)} {String(detail.externalNo ?? '—')} {detail.amount != null ? String(detail.amount) : '—'} {String(detail.requestUrl ?? '—')} {detail.errorMessage ? ( {String(detail.errorMessage)} ) : ( '—' )} {fmtTime(String(detail.createdAt))} )} ); }