import { useEffect, useState } from 'react'; import { Button, Descriptions, Drawer, Form, Input, Segmented, Space, Table, Tag, Typography } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import { useSearchParams } from 'react-router-dom'; import { PARTNER_LOG_CATEGORY_OPTIONS, PARTNER_STAFF_ROLE_LABELS, type PartnerLogCategory, type PartnerStaffRole, } from '@dukang/shared-types'; import { request } from '../lib/api'; import { AdminCellLine } from '../components/AdminCellLine'; import { fmtTime } from '../lib/constants'; import { clientAppLabel, eventNameLabel, formatRef, partnerEventCategoryLabel } 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; partnerId: string; partnerAccountId: string | null; accountName: string | null; accountPhone: string | null; companyName: string | null; isSubAccount?: boolean; staffRole?: string | null; category: PartnerLogCategory | null; eventName: string; clientApp: string | null; refType: string | null; refId: string | null; extraJson: Record | null; createdAt: string; }; function summarizeExtra(json: Record | null) { if (!json) return '—'; const text = JSON.stringify(json); return text.length > 80 ? `${text.slice(0, 80)}…` : text; } export default function PartnerLogsPage() { const [searchParams, setSearchParams] = useSearchParams(); const [form] = Form.useForm(); const [category, setCategory] = useState(searchParams.get('category') ?? ''); const [filters, setFilters] = useState>(() => ({ partnerId: searchParams.get('partnerId') ?? '', partnerAccountId: searchParams.get('partnerAccountId') ?? '', phone: searchParams.get('phone') ?? '', companyName: searchParams.get('companyName') ?? '', eventName: searchParams.get('eventName') ?? '', })); const { data, loading, page, pageSize, setPage, setPageSize } = useAdminList( '/admin/logs/partners', () => { const qs = new URLSearchParams(); if (filters.partnerId) qs.set('partnerId', filters.partnerId); if (filters.partnerAccountId) qs.set('partnerAccountId', filters.partnerAccountId); if (filters.phone) qs.set('phone', filters.phone); if (filters.companyName) qs.set('companyName', filters.companyName); if (filters.eventName) qs.set('eventName', filters.eventName); if (category) qs.set('category', category); return qs; }, [filters, category], ); const [detail, setDetail] = useState | null>(null); const [drawerOpen, setDrawerOpen] = useState(false); useEffect(() => { form.setFieldsValue(filters); }, [form, filters]); const baseColumns: ColumnsType = [ { title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime }, { title: '合伙人', width: 180, render: (_, r) => ( r.isSubAccount ? ( 子账号 ) : ( ) ), }, { title: '账号', width: 150, render: (_, r) => ( ), }, { title: '分类', dataIndex: 'category', width: 100, render: (v: PartnerLogCategory | null, r) => ( {partnerEventCategoryLabel(r.eventName, v)} ), }, { title: '事件', dataIndex: 'eventName', width: 180, render: (v, row) => ( { setDetail(await request(`/admin/logs/partners/${row.id}`)); setDrawerOpen(true); }} > {eventNameLabel(v)} ), }, { title: '关联', width: 120, render: (_, r) => formatRef(r.refType, r.refId), }, { title: '摘要', render: (_, r) => summarizeExtra(r.extraJson), }, { title: '操作', width: 80, render: (_, row) => ( ), }, ]; const { columns, settingsButton, settingsModal } = useAdminListColumns('logs-partners', baseColumns, { page, pageSize }); return (
{settingsModal} ({ value: o.value, label: o.label }))} value={category} onChange={(v) => { setCategory(String(v)); setPage(1); setSearchParams((prev) => { const next = new URLSearchParams(prev); if (v) next.set('category', String(v)); else next.delete('category'); return next; }); }} style={{ marginBottom: 16 }} />
{ setFilters(values); setPage(1); }} >
{ setPage(p); setPageSize(ps); }, }} scroll={{ x: 'max-content' }} /> setDrawerOpen(false)} width={520}> {detail && ( {String(detail.id ?? '—')} {String(detail.companyName || detail.partnerId || '—')} {String(detail.accountName || detail.accountPhone || '—')} {partnerEventCategoryLabel(String(detail.eventName ?? ''), detail.category ? String(detail.category) : null)} {eventNameLabel(String(detail.eventName ?? ''))} {clientAppLabel(detail.clientApp ? String(detail.clientApp) : null)} {formatRef(detail.refType ? String(detail.refType) : null, detail.refId ? String(detail.refId) : null)} {fmtTime(detail.createdAt ? String(detail.createdAt) : null)}
                {JSON.stringify(detail.extraJson ?? {}, null, 2)}
              
)}
); }