全站汉化 + antd zhCN locale

This commit is contained in:
admin committed 2026-08-07 15:04:19 +08:00
1 parent 2e4594fa77
commit b96323eb99
9 files changed
+134 -136

No files matched your search

+13 -14
View File
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'
import { Row, Col, Card, Statistic, Typography, Table, Tag, Space } from 'antd'
import { VideoCameraOutlined, EyeOutlined, CloudServerOutlined, SignalFilled } from '@ant-design/icons'
import { VideoCameraOutlined, EyeOutlined, SignalFilled } from '@ant-design/icons'
import { fetchStreams, type StreamInfo } from '../../api/streams'
const { Title } = Typography
@@ -25,35 +25,34 @@ export default function Dashboard() {
const liveCount = streams.filter((s) => s.status === 'live').length
const pendingCount = streams.filter((s) => s.status === 'pending').length
const endedCount = streams.filter((s) => s.status === 'ended').length
const statusMap: Record<string, { color: string; label: string }> = {
pending: { color: 'blue', label: 'Pending' },
live: { color: 'green', label: 'Live' },
ended: { color: 'default', label: 'Ended' },
cancelled: { color: 'red', label: 'Cancelled' },
pending: { color: 'blue', label: '待开播' },
live: { color: 'green', label: '直播中' },
ended: { color: 'default', label: '已结束' },
cancelled: { color: 'red', label: '已取消' },
}
const recentColumns = [
{ title: 'Title', dataIndex: 'title', key: 'title', ellipsis: true },
{ title: '标题', dataIndex: 'title', key: 'title', ellipsis: true },
{
title: 'Status', dataIndex: 'status', key: 'status',
title: '状态', dataIndex: 'status', key: 'status',
render: (status: string) => {
const s = statusMap[status] || { color: 'default', label: status }
return <Tag color={s.color}>{s.label}</Tag>
},
},
{ title: 'Created', dataIndex: 'created_at', key: 'created_at', render: (v: string) => v?.slice(0, 16) },
{ title: '创建时间', dataIndex: 'created_at', key: 'created_at', render: (v: string) => v?.slice(0, 16) },
]
return (
<div>
<Title level={3} style={{ marginBottom: 24 }}>Dashboard</Title>
<Title level={3} style={{ marginBottom: 24 }}>概览</Title>
<Row gutter={[24, 24]}>
<Col xs={24} sm={8}>
<Card>
<Statistic
title="Live Streams"
title="直播中"
value={liveCount}
prefix={<SignalFilled style={{ color: '#52c41a' }} />}
loading={loading}
@@ -63,7 +62,7 @@ export default function Dashboard() {
<Col xs={24} sm={8}>
<Card>
<Statistic
title="Pending"
title="待开播"
value={pendingCount}
prefix={<VideoCameraOutlined style={{ color: '#1677ff' }} />}
loading={loading}
@@ -73,7 +72,7 @@ export default function Dashboard() {
<Col xs={24} sm={8}>
<Card>
<Statistic
title="Total Streams"
title="直播总数"
value={streams.length}
prefix={<EyeOutlined />}
loading={loading}
@@ -81,7 +80,7 @@ export default function Dashboard() {
</Card>
</Col>
</Row>
<Card title="Recent Streams" style={{ marginTop: 24 }}>
<Card title="最近直播" style={{ marginTop: 24 }}>
<Table
dataSource={streams.slice(0, 10)}
columns={recentColumns}
+29 -20
View File
@@ -23,6 +23,12 @@ interface StrategyInfo {
multicast_available: boolean
}
const strategyLabels: Record<string, string> = {
'round-robin': '轮询',
'weighted': '权重',
'least-conn': '最少连接',
}
export default function NodeManager() {
const [nodes, setNodes] = useState<NodeInfo[]>([])
const [strategy, setStrategy] = useState<StrategyInfo | null>(null)
@@ -39,15 +45,15 @@ export default function NodeManager() {
])
setNodes(nodesRes.data)
setStrategy(strategyRes.data)
} catch { message.error('Failed to load') }
} catch { message.error('加载失败') }
setLoading(false)
}
async function updateWeight(nodeId: string, weight: number) {
try {
await api.put(`/nodes/${nodeId}`, { weight })
message.success('Updated')
} catch { message.error('Failed') }
message.success('已更新')
} catch { message.error('更新失败') }
}
async function toggleNode(nodeId: string, enabled: boolean) {
@@ -56,17 +62,17 @@ export default function NodeManager() {
try {
await api.put(`/nodes/${nodeId}`, { weight: node.weight, enabled })
setNodes((prev) => prev.map((n) => (n.id === nodeId ? { ...n, enabled } : n)))
message.success('Updated')
} catch { message.error('Failed') }
message.success('已更新')
} catch { message.error('更新失败') }
}
const columns = [
{ title: 'Name', dataIndex: 'name', key: 'name' },
{ title: 'Host', dataIndex: 'host', key: 'host' },
{ title: 'HLS Port', dataIndex: 'hls_port', key: 'hls_port', width: 100 },
{ title: 'API Port', dataIndex: 'api_port', key: 'api_port', width: 100 },
{ title: '名称', dataIndex: 'name', key: 'name' },
{ title: '主机', dataIndex: 'host', key: 'host' },
{ title: 'HLS 端口', dataIndex: 'hls_port', key: 'hls_port', width: 100 },
{ title: 'API 端口', dataIndex: 'api_port', key: 'api_port', width: 100 },
{
title: 'Weight', dataIndex: 'weight', key: 'weight', width: 140,
title: '权重', dataIndex: 'weight', key: 'weight', width: 140,
render: (_: number, record: NodeInfo) => (
<InputNumber
min={0}
@@ -83,7 +89,7 @@ export default function NodeManager() {
),
},
{
title: 'Enabled', dataIndex: 'enabled', key: 'enabled', width: 90,
title: '启用', dataIndex: 'enabled', key: 'enabled', width: 80,
render: (_: any, record: NodeInfo) => (
<Switch
checked={record.enabled}
@@ -93,42 +99,45 @@ export default function NodeManager() {
),
},
{
title: 'Health', key: 'health', width: 100,
render: () => <Tag icon={<CheckCircleOutlined />} color="success">Online</Tag>,
title: '状态', key: 'health', width: 100,
render: () => <Tag icon={<CheckCircleOutlined />} color="success">在线</Tag>,
},
]
return (
<div>
<Title level={3} style={{ marginBottom: 24 }}>Edge Nodes</Title>
<Title level={3} style={{ marginBottom: 24 }}>边缘节点管理</Title>
{strategy && (
<Row gutter={[24, 24]} style={{ marginBottom: 24 }}>
<Col xs={24} sm={8}>
<Card>
<Statistic title="Strategy" value={strategy.strategy} />
<Statistic
title="负载均衡策略"
value={strategyLabels[strategy.strategy] || strategy.strategy}
/>
</Card>
</Col>
<Col xs={24} sm={8}>
<Card>
<Statistic
title="Multicast"
value={strategy.multicast_available ? 'Available' : 'Unavailable'}
title="组播状态"
value={strategy.multicast_available ? '可用' : '不可用'}
valueStyle={{ color: strategy.multicast_available ? '#52c41a' : '#999' }}
/>
</Card>
</Col>
<Col xs={24} sm={8}>
<Card>
<Statistic title="Edge Nodes" value={nodes.length} />
<Statistic title="边缘节点数" value={nodes.length} />
</Card>
</Col>
</Row>
)}
<Card
title="Node List"
extra={<Button icon={<ReloadOutlined />} onClick={loadData}>Refresh</Button>}
title="节点列表"
extra={<Button icon={<ReloadOutlined />} onClick={loadData}>刷新</Button>}
>
<Table
dataSource={nodes}
+17 -17
View File
@@ -7,9 +7,9 @@ import api from '../../api/client'
const { Title } = Typography
const strategies = [
{ value: 'round-robin', label: 'Round Robin' },
{ value: 'weighted', label: 'Weighted' },
{ value: 'least-conn', label: 'Least Connections' },
{ value: 'round-robin', label: '轮询 (Round-Robin)' },
{ value: 'weighted', label: '权重 (Weighted)' },
{ value: 'least-conn', label: '最少连接 (Least Connections)' },
]
export default function SettingsPage() {
@@ -36,8 +36,8 @@ export default function SettingsPage() {
try {
await api.put(`/nodes/strategy?strategy=${val}&multicast_enabled=${multicastEnabled}`)
setStrategy(val)
message.success('Strategy updated')
} catch { message.error('Failed') }
message.success('策略已更新')
} catch { message.error('更新失败') }
setSaving(false)
}
@@ -45,36 +45,36 @@ export default function SettingsPage() {
setMulticastEnabled(val)
try {
await api.put(`/nodes/strategy?strategy=${strategy}&multicast_enabled=${val}`)
message.success('Multicast setting updated')
} catch { message.error('Failed') }
message.success('组播设置已更新')
} catch { message.error('更新失败') }
}
return (
<div style={{ maxWidth: 720 }}>
<Title level={3} style={{ marginBottom: 24 }}>Settings</Title>
<Title level={3} style={{ marginBottom: 24 }}>系统设置</Title>
<Card title="Load Balancing" style={{ marginBottom: 24 }}>
<Descriptions column={1} labelStyle={{ width: 180 }}>
<Descriptions.Item label="Strategy">
<Card title="负载均衡" style={{ marginBottom: 24 }}>
<Descriptions column={1} labelStyle={{ width: 140 }}>
<Descriptions.Item label="均衡策略">
<Select
value={strategy}
onChange={saveStrategy}
options={strategies}
loading={saving}
style={{ width: 240 }}
style={{ width: 280 }}
/>
</Descriptions.Item>
</Descriptions>
</Card>
<Card title="Multicast">
<Descriptions column={1} labelStyle={{ width: 180 }}>
<Descriptions.Item label="Enable Multicast">
<Card title="组播设置">
<Descriptions column={1} labelStyle={{ width: 140 }}>
<Descriptions.Item label="启用组播">
<Switch checked={multicastEnabled} onChange={toggleMulticast} />
</Descriptions.Item>
<Descriptions.Item label="Network Status">
<Descriptions.Item label="网络状态">
<span style={{ color: multicastAvailable ? '#52c41a' : '#999' }}>
{multicastAvailable ? 'Available' : 'Unavailable (fallback to unicast)'}
{multicastAvailable ? '可用 — 优先使用组播分发' : '不可用 — 回退至单播'}
</span>
</Descriptions.Item>
</Descriptions>
+22 -22
View File
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import {
Card, Form, Input, Button, DatePicker, Typography, message, Space, Alert, Divider,
Card, Form, Input, Button, DatePicker, Typography, message, Space, Alert,
} from 'antd'
import { CopyOutlined, ArrowLeftOutlined } from '@ant-design/icons'
import { createStream } from '../../api/streams'
@@ -24,9 +24,9 @@ export default function StreamForm() {
scheduled_at: values.scheduled_at?.toISOString(),
})
setResult({ rtmp_url: res.rtmp_url, stream_key: res.stream_key })
message.success('Stream created')
message.success('直播已创建')
} catch {
message.error('Failed to create stream')
message.error('创建失败')
}
setLoading(false)
}
@@ -34,14 +34,14 @@ export default function StreamForm() {
if (result) {
return (
<div style={{ maxWidth: 640 }}>
<Title level={3} style={{ marginBottom: 24 }}>Stream Created</Title>
<Title level={3} style={{ marginBottom: 24 }}>直播已创建</Title>
<Alert
type="success"
message="Your stream is ready"
message="推流信息已生成"
description={
<Space direction="vertical" size="middle" style={{ width: '100%' }}>
<div>
<Text strong>Stream Key (UUID):</Text>
<Text strong>推流码 (UUID):</Text>
<div style={{
marginTop: 8, padding: 12,
background: '#F5F2EE', borderRadius: 6,
@@ -52,7 +52,7 @@ export default function StreamForm() {
</div>
</div>
<div>
<Text strong>RTMP Push URL:</Text>
<Text strong>RTMP 推流地址:</Text>
<div style={{
marginTop: 8, padding: 12,
background: '#F5F2EE', borderRadius: 6,
@@ -72,15 +72,15 @@ export default function StreamForm() {
icon={<CopyOutlined />}
onClick={() => {
navigator.clipboard.writeText(
`Stream Key: ${result.stream_key}\nRTMP URL: ${result.rtmp_url}`
`推流码: ${result.stream_key}\nRTMP 地址: ${result.rtmp_url}`
)
message.success('Copied to clipboard')
message.success('已复制到剪贴板')
}}
>
Copy All
复制全部
</Button>
<Button type="primary" onClick={() => navigate('/admin/streams')}>
Back to Streams
返回列表
</Button>
</Space>
</div>
@@ -95,30 +95,30 @@ export default function StreamForm() {
onClick={() => navigate('/admin/streams')}
style={{ marginBottom: 16 }}
>
Back
返回
</Button>
<Card>
<Title level={3} style={{ marginBottom: 24 }}>New Stream</Title>
<Title level={3} style={{ marginBottom: 24 }}>创建直播</Title>
<Form layout="vertical" onFinish={handleSubmit}>
<Form.Item
name="title"
label="Title"
rules={[{ required: true, message: 'Enter a title' }]}
label="直播标题"
rules={[{ required: true, message: '请输入直播标题' }]}
>
<Input placeholder="Stream title" size="large" />
<Input placeholder="输入直播标题" size="large" />
</Form.Item>
<Form.Item name="description" label="Description">
<TextArea rows={3} placeholder="Stream description (optional)" />
<Form.Item name="description" label="直播简介">
<TextArea rows={3} placeholder="可选,直播内容简介" />
</Form.Item>
<Form.Item name="cover_url" label="Cover Image URL">
<Form.Item name="cover_url" label="封面图片地址">
<Input placeholder="https://..." />
</Form.Item>
<Form.Item name="scheduled_at" label="Scheduled Time">
<DatePicker showTime style={{ width: '100%' }} size="large" />
<Form.Item name="scheduled_at" label="预定开播时间">
<DatePicker showTime style={{ width: '100%' }} size="large" placeholder="选择预定时间" />
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" loading={loading} size="large" block>
Create Stream
创建直播
</Button>
</Form.Item>
</Form>
+23 -23
View File
@@ -9,10 +9,10 @@ import { fetchStreams, deleteStream, goLive, endStream, type StreamInfo } from '
const { Title, Text } = Typography
const statusMap: Record<string, { color: string; label: string }> = {
pending: { color: 'blue', label: 'Pending' },
live: { color: 'green', label: 'Live' },
ended: { color: 'default', label: 'Ended' },
cancelled: { color: 'red', label: 'Cancelled' },
pending: { color: 'blue', label: '待开播' },
live: { color: 'green', label: '直播中' },
ended: { color: 'default', label: '已结束' },
cancelled: { color: 'red', label: '已取消' },
}
export default function StreamList() {
@@ -27,47 +27,47 @@ export default function StreamList() {
try {
const data = await fetchStreams()
setStreams(data)
} catch { message.error('Failed to load streams') }
} catch { message.error('加载失败') }
setLoading(false)
}
async function handleDelete(id: number) {
try {
await deleteStream(id)
message.success('Stream deleted')
message.success('已删除')
loadData()
} catch { message.error('Delete failed') }
} catch { message.error('删除失败') }
}
async function handleGoLive(id: number) {
try {
await goLive(id)
message.success('Stream is now live')
message.success('已设置为直播中')
loadData()
} catch { message.error('Failed to set live') }
} catch { message.error('操作失败') }
}
async function handleEnd(id: number) {
try {
await endStream(id)
message.success('Stream ended')
message.success('已结束直播')
loadData()
} catch { message.error('Failed to end') }
} catch { message.error('操作失败') }
}
const columns = [
{ title: 'ID', dataIndex: 'id', key: 'id', width: 80 },
{ title: 'Title', dataIndex: 'title', key: 'title', ellipsis: true },
{ title: '标题', dataIndex: 'title', key: 'title', ellipsis: true },
{
title: 'Status', dataIndex: 'status', key: 'status', width: 110,
title: '状态', dataIndex: 'status', key: 'status', width: 100,
render: (s: string) => {
const info = statusMap[s] || { color: 'default', label: s }
return <Tag color={info.color}>{info.label}</Tag>
},
},
{ title: 'Created', dataIndex: 'created_at', key: 'created_at', render: (v: string) => v?.slice(0, 16), width: 170 },
{ title: '创建时间', dataIndex: 'created_at', key: 'created_at', render: (v: string) => v?.slice(0, 16), width: 170 },
{
title: 'Actions', key: 'actions', width: 280,
title: '操作', key: 'actions', width: 280,
render: (_: any, record: StreamInfo) => (
<Space size="small">
<Button
@@ -75,26 +75,26 @@ export default function StreamList() {
icon={<LinkOutlined />}
onClick={() => {
navigator.clipboard.writeText(record.stream_key)
message.success('Stream key copied')
message.success('推流码已复制')
}}
>
Copy Key
复制推流码
</Button>
{record.status !== 'live' ? (
<Tooltip title="Mark as live">
<Tooltip title="切换为直播中">
<Button size="small" type="primary" icon={<PlayCircleOutlined />}
onClick={() => handleGoLive(record.id)} ghost />
</Tooltip>
) : (
<Tooltip title="End stream">
<Tooltip title="结束直播">
<Button size="small" icon={<StopOutlined />}
onClick={() => handleEnd(record.id)} danger />
</Tooltip>
)}
<Button size="small" onClick={() => window.open(`/watch/${record.id}`, '_blank')}>
Watch
观看
</Button>
<Popconfirm title="Delete this stream?" onConfirm={() => handleDelete(record.id)}>
<Popconfirm title="确定删除这条直播?" onConfirm={() => handleDelete(record.id)}>
<Button size="small" icon={<DeleteOutlined />} danger />
</Popconfirm>
</Space>
@@ -105,9 +105,9 @@ export default function StreamList() {
return (
<div>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
<Title level={3} style={{ margin: 0 }}>Streams</Title>
<Title level={3} style={{ margin: 0 }}>直播列表</Title>
<Button type="primary" icon={<PlusOutlined />} onClick={() => navigate('/admin/streams/new')}>
New Stream
创建直播
</Button>
</div>
<Table