import * as React from 'react' import { AppDataTable, type AppDataTableColumn } from '@/components/app/AppDataTable' import { AppEmptyState } from '@/components/app/AppEmptyState' import { AppFilterBar } from '@/components/app/AppFilterBar' import { AppPageHeader } from '@/components/app/AppPageHeader' import { AppPriorityBadge } from '@/components/app/AppPriorityBadge' import { AppStatusBadge } from '@/components/app/AppStatusBadge' import { Button } from '@/components/ui/button' import { Card, CardContent } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { formatDateTime } from '@/lib/format' import { listTickets } from './api' import type { Ticket } from './types' const columns: AppDataTableColumn[] = [ { key: 'ticket_no', header: '编号', cell: (ticket) => {ticket.ticket_no} }, { key: 'title', header: '标题', cell: (ticket) => {ticket.title} }, { key: 'status', header: '状态', cell: (ticket) => }, { key: 'priority', header: '优先级', cell: (ticket) => }, { key: 'related_system', header: '关联系统', cell: (ticket) => {ticket.related_system || '-'} }, { key: 'impact_scope', header: '影响范围', cell: (ticket) => {ticket.impact_scope || '-'} }, { key: 'created_at', header: '创建时间', cell: (ticket) => {formatDateTime(ticket.created_at)} }, { key: 'actions', header: '操作', cell: (ticket) => ( ) } ] export function TicketListPage() { const [tickets, setTickets] = React.useState([]) const [status, setStatus] = React.useState('all') const [priority, setPriority] = React.useState('all') const [q, setQ] = React.useState('') const [error, setError] = React.useState('') React.useEffect(() => { listTickets({ status: status === 'all' ? '' : status, q }) .then(setTickets) .catch((reason: unknown) => setError(reason instanceof Error ? reason.message : '加载失败')) }, [status, q]) const visibleTickets = priority === 'all' ? tickets : tickets.filter((ticket) => ticket.priority === priority) const metrics = [ { label: '待处理', value: tickets.filter((ticket) => ticket.status === 'pending').length }, { label: '处理中', value: tickets.filter((ticket) => ticket.status === 'in_progress').length }, { label: '待确认', value: tickets.filter((ticket) => ticket.status === 'pending_confirm').length }, { label: '已解决', value: tickets.filter((ticket) => ticket.status === 'resolved' || ticket.status === 'closed').length } ] function resetFilters() { setStatus('all') setPriority('all') setQ('') } return (
(window.location.hash = '/tickets/new')}>新建工单} />
{metrics.map((metric) => (

{metric.label}

{metric.value}

))}
重置筛选}> setQ(event.target.value)} placeholder="搜索工单编号或标题" value={q} /> {error ? : null} {!error ? ( ticket.id} emptyTitle="暂无工单" emptyDescription="创建第一张工单后,列表会显示在这里。" footer={

当前显示 {visibleTickets.length} 条工单

} onRowClick={(ticket) => (window.location.hash = `/tickets/${ticket.id}`)} /> ) : null}
) }