2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
import{_ as e,r as t,m as a,p as l,E as n,c as o,o as i,b as r,d as s,n as u,t as c,e as d,l as v,v as f,f as y,q as p,P as m,u as g,x as b,C as h,D as x}from"./styles-G88NglGL.js";import"./pdfjs-DXqArq6h.js";import"./pdf-lib-AfLQbX6n.js";const S={class:"viewer-container"},w={class:"viewer-main"},k={class:"controls"},_=["disabled"],D={style:{"min-width":"54px","text-align":"center"}},T=["max"],J={style:{"margin-left":"4px"}},P={key:0,style:{display:"flex","align-items":"center",gap:"12px","margin-left":"8px","font-size":"12px",color:"#6b7280"}},z={class:"viewer"};x(e({__name:"ViewerApp",setup(e){const x=t(null),C=t(null),F=t(0),I=t(1),O=t(1),R=t(null),A=t(""),E=t({}),N=t(!1);let L=null;const M=t({startNumber:1,increment:1,prefix:"",suffix:"",fontSize:10,borderStyle:"none",annotationStyle:"circle-outline"});let B=null;const H=t({show:!1,message:"",type:"success"});let U=null;function W(e,t="success"){H.value={show:!0,message:e,type:t},clearTimeout(U),U=setTimeout(()=>{H.value.show=!1},2500)}const j=t(null),V=t(100),$=t(1),Y=a(()=>{const e=null!==j.value?j.value:$.value;return Math.round(100*e)});function Z(e){C.value=e.pdf,F.value=e.numPages,I.value=1,O.value=1,ie&&R.value&&h(()=>{R.value.setAnnotations(ie),h(()=>{R.value&&R.value.renderPage&&R.value.renderPage(I.value)}),W("标注数据已加载"),ie=null})}function q(e){$.value=e}function G(e){j.value=e,V.value=Math.round(100*e)}function K(){j.value=+V.value/100}async function Q(e){if(e&&e.trim())try{const t=await fetch(e);if(!t.ok)throw new Error(`获取失败: ${t.status}`);const a=await t.blob(),l=new FileReader;l.onload=e=>{const t=e.target.result;R.value?(R.value.setTemporaryImage(t,400),W("点击PDF上要放置图片的位置, 按ESC取消")):W("请先加载PDF","error")},l.onerror=()=>{W("读取图片数据失败","error")},l.readAsDataURL(a)}catch(t){console.error("导入图片错误:",t),W("导入图片失败: "+t.message,"error")}else W("图片URL为空","error")}async function X(){const e=document.getElementById("imgurl1"),t=e?.value?.trim();t?await Q(t):W("未找到图片地址1","error")}async function ee(){const e=document.getElementById("imgurl2"),t=e?.value?.trim();t?await Q(t):W("未找到图片地址2","error")}function te(){if(!R.value||!C.value)return void W("请先加载PDF","error");const e=document.getElementById("annotionData");if(!e||!e.value||!e.value.trim())return void W("未找到焊口数据","error");let t;try{const a=JSON.parse(e.value);t=Array.isArray(a)?a:a?.annotations&&"object"==typeof a.annotations?Object.entries(a.annotations).flatMap(([e,t])=>Array.isArray(t)?t.map(t=>({...t,page:t.page??Number(e)})):[]):null}catch(a){return void W("焊口数据格式错误","error")}if(t&&0!==t.length)try{const e=function(e){const t=document.createElement("canvas"),a=t.getContext("2d"),l=[{key:"index",label:"序号",width:50},{key:"JOT_JointNo",label:"焊口编号",width:100},{key:"WED_Code",label:"焊工代号",width:90},{key:"JOT_Location",label:"焊接位置",width:80},{key:"JOT_WeldDate",label:"焊接日期",width:100},{key:"DetectionTypeCode",label:"检测类型",width:80},{key:"IsRepair",label:"是否返修",width:70},{key:"IsHotProcess",label:"是否热处理",width:80},{key:"JOT_JointStatus",label:"焊口状态",width:80}],n=32,o=36,i=l.reduce((e,t)=>e+t.width,0)+16,r=o+n*e.length+16;t.width=2*i,t.height=2*r,t.style.width=i+"px",t.style.height=r+"px",a.scale(2,2),a.fillStyle="#ffffff",a.fillRect(0,0,i,r);const s=i-16;a.fillStyle="#e8edf2",a.fillRect(8,8,s,o),a.fillStyle="#1e3a5f",a.font='bold 14px "Microsoft YaHei", "SimHei", sans-serif',a.textAlign="center",a.textBaseline="middle";let u=8;for(const c of l)a.fillText(c.label,u+c.width/2,26),u+=c.width;a.font='13px "Microsoft YaHei", "SimHei", sans-serif';for(let c=0;c<e.length;c++){const t=e[c],o=44+c*n;c%2==1&&(a.fillStyle="#f5f7fa",a.fillRect(8,o,s,n)),a.fillStyle="#333333",a.textAlign="center",u=8;for(const e of l){let l="";l="index"===e.key?String(c+1):null!=t[e.key]?String(t[e.key]):"/";const n=e.width-8;let i=l;for(;a.measureText(i).width>n&&i.length>1;)i=i.slice(0,-1);i!==l&&(i+="…"),a.fillText(i,u+e.width/2,o+16),u+=e.width}}a.strokeStyle="#c0c8d4",a.lineWidth=1,a.strokeRect(8,8,s,o+n*e.length);for(let c=0;c<=e.length;c++){const e=44+c*n;a.beginPath(),a.moveTo(8,e),a.lineTo(8+s,e),a.stroke()}u=8;for(let c=0;c<l.length-1;c++)u+=l[c].width,a.beginPath(),a.moveTo(u,8),a.lineTo(u,44+n*e.length),a.stroke();return t.toDataURL("image/png")}(t);R.value.setTemporaryImage(e,500),W("点击PDF上要放置表格的位置, 按ESC取消")}catch(l){console.error("生成焊口表格失败:",l),W("生成焊口表格失败: "+l.message,"error")}else W("焊口数据为空","error")}function ae(){if(!R.value||!C.value)return void W("请先加载PDF","error");const e=document.getElementById("orgname"),t=e?.value?.trim()||"公司名称";try{const e=function(e){const t=document.createElement("canvas"),a=t.getContext("2d"),l=[120,120,120],n=l.reduce((e,t)=>e+t,0),o=36;t.width=2*n,t.height=232,t.style.width=n+"px",t.style.height="116px",a.scale(2,2),a.clearRect(0,0,n,116),a.strokeStyle="#000000",a.lineWidth=1.5,a.strokeRect(0,0,n,o),a.fillStyle="#000000",a.font='bold 14px "Microsoft YaHei", "SimHei", sans-serif',a.textAlign="center",a.textBaseline="middle",a.fillText(e,n/2,18);const i=["编制人","审核人","日期"];let r=0;for(let s=0;s<3;s++)a.strokeRect(r,36,l[s],o),a.fillStyle="#000000",a.font='bold 14px "Microsoft YaHei", "SimHei", sans-serif',a.textAlign="center",a.textBaseline="middle",a.fillText(i[s],r+l[s]/2,54),r+=l[s];r=0;for(let s=0;s<3;s++)a.strokeRect(r,72,l[s],44),r+=l[s];return t.toDataURL("image/png")}(t);R.value.setTemporaryImage(e,360),W("点击PDF上要放置签名的位置, 按ESC取消")}catch(a){console.error("生成签名表格失败:",a),W("生成签名表格失败: "+a.message,"error")}}function le(e){const t=I.value;E.value[t]||(E.value[t]=[]),E.value[t].push(e),R.value&&R.value.setImages(E.value),W("图片已放置")}function ne(){W("已取消图片放置")}function oe(e){E.value[e.page]=e.images,W("图片已删除")}let ie=null;function re(e,t="circle-outline"){const a={};for(const l in e||{}){const n=Array.isArray(e[l])?e[l]:[];a[l]=n.map(e=>{const a=e?.borderStyle??e?.settings?.borderStyle??"none",l=e?.fontSize??e?.settings?.fontSize??10,n=e?.annotationStyle??e?.settings?.annotationStyle??t;return{...e,displayValue:e?.displayValue??e?.label??"",style:e?.style??a,borderStyle:a,annotationStyle:n,fontSize:l,settings:{...e?.settings,prefix:e?.settings?.prefix??"",suffix:e?.settings?.suffix??"",fontSize:l,borderStyle:a,annotationStyle:n}}})}return a}function se(e){if(e&&e.trim())try{const t=JSON.parse(e);let a={};if(Array.isArray(t)){const e=t.map((e,t)=>{const a=e.page||"1",l=e.borderStyle||e.border_style||M.value.borderStyle||"none",n=e.fontSize??e.font_size??M.value.fontSize??10,o=e.annotationStyle||e.annotation_style||M.value.annotationStyle||"circle-outline";return{page:a,annotation:{x:parseFloat(e.x)||0,y:parseFloat(e.y)||0,x2:parseFloat(e.x2)||0,y2:parseFloat(e.y2)||0,displayValue:e.JOT_JointNo||t+1,label:e.JOT_JointNo||"",text:e.JOT_JointNo||"",style:l,borderStyle:l,fontSize:n,annotationStyle:o,JOT_ID:e.JOT_ID||"",JOT_JointNo:e.JOT_JointNo||"",WED_Code:e.WED_Code||null,JOT_Location:e.JOT_Location||"",JOT_WeldDate:e.JOT_WeldDate||null,DetectionTypeCode:e.DetectionTypeCode||"/",IsRepair:e.IsRepair||"/",IsHotProcess:e.IsHotProcess||"/",JOT_JointStatus:e.JOT_JointStatus||"",settings:{prefix:"",suffix:"",fontSize:n,borderStyle:l,annotationStyle:o}}}});for(const t of e)a[t.page]||(a[t.page]=[]),a[t.page].push(t.annotation);if(t.length>0&&t[0].JOT_JointNo){const e=t[0].JOT_JointNo.match(/^([A-Za-z]*)([0-9]+)([A-Za-z]*)$/);e&&(M.value.prefix=e[1],M.value.suffix=e[3])}}else{if(!t.annotations)return void console.warn("annotionData: 无法识别的数据格式");{const e=t.globalSettings?.annotationStyle||M.value.annotationStyle||"circle-outline";if(a=re(t.annotations,e),t.globalSettings){const e=t.globalSettings;M.value={startNumber:e.startNumber??1,increment:e.increment??1,prefix:e.prefix??"",suffix:e.suffix??"",fontSize:e.fontSize??e.font_size??10,borderStyle:e.borderStyle??e.border_style??"none",annotationStyle:e.annotationStyle??e.annotation_style??"circle-outline"}}else(t.fontSize||t.borderStyle||t.annotationStyle)&&(M.value={...M.value,fontSize:t.fontSize??t.font_size??M.value.fontSize??10,borderStyle:t.borderStyle??t.border_style??M.value.borderStyle??"none",annotationStyle:t.annotationStyle??t.annotation_style??M.value.annotationStyle??"circle-outline"})}}if(R.value&&C.value){const e=re(a,M.value.annotationStyle||"circle-outline");R.value.setAnnotations(e),h(()=>{R.value&&R.value.renderPage&&R.value.renderPage(I.value)}),W("标注数据已加载")}else ie=re(a,M.value.annotationStyle||"circle-outline");console.log("annotionData 解析成功,页面数:",Object.keys(a).length)}catch(t){console.error("annotionData 解析失败:",t)}}return l(()=>{const e=document.getElementById("hdpdfurl");let t=null;e&&e.value&&e.value.trim()&&(t=e.value.trim());const a=new URLSearchParams(window.location.search).get("url");a&&(t=a),t&&async function(e){if(e){W("正在加载PDF...");try{const a=await fetch(e);if(!a.ok)throw new Error(`加载失败: ${a.status} ${a.statusText}`);const l=await a.arrayBuffer(),n=new Blob([l],{type:"application/pdf"});L=l;let o="online.pdf";try{const t=new URL(e).pathname.split("/"),a=t[t.length-1];a&&a.includes(".pdf")&&(o=decodeURIComponent(a))}catch(t){}const i=new File([n],o,{type:"application/pdf"});x.value=i,A.value=o,I.value=1,O.value=1,j.value=1,V.value=100,W("PDF加载成功")}catch(a){console.error("Failed to load PDF from URL:",a),W("加载PDF失败: "+a.message,"error")}}}(t),function(){const e=document.getElementById("annotionData");e&&(e.value&&e.value.trim()&&se(e.value),B=new MutationObserver(t=>{for(const a of t)"attributes"===a.type&&"value"===a.attributeName&&se(e.getAttribute("value"))}),B.observe(e,{attributes:!0,attributeFilter:["value"]}),e.addEventListener("input",()=>se(e.value)),e.addEventListener("change",()=>se(e.value)))}()}),n(()=>{B&&(B.disconnect(),B=null)}),(e,t)=>(i(),o("div",S,[H.value.show?(i(),o("div",{key:0,style:u({position:"fixed",top:"20px",right:"20px",padding:"12px 16px",background:"success"===H.value.type?"#d1fae5":"#fee2e2",color:"success"===H.value.type?"#065f46":"#991b1b",borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:9999,animation:"slideIn 0.3s ease-out",fontSize:"14px",fontWeight:"500"})},c(H.value.message),5)):r("",!0),s("div",w,[s("div",k,[s("div",{class:"btn btn-secondary",onClick:X},"图片导入1"),s("div",{class:"btn btn-secondary",onClick:ee},"图片导入2"),s("div",{class:"btn btn-primary",onClick:te},"焊口表格"),s("div",{class:"btn btn-primary",onClick:ae},"添加签名"),s("div",{class:v(["btn",{"btn-primary":N.value,"btn-secondary":!N.value,disabled:!C.value}]),onClick:t[0]||(t[0]=e=>!C.value||(N.value=!N.value,void W(N.value?"已显示所有焊口数据":"已隐藏焊口数据"))),style:{display:"none"}},c(N.value?"隐藏焊口数据":"焊口数据展示"),3),s("div",{class:v(["btn btn-success",{disabled:!C.value}]),onClick:t[1]||(t[1]=e=>!C.value||async function(){if(L&&R.value)try{const e=R.value.getAnnotations(),t=R.value.getPageRotations(),a=await g(L,e,E.value,{startNumber:M.value.startNumber,increment:M.value.increment,prefix:M.value.prefix,suffix:M.value.suffix,fontSize:M.value.fontSize,borderStyle:M.value.borderStyle,annotationStyle:M.value.annotationStyle},t),l=(A.value||`annotated_${Date.now()}`).replace(/\.[^.]+$/,"");b(a,`${l}.pdf`),W("PDF已生成并下载")}catch(e){console.error("Failed to generate PDF:",e),W("生成PDF失败: "+e.message,"error")}else W("请先打开PDF文件","error")}())},"保存PDF",2),t[10]||(t[10]=s("div",{style:{width:"1px",background:"#e5e7eb",height:"24px",margin:"0 8px"}},null,-1)),s("div",{class:v(["btn",{disabled:!C.value||I.value<=1}]),onClick:t[2]||(t[2]=e=>!(!C.value||I.value<=1)&&void(I.value>1&&(I.value--,O.value=I.value)))},"上一页",2),s("div",{class:v(["btn",{disabled:!C.value||I.value>=F.value}]),onClick:t[3]||(t[3]=e=>!(!C.value||I.value>=F.value)&&void(I.value<F.value&&(I.value++,O.value=I.value)))},"下一页",2),t[11]||(t[11]=s("div",{style:{width:"1px",background:"#e5e7eb",height:"24px",margin:"0 8px"}},null,-1)),s("div",{class:v(["btn",{disabled:!C.value}]),onClick:t[4]||(t[4]=e=>!C.value||(null===j.value&&(j.value=$.value),j.value=Math.max(.5,+(j.value/1.2).toFixed(2)),void(V.value=Math.round(100*j.value))))},"-",2),s("div",{class:v(["btn",{disabled:!C.value}]),onClick:t[5]||(t[5]=e=>!C.value||(null===j.value&&(j.value=$.value),j.value=Math.min(3,+(1.2*j.value).toFixed(2)),void(V.value=Math.round(100*j.value))))},"+",2),d(s("input",{"onUpdate:modelValue":t[6]||(t[6]=e=>V.value=e),onInput:K,type:"range",min:"50",max:"300",style:{width:"140px"},disabled:!C.value},null,40,_),[[f,V.value,void 0,{number:!0}]]),s("div",D,c(Y.value)+"%",1),t[12]||(t[12]=s("div",{style:{width:"1px",background:"#e5e7eb",height:"24px",margin:"0 8px"}},null,-1)),t[13]||(t[13]=s("div",{style:{"margin-left":"8px"}},"第",-1)),d(s("input",{type:"number","onUpdate:modelValue":t[7]||(t[7]=e=>O.value=e),min:1,max:F.value,style:{width:"80px","margin-left":"4px"}},null,8,T),[[f,O.value,void 0,{number:!0}]]),s("div",{class:v(["btn",{disabled:!C.value}]),onClick:t[8]||(t[8]=e=>!C.value||void(O.value>=1&&O.value<=F.value&&(I.value=O.value)))},"跳转",2),s("div",J,"/ "+c(F.value||0)+" 页",1),t[14]||(t[14]=s("div",{style:{width:"1px",background:"#e5e7eb",height:"24px",margin:"0 8px"}},null,-1)),A.value?(i(),o("div",P,[s("div",null,[t[9]||(t[9]=s("strong",null,"文件:",-1)),y(" "+c(A.value),1)])])):r("",!0),t[15]||(t[15]=s("div",{style:{flex:"1"}},null,-1))]),s("div",z,[p(m,{file:x.value,page:I.value,scale:j.value,"annotation-mode":!1,"read-only":!0,"border-style":M.value.borderStyle,"annotation-style":M.value.annotationStyle,"start-number":M.value.startNumber,increment:M.value.increment,prefix:M.value.prefix,suffix:M.value.suffix,"font-size":M.value.fontSize,"show-all-weld-info":N.value,ref_key:"pdfViewerRef",ref:R,onLoaded:Z,onScaleChanged:q,onWheelZoom:G,onPlaceImage:le,onImagePlacingCancelled:ne,onImageDeleted:oe},null,8,["file","page","scale","border-style","annotation-style","start-number","increment","prefix","suffix","font-size","show-all-weld-info"])])])]))}},[["__scopeId","data-v-7710504d"]])).mount("#app");
|