"use client"; import { useState } from "react"; import { Calculator, Copy, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { toast } from "sonner"; export default function RadixConverterPage() { const [values, setValues] = useState({ bin: "", oct: "", dec: "", hex: "" }); const handleUpdate = (val: string, radix: number) => { if (val === "") { setValues({ bin: "", oct: "", dec: "", hex: "" }); return; } try { const decimal = parseInt(val, radix); if (isNaN(decimal)) return; setValues({ bin: decimal.toString(2), oct: decimal.toString(8), dec: decimal.toString(10), hex: decimal.toString(16).toUpperCase() }); } catch { // Ignore invalid input } }; const copyToClipboard = async (text: string) => { if (!text) return; try { await navigator.clipboard.writeText(text); toast.success("已复制到剪贴板"); } catch { toast.error("复制失败"); } }; const clearAll = () => setValues({ bin: "", oct: "", dec: "", hex: "" }); return (
二、八、十、十六进制数值相互转换