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 { useAdminList } from '../lib/useAdminList'; 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: 'WECHAT_AUTH' }, { value: 'WECHAT_PAY', label: 'WECHAT_PAY' }, { value: 'WECHAT_MAP', label: 'WECHAT_MAP' }, { value: 'ALIYUN_OSS', label: 'ALIYUN_OSS' }, { value: 'ALIYUN_SMS', label: 'ALIYUN_SMS' }, { value: 'MOCK_SMS', label: 'MOCK_SMS' }, { value: 'XFX', label: '小飞侠 (XFX)' }, { value: 'LOGISTICS', label: 'LOGISTICS' }, ]; 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 columns: ColumnsType = [ { title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime }, { title: 'Provider', dataIndex: 'provider', width: 120 }, { title: '场景', dataIndex: 'scene', width: 120 }, { title: '关联', width: 120, render: (_, r) => (r.refType && r.refId ? `${r.refType}#${r.refId}` : '—'), }, { title: '状态', dataIndex: 'status', width: 90, render: (v: string) => {v}, }, { title: '错误信息', dataIndex: 'errorMessage', ellipsis: true, render: (v: string | null | undefined) => v || '—', }, { title: '请求摘要', ellipsis: true, render: (_, r) => summarizeJson(r.requestBody), }, { title: '外部单号', dataIndex: 'externalNo', width: 140, render: (v) => v || '—' }, { title: '操作', width: 80, render: (_, row) => ( ), }, ]; return (
第三方日志
{ setFilters(v); setPage(1); }} >
{ setPage(p); setPageSize(ps); }, }} /> setDrawerOpen(false)}> {detail && ( {String(detail.id)} {String(detail.provider)} {String(detail.scene)} {String(detail.status)} {detail.refType ? `${String(detail.refType)}#${String(detail.refId)}` : '—'} {String(detail.externalNo ?? '—')} {detail.amount != null ? String(detail.amount) : '—'} {String(detail.requestUrl ?? '—')} {detail.errorMessage ? ( {String(detail.errorMessage)} ) : ( '—' )} {fmtTime(String(detail.createdAt))} )} ); }