import { useState } from 'react'; import { Device } from './InventoryManagement'; interface DeviceListProps { devices: Device[]; onUpdateDevice: (device: Device) => void; onDeleteDevice: (id: string) => void; showAlert: (message: string, type: 'success' | 'error' | 'warning') => void; } export default function DeviceList({ devices, onUpdateDevice, onDeleteDevice, showAlert }: DeviceListProps) { const [editingId, setEditingId] = useState(null); const handleEdit = (device: Device) => { setEditingId(device.id); }; const handleSave = (device: Device) => { onUpdateDevice(device); setEditingId(null); }; const handleDelete = (id: string) => { if (window.confirm('确定要删除这个设备吗?')) { onDeleteDevice(id); showAlert('设备已成功删除', 'success'); } }; return (

设备列表

{devices.map(device => ( ))}
名称 数量 序列号 操作
{editingId === device.id ? ( onUpdateDevice({ ...device, name: e.target.value })} className="border rounded p-1 w-full" /> ) : ( device.name )} {editingId === device.id ? ( onUpdateDevice({ ...device, quantity: parseInt(e.target.value) })} className="border rounded p-1 w-20" /> ) : ( device.quantity )} {device.serialNumber} {editingId === device.id ? ( ) : ( )}
); }