986 lines
42 KiB
Plaintext
986 lines
42 KiB
Plaintext
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="print_multi_new.aspx.cs" Inherits="admin_print_print_multi_new" %>
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head runat="server">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title></title>
|
|
<link href="~/js/bootstrap5/bootstrap.min.css" rel="stylesheet" />
|
|
<%--<link href="~/js/fontawesome6/css/all.css" rel="stylesheet" />--%>
|
|
<link href="~/js/mdi-font/css/materialdesignicons.min.css" rel="stylesheet" />
|
|
<link href="~/js/vuetify_ez.css" rel="stylesheet" />
|
|
<link href="~/js/sweetalert2/sweetalert2.min.css" rel="stylesheet" />
|
|
|
|
<link href="~/admin/Templates/TBS5ADM001/css/Style.css" rel="stylesheet" />
|
|
<link href="~/admin/item/css/floating.css" rel="stylesheet" />
|
|
<%--<link href="~/admin/item/css/tablet-design.css" rel="stylesheet" />--%>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="customMenu" style="top:20px;right:10mm;width:20vw;height:90vh; position: fixed; background-color: #f0f0f0;
|
|
border: 1px solid #ccc; padding: 10px; z-index: 1000; opacity: 1;">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<input type="radio" name="setup" id="indivualSetup" style="width:30px;height:30px;" checked="checked"/>個別設定
|
|
<input type="radio" name="setup" id="allSetup" style="width:30px;height:30px;"/>全域設定
|
|
</div>
|
|
</div>
|
|
<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.changeSetup('X')" />
|
|
<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.changeSetup('Y')" />
|
|
<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.changeSetup('fontSize')" />
|
|
<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.changeSetup('width')" />
|
|
<label class="small" for="textWidth">物件寬度</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-6">
|
|
<div class="form-floating mb-3">
|
|
<input type="text" id="textHeight" class="form-control form-control-sm mb-2" onchange="Printer.changeSetup('height')" />
|
|
<label class="small" for="textHeight">物件高度</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-6">
|
|
<div class="form-floating mb-3">
|
|
<input type="text" id="textBreakCount" class="form-control form-control-sm mb-2" onchange="Printer.changeWidth()" />
|
|
<label class="small" for="textBreakCount">文字斷行(依字數)</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-6">
|
|
<div class="form-floating mb-3">
|
|
<input type="text" id="textBreakWord" class="form-control form-control-sm mb-2" onchange="Printer.changeWidth()" />
|
|
<label class="small" for="textBreakWord">文字斷行(依文字)</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<span class="btn btn-primary no-print" onclick="Printer.print()">列印</span>
|
|
<select id="paperSizeSel" onchange="Printer.render()">
|
|
<!-- onchange="Printer.render()"-->
|
|
<option value="">紙張尺寸</option>
|
|
</select>
|
|
<div class="d-flex full-home no-print" style="height: auto;width:100%;">
|
|
<div id="printArea" class="printArea" style="width: auto; height: auto">
|
|
|
|
<%-- <div class="tablet-paper">
|
|
</div>--%>
|
|
<%-- </div>--%>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<form id="form1" runat="server">
|
|
</form>
|
|
</body>
|
|
<script src="<%=ResolveUrl("~/js/bootstrap5/js/bootstrap.bundle.min.js")%>"></script>
|
|
<script src="<%=ResolveUrl("~/js/jquery-4.0.0.min.js")%>"></script>
|
|
<script src="<%=ResolveUrl("~/js/vue.min.js")%>"></script>
|
|
<script src="<%=ResolveUrl("~/js/vuetify.min.js")%>"></script>
|
|
<script src="<%=ResolveUrl("~/js/axios.min.js")%>"></script>
|
|
<script src="<%=ResolveUrl("~/js/moment.min.js")%>"></script>
|
|
<script src="<%=ResolveUrl("~/js/sweetalert2/sweetalert2.all.min.js") %>"></script>
|
|
<script src="<%=ResolveUrl("~/admin/Templates/TBS5ADM001/js/Script.js")%>"></script>
|
|
<script src="<%=ResolveUrl("~/admin/item/jquery-ui/jquery-ui.min.js")%>"></script>
|
|
<script>
|
|
// 建立 MutationObserver 實例,並傳入 callback 函式
|
|
|
|
const Printer = {
|
|
selected: null,
|
|
http_host: "",
|
|
pageStyle: "",
|
|
pSize: "",
|
|
allStyle: [],
|
|
allSize: [],
|
|
allStyleDetails: [],
|
|
printData: [],
|
|
tabletElement: [],
|
|
observer: null,
|
|
isInit: true,
|
|
bg: [
|
|
{ name: "黃1", path: "../../admin/print/html/tablet-1_new.svg" },
|
|
{ name: "黃2", path: "../../admin/print/html/tablet-1B_new.svg" },
|
|
{ name: "紅1", path: "../../admin/print/html/tablet-2.svg" },
|
|
{ name: "紅2", path: "../../admin/print/html/tablet-2B.svg" }
|
|
],
|
|
async init() {
|
|
|
|
let HTTP_HOST = "<%=UrlHost()%>";
|
|
this.http_host = HTTP_HOST;
|
|
//
|
|
Promise.all([
|
|
this.getActItem(),
|
|
this.getPaperSize(),
|
|
]).then(() => {
|
|
Promise.all([
|
|
this.getTabletElement(),
|
|
this.getTabletStyles(),
|
|
this.getAllStyleDetails(),
|
|
this.getData(),
|
|
|
|
]).then(() => {
|
|
this.render();
|
|
})
|
|
})
|
|
},
|
|
async getActItem() {
|
|
axios
|
|
.post('/api/tablet/GetActItem', { itemNum: localStorage.getItem("item") })
|
|
.then(response => {
|
|
if (response.data.result == "Y" && response.data.data) {
|
|
this.pSize = response.data.data.printSize;
|
|
$("#paperSizeSel").val(this.pSize);
|
|
} else {
|
|
$("#paperSizeSel").val("0001");
|
|
}
|
|
//$("#paperSizeSel").trigger('change');
|
|
//this.render();
|
|
//this.print();
|
|
//this.isInit = false;
|
|
}
|
|
);
|
|
},
|
|
async getAllStyleDetails() {
|
|
await axios
|
|
.post(this.http_host + 'api/tablet/GetStyleDetailData', {})
|
|
.then(response => {
|
|
if (response.status == "200") {
|
|
let data = response.data;
|
|
if (data.result == "Y") {
|
|
let details = data.data;
|
|
this.allStyleDetails = details;
|
|
//console.log(data.data);
|
|
}
|
|
}
|
|
}
|
|
);
|
|
},
|
|
async getPaperSize() {
|
|
let self = this
|
|
await axios
|
|
.post(this.http_host + 'api/tablet/GetPaperSize', {})
|
|
.then(response => {
|
|
//if (response.result=="Y") {
|
|
if (response.status == "200") {
|
|
let data = response.data;
|
|
this.allSize = data.data;
|
|
//console.log(this.allSize);
|
|
if (this.allSize) {
|
|
this.allSize.forEach(x => {
|
|
$("#paperSizeSel").append(`<option value="${x.paperID}">${x.paperName}</option>`);
|
|
})
|
|
//if (this.printSize) {
|
|
// $("#paperSizeSel").val(this.printSize);
|
|
//} else {
|
|
// $("#paperSizeSel").val("0003")
|
|
//}
|
|
}
|
|
}
|
|
//$("#paperSizeSel").val("0003");
|
|
}
|
|
)
|
|
},
|
|
async getTabletElement() {
|
|
await axios
|
|
.post(this.http_host + 'api/tablet/GetTabletElement', {})
|
|
.then(response => {
|
|
//if (response.result=="Y") {
|
|
if (response.status == "200") {
|
|
let data = response.data;
|
|
this.tabletElement = data.data;
|
|
}
|
|
});
|
|
},
|
|
async getTabletStyles() {
|
|
await axios
|
|
.post(this.http_host + 'api/tablet/GetStyleData', {})
|
|
.then(response => {
|
|
if (response.status == "200") {
|
|
let data = response.data;
|
|
this.allStyle = data.data;
|
|
}
|
|
});
|
|
},
|
|
async getData() {
|
|
let list = localStorage.getItem("list")
|
|
let param = [];
|
|
let data = JSON.parse(list)
|
|
data.forEach(x => {
|
|
param.push({ order_no: x.order_no, num: x.num });
|
|
});
|
|
await axios
|
|
.post(this.http_host + 'api/orderdetail/GetDetailToPrint', { param: param })
|
|
.then(response => {
|
|
|
|
if (response.status == 200) {
|
|
this.printData = response.data;
|
|
|
|
//this.render();
|
|
//this.print();
|
|
}
|
|
});
|
|
},
|
|
render() {
|
|
//console.log(this.pSize)
|
|
//if (this.isInit) {
|
|
// return false;
|
|
//}
|
|
$("#printArea").empty();
|
|
let self = this;
|
|
let canvas = $(` <div class="canvas-area flex-grow-1 overflow-auto d-flex flex-row align-items-center position-relative" ></div>`)
|
|
let nowPageWidth = 0;
|
|
let tabletpaper;
|
|
//列印紙張的尺寸
|
|
if ($("#paperSizeSel").val() == "") {
|
|
if (this.pSize && this.pSize != undefined) {
|
|
$("#paperSizeSel").val(this.pSize);
|
|
} else {
|
|
$("#paperSizeSel").val("0001");
|
|
}
|
|
}
|
|
let pageSize = self.allSize.find(y => y.paperID == $("#paperSizeSel").val());
|
|
|
|
this.printData.forEach(x => {
|
|
console.log("x:", x)
|
|
let style = self.allStyle.find(y => y.styleID == x.style);
|
|
//用來印內容的尺寸
|
|
let size = self.allSize.find(y => y.paperID == style.paperSize);
|
|
//包含空白用來折的尺寸
|
|
let printSize = self.allSize.find(y => y.paperID == style.printSize);
|
|
|
|
//用長根寬算出一張紙可以印幾張
|
|
let xCount = parseFloat(pageSize.width) / parseFloat(printSize.width);
|
|
let yCount = parseFloat(pageSize.height) / parseFloat(printSize.height);
|
|
let total = Math.floor(xCount) * Math.floor(yCount);
|
|
console.log(xCount, yCount, total);
|
|
//if ((nowPageWidth + parseFloat(printSize.width)) > pageSize.width) {
|
|
if (nowPageWidth >= total) {
|
|
//$(canvas).css("width", printSize.width + "mm");
|
|
//$(canvas).css("height", printSize.height + "mm");
|
|
//$(canvas).css("justify-content", "center");
|
|
//$(canvas).css("break-after", "page");
|
|
//$(canvas).css("page-break-after", "always");
|
|
$(canvas).append(tabletpaper);
|
|
$("#printArea").append(canvas);
|
|
canvas = $(` <div class="canvas-area flex-grow-1 overflow-auto d-flex flex-row align-items-center position-relative" ></div>`)
|
|
nowPageWidth = 0;
|
|
}
|
|
nowPageWidth = nowPageWidth + 1; //parseFloat(printSize.width);
|
|
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: "relative",
|
|
"margin-bottom": "0",
|
|
"background-image": `url(${img.path})`,
|
|
'background-size': '100% 100%',
|
|
"break-after": "page",
|
|
"page-break-after": "always"
|
|
});*/
|
|
let tablet = JSON.parse(x.f_num_tablet);
|
|
|
|
let mid_items = tablet.mid_items;
|
|
let left_items = tablet.left_items;
|
|
|
|
let details = this.allStyleDetails.filter(y => y.styleID == x.style);
|
|
console.log("details:", details);
|
|
let mid = [];
|
|
mid_items.forEach(y => {
|
|
mid.push(y.fam_name);
|
|
});
|
|
let left = []
|
|
if (left_items) {
|
|
left_items.forEach(y => {
|
|
left.push(y.fam_name);
|
|
});
|
|
}
|
|
|
|
details.forEach(d => {
|
|
if (d.isActive != "hidden") {
|
|
let newFontSize = self.scaleFontSize(mid, d.fontSize, d.width);
|
|
|
|
let html = "";
|
|
let alive = "";
|
|
let yang = "";
|
|
let bi = "";
|
|
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": style.fontFamily,
|
|
"letter-spacing": "0.1em",
|
|
"column-gap": "1px",
|
|
"row-gap": "1px",
|
|
"align-items": "center",
|
|
"justify-content": "space-between",
|
|
});
|
|
|
|
mid.forEach(z => {
|
|
let info = self.getTextInfo(z, newFontSize);
|
|
let spanWidth = mid.length > 1 ? newFontSize : d.width
|
|
console.log("spanWidth:", spanWidth);
|
|
let height = d.textHeight;
|
|
if (info.width >= d.textHeight) {
|
|
height = d.height;
|
|
}
|
|
let $span = $(`<span class="nameSpan">${z}</span>`).css({
|
|
display: "block",
|
|
"min-height": `${height}px`,
|
|
"max-height": `${d.height}px`,
|
|
"max-width": `${spanWidth}px`,
|
|
//width: `${newFontSize}px`,
|
|
"text-align": "justify",
|
|
"text-align-last": "justify",
|
|
"margin-bottom": "20px",
|
|
"margin-left": "5px",
|
|
"text-justify": "inter-character",
|
|
//"justify-content":"center"
|
|
});
|
|
$namelist.append($span);
|
|
});
|
|
|
|
html = $namelist;
|
|
} else if (d.elementID === "alive") {
|
|
html = self.renderLiveList(left, d);
|
|
|
|
newFontSize = d.fontSize;
|
|
} else if (d.elementID === "titletriangle") {
|
|
html = self.renderRoster(mid, d)
|
|
}
|
|
if (newFontSize < 10) {
|
|
newFontSize = 10;
|
|
}
|
|
let content = $(`<div class="tablet-element vertical-text "></div>`)
|
|
.css({
|
|
position: "absolute", left: d.startX + "mm", top: d.startY + "mm", fontSize: newFontSize + 'px',
|
|
fontFamily: d.fontFamily, "font-weight": "bold", "z-index": 9999, visibility: d.isActive,
|
|
"align-items": "center"
|
|
|
|
})
|
|
.html(html);
|
|
tabletpaper.append(content);
|
|
html = "";
|
|
alive = "";
|
|
yang = "";
|
|
bi = "";
|
|
}
|
|
|
|
})
|
|
|
|
//console.log("xCount:", Math.floor( xCount));
|
|
let xFloor = Math.floor(xCount);
|
|
|
|
self.pageStyle = `<style id="pageStyle">
|
|
{
|
|
-webkit-print-color-adjust: exact !important;
|
|
print-color-adjust: exact !important;
|
|
color-adjust: exact !important;
|
|
}
|
|
.vertical-text {
|
|
writing-mode: vertical-rl !important;
|
|
-webkit-writing-mode: vertical-rl !important;
|
|
text-orientation: mixed !important;
|
|
}
|
|
body{
|
|
overflow: visible !important;
|
|
}
|
|
|
|
@media print{
|
|
:host {
|
|
width:auto !important;
|
|
height:auto !important;
|
|
}
|
|
@page {
|
|
size:${pageSize.width}mm ${pageSize.height}mm !important;
|
|
margin:0;
|
|
}
|
|
html, body, form, .full-home, #printArea, .canvas-area {
|
|
height: auto !important;
|
|
width: auto !important;
|
|
overflow: visible !important; /*必須為 visible */
|
|
margin: 0 !important;
|
|
padding: 0 !important;
|
|
display: block !important;
|
|
}
|
|
.no-print, #customMenu {
|
|
display: none !important;
|
|
}
|
|
|
|
|
|
.canvas-area{
|
|
display:${xFloor > 1 ? 'block' : 'flex'} !important;
|
|
grid-template-columns: repeat(${xFloor},1fr);
|
|
flex-direction: row !important;
|
|
justify-content: ${xFloor > 1 ? 'start' : 'center'} !important;
|
|
align-items:center !important;
|
|
${xFloor > 1 ? 'margin-left:20px !important' : ''};
|
|
${xFloor > 1 ? 'margin-right:20px !important' : ''};
|
|
${xFloor > 1 ? 'margin-top:-20px !important' : ''};
|
|
}
|
|
//.no-print, #customMenu {
|
|
// display: none !important;
|
|
//}
|
|
.tablet-paper {
|
|
position: relative !important;
|
|
display: ${xFloor > 1 ? 'inline-block' : 'block'} !important;
|
|
break-inline:avoid;
|
|
page-break-inline:avoid;
|
|
break-after: page !important;
|
|
page-break-after: always !important;
|
|
margin: 0 !important;
|
|
border: none !important;
|
|
background-repeat: no-repeat;
|
|
background-size: 100% 100%;
|
|
}
|
|
|
|
.tablet-element {
|
|
position: absolute !important;
|
|
white-space: normal;
|
|
color: black !important; /* 確保文字是黑色的 */
|
|
}
|
|
|
|
}
|
|
|
|
/* 名單金字塔佈局容器 */
|
|
.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: normal;
|
|
line-height: 1.2;
|
|
font-family: DFKai-sb;
|
|
/* 確保名字本身不會佔據過多寬度導致間距看起來很大 */
|
|
width: fit-content;
|
|
}
|
|
|
|
/* 【修復底圖沒出現】強制印出背景設定 */
|
|
* {
|
|
-webkit-print-color-adjust: exact !important;
|
|
print-color-adjust: exact !important;
|
|
color-adjust: exact !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: normal; /* 避免自動換行 */
|
|
writing-mode:vertical-rl
|
|
}
|
|
|
|
.canvas-area{
|
|
width: ${pageSize.width}mm;
|
|
height: ${pageSize.height}mm;
|
|
break-after: page;
|
|
page-break-after: always;
|
|
display:${xFloor > 1 ? 'block' : 'flex'} !important;
|
|
grid-template-columns: repeat(${xFloor},1fr);
|
|
${xFloor > 1 ? 'margin-left:20px !important' : ''};
|
|
${xFloor > 1 ? 'margin-right:20px !important' : ''};
|
|
/*align-items: center !important;
|
|
justify-content: ${xFloor > 1 ? 'start' : 'center'} !important;*/
|
|
}
|
|
|
|
.tablet-paper{
|
|
background-color: white;
|
|
display: inline-block;
|
|
width: ${size.width}mm !important;
|
|
height: ${size.height}mm !important;
|
|
position: relative;
|
|
margin-bottom: 0;
|
|
background-image: url(${img.path});
|
|
background-size: 100% 100%;
|
|
/*break-after: page;
|
|
page-break-after: always;*/
|
|
break-inline:avoid;
|
|
page-break-inline:avoid;
|
|
}
|
|
.tablet-element {
|
|
cursor: move;
|
|
padding: 4px;
|
|
color: black !important; /* 強制墨水為黑色 */
|
|
border: 1px solid transparent;
|
|
transition: writing-mode 0.3s, transform 0.2s;
|
|
}
|
|
.tablet-element:hover { border-color: rgba(13, 110, 253, 0.3); }
|
|
.tablet-paper:last-child { page-break-after: auto; }
|
|
|
|
.tablet-element span{
|
|
z-index: 999;
|
|
}
|
|
</style>
|
|
`
|
|
$("#pageStyle").remove();
|
|
$("head").append(self.pageStyle);
|
|
$(canvas).append(tabletpaper);
|
|
//$(canvas).css("width", printSize.width + "mm");
|
|
//$(canvas).css("height", printSize.height + "mm");
|
|
//$(canvas).css("justify-content", "center");
|
|
$("#printArea").append(canvas);
|
|
});
|
|
//$(".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();
|
|
// self.selected = $(this);
|
|
// let fontSize = $(this).css("fontSize");
|
|
// let fontFamily = $(this).css("fontFamily");
|
|
// let left = $(this).css("left");
|
|
// let top = $(this).css("top");
|
|
//});
|
|
|
|
$(".tablet-element").on("contextmenu", function (e) {
|
|
e.preventDefault();
|
|
self.selected = $(this);
|
|
let fontSize = $(this).css("font-size");
|
|
let fontFamily = $(this).css("font-family");
|
|
|
|
let textWidth;//= $(this).css("width");//find("span").first().css("width");
|
|
let textHeight; //= $(this).css("height");
|
|
|
|
if ($(this).find(".nameList").first()) {
|
|
textWidth = $(this).find(".nameList").first().css("width");
|
|
textHeight = $(this).find(".nameList").first().css("height");
|
|
} else if ($(this).find(".liveList").first()) {
|
|
textWidth = $(this).find(".liveList").first().css("width");
|
|
textHeight = $(this).find(".liveList").first().css("height");
|
|
} else if ($(this).find(".rosterList").first()) {
|
|
textWidth = $(this).find(".rosterList").first().css("width");
|
|
textHeight = $(this).find(".rosterList").first().css("height");
|
|
}
|
|
|
|
let left = $(this).css("left");
|
|
let top = $(this).css("top");
|
|
|
|
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(textWidth);
|
|
$("#textHeight").val(textHeight);
|
|
$("#textX").prop("readonly", false);
|
|
$("#textY").prop("readonly", false);
|
|
$("#fontSize").prop("readonly", false);
|
|
});
|
|
|
|
$(".tablet-element span").on("click", function (e) {
|
|
e.preventDefault();
|
|
self.selected = $(this);
|
|
let fontSize = $(this).css("font-size");
|
|
let fontFamily = $(this).css("font-family");
|
|
let textWidth = $(this).css("max-width");
|
|
let textHeight = $(this).css("min-height");
|
|
let left = $(this).css("left");
|
|
let top = $(this).css("top");
|
|
left = left.replace("px", "");
|
|
top = top.replace("px", "");
|
|
$("#textX").val("");
|
|
$("#textY").val("");
|
|
$("#fontSize").val("");
|
|
$("#textWidth").val(textWidth);
|
|
$("#textHeight").val(textHeight);
|
|
let parentElement = this.parentElement;
|
|
if ($(parentElement).hasClass("nameList") || $(parentElement).hasClass("liveList") || $(parentElement).hasClass("rosterList")) {
|
|
$("#textX").prop("readonly", true);
|
|
$("#textY").prop("readonly", true);
|
|
$("#fontSize").prop("readonly", true);
|
|
}
|
|
|
|
});
|
|
|
|
|
|
},
|
|
fix2(val) {
|
|
return Number.parseFloat(val).toFixed(2);
|
|
},
|
|
renderLiveList(names, el) {
|
|
let $namelist = $(`<div class='liveList'></div>`).css({
|
|
"writing-mode": "vertical rl",
|
|
display: "flex",
|
|
"flex-direction": "row",
|
|
"flex-wrap": "wrap",
|
|
margin: "auto",
|
|
width: `${el.width}px`,
|
|
height: `${el.height}px`,
|
|
border: "0px solid #ccc",
|
|
padding: "1px",
|
|
"font-family": el.fontFamily,
|
|
"letter-spacing": "0.1em",
|
|
"column-gap": "1px",
|
|
"row-gap": "1px",
|
|
"align-items": "center",
|
|
});
|
|
let self = this;
|
|
names.forEach(n => {
|
|
$namelist.append(self.renderLiveSpan(n, el))
|
|
})
|
|
return $namelist;
|
|
},
|
|
renderLiveSpan(name, el) {
|
|
return $(`<span class="liveSpan">${name}</span>`).css({
|
|
display: "block",
|
|
"min-height": `${el.textHeight}px`,
|
|
"max-height": `${el.height}px`,
|
|
width: `${el.textWidth}px`,
|
|
height: `${el.textHeight}px`,
|
|
"text-align": "justify",
|
|
"text-align-last": "justify",
|
|
"margin-bottom": "10px",
|
|
"text-justify": "inter-character",
|
|
});
|
|
},
|
|
// 品字佈局邏輯:一上二下
|
|
renderRoster(names, el) {
|
|
if (!names.length) return '';
|
|
const mid = names.length === 1 ? 1 : Math.floor(names.length / 2);
|
|
const top = names.slice(0, mid);
|
|
const bot = names.slice(mid);
|
|
const size = this.autoScale(names, el.fontSize);
|
|
|
|
let h = $(`<div class="rosterList"></div>`).css(
|
|
{
|
|
width: el.width, height: el.height,
|
|
"writing-mode": "vertical-rl", /* 直書 */
|
|
display: "flex",
|
|
"flex-direction": "row", /* 上下分層 (Top / Bottom) */
|
|
"align-items": "center", /* 左右置中對齊 */
|
|
"justify-content": "start",
|
|
gap: "20px",
|
|
});
|
|
h.append(this.renderNameGroups(top, el));
|
|
if (bot.length) h.append(this.renderNameGroups(bot, el));
|
|
return h
|
|
},
|
|
renderNameGroups(items, el) {
|
|
let g = $(`<div class="rosterspan"></div>`).css({
|
|
"display": "flex",
|
|
"flex-direction": "column",
|
|
"justify-content": "center",
|
|
"height": el.textHeight,
|
|
})
|
|
items.forEach(x => {
|
|
g.append($(`<div class="" style="font-size:${el.fontSize}pt;letter-spacing: 10px;">${x}</div>`))
|
|
})
|
|
return g;
|
|
},
|
|
autoScale(names, base) {
|
|
const max = Math.max(...names.map(n => n.length), 0);
|
|
return max > 5 ? Math.max(base * (5 / max), base * 0.6) : base;
|
|
},
|
|
getTextInfo(text, font) {
|
|
const canvas = document.createElement("canvas");
|
|
const context = canvas.getContext("2d");
|
|
context.font = font;
|
|
const metrics = context.measureText(text);
|
|
return metrics
|
|
},
|
|
getTextWidth(text, font) {
|
|
const canvas = document.createElement("canvas");
|
|
const context = canvas.getContext("2d");
|
|
context.font = font;
|
|
const metrics = context.measureText(text);
|
|
|
|
return metrics;
|
|
},
|
|
getTextSize(txt, fontsize) {
|
|
let span = document.createElement("span");
|
|
span.style.visibility = "hidden";
|
|
span.style.position = "absolute";
|
|
span.style.fontSize = fontsize + "px";
|
|
span.style.fontFamily = "";
|
|
span.innerText = txt;
|
|
document.body.appendChild(span);
|
|
let result = {
|
|
width: span.offsetWidth,
|
|
height: span.offsetHeight
|
|
}
|
|
document.body.removeChild(span);
|
|
return result;
|
|
},
|
|
scaleFontSize(txtContent, fontSize, elementWidth) {
|
|
|
|
let font = this.getTextSize("講", parseInt(fontSize));
|
|
//自動判斷縮小字型的規則,要同時縮小間距
|
|
|
|
//if (dStyle.elementID === 'title1') {//表示是一般正名,也就是牌位正中間的一般格式,排法是上下上下
|
|
if ((Math.ceil(txtContent.length / 2) * font.width) * 2 > parseFloat(elementWidth)) {
|
|
let newfontSize = parseInt(fontSize) - 1;
|
|
console.log("newfontSize:", newfontSize);
|
|
if (newfontSize <= 8) {
|
|
return newfontSize;
|
|
}
|
|
//console.log("newfontSize:",newfontSize)
|
|
return this.scaleFontSize(txtContent, newfontSize, elementWidth);
|
|
}
|
|
return fontSize;
|
|
},
|
|
breakWord(txtContent, style, dStyle) {
|
|
//自動判斷斷字
|
|
//1. by 特定字 2.by長度
|
|
|
|
},
|
|
async changeSetup(config) {
|
|
switch (config) {
|
|
case "X":
|
|
if ($("#indivualSetup").prop("checked")) {
|
|
$(this.selected).css("left", $("#textX").val() + "mm");
|
|
} else if ($("#allSetup").prop("checked")) {
|
|
|
|
}
|
|
break;
|
|
case "Y":
|
|
if ($("#indivualSetup").prop("checked")) {
|
|
$(this.selected).css("top", $("#textY").val() + "mm");
|
|
} else if ($("#allSetup").prop("checked")) {
|
|
|
|
}
|
|
break;
|
|
case "fontSize":
|
|
if ($("#indivualSetup").prop("checked")) {
|
|
$(this.selected).css("font-size", $("#fontSize").val())
|
|
} else if ($("#allSetup").prop("checked")) {
|
|
|
|
}
|
|
break;
|
|
case "width":
|
|
|
|
if ($("#indivualSetup").prop("checked")) {
|
|
if (this.selected.find(".nameList").length>=1) {
|
|
$(this.selected.find(".nameList").first()).css("width", $("#textWidth").val())
|
|
} else if (this.selected.find(".liveList").length >= 1) {
|
|
this.selected.find(".liveList").first().css("width", $("#textWidth").val())
|
|
} else if (this.selected.find(".rosterList").length >= 1) {
|
|
this.selected.find(".rosterList").first().css("width", $("#textWidth").val())
|
|
} else if (this.selected.hasClass("nameSpan")) {
|
|
let spans = $(this.selected.parent().first()).find(".nameSpan");
|
|
spans.each(function (index, x) {
|
|
$(x).css("max-width", $("#textWidth").val());
|
|
});
|
|
} else if (this.selected.hasClass("liveSpan")) {
|
|
let spans = $(this.selected.parent().first()).find(".liveSpan");
|
|
spans.each(function (index, x) {
|
|
$(x).css("max-width", $("#textWidth").val());
|
|
});
|
|
} else if (this.selected.hasClass("rosterSpan")) {
|
|
let spans = $(this.selected.parent().first()).find(".rosterSpan");
|
|
spans.each(function(index, x) {
|
|
$(x).css("max-width", $("#textWidth").val());
|
|
});
|
|
}
|
|
|
|
} else if ($("#allSetup").prop("checked")) {
|
|
|
|
}
|
|
break;
|
|
case "height":
|
|
if ($("#indivualSetup").prop("checked")) {
|
|
if (this.selected.find(".nameList").length >= 1) {
|
|
$(this.selected.find(".nameList").first()).css("height", $("#textHeight").val())
|
|
} else if (this.selected.find(".liveList").length >= 1) {
|
|
this.selected.find(".liveList").first().css("height", $("#textHeight").val())
|
|
} else if (this.selected.find(".rosterList").length >= 1) {
|
|
this.selected.find(".rosterList").first().css("height", $("#textHeight").val())
|
|
} else if (this.selected.hasClass("nameSpan")) {
|
|
let spans = $(this.selected.parent().first()).find(".nameSpan");
|
|
spans.each(function (index, x) {
|
|
console.log($(x))
|
|
$(x).css("min-height", $("#textHeight").val());
|
|
});
|
|
} else if (this.selected.hasClass("liveSpan")) {
|
|
let spans = $(this.selected.parent().first()).find(".liveSpan");
|
|
spans.each(function (index, x) {
|
|
$(x).css("min-height", $("#textHeight").val());
|
|
});
|
|
} else if (this.selected.hasClass("rosterSpan")) {
|
|
let spans = $(this.selected.parent().first()).find(".rosterSpan");
|
|
spans.each(function (index, x){
|
|
$(x).css("min-height", $("#textHeight").val());
|
|
});
|
|
}
|
|
|
|
} else if ($("#allSetup").prop("checked")) {
|
|
|
|
}
|
|
break;
|
|
case "breakCount":
|
|
if ($("#indivualSetup").prop("checked")) {
|
|
|
|
} else if ($("#allSetup").prop("checked")) {
|
|
|
|
}
|
|
break;
|
|
case "breakWord":
|
|
if ($("#indivualSetup").prop("checked")) {
|
|
|
|
} else if ($("#allSetup").prop("checked")) {
|
|
|
|
}
|
|
break;
|
|
}
|
|
},
|
|
async changeLocation() {
|
|
$(this.selected).css("left", $("#textX").val() + "mm");
|
|
$(this.selected).css("top", $("#textY").val() + "mm");
|
|
},
|
|
async changeSize() {
|
|
$(this.selected).css("font-size", $("#fontSize").val())
|
|
},
|
|
async changeWidth() {
|
|
let nameList = $(this.selected).find(".nameList").first();
|
|
|
|
if (nameList) {
|
|
let spans = $(nameList).find("span");
|
|
if (spans) {
|
|
spans.each(function (index, x) {
|
|
$(x).css("width", $("#textWidth").val())
|
|
});
|
|
|
|
}
|
|
}
|
|
let liveList = $(this.selected).find(".liveList").first();
|
|
if (liveList) {
|
|
let spans = $(liveList).find("span");
|
|
if (spans) {
|
|
spans.each(function (index, x) {
|
|
$(x).css("width", $("#textWidth").val())
|
|
});
|
|
|
|
}
|
|
}
|
|
},
|
|
print() {
|
|
|
|
//let pageSize = this.allSize.find(x => x.paperID == $("#paperSizeSel").val());
|
|
//let printSize = this.allSize.find(x => x.paperID == $("#paperSizeSel").val());
|
|
//console.log("a:",pageSize," b:",printSize);
|
|
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">
|
|
${this.pageStyle}
|
|
|
|
|
|
</head>
|
|
<body>
|
|
${canvasHtml}
|
|
</body>
|
|
</html>
|
|
`;
|
|
|
|
w.document.write(htmlContent);
|
|
w.document.close();
|
|
|
|
// 5. 將等待時間稍微拉長至 1.2 秒,確保大張的 SVG 底圖與外部字體(如標楷體)下載完畢
|
|
setTimeout(() => {
|
|
w.focus();
|
|
w.print();
|
|
}, 1200);
|
|
},
|
|
}
|
|
$(document).click(function (e) {
|
|
//if (!$("#customMenu").is(e.target) && $("#customMenu").has(e.target).length === 0) {
|
|
// $("#customMenu").hide();
|
|
//}
|
|
});
|
|
$(() => Printer.init());
|
|
</script>
|
|
|
|
|
|
</html>
|