import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { Card, Table, Button, Tag, Space, Input, Typography, Modal, Form, Row, Col, Statistic, message, } from 'antd'; import { PlusOutlined, SearchOutlined, FolderOpenOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined, } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; import type { CaseRecord, CaseStatus } from '../../types'; import { fetchCases, createCase } from '../../services/api'; const statusConfig: Record = { pending: { color: 'default', label: '待处理' }, uploading: { color: 'processing', label: '上传中' }, analyzing: { color: 'blue', label: '分析中' }, reviewing: { color: 'orange', label: '待复核' }, completed: { color: 'green', label: '已完成' }, }; const CaseList: React.FC = () => { const navigate = useNavigate(); const qc = useQueryClient(); const [createOpen, setCreateOpen] = useState(false); const [form] = Form.useForm(); const [search, setSearch] = useState(''); const { data, isLoading } = useQuery({ queryKey: ['cases', search], queryFn: () => fetchCases({ search: search || undefined }), }); const cases = data?.items ?? []; const createMutation = useMutation({ mutationFn: createCase, onSuccess: () => { message.success('案件创建成功'); qc.invalidateQueries({ queryKey: ['cases'] }); setCreateOpen(false); form.resetFields(); }, }); const totalCases = cases.length; const pendingReview = cases.filter((c) => c.status === 'reviewing').length; const completedCount = cases.filter((c) => c.status === 'completed').length; const analyzingCount = cases.filter( (c) => c.status === 'analyzing' || c.status === 'uploading', ).length; const columns: ColumnsType = [ { title: '案件编号', dataIndex: 'caseNo', width: 180, render: (text, record) => ( navigate(`/cases/${record.id}/workspace`)}>{text} ), }, { title: '案件名称', dataIndex: 'title', ellipsis: true }, { title: '受害人', dataIndex: 'victimName', width: 100 }, { title: '承办人', dataIndex: 'handler', width: 100 }, { title: '状态', dataIndex: 'status', width: 100, render: (s: CaseStatus) => ( {statusConfig[s].label} ), }, { title: '截图数', dataIndex: 'imageCount', width: 80, align: 'center', }, { title: '识别金额(元)', dataIndex: 'totalAmount', width: 140, align: 'right', render: (v: number) => v > 0 ? ( ¥{v.toLocaleString('zh-CN', { minimumFractionDigits: 2 })} ) : ( - ), }, { title: '更新时间', dataIndex: 'updatedAt', width: 170, }, { title: '操作', width: 160, render: (_, record) => ( ), }, ]; return (
} /> } valueStyle={{ color: '#1677ff' }} /> } valueStyle={{ color: '#fa8c16' }} /> } valueStyle={{ color: '#52c41a' }} /> } style={{ width: 240 }} allowClear onPressEnter={(e) => setSearch((e.target as HTMLInputElement).value)} onChange={(e) => !e.target.value && setSearch('')} /> } > `共 ${t} 条` }} /> setCreateOpen(false)} onOk={() => { form.validateFields().then((values) => createMutation.mutate(values)); }} confirmLoading={createMutation.isPending} okText="创建" cancelText="取消" destroyOnClose >
); }; export default CaseList;