const barcodeSample = "/images/barcode-sample.png"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/Components/ui/dialog"; import { Button } from "@/Components/ui/button"; import { Download, Printer } from "lucide-react"; const barcodePlaceholder = "/images/barcode-placeholder.png"; interface BarcodeViewDialogProps { open: boolean; onOpenChange: (open: boolean) => void; productName: string; productCode: string; barcodeValue: string; } export default function BarcodeViewDialog({ open, onOpenChange, productName, productCode, barcodeValue, }: BarcodeViewDialogProps) { const handlePrint = () => { const printWindow = window.open("", "_blank"); if (printWindow) { printWindow.document.write(` 列印條碼 - ${productName}
${productName}
商品代號: ${productCode}
商品條碼
`); printWindow.document.close(); setTimeout(() => { printWindow.print(); }, 250); } }; const handleDownload = () => { const link = document.createElement("a"); link.href = barcodePlaceholder; link.download = `${productCode}_barcode.png`; link.target = "_blank"; link.click(); }; return ( 商品條碼 {productName} ({productCode})
{/* 條碼顯示區 */}
商品條碼
{/* 條碼資訊 */}
條碼內容 {barcodeValue}
條碼格式 Code128
{/* 操作按鈕 */}
); }