import { useEffect, useState } from 'react'; import { Button, Descriptions, Drawer, Form, Input, Select, Space, Table, Tag, Typography, } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import { useSearchParams } from 'react-router-dom'; import { request } from '../lib/api'; import { fmtTime } from '../lib/constants'; import { HQ_OPERATION_ACTION_OPTIONS, resolveHqOperationLabel } from '../lib/hq-log'; import { useAdminList } from '../lib/useAdminList'; type Row = { id: string; hqAccountId: string | null; hqName: string | null; hqPhone: string | null; hqRole: string | null; action: string | null; actionLabel: string; refType: string | null; refId: string | null; status: string | null; remark: string | null; detail: Record | null; createdAt: string; }; export default function HqLogsPage() { const [searchParams, setSearchParams] = useSearchParams(); const [form] = Form.useForm(); const [filters, setFilters] = useState>(() => ({ hqAccountId: searchParams.get('hqAccountId') ?? '', action: searchParams.get('action') ?? '', refType: searchParams.get('refType') ?? '', })); const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList( '/admin/logs/hq', () => { const qs = new URLSearchParams(); if (filters.hqAccountId) qs.set('hqAccountId', filters.hqAccountId); if (filters.action) qs.set('action', filters.action); if (filters.refType) qs.set('refType', filters.refType); return qs; }, [filters], ); const [detail, setDetail] = useState(null); const [drawerOpen, setDrawerOpen] = useState(false); useEffect(() => { form.setFieldsValue(filters); }, [form, filters]); const columns: ColumnsType = [ { title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime }, { title: '操作人', width: 160, render: (_, r) => (
{r.hqName || '—'}
{r.hqPhone || ''} {r.hqAccountId ? `(#${r.hqAccountId})` : ''}
), }, { title: '行为', dataIndex: 'actionLabel', width: 160, render: (v, r) => {v || resolveHqOperationLabel(r.action)}, }, { title: '对象类型', dataIndex: 'refType', width: 120, render: (v) => v || '—' }, { title: '对象 ID', dataIndex: 'refId', width: 100, render: (v) => v || '—' }, { title: '操作', width: 80, render: (_, row) => ( ), }, ]; return (
HQ 操作日志 记录总部后台写操作(开城、订单、用户、权限、合伙人等),仅追加不删除。
{ setFilters(values); setPage(1); const qs = new URLSearchParams(); if (values.hqAccountId) qs.set('hqAccountId', values.hqAccountId); if (values.action) qs.set('action', values.action); if (values.refType) qs.set('refType', values.refType); setSearchParams(qs); }} >
{ setPage(p); setPageSize(ps); }, }} /> setDrawerOpen(false)}> {detail && ( <> {detail.id} {fmtTime(detail.createdAt)} {detail.hqName} / {detail.hqPhone} (ID: {detail.hqAccountId}) {detail.hqRole || '—'} {detail.actionLabel || resolveHqOperationLabel(detail.action)} {detail.refType} / {detail.refId} {detail.status || '—'} {detail.remark || '—'} 请求/响应快照
              {JSON.stringify(detail.detail, null, 2)}
            
)}
); }