Files
web-Iot/src/pages/Video.tsx
2026-08-14 09:02:52 +08:00

209 lines
8.1 KiB
TypeScript

import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
Row,
Col,
Card,
Button,
Tag,
Typography,
Space,
Tooltip,
List,
Avatar,
Select,
Divider,
} from 'antd';
import {
CaretUpOutlined,
CaretDownOutlined,
CaretLeftOutlined,
CaretRightOutlined,
FullscreenOutlined,
ReloadOutlined,
MonitorOutlined,
VideoCameraOutlined,
ThunderboltOutlined,
CustomerServiceOutlined,
AlertOutlined,
EyeOutlined
} from '@ant-design/icons';
const { Text, Title } = Typography;
function cn(...classes: string[]) {
return classes.filter(Boolean).join(' ');
}
export default function VideoControl() {
const { t } = useTranslation();
const [selectedDevice, setSelectedDevice] = useState(DEVICES[0]);
const onlineDevices = DEVICES.filter(d => d.status === 'online' || d.status === 'alert');
const getVideoConfig = (type: string) => {
switch (type) {
case '安防型':
return {
count: 4,
labels: [t('video.labelMainFront'), t('video.labelRear'), t('video.labelLeft'), t('video.labelRight')],
gridClass: 'grid-cols-2 grid-rows-2'
};
case '运输型':
return {
count: 5,
labels: [t('video.labelFrontDrive'), t('video.labelRearMount'), t('video.labelLeftWing'), t('video.labelRightWing'), t('video.labelCargo')],
gridClass: 'grid-cols-4 grid-rows-2'
};
case '巡检型':
default:
return {
count: 3,
labels: [t('video.labelMainProbe'), t('video.labelPanorama'), t('video.labelDetail')],
gridClass: 'grid-cols-2 grid-rows-2'
};
}
};
const config = getVideoConfig(selectedDevice.type);
return (
<Row gutter={16} className="h-full overflow-hidden" style={{ minHeight: 0 }}>
{/* Video Content */}
<Col flex="auto" className="h-full flex flex-col gap-4 overflow-hidden">
{/* Top Control Bar */}
<div className="flex items-center justify-between bg-white p-3 rounded shadow-sm border border-gray-100">
<Space size="large">
<div className="flex flex-col">
<Text type="secondary" style={{ fontSize: 10, textTransform: 'uppercase', letterSpacing: 1 }}>{t('video.currentDutyDevice')}</Text>
<Select
value={selectedDevice.id}
onChange={(id) => setSelectedDevice(onlineDevices.find(d => d.id === id)!)}
style={{ width: 220, fontWeight: 'bold' }}
variant={false}
options={onlineDevices.map(d => ({ label: d.name, value: d.id }))}
suffixIcon={<VideoCameraOutlined style={{ color: '#1890ff' }} />}
/>
</div>
<Divider type="vertical" style={{ height: 32 }} />
<div className="flex flex-col">
<Text type="secondary" style={{ fontSize: 10, textTransform: 'uppercase', letterSpacing: 1 }}>{t('video.videoStreamChannels')}</Text>
<Tag color="processing" style={{ marginTop: 2, fontWeight: 'bold', fontFamily: 'monospace' }}>
{config.count} CHANNELS ACTIVE
</Tag>
</div>
</Space>
<Space>
<Button size="small" icon={<ReloadOutlined />}>{t('video.refreshSignal')}</Button>
<Button size="small" type="primary" ghost>{t('video.fullScreenWall')}</Button>
</Space>
</div>
{/* Multi-Video Grid */}
<div className={cn(
"bg-black rounded border border-gray-800 p-1 gap-1 flex-1 overflow-hidden grid",
config.gridClass
)}>
{Array.from({ length: config.count }).map((_, idx) => (
<div
key={idx}
className={cn(
"relative bg-gray-900 overflow-hidden flex items-center justify-center group border border-white/5",
config.count === 3 && idx === 0 && "col-span-2",
config.count === 5 && idx === 0 && "col-span-2 row-span-2"
)}
>
<img
src={`https://picsum.photos/seed/${selectedDevice.id}_cam${idx}/640/360`}
alt={`Camera ${idx}`}
className="w-full h-full object-cover opacity-60 group-hover:opacity-100 transition-opacity"
/>
<div className="absolute top-2 left-2 bg-black/60 text-white px-2 py-0.5 text-[10px] rounded-sm backdrop-blur-sm flex items-center gap-2 border border-white/10 uppercase font-mono">
<div className="w-1.5 h-1.5 rounded-full bg-red-500 animate-pulse shadow-[0_0_8px_rgba(239,68,68,0.8)]" />
CAM-0{idx + 1} | {config.labels[idx]}
</div>
<div className="absolute inset-0 bg-blue-500/10 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center pointer-events-none">
<Button shape="circle" icon={<FullscreenOutlined />} className="pointer-events-auto shadow-2xl" />
</div>
</div>
))}
</div>
{/* Console Controls */}
<Card size="small" styles={{ body: { padding: 12 } }}>
<Row gutter={16} align="middle">
<Col flex="0 0 160px" style={{ borderRight: '1px solid #f0f0f0', paddingRight: 24 }}>
<Text strong type="secondary" style={{ fontSize: 10, textTransform: 'uppercase', display: 'block', textAlign: 'center', marginBottom: 8 }}>{t('video.ptzServoControl')}</Text>
<div className="flex flex-col items-center gap-1">
<Button type="text" size="small" icon={<CaretUpOutlined />} />
<Space>
<Button type="text" size="small" icon={<CaretLeftOutlined />} />
<div className="w-4 h-4 rounded-full bg-blue-500 shadow-[0_0_8px_rgba(24,144,255,0.8)]" />
<Button type="text" size="small" icon={<CaretRightOutlined />} />
</Space>
<Button type="text" size="small" icon={<CaretDownOutlined />} />
</div>
</Col>
<Col flex="auto">
<div className="flex items-center justify-between mb-4">
<Text strong type="secondary" style={{ fontSize: 10, textTransform: 'uppercase' }}>{t('video.systemIntegratedCommand', { type: selectedDevice.type })}</Text>
<Tag color="success" variant={false} style={{ fontSize: 10, fontWeight: 'bold' }}>SIGNAL: 100% EXCELLENT</Tag>
</div>
<Space className="w-full" size="middle">
<Button icon={<CustomerServiceOutlined />} style={{ borderRadius: 2 }} block>{t('video.twoWayIntercom')}</Button>
<Button danger icon={<AlertOutlined />} style={{ borderRadius: 2 }} block>{t('video.triggerRemoteRepellent')}</Button>
<Button type="primary" icon={<EyeOutlined />} style={{ borderRadius: 2 }} block>{t('video.aiVisualTracking')}</Button>
</Space>
</Col>
</Row>
</Card>
</Col>
{/* Sidebar Channels */}
<Col flex="0 0 260px" className="h-full">
<Card
title={<Space><MonitorOutlined /><Text strong style={{ fontSize: 13 }}>{t('video.activeVideoStreams', { count: onlineDevices.length })}</Text></Space>}
extra={<Button type="text" size="small" icon={<ReloadOutlined />} />}
styles={{ body: { padding: 0 } }}
className="h-full flex flex-col overflow-hidden"
>
<div className="flex-1 overflow-y-auto">
<List
dataSource={onlineDevices}
renderItem={(device) => (
<List.Item
onClick={() => setSelectedDevice(device)}
className={cn(
"px-4 py-3 cursor-pointer transition-colors border-b last:border-0",
selectedDevice.id === device.id ? "bg-blue-50 border-l-4 border-l-blue-500" : "hover:bg-gray-50 border-l-4 border-l-transparent"
)}
>
<List.Item.Meta
avatar={
<div className={cn("w-12 h-12 rounded overflow-hidden border", selectedDevice.id === device.id ? "border-blue-300" : "border-gray-200")}>
<img src={`https://picsum.photos/seed/${device.id}/80/80`} className="w-full h-full object-cover" />
</div>
}
title={
<Text strong style={{ fontSize: 13, color: selectedDevice.id === device.id ? '#1890ff' : 'inherit' }}>
{device.name}
</Text>
}
description={
<Space size={4} style={{ fontSize: 10 }}>
<Text type="secondary" style={{ fontFamily: 'monospace' }}>{device.id}</Text>
<div className={cn("w-2 h-2 rounded-full", device.status === 'alert' ? "bg-red-500" : "bg-green-500")} />
<Text type="secondary" italic>{device.type}</Text>
</Space>
}
/>
</List.Item>
)}
/>
</div>
</Card>
</Col>
</Row>
);
}