上传图片
58 | 65 | 73 || 102 | {cell} 103 | | 104 | ))} 105 |
|---|
| 119 | {cell} 120 | | 121 | ))} 122 |
163 | {body} 164 |
165 | ) 166 | }) 167 | FormMessage.displayName = "FormMessage" 168 | 169 | export { 170 | useFormField, 171 | Form, 172 | FormItem, 173 | FormLabel, 174 | FormControl, 175 | FormDescription, 176 | FormMessage, 177 | FormField, 178 | } 179 | -------------------------------------------------------------------------------- /lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { type ClassValue, clsx } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | import html2canvas from "html2canvas" 4 | import { useEditorStore } from "@/lib/editor-store" 5 | 6 | export function cn(...inputs: ClassValue[]) { 7 | return twMerge(clsx(inputs)) 8 | } 9 | 10 | // 修改 printDesign 函数,调整打印预览的比例并移除底部尺寸文本 11 | 12 | export async function printDesign() { 13 | try { 14 | // 创建一个新的打印窗口 15 | const printWindow = window.open("", "_blank") 16 | if (!printWindow) { 17 | alert("请允许弹出窗口以打印设计") 18 | return 19 | } 20 | 21 | // 获取画布元素 22 | const canvas = document.querySelector(".canvas") as HTMLElement 23 | if (!canvas) return 24 | 25 | // 使用html2canvas将画布转换为图像 26 | const canvasImage = await html2canvas(canvas, { 27 | scale: 2, // 提高清晰度 28 | useCORS: true, // 允许跨域图像 29 | allowTaint: true, // 允许污染画布 30 | backgroundColor: null, // 允许透明背景,以便我们可以看到自定义背景 31 | logging: false, 32 | onclone: (clonedDoc) => { 33 | // 在克隆的文档中移除所有控制点和选中样式 34 | const resizeHandles = clonedDoc.querySelectorAll(".resize-handle") 35 | resizeHandles.forEach((handle) => { 36 | handle.remove() 37 | }) 38 | 39 | const selectedElements = clonedDoc.querySelectorAll(".selected") 40 | selectedElements.forEach((element) => { 41 | element.classList.remove("selected") 42 | }) 43 | }, 44 | }) 45 | 46 | // 获取画布尺寸 47 | const canvasSize = useEditorStore.getState().canvasSize 48 | 49 | // 设置打印窗口内容 50 | printWindow.document.write(` 51 | 52 | 53 | 54 |