Files
qhmes/web-dist/js/NativeTemplateListPreviewModal-CsdnFNwg.js
2026-06-16 18:19:57 +08:00

2 lines
11 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var ze=Object.defineProperty,Ce=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var je=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable;var ie=(f,c,n)=>c in f?ze(f,c,{enumerable:!0,configurable:!0,writable:!0,value:n}):f[c]=n,re=(f,c)=>{for(var n in c||(c={}))je.call(c,n)&&ie(f,n,c[n]);if(le)for(var n of le(c))De.call(c,n)&&ie(f,n,c[n]);return f},ue=(f,c)=>Ce(f,Te(c));var E=(f,c,n)=>new Promise((W,w)=>{var R=v=>{try{k(n.next(v))}catch(s){w(s)}},D=v=>{try{k(n.throw(v))}catch(s){w(s)}},k=v=>v.done?W(v.value):Promise.resolve(v.value).then(R,D);k((n=n.apply(f,c)).next())});import{e as Je,h as H,y as L,z as P,A as i,c as N,K as Ie,f as o,r as p,C as X,H as F,G as ce,Q as d,O as ve,J as pe,E as U,P as me,R as He,u as G,T as Q,n as Y}from"./vue-vendor-DNhG1Cve.js";import{ft as Le,M as Re,s as $e,aH as Be,aU as Ee,aX as Fe,bR as Ue,aE as We,T as Ae,x as ee,bL as Ke,J as Ve,au as qe}from"./index-X7Y8jykP.js";import{f as Ze}from"./printTemplate.api-Dfuyi-ab.js";import{n as Xe,a as Ge,r as Qe}from"./nativeSchemaNormalize-WzV7gGZh.js";import{g as de,s as Ye}from"./nativeMockData-D5nIVXYv.js";import{p as et}from"./printNativeViaPrintDot-hFBchMti.js";import{O as tt}from"./index-CuWaQdlK.js";import{A as at}from"./index-DO7ZhK45.js";import"./emoji-mart-vue-fast-R0uJEDq-.js";import"./browser-D2DxMZOB.js";import"./tableMerge-CpKVscEF.js";import"./tableBuilder-lOY0L2dW.js";import"./freeTableGrid-BXWKfNhh.js";import"./freeTableBorders-i5ck0FPH.js";import"./freeTableTracks--U1Y5u-V.js";import"./barcodeRenderer-cjxjmb-t.js";const nt={key:0,class:"native-preview-error"},ot={class:"json-template-pane"},st={class:"params-json-pane"},lt={class:"params-json-head"},it={class:"json-sub-tabs json-sub-tabs--segmented",role:"tablist","aria-label":"参数数据来源"},rt={class:"preview-header-row"},ut={class:"preview-zoom-label"},ct={key:0,class:"preview-scroll-flex"},vt={class:"preview-zoom-slot"},pt=["srcdoc"],fe=1.15,mt=.25,dt=4,he=96/25.4,ft=Je({__name:"NativeTemplateListPreviewModal",props:{open:{type:Boolean},templateId:{}},emits:["update:open"],setup(f,{emit:c}){const n=f,W=c,{createMessage:w}=$e(),R=N({get:()=>n.open,set:e=>W("update:open",e)}),D=p(!1),k=p(!1),v=p(""),s=p(null),J=p("{}"),A=p("template"),y=p("mock"),$=p("{}"),O=p("{}"),g=p(""),B=p(null),K=p(null),z=p(1),b=p(1),V=N(()=>{const e=z.value*b.value;return!Number.isFinite(e)||e<=0?1:Math.min(4,Math.max(.08,e))}),we=N(()=>`${Math.round(b.value*100)}%`),te=N(()=>y.value==="mock"?O.value:$.value),q=N(()=>{try{return JSON.parse(te.value||"{}")}catch(e){return{}}}),ae=N(()=>{var u,m;if(!s.value)return null;const e=Math.max(1,Ge(s.value,q.value)),t=Number(((u=s.value.page)==null?void 0:u.width)||210),r=Number(((m=s.value.page)==null?void 0:m.height)||297),a=t*he,l=r*e*he;return{wPx:a,hPx:l,pageCount:e}}),C=p({w:0,h:0}),M=N(()=>{const e=ae.value;if(!e)return null;const t=C.value;return ue(re({},e),{wPx:Math.max(e.wPx,t.w||0),hPx:Math.max(e.hPx,t.h||0)})});function xe(e){const t=e.body;let r=1/0,a=0,l=1/0,u=0;const m=j=>{if(j instanceof HTMLElement){const h=j.getBoundingClientRect();h.height>.5&&h.width>.5&&(r=Math.min(r,h.top),a=Math.max(a,h.bottom),l=Math.min(l,h.left),u=Math.max(u,h.right))}for(let h=0;h<j.children.length;h++)m(j.children[h])};m(t);const x=Number.isFinite(r)&&a>0?{w:Math.ceil(u-l+6),h:Math.ceil(a-r+12)}:{w:0,h:0},T=Math.max(e.documentElement.scrollHeight,t.scrollHeight,x.h),I=Math.max(e.documentElement.scrollWidth,t.scrollWidth,x.w);return{w:Math.ceil(I),h:Math.ceil(T)}}function ne(){Y(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{var t;const e=(t=K.value)==null?void 0:t.contentDocument;if(!(e!=null&&e.body)){C.value={w:0,h:0},S();return}C.value=xe(e),S()})})})}function oe(){return E(this,null,function*(){if(!s.value){g.value="";return}try{g.value=yield Qe(s.value,q.value)}catch(e){g.value="",w.error(`预览渲染失败:${(e==null?void 0:e.message)||"未知错误"}`)}})}const _e=Ve(()=>void oe(),320);function ye(){const e=B.value,t=M.value;if(!e||!t){z.value=1;return}const r=20,a=Math.max(0,e.clientWidth-r),l=Math.max(0,e.clientHeight-r);if(a<=0||l<=0||t.wPx<=0||t.hPx<=0){z.value=1;return}const u=Math.min(a/t.wPx,l/t.hPx,1)*.96;z.value=Number.isFinite(u)&&u>0?u:1}function ge(){b.value=Math.min(dt,b.value*fe),Z()}function be(){b.value=Math.max(mt,b.value/fe),Z()}function Z(){Y(()=>{const e=B.value;if(!e)return;const t=e.querySelector(".preview-zoom-slot");if(!t)return;const r=t.getBoundingClientRect(),a=e.getBoundingClientRect(),l=e.scrollLeft+(r.left-a.left)+r.width/2-e.clientWidth/2,u=e.scrollTop+(r.top-a.top)+r.height/2-e.clientHeight/2;e.scrollTo({left:Math.max(0,l),top:Math.max(0,u),behavior:"smooth"})})}function Me(){b.value=1,S(),Z()}function Pe(){ne(),window.setTimeout(()=>ne(),400)}function ke(){return E(this,null,function*(){if(!s.value){w.warning("模板未加载");return}k.value=!0;try{yield et({schema:s.value,data:q.value,jobName:n.templateId?`tpl-${n.templateId}`:"native-preview"}),w.success("已通过 PrintDot 提交打印")}catch(e){w.error((e==null?void 0:e.message)||"PrintDot 打印失败")}finally{k.value=!1}})}function Se(){var t;const e=(t=K.value)==null?void 0:t.contentWindow;if(!e){w.warning("预览未就绪请稍后再试");return}try{e.focus(),e.print()}catch(r){w.error("无法唤起打印请检查浏览器是否拦截弹窗")}}function S(){Y(()=>ye())}Le(B,()=>{S()}),H([ae,g,()=>n.open],()=>{C.value={w:0,h:0},S()}),H([M,()=>n.open],()=>{n.open&&S()});function se(){v.value="",s.value=null,g.value="",b.value=1,z.value=1,C.value={w:0,h:0}}function Ne(){if(s.value)try{const e=de(s.value.elements,J.value);O.value=JSON.stringify(e,null,2),w.success("已根据画布组件生成模拟数据 JSON")}catch(e){w.error(`生成失败:${(e==null?void 0:e.message)||"未知错误"}`)}}return H(()=>[n.open,n.templateId],r=>E(null,[r],function*([e,t]){if(!(!e||!t)){D.value=!0,v.value="",s.value=null,g.value="",b.value=1,z.value=1,C.value={w:0,h:0};try{const a=yield Ze(t),l=String((a==null?void 0:a.templateJson)||"").trim();if(!l){v.value="该记录没有模板 JSON";return}const u=JSON.parse(l);if((u==null?void 0:u.engine)!=="native"){v.value="仅原生模板engine=native支持此预览";return}const m=Xe(u),x=Number(a==null?void 0:a.paperWidthMm),T=Number(a==null?void 0:a.paperHeightMm);x>0&&T>0&&(m.page.width=x,m.page.height=T),s.value=m,J.value=Ye(m);const I=de(m.elements,J.value);O.value=JSON.stringify(I,null,2),$.value=O.value,y.value="mock",A.value="params",yield oe(),S()}catch(a){v.value=(a==null?void 0:a.message)||"加载模板失败"}finally{D.value=!1}}}),{immediate:!1}),H([te,s,()=>n.open],()=>{!n.open||!s.value||_e()}),H(()=>n.open,e=>{e||se()}),(e,t)=>{const r=Ue,a=Fe,l=Ie("a-button"),u=Ee,m=at,x=Ae,T=We,I=Ke,j=tt,h=Be,Oe=Re;return P(),L(Oe,{open:R.value,"onUpdate:open":t[7]||(t[7]=_=>R.value=_),title:"模板预览",width:"1240px",footer:null,"body-style":{padding:"16px 20px 22px"},"destroy-on-close":"","wrap-class-name":"native-template-list-preview-modal",onCancel:se},{default:i(()=>[o(h,{spinning:D.value},{default:i(()=>[v.value?(P(),X("div",nt,ce(v.value),1)):s.value?(P(),L(j,{key:1,gutter:20,class:"native-preview-row"},{default:i(()=>[o(m,{xs:24,lg:11,class:"native-preview-left"},{default:i(()=>[o(u,{activeKey:A.value,"onUpdate:activeKey":t[5]||(t[5]=_=>A.value=_),size:"small",class:"json-tabs"},{default:i(()=>[o(a,{key:"template",tab:"模板JSON"},{default:i(()=>[d("div",ot,[t[8]||(t[8]=d("div",{class:"json-box-title"},"画布实际 JSON模板样式",-1)),o(r,{value:J.value,"onUpdate:value":t[0]||(t[0]=_=>J.value=_),rows:16,class:"json-textarea",placeholder:"模板 JSON"},null,8,["value"])])]),_:1}),o(a,{key:"params",tab:"参数JSON"},{default:i(()=>[d("div",st,[d("div",lt,[d("div",it,[d("button",{type:"button",role:"tab",class:pe(["capsule-tab",{"is-active":y.value==="manual"}]),onClick:t[1]||(t[1]=_=>y.value="manual")}," 手动JSON ",2),d("button",{type:"button",role:"tab",class:pe(["capsule-tab",{"is-active":y.value==="mock"}]),onClick:t[2]||(t[2]=_=>y.value="mock")}," 模拟JSON ",2)]),ve(o(l,{size:"small",type:"primary",ghost:"",class:"json-capsule-btn",onClick:Ne},{default:i(()=>[...t[9]||(t[9]=[U(" 根据画布生成 ",-1)])]),_:1},512),[[me,y.value==="mock"]])]),ve(o(r,{value:$.value,"onUpdate:value":t[3]||(t[3]=_=>$.value=_),rows:14,class:"json-textarea json-textarea--main",placeholder:"手动输入预览数据 JSON"},null,8,["value"]),[[me,y.value==="manual"]]),y.value==="mock"?(P(),L(r,{key:0,value:O.value,"onUpdate:value":t[4]||(t[4]=_=>O.value=_),rows:12,class:"json-textarea json-textarea--main",placeholder:"点击根据画布生成自动填充模拟数据"},null,8,["value"])):F("",!0)])]),_:1})]),_:1},8,["activeKey"])]),_:1}),o(m,{xs:24,lg:13,class:"native-preview-right"},{default:i(()=>[d("div",rt,[t[13]||(t[13]=d("div",{class:"preview-title"},"预览样式",-1)),g.value?(P(),L(T,{key:0,size:"small",align:"center",wrap:"",class:"preview-header-actions",onClick:t[6]||(t[6]=He(()=>{},["stop"]))},{default:i(()=>[o(x,{title:"缩小"},{default:i(()=>[o(l,{type:"default",size:"small",class:"preview-zoom-btn",onClick:be},{default:i(()=>[o(G(ee),{icon:"ant-design:zoom-out-outlined"})]),_:1})]),_:1}),d("span",ut,ce(we.value),1),o(x,{title:"放大"},{default:i(()=>[o(l,{type:"default",size:"small",class:"preview-zoom-btn",onClick:ge},{default:i(()=>[o(G(ee),{icon:"ant-design:zoom-in-outlined"})]),_:1})]),_:1}),o(x,{title:"恢复按窗口适应"},{default:i(()=>[o(l,{type:"default",size:"small",class:"preview-zoom-fit-btn",onClick:Me},{default:i(()=>[...t[10]||(t[10]=[U("适应",-1)])]),_:1})]),_:1}),o(x,{title:"使用浏览器打印当前预览内容"},{default:i(()=>[o(l,{type:"primary",size:"small",class:"preview-print-btn",onClick:Se},{default:i(()=>[o(G(ee),{icon:"ant-design:printer-outlined"}),t[11]||(t[11]=U(" 打印 ",-1))]),_:1})]),_:1}),o(x,{title:" PrintDot 本地客户端以 PDF 静默打印需本机桥接器运行"},{default:i(()=>[o(l,{type:"default",size:"small",class:"preview-print-btn",loading:k.value,onClick:ke},{default:i(()=>[...t[12]||(t[12]=[U(" PrintDot ",-1)])]),_:1},8,["loading"])]),_:1})]),_:1})):F("",!0)]),M.value?(P(),X("div",{key:0,ref_key:"previewHostRef",ref:B,class:"preview-frame-wrap"},[g.value?(P(),X("div",ct,[d("div",vt,[d("div",{class:"preview-scale-shim",style:Q({width:`${M.value.wPx*V.value}px`,height:`${M.value.hPx*V.value}px`})},[d("div",{class:"preview-scale-inner",style:Q({width:`${M.value.wPx}px`,height:`${M.value.hPx}px`,transform:`scale(${V.value})`})},[d("iframe",{ref_key:"previewIframeRef",ref:K,class:"preview-iframe",title:"原生模板预览",srcdoc:g.value,style:Q({width:`${M.value.wPx}px`,height:`${M.value.hPx}px`}),onLoad:Pe},null,44,pt)],4)],4)])])):(P(),L(I,{key:1,description:"正在生成预览"}))],512)):F("",!0)]),_:1})]),_:1})):F("",!0)]),_:1},8,["spinning"])]),_:1},8,["open"])}}}),Dt=qe(ft,[["__scopeId","data-v-f390eb1e"]]);export{Dt as default};