This commit is contained in:
@@ -601,10 +601,10 @@
|
||||
//list = this.data_table.selected.map(x => x.num);
|
||||
|
||||
list = this.data_table.selected
|
||||
.sort((a, b) => a.print_id.localeCompare(b.print_id))
|
||||
.sort((a, b) => (a.print_id==null?"":a.print_id).localeCompare(b.print_id==null?"":b.print_id))
|
||||
.map(x => x.num);
|
||||
|
||||
console.log("what:",list);
|
||||
//console.log("what:",list);
|
||||
|
||||
if (list.length > 0) {
|
||||
// 記錄已列印
|
||||
@@ -645,7 +645,7 @@
|
||||
addHiddenField("file", this.thisFilesSelected.val);
|
||||
addHiddenField("list", JSON.stringify(list));
|
||||
addHiddenField("title", `${this.thisItemSelected.text} / ${this.thisFilesSelected.text}`);
|
||||
|
||||
//console.log("底家:",this.data_table.selected);
|
||||
localStorage.setItem("list", JSON.stringify(this.data_table.selected));
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,12 +18,46 @@
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" runat="server">
|
||||
<div class="d-flex overflow-hidden" style="height:1920px">
|
||||
<div id="printArea" style="width: 100vw; height: 100vh">
|
||||
<div class="canvas-area flex-grow-1 overflow-auto d-flex flex-column align-items-center position-relative" id="canvas">
|
||||
|
||||
<%-- <div class="tablet-paper">
|
||||
</div>--%>
|
||||
</div>
|
||||
<%-- </div>--%>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="customMenu" style="display: none; position: absolute; background-color: #f9f9f9; border: 1px solid #ccc; padding: 10px; z-index: 1000;opacity:1;">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" id="textX" class="form-control form-control-sm mb-2" onchange="Printer.changeLocation()" />
|
||||
<label class="small" for="textX">X軸位置</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" id="textY" class="form-control form-control-sm mb-2" onchange="Printer.changeLocation()" />
|
||||
<label class="small" for="textY">Y軸位置</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" id="fontSize" class="form-control form-control-sm mb-2" onchange="Printer.changeSize()" />
|
||||
<label class="small" for="fontSize">字體大小</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" id="textWidth" class="form-control form-control-sm mb-2" onchange="Printer.changeWidth()" />
|
||||
<label class="small" for="textWidth">文字寬度</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
<script src="<%=ResolveUrl("~/js/bootstrap5/js/bootstrap.bundle.min.js")%>"></script>
|
||||
@@ -37,6 +71,7 @@
|
||||
<script src="<%=ResolveUrl("~/admin/item/jquery-ui/jquery-ui.min.js")%>"></script>
|
||||
<script>
|
||||
const Printer = {
|
||||
selected:null,
|
||||
http_host: "",
|
||||
allStyle: [],
|
||||
allSize: [],
|
||||
@@ -50,6 +85,7 @@
|
||||
{ name: "紅2", path: "../../admin/print/html/tablet-2B.svg" }
|
||||
],
|
||||
async init() {
|
||||
console.log("init");
|
||||
let HTTP_HOST = "<%=UrlHost()%>";
|
||||
this.http_host = HTTP_HOST;
|
||||
await Promise.all([
|
||||
@@ -131,52 +167,347 @@
|
||||
this.printData = response.data;
|
||||
|
||||
this.render();
|
||||
|
||||
this.print();
|
||||
}
|
||||
});
|
||||
},
|
||||
render() {
|
||||
|
||||
let self = this;
|
||||
this.printData.forEach(x => {
|
||||
|
||||
let style = this.allStyle.find(y => y.style == x.styleID);
|
||||
let style = this.allStyle.find(y => y.styleID == x.style);
|
||||
console.log("style:",style);
|
||||
let size = this.allSize.find(y => y.paperID == style.paperSize);
|
||||
|
||||
let canvas = $(` <div class="canvas-area flex-grow-1 overflow-auto d-flex flex-column align-items-center position-relative" ></div>`)
|
||||
let tabletpaper = $(` <div class="tablet-paper">
|
||||
</div>`)
|
||||
|
||||
let img = self.bg.find(y=>y.name==style.backendImg);
|
||||
tabletpaper.css({
|
||||
"background-color": "white",
|
||||
width: size.width + 'mm',
|
||||
height:size.height + 'mm',
|
||||
position: "absolute",
|
||||
|
||||
"background-image": 'url("../../admin/print/html/tablet-2.svg")', 'background-size': '100% 100%',
|
||||
"background-image": `url(${img.path})`, 'background-size': '100% 100%',
|
||||
});
|
||||
let tablet = JSON.parse(x.f_num_tablet);
|
||||
|
||||
let mid_items = tablet.mid_items;
|
||||
let left_items = tablet.left_items;
|
||||
|
||||
console.log("mid_items:",mid_items)
|
||||
let details = this.allStyleDetails.filter(y => y.styleID == x.style);
|
||||
console.log("QQ:",details,x.style);
|
||||
let mid = [];
|
||||
mid_items.forEach(y => {
|
||||
mid.push(y.fam_name);
|
||||
});
|
||||
details.forEach(d => {
|
||||
if (d.isActive!="hidden") {
|
||||
if (d.isActive != "hidden") {
|
||||
console.log(d);
|
||||
let html="";
|
||||
if (d.elementID = 'title1') {
|
||||
let $namelist = $(`<div class='nameList'></div>`).css({
|
||||
"writing-mode": "vertical rl",
|
||||
display: "flex",
|
||||
"flex-direction": "row",
|
||||
"flex-wrap": "wrap",
|
||||
margin: "auto",
|
||||
width: `${d.width}px`,
|
||||
height: `${d.height}px`,
|
||||
border: "0px solid #ccc",
|
||||
padding: "1px",
|
||||
"font-family": "BiauKai",
|
||||
"letter-spacing": "0.1em",
|
||||
"column-gap": "1px",
|
||||
"row-gap": "1px",
|
||||
"align-items": "center",
|
||||
});
|
||||
mid.forEach(z => {
|
||||
let $span = $(`<span>${z}</span>`).css({
|
||||
display: "block",
|
||||
"min-height": `${d.textHeight}px`,
|
||||
"max-height": `${d.height}px`,
|
||||
width: `${d.textWidth}px`,
|
||||
"text-align": "justify",
|
||||
"text-align-last": "justify",
|
||||
"margin-bottom": "40px",
|
||||
"margin-left": "5px",
|
||||
"text-justify": "inter-character",
|
||||
"z-index": 10000,
|
||||
});
|
||||
$namelist.append($span);
|
||||
});
|
||||
|
||||
html = $namelist;
|
||||
}
|
||||
|
||||
let content = $(`<div class="tablet-element vertical-text "></div>`)
|
||||
.css({
|
||||
position: "absolute", left: d.x + "mm", top: d.y + "mm", fontSize: d.fontSize + 'pt', fontFamily: d.fontFamily, "z-index": 9999, visibility: d.isActive
|
||||
position: "absolute", left: d.startX + "mm", top: d.startY + "mm", fontSize: d.fontSize + 'pt', fontFamily: d.fontFamily, "z-index": 9999, visibility: d.isActive
|
||||
//position: "absolute", left: el.startX + "mm", top: el.startY + "mm", fontSize: el.fontSize + 'pt', fontFamily: el.fontFamily, "z-index": 9999, visibility: el.isActive
|
||||
})
|
||||
.html("測試");
|
||||
.html(html);
|
||||
tabletpaper.append(content);
|
||||
}
|
||||
console.log("tabletDetails:",d);
|
||||
|
||||
})
|
||||
$("#canvas").append(tabletpaper);
|
||||
|
||||
$(canvas).append(tabletpaper);
|
||||
$("#printArea").append(canvas);
|
||||
//this.bindKeyEvent();
|
||||
});
|
||||
$(".tablet-element").draggable({
|
||||
start(e, ui) {
|
||||
console.log("gogogogo");
|
||||
},
|
||||
stop(e, ui) {
|
||||
console.log(ui.position.left, ui.position.top);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(".tablet-element").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
console.log(this);
|
||||
self.selected = $(this);
|
||||
let fontSize = $(this).css("fontSize");
|
||||
let fontFamily = $(this).css("fontFamily");
|
||||
let left = $(this).css("left");
|
||||
let top = $(this).css("top");
|
||||
console.log(fontSize, fontFamily, left, top);
|
||||
});
|
||||
|
||||
$(".tablet-element").on("contextmenu", function (e) {
|
||||
e.preventDefault();
|
||||
console.log(this);
|
||||
self.selected = $(this);
|
||||
let fontSize = $(this).css("fontSize");
|
||||
let fontFamily = $(this).css("fontFamily");
|
||||
let left = $(this).css("left");
|
||||
let top = $(this).css("top");
|
||||
console.log(fontSize, fontFamily, left, top);
|
||||
$("#customMenu").css({
|
||||
top: e.pageY + "px",
|
||||
left: (e.pageX+30) + "px"
|
||||
});
|
||||
left = left.replace("px", "");
|
||||
top = top.replace("px", "");
|
||||
$("#textX").val(self.fix2(left*0.265));
|
||||
$("#textY").val(self.fix2(top * 0.265));
|
||||
$("#fontSize").val(fontSize);
|
||||
//$("#textWidth").val("");
|
||||
// Show the custom div
|
||||
$("#customMenu").show();
|
||||
});
|
||||
},
|
||||
fix2(val) {
|
||||
return Number.parseFloat(val).toFixed(2);
|
||||
},
|
||||
async changeLocation() {
|
||||
console.log(this.selected);
|
||||
$(this.selected).css("left", $("#textX").val()+"mm");
|
||||
$(this.selected).css("top", $("#textY").val()+"mm");
|
||||
},
|
||||
async changeSize() {
|
||||
$(this.selected).css("fontSize", $("#fontSize").val())
|
||||
},
|
||||
async changeWidth() {
|
||||
let nameList = $(this.selected).find(".nameList").first();
|
||||
console.log("nameList:", nameList);
|
||||
|
||||
if (nameList) {
|
||||
let spans = $(nameList).find("span");
|
||||
console.log(spans);
|
||||
if (spans) {
|
||||
spans.each(function(index,x) {
|
||||
$(x).css("width",$("#textWidth").val())
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
print() {
|
||||
//let s = this.allStyle.find(x => x.styleID == this.styleID)
|
||||
let size = this.allSize.find(x => x.paperID = "0001")
|
||||
let w = window.open('', '_blank');
|
||||
if (!w) {
|
||||
alert("請允許瀏覽器開啟彈出式視窗!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 抓取您原本網頁定義的 HTTP_HOST (您的全域變數),如果沒有則抓取當前網址
|
||||
let hostUrl = typeof this.http_host !== 'undefined' ? this.http_host : (window.location.protocol + "//" + window.location.host);
|
||||
if (!hostUrl.endsWith('/')) hostUrl += '/';
|
||||
|
||||
// 2. 抓出畫布完整的 HTML
|
||||
let canvasHtml = $("#printArea").html();
|
||||
|
||||
// 3. 【關鍵修復】把所有的 "../../" 替換成完整的網址,解決底圖破圖問題!
|
||||
canvasHtml = canvasHtml.replace(/\.\.\/\.\.\//g, hostUrl);
|
||||
|
||||
// 4. 組合列印視窗的 HTML
|
||||
let htmlContent = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>預覽列印 - 牌位設計</title>
|
||||
<meta charset="utf-8">
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
/* 名單金字塔佈局容器 */
|
||||
.roster-container {
|
||||
width: 100%; height: 100%;
|
||||
writing-mode: vertical-rl; /* 直書 */
|
||||
display: flex;
|
||||
/*flex-direction: column;*/ /* 雖然是直書,但物理上我們是將「上層區」和「下層區」垂直堆疊 */
|
||||
flex-direction: row; /* 上下分層 (Top / Bottom) */
|
||||
align-items: center; /* 左右置中對齊 */
|
||||
justify-content: center;
|
||||
gap: 20px; /* 這是「上層」跟「下層」之間的距離,可以設大一點 */
|
||||
}
|
||||
|
||||
.roster-row {
|
||||
display: flex;
|
||||
flex-direction: row-reverse; /* 直書由右至左,所以 Row 要反向或依需求調整 */
|
||||
justify-content: center;
|
||||
gap: 8px; /* 名字之間的間距 */
|
||||
margin-left: 10px; /* 上下排之間的間距 (因為是直書,margin-left 是物理上的左邊/下方) */
|
||||
}
|
||||
|
||||
.name-group {
|
||||
display: flex;
|
||||
flex-direction: column; /* ★★★ 關鍵:這讓名字左右並排 ★★★ */
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
/* gap 由 HTML 動態綁定 */
|
||||
}
|
||||
|
||||
.roster-name {
|
||||
text-orientation: upright;
|
||||
/*font-weight: bold;*/
|
||||
white-space: nowrap;
|
||||
line-height: 1.2;
|
||||
font-family: 'Kaiti', serif;
|
||||
/* 確保名字本身不會佔據過多寬度導致間距看起來很大 */
|
||||
width: fit-content;
|
||||
}
|
||||
.vertical-text {
|
||||
writing-mode: vertical-rl !important;
|
||||
-webkit-writing-mode: vertical-rl !important;
|
||||
text-orientation: mixed !important;
|
||||
}
|
||||
|
||||
/* 【修復底圖沒出現】強制印出背景設定 */
|
||||
* {
|
||||
-webkit-print-color-adjust: exact !important;
|
||||
print-color-adjust: exact !important;
|
||||
color-adjust: exact !important;
|
||||
}
|
||||
|
||||
|
||||
/* 【修復排版沒照設定】覆寫原本 HTML 裡的 fixed,並防止 Bootstrap 洗掉 absolute */
|
||||
.tablet-paper {
|
||||
position: relative !important;
|
||||
margin: 0 auto !important;
|
||||
page-break-after: always !important;
|
||||
box-shadow: none !important;
|
||||
width: var(--page-w);
|
||||
height: var(--page-h);
|
||||
}
|
||||
|
||||
.tablet-element {
|
||||
position: absolute !important; /* 絕對不能被 Bootstrap 覆蓋為 static */
|
||||
color: black !important; /* 確保文字是黑色的 */
|
||||
}
|
||||
|
||||
|
||||
.ancestor-wrapper {
|
||||
/* 重置為橫向流,這樣 column 才會是真正的上下堆疊 */
|
||||
writing-mode: horizontal-tb;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center; /* 水平置中 */
|
||||
justify-content: center;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.main-name {
|
||||
line-height: 1.2;
|
||||
/* 保持大字 */
|
||||
}
|
||||
|
||||
.sub-text {
|
||||
font-size: 0.6em; /* 縮小字體 */
|
||||
line-height: 1.2;
|
||||
margin-top: 4px; /* 與上方林張的間距 */
|
||||
white-space: nowrap; /* 避免自動換行 */
|
||||
writing-mode:vertical-rl
|
||||
}
|
||||
|
||||
/* 列印時的紙張大小與頁面歸零 */
|
||||
@media print {
|
||||
@page {
|
||||
/* 動態套用您設定的紙張寬高 */
|
||||
size: ${size.width}mm ${size.height}mm portrait;
|
||||
margin: 0;
|
||||
}
|
||||
body, html {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
|
||||
}
|
||||
body{
|
||||
--page-w: ${size.width}mm;
|
||||
--page-h: ${size.height}mm;
|
||||
--font-max: 22pt;
|
||||
--bg-padding: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
${canvasHtml}
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
w.document.write(htmlContent);
|
||||
w.document.close();
|
||||
|
||||
// 5. 將等待時間稍微拉長至 1.2 秒,確保大張的 SVG 底圖與外部字體(如標楷體)下載完畢
|
||||
setTimeout(() => {
|
||||
w.focus();
|
||||
w.print();
|
||||
}, 1200);
|
||||
},
|
||||
//bindKeyEvent() {
|
||||
// let element = document.querySelectorAll(".tablet-element");
|
||||
// element.forEach(y => {
|
||||
// console.log("QQ:",y);
|
||||
// $(y).on("keydown", (e) => {
|
||||
// console.log(e.key);
|
||||
// e.preventDefault();
|
||||
// let top = parseInt(y.style.top);
|
||||
// let left = parseInt(y.style.left);
|
||||
|
||||
// switch (e.key) {
|
||||
// case 'ArrowUp': top = top - 10; break;
|
||||
// case 'ArrowDown': top = top + 10; break;
|
||||
// case 'ArrowLeft': left = left - 10; break;
|
||||
// case 'ArrowRight': left = left + 10; break;
|
||||
// }
|
||||
|
||||
// y.style.top = top + 'px';
|
||||
// y.style.left = left + 'px';
|
||||
// })
|
||||
// })
|
||||
//}
|
||||
}
|
||||
$(document).click(function (e) {
|
||||
if (!$("#customMenu").is(e.target) && $("#customMenu").has(e.target).length === 0) {
|
||||
$("#customMenu").hide();
|
||||
}
|
||||
});
|
||||
$(() => Printer.init());
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user