Files
17168ERP/web/admin/printpw/print.js
2025-08-29 01:27:25 +08:00

51 lines
1.8 KiB
JavaScript

var body_class = $("[data-body-class]").data("body-class");
function init_print() {
console.log("init_print");
if (body_class) {
$("body").addClass(body_class);
}
$(".fit-text").each(function (i, e) {
//var txt = $(this).text();
var txt = $(this).html();
txt = txt.replace('\r', '\n');
txt = txt.replace('\n\n', '\n');
var htm = $(this).html();
//var txt_arr = txt.split('\n');
var txt_arr = txt.split('<br>');
var txt_arr2 = Array();
//debugger;
var line = 0;
var line_len = 1;
var css = "", htm_lines = "";
txt_arr.forEach((t, n) => {
var len = t.trim().length;
if (len > 0) {
line++;
if (len > line_len) { line_len = len }
//let trim_text = t.trim();//去除任何空白:全型,半型, \t, \n...
//let trim_text = str.replace(/^[^\S\u3000]+|[^\S\u3000]+$/g, "");//去空白但保留全型空白
let trim_text = t; //完全不去空白
txt_arr2.push(trim_text);
}
//console.log(n,t,t.trim().length);
});
//console.log(i, $(this).html(),$(this).text());
//console.log(i, txt==htm);
//console.log(i, txt_arr, line, line_len);
line_len = Math.ceil(line_len / 5) * 5;
//if(line>1){
css = $(this).attr("style")||"";
if(css.length>0){
css += ";";
}
css += "--lines:" + line + ";--line_len:" + line_len + ";";
//debugger;
htm_lines = txt_arr2.join("<br>");
$(this).attr("style", css);
$(this).html(htm_lines);
//}
//console.log(i, line, line_len, css,txt);
});
}
init_print();