import { createSignal, For, Show } from 'solid-js'; import { Portal } from 'solid-js/web'; import type { DeckStore } from './hooks/deckStore'; import { usePageLayout } from './hooks/usePageLayout'; import { usePDFExport, type ExportOptions } from './hooks/usePDFExport'; import { usePlotterExport } from './hooks/usePlotterExport'; import { getShapeSvgClipPath } from './hooks/shape-styles'; import { PrintPreviewHeader } from './PrintPreviewHeader'; import { PrintPreviewFooter } from './PrintPreviewFooter'; import { CardLayer } from './CardLayer'; import { PltPreview } from './PltPreview'; export interface PrintPreviewProps { store: DeckStore; onClose: () => void; onExport: () => void; } /** * 打印预览组件:在 A4 纸张上排列所有卡牌 */ export function PrintPreview(props: PrintPreviewProps) { const { store } = props; const { getA4Size, pages, cropMarks } = usePageLayout(store); const { exportToPDF } = usePDFExport(store, props.onClose); const { generatePltData } = usePlotterExport(store); const [showPltPreview, setShowPltPreview] = createSignal(false); const [pltCode, setPltCode] = createSignal(''); const frontVisibleLayers = () => store.state.frontLayerConfigs.filter((l) => l.visible); const backVisibleLayers = () => store.state.backLayerConfigs.filter((l) => l.visible); const handleExport = async () => { const options: ExportOptions = { orientation: store.state.printOrientation, cardWidth: store.state.dimensions?.cardWidth || 56, cardHeight: store.state.dimensions?.cardHeight || 88, gridOriginX: store.state.dimensions?.gridOriginX || 0, gridOriginY: store.state.dimensions?.gridOriginY || 0, gridAreaWidth: store.state.dimensions?.gridAreaWidth || 56, gridAreaHeight: store.state.dimensions?.gridAreaHeight || 88, visibleLayers: frontVisibleLayers(), dimensions: store.state.dimensions! }; await exportToPDF(pages(), cropMarks(), options); }; const handleOpenPltPreview = () => { const data = generatePltData(); if (data) { setPltCode(data.pltCode); setShowPltPreview(true); } else { alert('没有可预览的卡片'); } }; const handleClosePltPreview = () => { setShowPltPreview(false); }; return ( }>
{(page) => { // 根据页面类型(正面/背面)决定使用哪个图层配置 const isFrontPage = page.cards[0]?.side !== 'back'; const visibleLayersForPage = isFrontPage ? frontVisibleLayers() : backVisibleLayers(); return ( {(line) => ( <> )} {(line) => ( <> )} {(card) => { const cardWidth = store.state.dimensions?.cardWidth || 56; const cardHeight = store.state.dimensions?.cardHeight || 88; const clipPathId = `clip-${page.pageIndex}-${card.data.id || card.x}-${card.y}`; const shapeClipPath = getShapeSvgClipPath(clipPathId, cardWidth, cardHeight, store.state.shape, store.state.cornerRadius); return ( {shapeClipPath}
); }}
); }}
); }