import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { Table, Button, Tag, Space, Modal, Typography, message, Tooltip, Popconfirm, } from 'antd' import { PlusOutlined, PlayCircleOutlined, StopOutlined, DeleteOutlined, LinkOutlined } 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 { const data = await fetchStreams() setStreams(data) } 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: 80 }, { title: '标题', dataIndex: 'title', key: 'title', ellipsis: true }, { title: '状态', dataIndex: 'status', key: 'status', width: 100, render: (s: string) => { const info = statusMap[s] || { color: 'default', label: s } return {info.label} }, }, { title: '创建时间', dataIndex: 'created_at', key: 'created_at', render: (v: string) => v?.slice(0, 16), width: 170 }, { title: '操作', key: 'actions', width: 280, render: (_: any, record: StreamInfo) => ( {record.status !== 'live' ? ( handleDelete(record.id)}> ) }