2 lines
34 KiB
JavaScript
2 lines
34 KiB
JavaScript
import{_ as e,r as t,w as l,c as n,o as a,a as o,b as i,t as s,d as r,v as u,e as d,f as c,g as v,n as p,h as f,i as m,j as y,k as g,P as x,l as b,m as h,p as w}from"./styles-Bno-H3Kc.js";import"./pdfjs-HfNT2Y4W.js";import"./pdf-lib-D5zKcp81.js";const S={key:0,class:"annotation-detail-panel"},k={class:"panel-header"},C={class:"detail-content"},F={class:"detail-row"},V={class:"label-preview"},A={class:"detail-row"},P={class:"detail-row"},U={class:"detail-row"},D={class:"detail-row"},E={class:"detail-row"},I={key:0,class:"detail-row"},N={key:1,class:"detail-row"},R={class:"detail-row"},z={class:"detail-row readonly"},j={class:"detail-row readonly"},O={style:{"margin-top":"16px","padding-top":"12px","border-top":"1px solid #e5e7eb"}},T={style:{display:"flex","flex-direction":"column",gap:"8px"}},$={style:{display:"flex",gap:"8px","flex-wrap":"wrap"}},B={style:{display:"none",gap:"8px","flex-wrap":"wrap"}},J={style:{display:"flex","align-items":"center",gap:"6px"}},L={style:{display:"flex","flex-direction":"column",gap:"10px","margin-bottom":"12px"}},_={style:{display:"flex","flex-direction":"column",gap:"6px"}},M={style:{display:"flex","align-items":"center",gap:"8px"}},X={style:{display:"flex","align-items":"center",gap:"8px"}},Y={style:{display:"flex","align-items":"center",gap:"8px"}},W={style:{display:"flex","align-items":"center",gap:"8px"}},G={style:{display:"flex","align-items":"center",gap:"8px"}},Z={style:{display:"flex","align-items":"center",gap:"8px","flex-wrap":"wrap"}},q={style:{display:"flex","align-items":"center",gap:"8px","flex-wrap":"wrap"}},H={style:{display:"none","flex-direction":"column","margin-top":"24px","padding-top":"16px","border-top":"1px solid #e5e7eb"}},K={style:{"margin-bottom":"12px"}},Q={style:{"margin-bottom":"12px"}},ee=e({__name:"LeftPanel",props:{selectedAnnotation:{type:Object,default:null},selectedAnnotationPage:{type:Number,default:null},selectedAnnotationIndex:{type:Number,default:null},annotationsJson:{type:String,default:"{}"},initialCsvData:{type:String,default:""}},emits:["file-selected","open-pdf","save-pdf-editable","saveas-pdf-editable","save-pdf-final","export-csv","export-json","import-annotations","import-csv","import-image","undo-annotation","clear-page-annotations","delete-selected-annotation","apply-settings","update-annotation","delete-annotation","deselect-annotation","load-pdf-url"],setup(e,{emit:m}){const y=e,g=m,x=t(0),b=t(""),h=t(""),w=t(10),ee=t(!1),te=t(""),le=t(""),ne=t("");function ae(){if(!y.selectedAnnotation)return;const e={...y.selectedAnnotation,displayValue:x.value,settings:{...y.selectedAnnotation.settings,prefix:b.value,suffix:h.value,fontSize:w.value},completed:ee.value,completedTime:ee.value?te.value:"",completedBy:ee.value?le.value:"",note:ne.value};g("update-annotation",e)}function oe(){confirm("确定要删除这个标注吗?")&&g("delete-annotation")}l(()=>y.selectedAnnotation,e=>{e&&(x.value=e.displayValue||0,b.value=e.settings?.prefix??"",h.value=e.settings?.suffix??"",w.value=e.settings?.fontSize??10,ee.value=e.completed||!1,te.value=e.completedTime||"",le.value=e.completedBy||"",ne.value=e.note||"")},{immediate:!0,deep:!0});const ie=t(null),se=t(null),re=t(null),ue=t(null),de=t(1),ce=t(1),ve=t("GB"),pe=t("XX"),fe=t(10),me=t("none"),ye=t("arrow"),ge=t(!0),xe=t(80),be=t("测试数据A,测试数据B,测试数据C,测试数据D,测试数据E\n13213213,13213213,13213213,13213213,13213213\n312321312,312321312,312321312,312321312,312321312\n611429411,611429411,611429411,611429411,611429411\n910537510,910537510,910537510,910537510,910537510\n1209645609,1209645609,1209645609,1209645609,1209645609\n1508753708,1508753708,1508753708,1508753708,1508753708\n1807861807,1807861807,1807861807,1807861807,1807861807\n2106969906,2106969906,2106969906,2106969906,2106969906\n2406078005,2406078005,2406078005,2406078005,2406078005\n2705186104,2705186104,2705186104,2705186104,2705186104\n3004294203,3004294203,3004294203,3004294203,3004294203\n3303402302,3303402302,3303402302,3303402302,3303402302\n3602510401,3602510401,3602510401,3602510401,3602510401\n3901618500,3901618500,3901618500,3901618500,3901618500\n4200726599,4200726599,4200726599,4200726599,4200726599\n4499834698,4499834698,4499834698,4499834698,4499834698\n4798942797,4798942797,4798942797,4798942797,4798942797\n5098050896,5098050896,5098050896,5098050896,5098050896\n5397158995,5397158995,5397158995,5397158995,5397158995\n5696267094,5696267094,5696267094,5696267094,5696267094\n5995375193,5995375193,5995375193,5995375193,5995375193\n6294483292,6294483292,6294483292,6294483292,6294483292\n6593591391,6593591391,6593591391,6593591391,6593591391"),he=t(""),we=t("{}"),Se=t(!1),ke=t(""),Ce=t("");l(()=>y.annotationsJson,e=>{e&&(we.value=e)},{immediate:!0}),l(()=>y.initialCsvData,e=>{e&&e.trim()&&(be.value=e,console.log("CSV table data updated from props:",e.substring(0,100)+"..."))},{immediate:!0}),l(we,e=>{try{const t=document.getElementById("hdworkRecord");t&&(t.value=e||"{}",console.log("Synced JSON data to workRecord-inputEl:",e?.substring(0,100)+"..."))}catch(t){console.warn("Error syncing to workRecord-inputEl:",t)}},{immediate:!0});let Fe=null;function Ve(e){const t=e.target.files&&e.target.files[0];t&&g("file-selected",t)}function Ae(){ie.value&&(ie.value.value="",ie.value.click()),g("open-pdf")}function Pe(){g("apply-settings",{startNumber:de.value,increment:ce.value,prefix:ve.value,suffix:pe.value,fontSize:fe.value,borderStyle:me.value,annotationStyle:ye.value,highDpi:!!ge.value})}async function Ue(){if(he.value&&we.value.trim()){Se.value=!0,ke.value="";try{let t;try{t=JSON.parse(we.value)}catch(e){throw new Error("JSON 格式错误: "+e.message)}const l=await async function(e,t){try{const l=await fetch("http://localhost:8000/api/pdf/process",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:e,pdfPath:t,timestamp:(new Date).toISOString()})});if(!l.ok)throw new Error(`API Error: ${l.status} ${l.statusText}`);return await l.json()}catch(l){throw console.error("API call failed:",l),l}}(t,he.value);ke.value="提交成功!",Ce.value="success",console.log("API Response:",l)}catch(t){ke.value="错误: "+(t.message||"网络请求失败"),Ce.value="error",console.error("Submit failed:",t)}finally{Se.value=!1}}}function De(){confirm("确定要清除本页所有标注吗?此操作不可撤销。")&&g("clear-page-annotations")}function Ee(){g("export-csv")}function Ie(){g("export-json")}function Ne(){se.value&&(se.value.value="",se.value.click())}function Re(){re.value&&(re.value.value="",re.value.click())}function ze(e){const t=e.target.files&&e.target.files[0];t&&g("import-annotations",t)}function je(e){const t=e.target.files&&e.target.files[0];t&&g("import-csv",t)}function Oe(){ue.value&&(ue.value.value="",ue.value.click())}function Te(e){const t=e.target.files&&e.target.files[0];t&&g("import-image",{file:t,size:xe.value})}async function $e(e){if(e&&e.trim())try{const t=await fetch(e);if(!t.ok)throw new Error(`获取失败: ${t.status}`);const l=await t.blob(),n=new FileReader;n.onload=e=>{const t=e.target.result;console.log("图片加载成功,大小:",t.length,"字节"),g("import-image",{file:null,imageData:t,size:400})},n.onerror=()=>{throw new Error("读取图片数据失败")},n.readAsDataURL(l)}catch(t){console.error("导入图片错误:",t),alert("导入图片失败: "+t.message)}else alert("图片URL为空")}async function Be(){const e=document.getElementById("imgurl1");if(!e)return void alert("未找到 imgurl1 元素");const t=e.value?.trim();t?await $e(t):alert("imgurl1 的值为空")}async function Je(){const e=document.getElementById("imgurl2");if(!e)return void alert("未找到 imgurl2 元素");const t=e.value?.trim();t?await $e(t):alert("imgurl2 的值为空")}async function Le(){const e=be.value.trim();if(e)try{console.log("开始生成表格图片,CSV 数据:",e.substring(0,100));const{imageUrl:t,width:l}=await async function(e){return new Promise((t,l)=>{try{const l=e.trim().split("\n").map(e=>e.split(",").map(e=>e.trim()));if(0===l.length)throw new Error("CSV 数据为空");const n=document.createElement("canvas").getContext("2d"),a=12,o=12,i=35,s=30,r=15,u=15,d=r+u;n.font=`${o}px Arial`;const c=l[0].length,v=new Array(c).fill(0);for(const e of l)e.forEach((e,t)=>{const l=n.measureText(String(e)).width;v[t]=Math.max(v[t],l+2*a)});const p=60;for(let e=0;e<v.length;e++)v[e]=Math.max(v[e],p);const f=v.reduce((e,t)=>e+t,0),m=f+d,y=i+l.length*s+2,g=document.createElement("canvas"),x=g.getContext("2d");g.width=m,g.height=y,x.fillStyle="#ffffff",x.fillRect(0,0,m,y),x.font=`${o}px Arial`,x.textAlign="center",x.textBaseline="middle",x.strokeStyle="#000000",x.lineWidth=1,x.fillStyle="#334155",x.fillRect(r,0,f,i);const b=[r];for(let e=0;e<c;e++)b.push(b[e]+v[e]);x.fillStyle="#ffffff",l[0].forEach((e,t)=>{const l=b[t]+v[t]/2,n=i/2;x.fillText(e,l,n)});for(let e=1;e<l.length;e++){const t=l[e],n=i+(e-1)*s;e%2==0&&(x.fillStyle="#f3f4f6",x.fillRect(r,n,f,s)),x.fillStyle="#000000",t.forEach((e,t)=>{const l=b[t]+v[t]/2,a=n+s/2;x.fillText(String(e),l,a)})}x.strokeStyle="#d1d5db",x.lineWidth=.5;for(let e=0;e<=c;e++){const t=b[e];x.beginPath(),x.moveTo(t,0),x.lineTo(t,y),x.stroke()}for(let e=0;e<=l.length;e++){const t=(0===e?0:i)+e*s;x.beginPath(),x.moveTo(r,t),x.lineTo(m-u,t),x.stroke()}t({imageUrl:g.toDataURL("image/png"),width:m})}catch(n){l(n)}})}(e);console.log("表格图片生成成功,大小:",t.length,"字节,宽度:",l),g("import-image",{file:null,imageData:t,size:l})}catch(t){console.error("生成表格图片错误:",t),alert("生成表格图片失败: "+t.message)}else alert("请先输入 CSV 数据")}return l(he,(e,t)=>{Fe&&clearTimeout(Fe),e&&e.trim()&&(Fe=setTimeout(()=>{const t=e.trim();(t.startsWith("http://")||t.startsWith("https://"))&&g("load-pdf-url",t)},500))},{immediate:!0}),(t,l)=>(a(),n("div",null,[e.selectedAnnotation?(a(),n("div",S,[i("div",k,[l[24]||(l[24]=i("h3",{style:{margin:"0","font-size":"14px"}},"标注详情",-1)),i("div",{class:"btn close-btn",onClick:l[0]||(l[0]=e=>g("deselect-annotation")),title:"关闭"},"×")]),i("div",C,[i("div",F,[l[25]||(l[25]=i("label",null,"标签内容:",-1)),i("div",V,s(b.value)+s(x.value)+s(h.value),1)]),i("div",A,[l[26]||(l[26]=i("label",null,"编号:",-1)),r(i("input",{"onUpdate:modelValue":l[1]||(l[1]=e=>x.value=e),type:"number",min:"0",class:"detail-input"},null,512),[[u,x.value,void 0,{number:!0}]])]),i("div",P,[l[27]||(l[27]=i("label",null,"前缀:",-1)),r(i("input",{"onUpdate:modelValue":l[2]||(l[2]=e=>b.value=e),type:"text",class:"detail-input"},null,512),[[u,b.value]])]),i("div",U,[l[28]||(l[28]=i("label",null,"后缀:",-1)),r(i("input",{"onUpdate:modelValue":l[3]||(l[3]=e=>h.value=e),type:"text",class:"detail-input"},null,512),[[u,h.value]])]),i("div",D,[l[29]||(l[29]=i("label",null,"字体大小:",-1)),r(i("input",{"onUpdate:modelValue":l[4]||(l[4]=e=>w.value=e),type:"number",min:"6",max:"72",class:"detail-input"},null,512),[[u,w.value,void 0,{number:!0}]])]),l[37]||(l[37]=i("div",{class:"detail-divider"},null,-1)),i("div",E,[l[31]||(l[31]=i("label",null,"状态:",-1)),r(i("select",{"onUpdate:modelValue":l[5]||(l[5]=e=>ee.value=e),class:"detail-input"},[...l[30]||(l[30]=[i("option",{value:!1},"未完成",-1),i("option",{value:!0},"已完成",-1)])],512),[[d,ee.value]])]),ee.value?(a(),n("div",I,[l[32]||(l[32]=i("label",null,"完成时间:",-1)),r(i("input",{"onUpdate:modelValue":l[6]||(l[6]=e=>te.value=e),type:"datetime-local",class:"detail-input"},null,512),[[u,te.value]])])):o("",!0),ee.value?(a(),n("div",N,[l[33]||(l[33]=i("label",null,"完成人:",-1)),r(i("input",{"onUpdate:modelValue":l[7]||(l[7]=e=>le.value=e),type:"text",placeholder:"输入完成人姓名",class:"detail-input"},null,512),[[u,le.value]])])):o("",!0),i("div",R,[l[34]||(l[34]=i("label",null,"备注:",-1)),r(i("textarea",{"onUpdate:modelValue":l[8]||(l[8]=e=>ne.value=e),placeholder:"添加备注...",class:"detail-textarea"},null,512),[[u,ne.value]])]),i("div",z,[l[35]||(l[35]=i("label",null,"页码:",-1)),i("span",null,"第 "+s(e.selectedAnnotationPage)+" 页",1)]),i("div",j,[l[36]||(l[36]=i("label",null,"位置:",-1)),i("span",null,"X: "+s(Math.round(e.selectedAnnotation.x))+", Y: "+s(Math.round(e.selectedAnnotation.y)),1)]),i("div",{class:"detail-actions"},[i("div",{class:"btn btn-primary",onClick:ae},"保存修改"),i("div",{class:"btn btn-danger",onClick:oe},"删除标注")])])])):o("",!0),i("div",O,[l[39]||(l[39]=i("h3",{style:{margin:"0 0 12px 0"}},"设置",-1)),i("div",T,[i("input",{ref_key:"fileInput",ref:ie,type:"file",accept:"application/pdf",onChange:Ve,style:{display:"none"}},null,544),i("input",{ref_key:"jsonInput",ref:se,type:"file",accept:"application/json,.json",onChange:ze,style:{display:"none"}},null,544),i("input",{ref_key:"csvInput",ref:re,type:"file",accept:"text/csv,.csv",onChange:je,style:{display:"none"}},null,544),i("input",{ref_key:"imageInput",ref:ue,type:"file",accept:"image/*",onChange:Te,style:{display:"none"}},null,544),i("div",$,[i("div",{class:"btn btn-primary",onClick:Ae},"打开PDF"),i("div",{class:"btn btn-success",onClick:l[9]||(l[9]=e=>g("save-pdf-editable"))},"保存PDF"),i("div",{class:"btn btn-secondary",onClick:Ee},"导出CSV"),i("div",{class:"btn btn-secondary",onClick:Ie},"导出JSON"),i("div",{class:"btn btn-secondary",onClick:Ne},"导入JSON"),i("div",{class:"btn btn-secondary",onClick:Re},"导入CSV")]),i("div",B,[l[38]||(l[38]=i("label",{style:{display:"block","font-size":"12px","margin-bottom":"4px",color:"#6b7280"}},"CSV 表格数据",-1)),r(i("textarea",{"onUpdate:modelValue":l[10]||(l[10]=e=>be.value=e),placeholder:"粘贴或输入CSV数据",style:{width:"100%",height:"80px",padding:"6px",border:"1px solid #d1d5db","border-radius":"4px","font-size":"12px","font-family":"monospace",resize:"vertical"}},null,512),[[u,be.value]])]),i("div",{style:{"margin-bottom":"8px"}},[i("div",{class:"btn btn-secondary",onClick:Le,style:{width:"100%"}},"图表导入")]),i("div",J,[r(i("input",{"onUpdate:modelValue":l[11]||(l[11]=e=>xe.value=e),type:"number",min:"30",max:"300",style:{display:"none",width:"60px",padding:"4px 6px",border:"1px solid #d1d5db","border-radius":"4px","font-size":"12px"},placeholder:"大小",title:"图片默认大小(px)"},null,512),[[u,xe.value,void 0,{number:!0}]]),i("div",{class:"btn btn-secondary",onClick:Oe,style:{flex:"1"}},"导入图片")]),i("div",{style:{display:"flex",gap:"6px"}},[i("div",{class:"btn btn-secondary",onClick:Be,style:{flex:"1"}},"图片导入1"),i("div",{class:"btn btn-secondary",onClick:Je,style:{flex:"1"}},"图片导入2")]),i("div",{class:"btn btn-secondary",onClick:l[12]||(l[12]=e=>g("undo-annotation"))},"撤销上一标注"),i("div",{class:"btn btn-danger",onClick:De},"清除本页标注")])]),i("div",L,[i("div",_,[i("div",M,[l[40]||(l[40]=i("label",{style:{"min-width":"70px"}},"起始编号:",-1)),r(i("input",{"onUpdate:modelValue":l[13]||(l[13]=e=>de.value=e),type:"number",min:"0",style:{flex:"1"}},null,512),[[u,de.value,void 0,{number:!0}]])]),i("div",X,[l[41]||(l[41]=i("label",{style:{"min-width":"70px"}},"增量:",-1)),r(i("input",{"onUpdate:modelValue":l[14]||(l[14]=e=>ce.value=e),type:"number",min:"1",style:{flex:"1"}},null,512),[[u,ce.value,void 0,{number:!0}]])]),i("div",Y,[l[42]||(l[42]=i("label",{style:{"min-width":"70px"}},"前缀:",-1)),r(i("input",{"onUpdate:modelValue":l[15]||(l[15]=e=>ve.value=e),type:"text",style:{flex:"1"}},null,512),[[u,ve.value]])]),i("div",W,[l[43]||(l[43]=i("label",{style:{"min-width":"70px"}},"后缀:",-1)),r(i("input",{"onUpdate:modelValue":l[16]||(l[16]=e=>pe.value=e),type:"text",style:{flex:"1"}},null,512),[[u,pe.value]])]),i("div",G,[l[44]||(l[44]=i("label",{style:{"min-width":"70px"}},"字体大小:",-1)),r(i("input",{"onUpdate:modelValue":l[17]||(l[17]=e=>fe.value=e),type:"number",min:"6",max:"72",step:"1",style:{width:"120px"}},null,512),[[u,fe.value,void 0,{number:!0}]])]),i("div",Z,[l[47]||(l[47]=i("label",{style:{"min-width":"70px"}},"边框样式:",-1)),i("label",null,[r(i("input",{type:"radio",value:"none","onUpdate:modelValue":l[18]||(l[18]=e=>me.value=e)},null,512),[[v,me.value]]),l[45]||(l[45]=c(" 无",-1))]),i("label",null,[r(i("input",{type:"radio",value:"rect","onUpdate:modelValue":l[19]||(l[19]=e=>me.value=e)},null,512),[[v,me.value]]),l[46]||(l[46]=c(" 矩形",-1))])]),i("div",q,[l[50]||(l[50]=i("label",{style:{"min-width":"70px"}},"标注样式:",-1)),i("label",null,[r(i("input",{type:"radio",value:"arrow","onUpdate:modelValue":l[20]||(l[20]=e=>ye.value=e)},null,512),[[v,ye.value]]),l[48]||(l[48]=c(" 箭头",-1))]),i("label",null,[r(i("input",{type:"radio",value:"dot","onUpdate:modelValue":l[21]||(l[21]=e=>ye.value=e)},null,512),[[v,ye.value]]),l[49]||(l[49]=c(" 圆点",-1))])])]),i("div",{class:"btn",onClick:Pe,style:{width:"100%",padding:"10px",background:"#334155",color:"#fff",border:"none","border-radius":"4px",cursor:"pointer","margin-top":"8px"}},"应用设置")]),i("div",H,[l[53]||(l[53]=i("h4",{style:{margin:"0 0 12px 0"}},"网络接口",-1)),i("div",K,[l[51]||(l[51]=i("label",{style:{display:"block","font-size":"12px","margin-bottom":"4px",color:"#6b7280"}},"PDF 目录路径",-1)),r(i("input",{"onUpdate:modelValue":l[22]||(l[22]=e=>he.value=e),type:"text",placeholder:"/path/to/pdf",style:{width:"100%",padding:"6px",border:"1px solid #d1d5db","border-radius":"4px","font-size":"12px"}},null,512),[[u,he.value]])]),i("div",Q,[l[52]||(l[52]=i("label",{style:{display:"block","font-size":"12px","margin-bottom":"4px",color:"#6b7280"}},"数据 (JSON)",-1)),r(i("textarea",{"onUpdate:modelValue":l[23]||(l[23]=e=>we.value=e),placeholder:'{"key":"value"}',style:{width:"100%",height:"100px",padding:"6px",border:"1px solid #d1d5db","border-radius":"4px","font-size":"12px","font-family":"monospace",resize:"vertical"}},null,512),[[u,we.value]])]),i("div",{class:p(["btn",{disabled:!he.value||!we.value}]),onClick:Ue,style:{width:"100%",padding:"8px",background:"#3b82f6",color:"white",border:"none","border-radius":"4px",cursor:"pointer","font-size":"14px"}},s(Se.value?"提交中...":"提交数据"),3),ke.value?(a(),n("div",{key:0,style:f({marginTop:"8px",padding:"8px",borderRadius:"4px",fontSize:"12px",color:"success"===Ce.value?"#10b981":"#ef4444",background:"success"===Ce.value?"#d1fae5":"#fee2e2"})},s(ke.value),5)):o("",!0)])]))}},[["__scopeId","data-v-6090802b"]]);function te(e){const t=[];let l="",n=!1;for(let a=0;a<e.length;a++){const o=e[a],i=e[a+1];'"'===o?n&&'"'===i?(l+='"',a++):n=!n:","!==o||n?l+=o:(t.push(l.trim()),l="")}return t.push(l.trim()),t}const le={class:"container"},ne={class:"left"},ae={class:"right"},oe={class:"controls"},ie=["disabled"],se={style:{"min-width":"54px","text-align":"center"}},re=["max"],ue={style:{"margin-left":"4px"}},de={key:0,style:{display:"flex","align-items":"center",gap:"12px","margin-left":"8px","font-size":"12px",color:"#6b7280"}},ce={class:"viewer"};w({__name:"App",setup(e){const d=t(null),v=t(null),w=t(0),S=t(1),k=t(1),C=t(!1),F=t(null),V=t(""),A=t(""),P=t({}),U=t("{}"),D=t(""),E=t(null),I=t(null),N=t(null);function R(e){e?(E.value={...e.annotation},I.value=e.page,N.value=e.index):(E.value=null,I.value=null,N.value=null),W()}function z(e){F.value&&null!==I.value&&null!==N.value&&(F.value.updateAnnotation(I.value,N.value,e),E.value={...e},B("标注已更新"),W())}function j(){F.value&&null!==I.value&&null!==N.value&&(F.value.deleteAnnotation(I.value,N.value),E.value=null,I.value=null,N.value=null,B("标注已删除"),W())}function O(){E.value=null,I.value=null,N.value=null,F.value&&F.value.clearSelection()}const T=t({show:!1,message:"",type:"success"});let $=null;function B(e,t="success"){T.value={show:!0,message:e,type:t},clearTimeout($),$=setTimeout(()=>{T.value.show=!1},2500)}let J=null;const L=t(null),_=t(100),M=t(1),X=m(()=>{const e=null!==L.value?L.value:M.value;return Math.round(100*e)}),Y=m(()=>{if(!F.value)return 0;const e=F.value.getAnnotations();let t=0;for(const l in e)t+=e[l].length;return t});function W(){if(F.value&&V.value)try{const e=F.value.getAnnotations();U.value=function(e,t,l){const n={version:"1.0",exportDate:(new Date).toISOString(),sourceFile:l,globalSettings:t,annotations:{}};for(const a in e){const l=e[a];Array.isArray(l)&&l.length>0&&(n.annotations[a]=l.map(e=>{const l=e.settings?.prefix??t.prefix??"",n=e.settings?.suffix??t.suffix??"",a=l+e.displayValue+n;return{x:e.x,y:e.y,x2:e.x2,y2:e.y2,displayValue:e.displayValue,label:a,style:e.style,annotationStyle:e.annotationStyle}}))}return JSON.stringify(n,null,2)}(e,{startNumber:ve.value,increment:pe.value,prefix:fe.value,suffix:me.value,fontSize:ye.value,borderStyle:K.value,annotationStyle:Q.value},V.value)}catch(e){console.error("Failed to generate annotations JSON:",e)}else U.value="{}"}function G(e){d.value=e,V.value=e.name,S.value=1,k.value=1,L.value=1,_.value=100;const t=new FileReader;t.onload=e=>{J=e.target.result},t.readAsArrayBuffer(e)}function Z(e){v.value=e.pdf,w.value=e.numPages,S.value=1,k.value=1}function q(e){M.value=e}function H(e){L.value=e,_.value=Math.round(100*e)}const K=t("none"),Q=t("arrow"),ve=t(1),pe=t(1),fe=t("GB"),me=t("XX"),ye=t(10);function ge(e){K.value=e.borderStyle,Q.value=e.annotationStyle,ve.value=e.startNumber,pe.value=e.increment,fe.value=e.prefix,me.value=e.suffix,ye.value=e.fontSize,B("设置已应用")}function xe(){L.value=+_.value/100}function be(){F.value&&(F.value.clearCurrentPageAnnotations(),W())}function he(){F.value&&(F.value.undoLastAnnotation(),W())}async function we(){if(J&&F.value)try{const e=F.value.getAnnotations(),t=F.value.getPageRotations(),l=await b(J,e,P.value,{startNumber:ve.value,increment:pe.value,prefix:fe.value,suffix:me.value,fontSize:ye.value,borderStyle:K.value,annotationStyle:Q.value},t);h(l,`annotated_${Date.now()}.pdf`),B("PDF已生成并下载")}catch(e){console.error("Failed to generate PDF:",e),B("生成PDF失败: "+e.message,"error")}else B("请先打开PDF文件","error")}async function Se(){if(J&&F.value)try{const e=F.value.getAnnotations(),t=F.value.getPageRotations(),l=await b(J,e,P.value,{startNumber:ve.value,increment:pe.value,prefix:fe.value,suffix:me.value,fontSize:ye.value,borderStyle:K.value,annotationStyle:Q.value},t);h(l,`final_${Date.now()}.pdf`),B("PDF已生成并下载")}catch(e){console.error("Failed to generate PDF:",e),B("生成PDF失败: "+e.message,"error")}else B("请先打开PDF文件","error")}function ke(){if(F.value&&V.value)try{!function(e,t,l){const{startNumber:n,increment:a,prefix:o,suffix:i}=t,s=[];s.push(["页码","标签","显示值","标签X坐标","标签Y坐标","指向X坐标","指向Y坐标","边框样式","标注样式","字体大小","前缀","后缀","起始值","增量"]);for(const v in e){const t=e[v];Array.isArray(t)&&t.forEach(e=>{const t=e.settings?.prefix??o,l=e.settings?.suffix??i,r=e.settings?.startNumber??n,u=e.settings?.increment??a,d=e.settings?.fontSize??10,c=t+e.displayValue+l;s.push([v,c,e.displayValue,Math.round(1e3*e.x)/1e3,Math.round(1e3*e.y)/1e3,void 0!==e.x2?Math.round(1e3*e.x2)/1e3:"",void 0!==e.y2?Math.round(1e3*e.y2)/1e3:"",e.style||"none",e.annotationStyle||"arrow",d,t,l,r,u])})}const r=s.map(e=>e.map(e=>{const t=String(e);return t.includes(",")||t.includes('"')||t.includes("\n")?`"${t.replace(/"/g,'""')}"`:t}).join(",")).join("\n"),u=new Blob(["\ufeff"+r],{type:"text/csv;charset=utf-8;"}),d=document.createElement("a"),c=URL.createObjectURL(u);d.href=c,d.download=`${l.replace(/\.[^.]+$/,"")}_annotations.csv`,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(c)}(F.value.getAnnotations(),{startNumber:ve.value,increment:pe.value,prefix:fe.value,suffix:me.value},V.value),B("CSV数据已导出")}catch(e){console.error("Failed to export CSV:",e),B("导出CSV失败: "+e.message,"error")}else B("请先打开PDF文件","error")}function Ce(){if(F.value&&V.value)try{!function(e,t,l){const n={version:"1.0",exportDate:(new Date).toISOString(),sourceFile:l,globalSettings:t,annotations:{}};for(const r in e){const l=e[r];Array.isArray(l)&&l.length>0&&(n.annotations[r]=l.map(e=>{const l=e.settings?.prefix??t.prefix??"",n=e.settings?.suffix??t.suffix??"",a=l+e.displayValue+n;return{x:e.x,y:e.y,x2:e.x2,y2:e.y2,displayValue:e.displayValue,label:a,style:e.style,annotationStyle:e.annotationStyle}}))}const a=JSON.stringify(n,null,2),o=new Blob([a],{type:"application/json;charset=utf-8;"}),i=document.createElement("a"),s=URL.createObjectURL(o);i.href=s,i.download=`${l.replace(/\.[^.]+$/,"")}_annotations.json`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(s)}(F.value.getAnnotations(),{startNumber:ve.value,increment:pe.value,prefix:fe.value,suffix:me.value,fontSize:ye.value,borderStyle:K.value,annotationStyle:Q.value},V.value),B("JSON数据已导出(可用于还原标注)")}catch(e){console.error("Failed to export JSON:",e),B("导出JSON失败: "+e.message,"error")}else B("请先打开PDF文件","error")}async function Fe(e){if(e)try{const t=await async function(e){return new Promise((t,l)=>{const n=new FileReader;n.onload=e=>{try{const l=JSON.parse(e.target.result);if(!l.annotations||!l.globalSettings)throw new Error("无效的标注数据格式");t({annotations:l.annotations,settings:l.globalSettings,sourceFile:l.sourceFile,version:l.version})}catch(n){l(new Error("解析JSON文件失败: "+n.message))}},n.onerror=()=>{l(new Error("读取文件失败"))},n.readAsText(e)})}(e);if(!window.confirm(`确定要导入标注数据吗?\n来源文件: ${t.sourceFile||"未知"}\n版本: ${t.version||"未知"}\n当前标注将被覆盖。`))return;F.value&&(F.value.setAnnotations(t.annotations),t.settings&&(ve.value=t.settings.startNumber||1,pe.value=t.settings.increment||1,fe.value=t.settings.prefix||"",me.value=t.settings.suffix||"",ye.value=t.settings.fontSize||10,K.value=t.settings.borderStyle||"none",Q.value=t.settings.annotationStyle||"arrow"),B("标注数据导入成功"),W())}catch(t){console.error("Failed to import annotations:",t),B("导入失败: "+t.message,"error")}}async function Ve(e){if(e)try{const t=await async function(e){return new Promise((t,l)=>{const n=new FileReader;n.onload=n=>{try{const l=n.target.result.trim().split("\n");if(l.length<2)throw new Error("CSV文件内容不足,至少需要标题行和数据行");const a=te(l[0]),o=["页码","标签X坐标","标签Y坐标"];for(const e of o)if(!a.includes(e))throw new Error(`缺少必要的列: ${e}`);const i={};let s={startNumber:1,increment:1,prefix:"",suffix:"",fontSize:10,borderStyle:"none",annotationStyle:"arrow"};for(let e=1;e<l.length;e++){const t=te(l[e]);if(0===t.length||t.every(e=>!e))continue;const n={};for(let e=0;e<a.length;e++)n[a[e]]=t[e]||"";const o=n["页码"]?.trim();if(!o)continue;const r=parseFloat(n["标签X坐标"]),u=parseFloat(n["标签Y坐标"]),d=n["指向X坐标"]?parseFloat(n["指向X坐标"]):void 0,c=n["指向Y坐标"]?parseFloat(n["指向Y坐标"]):void 0;if(isNaN(r)||isNaN(u))throw new Error(`第${e+1}行: 坐标格式错误`);const v=n["显示值"]?parseInt(n["显示值"]):0,p=n["边框样式"]?.trim()||"none",f=n["标注样式"]?.trim()||"arrow",m=n["字体大小"]?parseInt(n["字体大小"]):10,y=n["前缀"]?.trim()||"",g=n["后缀"]?.trim()||"",x=n["起始值"]?parseInt(n["起始值"]):1,b=n["增量"]?parseInt(n["增量"]):1;1===e&&(s={startNumber:x,increment:b,prefix:y,suffix:g,fontSize:m,borderStyle:p,annotationStyle:f});const h={x:r,y:u,displayValue:v,style:p,annotationStyle:f,settings:{prefix:y,suffix:g,fontSize:m,startNumber:x,increment:b}};void 0===d||void 0===c||isNaN(d)||isNaN(c)||(h.x2=d,h.y2=c),i[o]||(i[o]=[]),i[o].push(h)}if(0===Object.keys(i).length)throw new Error("CSV文件中没有有效的标注数据");t({annotations:i,settings:s,sourceFile:e.name,version:"1.0"})}catch(a){l(new Error("解析CSV文件失败: "+a.message))}},n.onerror=()=>{l(new Error("读取文件失败"))},n.readAsText(e,"utf-8")})}(e);if(!window.confirm(`确定要导入CSV标注数据吗?\n来源文件: ${t.sourceFile||"未知"}\n当前标注将被覆盖。`))return;F.value&&(F.value.setAnnotations(t.annotations),t.settings&&(ve.value=t.settings.startNumber||1,pe.value=t.settings.increment||1,fe.value=t.settings.prefix||"",me.value=t.settings.suffix||"",ye.value=t.settings.fontSize||10,K.value=t.settings.borderStyle||"none",Q.value=t.settings.annotationStyle||"arrow"),B("CSV标注数据导入成功"),W())}catch(t){console.error("Failed to import CSV:",t),B("导入CSV失败: "+t.message,"error")}}function Ae(e){const t=S.value;P.value[t]||(P.value[t]=[]),P.value[t].push(e),F.value&&F.value.setImages(P.value),B("图片已放置")}function Pe(){B("已取消图片放置")}function Ue(e){P.value[e.page]=e.images,B("图片已删除")}async function De(e){const t=e?.file,l=e?.size||80,n=e?.imageData;try{if(n)return F.value?(F.value.setTemporaryImage(n,l),void B("点击PDF上要放置表格的位置, 按ESC取消")):void B("请先加载PDF","error");if(!t)return void B("请先选择图片文件","error");const e=new FileReader;e.onload=e=>{const t=e.target.result;F.value?(F.value.setTemporaryImage(t,l),B("点击PDF上要放置图片的位置, 按ESC取消")):B("请先加载PDF","error")},e.readAsDataURL(t)}catch(a){console.error("Failed to import image:",a),B("导入图片失败: "+a.message,"error")}}function Ee(){let e=A.value;if(!e){const t=document.getElementById("hdpdfurl");t&&t.value&&(e=t.value.trim())}if(e){let t=`/viewer.html?url=${encodeURIComponent(e)}`;const l=document.getElementById("imgurl1"),n=document.getElementById("imgurl2");l&&l.value&&l.value.trim()&&(t+=`&imgurl1=${encodeURIComponent(l.value.trim())}`),n&&n.value&&n.value.trim()&&(t+=`&imgurl2=${encodeURIComponent(n.value.trim())}`),window.open(t,"_blank")}else B("未找到PDF地址","error")}async function Ie(e){if(e){A.value=e,B("正在加载在线PDF...");try{const l=await fetch(e);if(!l.ok)throw new Error(`加载失败: ${l.status} ${l.statusText}`);const n=await l.arrayBuffer(),a=new Blob([n],{type:"application/pdf"});let o="online.pdf";try{const t=new URL(e).pathname.split("/"),l=t[t.length-1];l&&l.includes(".pdf")&&(o=decodeURIComponent(l))}catch(t){}const i=new File([a],o,{type:"application/pdf"});J=n,d.value=i,V.value=o,S.value=1,k.value=1,L.value=1,_.value=100,B("PDF加载成功")}catch(l){console.error("Failed to load PDF from URL:",l),B("加载PDF失败: "+l.message,"error")}}}return y(()=>{try{const e=document.getElementById("hdpdfurl");if(e&&"string"==typeof e.value&&e.value.trim()){const t=e.value.trim();A.value=t,console.log("Found pdfUrl element, loading PDF from:",t),Ie(t)}const t=document.getElementById("hdjoinInfo");if(t&&"string"==typeof t.value&&t.value.trim()){const e=t.value.trim();console.log("Found workRecord element, setting CSV data:",e.substring(0,100)+"..."),D.value=e}}catch(e){console.warn("Error checking for elements:",e)}}),l(S,e=>{}),(e,t)=>(a(),n("div",le,[T.value.show?(a(),n("div",{key:0,style:f({position:"fixed",top:"20px",right:"20px",padding:"12px 16px",background:"success"===T.value.type?"#d1fae5":"#fee2e2",color:"success"===T.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"})},s(T.value.message),5)):o("",!0),i("div",ne,[g(ee,{"selected-annotation":E.value,"selected-annotation-page":I.value,"selected-annotation-index":N.value,"annotations-json":U.value,"initial-csv-data":D.value,onFileSelected:G,onApplySettings:ge,onClearPageAnnotations:be,onUndoAnnotation:he,onSavePdfEditable:we,onSavePdfFinal:Se,onExportCsv:ke,onExportJson:Ce,onImportAnnotations:Fe,onImportCsv:Ve,onImportImage:De,onUpdateAnnotation:z,onDeleteAnnotation:j,onDeselectAnnotation:O,onLoadPdfUrl:Ie},null,8,["selected-annotation","selected-annotation-page","selected-annotation-index","annotations-json","initial-csv-data"])]),i("div",ae,[i("div",oe,[i("div",{onClick:t[0]||(t[0]=e=>C.value=!C.value),style:f({background:C.value?"#334155":"#e2e8f0",color:C.value?"white":"#475569",padding:"6px 12px",borderRadius:"4px",cursor:"pointer",userSelect:"none",fontSize:"14px"})},"标注模式"+s(C.value?":开":":关"),5),t[10]||(t[10]=i("div",{style:{width:"1px",background:"#e5e7eb",height:"24px",margin:"0 8px"}},null,-1)),i("div",{class:p(["btn",{disabled:!v.value||S.value<=1}]),onClick:t[1]||(t[1]=e=>!(!v.value||S.value<=1)&&void(S.value>1&&(S.value--,k.value=S.value)))},"上一页",2),i("div",{class:p(["btn",{disabled:!v.value||S.value>=w.value}]),onClick:t[2]||(t[2]=e=>!(!v.value||S.value>=w.value)&&void(S.value<w.value&&(S.value++,k.value=S.value)))},"下一页",2),t[11]||(t[11]=i("div",{style:{width:"1px",background:"#e5e7eb",height:"24px",margin:"0 8px"}},null,-1)),i("div",{class:p(["btn",{disabled:!v.value}]),onClick:t[3]||(t[3]=e=>!v.value||(null===L.value&&(L.value=M.value),L.value=Math.max(.5,+(L.value/1.2).toFixed(2)),void(_.value=Math.round(100*L.value))))},"-",2),i("div",{class:p(["btn",{disabled:!v.value}]),onClick:t[4]||(t[4]=e=>!v.value||(null===L.value&&(L.value=M.value),L.value=Math.min(3,+(1.2*L.value).toFixed(2)),void(_.value=Math.round(100*L.value))))},"+",2),r(i("input",{"onUpdate:modelValue":t[5]||(t[5]=e=>_.value=e),onInput:xe,type:"range",min:"50",max:"300",style:{width:"140px"},disabled:!v.value},null,40,ie),[[u,_.value,void 0,{number:!0}]]),i("div",se,s(X.value)+"%",1),t[12]||(t[12]=i("div",{style:{width:"1px",background:"#e5e7eb",height:"24px",margin:"0 8px"}},null,-1)),t[13]||(t[13]=i("div",{style:{"margin-left":"8px"}},"第",-1)),r(i("input",{type:"number","onUpdate:modelValue":t[6]||(t[6]=e=>k.value=e),min:1,max:w.value,style:{width:"80px","margin-left":"4px"}},null,8,re),[[u,k.value,void 0,{number:!0}]]),i("div",{class:p(["btn",{disabled:!v.value}]),onClick:t[7]||(t[7]=e=>!v.value||void(k.value>=1&&k.value<=w.value&&(S.value=k.value)))},"跳转",2),i("div",ue,"/ "+s(w.value||0)+" 页",1),t[14]||(t[14]=i("div",{style:{width:"1px",background:"#e5e7eb",height:"24px",margin:"0 8px"}},null,-1)),V.value?(a(),n("div",de,[i("div",null,[t[8]||(t[8]=i("strong",null,"文件:",-1)),c(" "+s(V.value),1)]),i("div",null,[t[9]||(t[9]=i("strong",null,"标签:",-1)),c(" "+s(Y.value),1)])])):o("",!0),t[15]||(t[15]=i("div",{style:{flex:"1"}},null,-1)),i("div",{class:"btn",onClick:Ee,title:"在新窗口中打开纯PDF预览"},"PDF预览")]),i("div",ce,[g(x,{file:d.value,page:S.value,scale:L.value,"annotation-mode":C.value,"border-style":K.value,"annotation-style":Q.value,"start-number":ve.value,increment:pe.value,prefix:fe.value,suffix:me.value,"font-size":ye.value,ref_key:"pdfViewerRef",ref:F,onLoaded:Z,onScaleChanged:q,onWheelZoom:H,onPlaceImage:Ae,onAnnotationSelected:R,onImagePlacingCancelled:Pe,onImageDeleted:Ue,onAnnotationChanged:W},null,8,["file","page","scale","annotation-mode","border-style","annotation-style","start-number","increment","prefix","suffix","font-size"])])])]))}}).mount("#app");
|