"use client"; import { useState } from "react"; import { QrCode, Download, Settings, Eye } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { QRCodeCanvas } from "qrcode.react"; import { toast } from "sonner"; interface QRConfig { size: number; icon: string; iconSize: number; fgColor: string; bgColor: string; includeMargin: boolean; level: "L" | "M" | "Q" | "H"; } export default function QRCodeGenerator() { const [text, setText] = useState(""); const [config, setConfig] = useState({ size: 200, icon: "", iconSize: 40, fgColor: "#000000", bgColor: "#ffffff", includeMargin: true, level: "M", }); const handleConfigChange = (field: keyof QRConfig, value: any) => { setConfig((prev) => ({ ...prev, [field]: value })); }; const downloadQRCode = () => { const canvas = document.getElementById("qr-code-canvas") as HTMLCanvasElement; if (canvas) { try { const link = document.createElement("a"); link.download = "qrcode.png"; link.href = canvas.toDataURL("image/png"); link.click(); toast.success("二维码下载成功"); } catch { toast.error("下载失败"); } } else { toast.error("未找到二维码"); } }; return (
{/* Page Header */}

二维码生成器

快速生成自定义二维码,支持多种样式配置

{/* Left: Configuration */}
内容设置