13 lines
8.2 KiB
Java
13 lines
8.2 KiB
Java
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/jspdf.es.min-BDt4QlpV.js","js/index-X7Y8jykP.js","js/emoji-mart-vue-fast-R0uJEDq-.js","js/vue-vendor-DNhG1Cve.js","assets/index-GuhSw_Yp.css","js/browser-CC9DCAWJ.js"])))=>i.map(i=>d[i]);
|
||
var B=(t,e,n)=>new Promise((o,i)=>{var m=a=>{try{s(n.next(a))}catch(f){i(f)}},l=a=>{try{s(n.throw(a))}catch(f){i(f)}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(m,l);s((n=n.apply(t,e)).next())});import{r as it}from"./nativeSchemaNormalize-WzV7gGZh.js";import{_ as z}from"./index-X7Y8jykP.js";function j(t){return t*96/25.4}function U(t){return t*25.4/96}function q(t){const e=t.getBoundingClientRect();let n=0,o=0;const i=s=>{const a=s.getBoundingClientRect();n=Math.max(n,a.right-e.left),o=Math.max(o,a.bottom-e.top),Array.from(s.children).forEach(i)};i(t);const m=Math.max(1,Math.ceil(n),t.scrollWidth,t.clientWidth),l=Math.max(1,Math.ceil(o),t.scrollHeight,t.clientHeight);return{sw:m,sh:l}}function J(t){const e=new Uint8Array(t),n=32768;let o="";for(let i=0;i<e.length;i+=n){const m=e.subarray(i,i+n);o+=String.fromCharCode(...m)}return btoa(o)}function at(t){var e,n;try{return((n=(e=new DOMParser().parseFromString(t,"text/html").body)==null?void 0:e.innerHTML)==null?void 0:n.trim())||t}catch(o){return t}}function st(i,m,l){return B(this,arguments,function*(t,e,n,o={}){const s=o.paginate!==!1,a=o.exactPaperSize===!0,[{jsPDF:f},c]=yield Promise.all([z(()=>import("./jspdf.es.min-BDt4QlpV.js"),__vite__mapDeps([0,1,2,3,4,5])),z(()=>import("./html2canvas.esm-DIwbOgLI.js"),[])]),u=c.default,r=document.createElement("div");r.style.position="fixed",r.style.left="-20000px",r.style.top="0",r.style.width="auto",r.style.maxWidth="none",r.style.overflow="visible",r.style.background="#fff",r.style.zIndex="-1",r.innerHTML=`<div class="lodop-print-root" style="width:${e}mm;min-width:${e}mm;margin:0;padding:0;background:#fff;overflow:visible;box-sizing:border-box;">${t}</div>`,document.body.appendChild(r);try{const d=r.querySelector(".lodop-print-root")||r;yield new Promise(p=>setTimeout(p,400));const A=()=>{const p=Math.max(d.scrollWidth,d.clientWidth,1),w=Math.max(d.scrollHeight,d.clientHeight,1);return{sw:p,sh:w}};let{sw:h,sh:g}=A();const T=j(Math.max(1,e));h<T&&(d.style.width=`${T}px`),h>T&&(d.style.width=`${h}px`),{sw:h,sh:g}=A();let M=q(d);h=Math.max(h,M.sw),g=Math.max(g,M.sh),d.style.minHeight=`${g}px`,d.style.width=`${Math.max(T,h)}px`,{sw:h,sh:g}=A(),M=q(d),h=Math.max(h,M.sw),g=Math.max(g,M.sh);const Q=12e3;let b=2;for(;Math.max(h,g)*b>Q&&b>.75;)b-=.25;const H=yield u(d,{backgroundColor:"#ffffff",scale:b,useCORS:!0,allowTaint:!0,logging:!1,width:h,height:g,windowWidth:h,windowHeight:g,onclone:(p,w)=>{var _;const P=((_=w.querySelector)==null?void 0:_.call(w,".lodop-print-root"))||w;if(!P)return;P.style.minHeight=`${g}px`,P.style.width=`${h}px`,P.style.overflow="visible";const W=y=>{const x=y.style;(x.overflow==="hidden"||x.overflowX==="hidden"||x.overflowY==="hidden")&&x.setProperty("overflow","visible","important"),Array.from(y.children).forEach(N=>W(N))};W(P)}}),v=Math.max(1,H.width),F=Math.max(1,H.height),I=1;if(s){const p=a?Math.max(1,e):Math.max(e,U(h)+I),w=Math.max(1,n),P=Math.max(1,Math.round(j(w)*b)),W=p>w?"landscape":"portrait",_=new f({unit:"mm",orientation:W,format:[p,w]});let y=0,x=!0;const N=Math.max(8,Math.floor(P*.02));for(;y<F;){const O=F-y;if(!x&&O<=N)break;const D=Math.min(P,O);if(D<1)break;const k=document.createElement("canvas");k.width=v,k.height=D;const R=k.getContext("2d");R&&(R.fillStyle="#ffffff",R.fillRect(0,0,v,D),R.drawImage(H,0,y,v,D,0,0,v,D));const rt=k.toDataURL("image/jpeg",.92),ot=w*(D/P);x||_.addPage(),x=!1,_.addImage(rt,"JPEG",0,0,p,ot),y+=P}return J(_.output("arraybuffer"))}const X=U(h),Z=U(g),C=a?Math.max(1,e):Math.max(e,X)+I,tt=Math.max(n,Z)+I,$=v/F;let E=Math.max(tt,C/$),S=E*$;S<C&&(S=C,E=S/$);const et=S>E?"landscape":"portrait",L=new f({unit:"mm",orientation:et,format:[S,E]}),nt=H.toDataURL("image/jpeg",.92);return L.addImage(nt,"JPEG",0,0,S,E),J(L.output("arraybuffer"))}finally{r.remove()}})}const G="qhmes_print_dot_ws_url",V="qhmes_print_dot_key";function Y(){return{wsUrl:localStorage.getItem(G)||"ws://127.0.0.1:1122/ws",key:localStorage.getItem(V)||""}}function wt(t,e){localStorage.setItem(G,(t||"").trim()),localStorage.setItem(V,e!=null?e:"")}function K(t,e){const n=(t||"").trim(),o=(e||"").trim();if(!o)return n;const i=n.includes("?")?"&":"?";return`${n}${i}key=${encodeURIComponent(o)}`}function ct(t=8e3){const{wsUrl:e,key:n}=Y();return new Promise((o,i)=>{let m=!1;const l=new WebSocket(K(e,n)),s=window.setTimeout(()=>{if(!m){m=!0;try{l.close()}catch(f){}i(new Error("连接 PrintDot 超时,请确认客户端已启动且 WebSocket 地址正确"))}},t),a=f=>{if(!m){m=!0,window.clearTimeout(s);try{l.close()}catch(c){}f()}};l.onmessage=f=>{try{const c=JSON.parse(f.data);if((c==null?void 0:c.type)==="printer_list"&&Array.isArray(c.data)){const u=c.data.map(r=>({name:String((r==null?void 0:r.name)||"").trim(),isDefault:(r==null?void 0:r.isDefault)===!0})).filter(r=>!!r.name);a(()=>o(u))}}catch(c){}},l.onerror=()=>{a(()=>i(new Error("无法连接 PrintDot WebSocket,请检查地址与客户端是否运行")))}})}function lt(t){const e=String(t||"").trim();return/SumatraPDF\.exe not found/i.test(e)||/SUMATRAPDF_PATH/i.test(e)?`${e}。本地处理:PrintDot 依赖 SumatraPDF 静默打印 PDF。请安装 Sumatra PDF 后任选其一:将 SumatraPDF.exe 放在 PrintDot 客户端 exe 同目录;或将 Sumatra 安装目录加入系统 PATH;或设置用户/系统环境变量 SUMATRAPDF_PATH 指向 SumatraPDF.exe 的完整路径,然后重启 PrintDot。`:/not queued/i.test(e)||/Printed\s+0\s*\/\s*\d+\s+copies/i.test(e)?`${e}
|
||
|
||
【说明】PrintDot 已通过 SumatraPDF 发起静默打印,但在约定时间内未检测到作业进入系统打印队列。
|
||
|
||
【建议逐项排查】
|
||
1. 打印机是否开机、联网(网络打印机)、线缆/USB 是否正常。
|
||
2. Windows「设备和打印机」中该打印机是否就绪、无暂停;打印队列里是否有卡住的任务(可先清空队列)。
|
||
3. 下拉选择的打印机名称是否与系统完全一致(可在本页「刷新打印机」后重选)。
|
||
4. 重启「Print Spooler」打印后台服务,或重启 PrintDot 客户端后再试。
|
||
5. 模板版面过大时生成的 PDF 体积大,可能导致 Sumatra 处理变慢——可先简化模板或缩小画布后再试。
|
||
6. 若频繁超时,需在 PrintDot 桌面端放宽「队列确认」超时(该 2 分钟由客户端决定,浏览器无法修改)。`:e}function mt(t){const{wsUrl:e,key:n}=Y(),o=t.timeoutMs;return new Promise((i,m)=>{let l=!1;const s=new WebSocket(K(e,n)),a=window.setTimeout(()=>{if(!l){l=!0;try{s.close()}catch(c){}m(new Error("PrintDot 打印等待结果超时"))}},o),f=(c,u)=>{if(!l){l=!0,window.clearTimeout(a);try{s.close()}catch(r){}i({ok:c,message:u})}};s.onopen=()=>{let c=String(t.pdfBase64||"").trim();if(c.startsWith("data:")){const r=c.indexOf(",");r!==-1&&(c=c.slice(r+1))}const u={printer:String(t.printer||"").trim(),content:c,job:{name:String(t.jobName||"QH-MES").trim()||"QH-MES",copies:Math.max(1,Number(t.copies)||1)}};s.send(JSON.stringify(u))},s.onmessage=c=>{try{const u=JSON.parse(c.data);if((u==null?void 0:u.type)==="printer_list")return;if(u!=null&&u.status){const r=u.status==="success",d=String(u.message||"");f(r,r?d:lt(d))}}catch(u){f(!1,"PrintDot 返回无法解析")}},s.onerror=()=>{if(!l){l=!0,window.clearTimeout(a);try{s.close()}catch(c){}m(new Error("PrintDot WebSocket 错误"))}}})}function ft(t,e){var i;const n=String(t||"").trim();if(n&&n!=="__system_default__")return n;const o=e.find(m=>m.isDefault);return(o==null?void 0:o.name)||((i=e[0])==null?void 0:i.name)||""}const ut="print_template_selected_printer";function Pt(t){return B(this,null,function*(){var a,f;const e=yield it(t.schema,t.data),n=at(e),o=yield st(n,t.schema.page.width,t.schema.page.height,{paginate:!0,exactPaperSize:!0}),i=yield ct(),m=(f=(a=t.printerSelection)!=null?a:localStorage.getItem(ut))!=null?f:"__system_default__",l=ft(m,i);if(!l)throw new Error("未解析到可用打印机:请在本页或打印模板页选择打印机,并确保本机 PrintDot 已启动后刷新打印机列表");const s=yield mt({printer:l,pdfBase64:o,jobName:t.jobName,timeoutMs:18e4});if(!s.ok)throw new Error(s.message||"PrintDot 打印失败")})}export{ut as P,st as b,ct as f,Y as g,Pt as p,wt as s};
|