import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { Table, Button, Tag, Space, Typography, message, Tooltip, Popconfirm } from 'antd' import { PlusOutlined, PlayCircleOutlined, StopOutlined, DeleteOutlined, LinkOutlined, EyeOutlined, EditOutlined } from '@ant-design/icons' import { fetchStreams, deleteStream, goLive, endStream, type StreamInfo } from '../../api/streams' const { Title, Text } = Typography const statusMap: Record = { pending: { color: 'blue', label: '待开播' }, live: { color: 'green', label: '直播中' }, ended: { color: 'default', label: '已结束' }, cancelled: { color: 'red', label: '已取消' }, } export default function StreamList() { const [streams, setStreams] = useState([]) const [loading, setLoading] = useState(true) const navigate = useNavigate() useEffect(() => { loadData() }, []) async function loadData() { setLoading(true) try { setStreams(await fetchStreams(true)) } catch { message.error('加载失败') } setLoading(false) } async function handleDelete(id: number) { try { await deleteStream(id); message.success('已删除'); loadData() } catch { message.error('删除失败') } } async function handleGoLive(id: number) { try { await goLive(id); message.success('已开播'); loadData() } catch { message.error('操作失败') } } async function handleEnd(id: number) { try { await endStream(id); message.success('已结束'); loadData() } catch { message.error('操作失败') } } const columns = [ { title: 'ID', dataIndex: 'id', key: 'id', width: 60 }, { title: '标题', dataIndex: 'title', key: 'title', ellipsis: true }, { title: '状态', dataIndex: 'status', key: 'status', width: 90, render: (s: string) => {(statusMap[s] || { label: s }).label} }, { title: '推流码', dataIndex: 'stream_key', key: 'stream_key', width: 120, render: (v: string) => {v.slice(0, 12)}... }, { title: '创建时间', dataIndex: 'created_at', key: 'created_at', render: (v: string) => v?.slice(0, 16), width: 160 }, { title: '操作', key: 'actions', width: 240, render: (_: any, r: StreamInfo) => (
) }