"use client" import { useState, useEffect } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent } from "@/components/ui/card" import { Checkbox } from "@/components/ui/checkbox" import { Input } from "@/components/ui/input" import { ScrollArea } from "@/components/ui/scroll-area" import { Search, Smartphone, CheckCircle2, Circle } from "lucide-react" import { cn } from "@/lib/utils" interface Device { id: string name: string status: "online" | "offline" | "busy" type: string lastActive?: string } interface DeviceSelectorProps { selectedDevices: string[] onDevicesChange: (deviceIds: string[]) => void showNextButton?: boolean onNext?: () => void onPrevious?: () => void className?: string } export function DeviceSelector({ selectedDevices, onDevicesChange, showNextButton = false, onNext, onPrevious, className, }: DeviceSelectorProps) { const [devices, setDevices] = useState([]) const [searchTerm, setSearchTerm] = useState("") const [loading, setLoading] = useState(true) useEffect(() => { // 模拟加载设备数据 setTimeout(() => { setDevices([ { id: "1", name: "设备 001", status: "online", type: "Android" }, { id: "2", name: "设备 002", status: "online", type: "iOS" }, { id: "3", name: "设备 003", status: "offline", type: "Android" }, { id: "4", name: "设备 004", status: "busy", type: "Android" }, { id: "5", name: "设备 005", status: "online", type: "iOS" }, ]) setLoading(false) }, 500) }, []) const filteredDevices = devices.filter((device) => device.name.toLowerCase().includes(searchTerm.toLowerCase())) const handleSelectAll = () => { const allOnlineDeviceIds = filteredDevices.filter((d) => d.status === "online").map((d) => d.id) onDevicesChange(allOnlineDeviceIds) } const handleClearAll = () => { onDevicesChange([]) } const handleToggleDevice = (deviceId: string) => { if (selectedDevices.includes(deviceId)) { onDevicesChange(selectedDevices.filter((id) => id !== deviceId)) } else { onDevicesChange([...selectedDevices, deviceId]) } } const getStatusColor = (status: string) => { switch (status) { case "online": return "text-green-500" case "offline": return "text-gray-400" case "busy": return "text-yellow-500" default: return "text-gray-400" } } const getStatusText = (status: string) => { switch (status) { case "online": return "在线" case "offline": return "离线" case "busy": return "忙碌" default: return "未知" } } if (loading) { return (
加载设备中...
) } return (
setSearchTerm(e.target.value)} className="pl-10" />
已选择 {selectedDevices.length} 个设备
{filteredDevices.map((device) => ( device.status === "online" && handleToggleDevice(device.id)} >
handleToggleDevice(device.id)} onClick={(e) => e.stopPropagation()} />
{device.name}
{device.type}
{device.status === "online" ? : } {getStatusText(device.status)}
))}
{showNextButton && (
{onPrevious && ( )}
)}
) } export default DeviceSelector