From 88e50525bd8bcd657f86f489174c63678adebd4e Mon Sep 17 00:00:00 2001 From: minom Date: Mon, 2 Mar 2026 17:52:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E9=9D=A2=E8=A8=AD=E8=A8=88=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/admin/item/TabletDesigner.aspx | 78 +++++++++++++++++++++++---- web/admin/item/TabletDesigner.aspx.cs | 4 ++ 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/web/admin/item/TabletDesigner.aspx b/web/admin/item/TabletDesigner.aspx index 6d7dff3..201f532 100644 --- a/web/admin/item/TabletDesigner.aspx +++ b/web/admin/item/TabletDesigner.aspx @@ -15,17 +15,28 @@
設計工具箱
- -
+ +
+
地址欄 牌位正名 品字名單 正名合併置中 - 陽上報恩 + 陽上報恩 +
+ + 上傳自訂底圖 (PNG/JPG) + + +
+
@@ -91,24 +102,30 @@ //$(".tablet-element").draggable({}); this.bindEvents(); this.loadConfig(); + this.bindBackend(); this.allSize.forEach(x => { $("#paperSize").append("") }) $("#paperOrientation").html("直向") }, changeOrientation() { - this.orientation = this.orientation == "portrait" ? "land" : "portrait"; + this.orientation = (this.orientation === "portrait" ? "land" : "portrait"); + console.log(this.orientation); $("#paperOrientation").empty(); - $("#paperOrientation").html("" + this.orientation == "portrait" ? "直向" : "橫向" + ""); + let ori = this.orientation == "portrait" ? "直向" : "橫向"; + console.log(this.orientation,ori) + $("#paperOrientation").html("" +ori + ""); let paperSize = $("#paperSize").val() + let size = this.allSize.find(x => x.name == paperSize) - this.paper.width = size.width; - this.paper.height = size.height; + console.log(paperSize, size); + this.paper.width = this.orientation == "portrait" ? size.width : size.height; + this.paper.height = this.orientation == "portrait" ? size.height : size.width; $(".tablet-paper").css({ "background-color": "red", - width: this.orientation == "portrait" ? size.width : size.height + "mm", - height: this.orientation == "portrait" ? size.height : size.width + "mm", + width: this.paper.width + "mm", + height: this.paper.height + "mm", }); }, changePaper() { @@ -277,8 +294,51 @@ }, addElement() { console.log("QQQ"); + }, + wrapImageInSvg(imageBase64) { + // 建立一個簡單的 SVG 字串,將圖片鋪滿 + // preserveAspectRatio="none" 確保圖片會拉伸填滿 SVG 容器 + const svgString = ` + + + + `.trim(); + + // 轉成 Data URI 格式 + // 注意:SVG 內容若包含特殊字元需編碼,但 base64 圖片通常是安全的 + // 為了保險,我們使用 encodeURIComponent 對 svgString 編碼 + return `data:image/svg+xml;utf8,${encodeURIComponent(svgString)}`; + }, + clickBackend() { + $("#backendInp").click(); + }, + bindBackend() { + $("#backendInp").on('change', function (e) { + console.log($("#backendInp")) + const input = e.target; + if (input.files && input.files[0]) { + console.log("file:", input.files[0]); + const file = input.files[0]; + + // 1. 先讀取檔案轉成 Base64 + const reader = new FileReader(); + reader.onload = (e) => { + const base64Image = e.target.result; // 這會是 data:image/png;base64,xxxx... + + // 2. 將 Base64 PNG 包裝成 SVG + //const svgDataUri = this.wrapImageInSvg(base64Image); + console.log(base64Image) + // 3. 設定到底圖 + //this.service.setBackground(svgDataUri); + $(".tablet-paper").css({ 'background-image': 'url(' + base64Image + ')','background-size':'100% 100%' }) + }; + + reader.readAsDataURL(file); + } + }) } }; + $(() => Designer.init()); diff --git a/web/admin/item/TabletDesigner.aspx.cs b/web/admin/item/TabletDesigner.aspx.cs index 9510165..3ea18ce 100644 --- a/web/admin/item/TabletDesigner.aspx.cs +++ b/web/admin/item/TabletDesigner.aspx.cs @@ -63,6 +63,10 @@ public partial class admin_item_TabletDesigner :MyWeb.config { id="combined",type="combined-center",text="林張吳\n氏歷代祖先", x = 130, y = 80, style = new ElementStyle { fontSize = 24, fontFamily = "Kaiti", isVertical = true, letterSpacing = 5, lineHeight = 1.5 ,visibility="hidden" } + }, new TabletElement + { + id="alive",type="alive",text="劉大哥", x = 60, y = 200, + style = new ElementStyle { fontSize = 18, fontFamily = "Kaiti", isVertical = true, letterSpacing = 5, lineHeight = 1.5 ,visibility="" } } }, paper = new { width = 100, height = 272, name = "Yellow" }