物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
9.5 KiB

  1. import{d as R,i as Q,c as C,s as H,t as J,v as ot,x as at,y as it,z as st,o as m,b as g,n as Z,p as tt,A as rt,u as e,B as lt,C as ct,e as N,F as q,r as z,h as K,g as V,m as dt,k as ut,f as ht}from"./index-bVOhw2NF.js";function ft(s,n){const h=[],x=[],y=[],p=[];for(let v=0;v<s.length;v++){const t=s[v],S=s[(v+1)%s.length];if(v===0)h.push(`M${t.x},${t.y}`),p.push({x:t.x,y:t.y});else{const b=s[v-1];if(Math.sqrt((t.x-b.x)**2+(t.y-b.y)**2)<=n)h.push(`L${t.x},${t.y}`),p.push({x:t.x,y:t.y});else{const w=t.x-b.x,l=t.y-b.y,k=Math.sqrt(w**2+l**2),L=w/k,A=l/k,I=S.x-t.x,M=S.y-t.y,E=Math.sqrt(I**2+M**2),X=I/E,Y=M/E,r=t.x-n*L,f=t.y-n*A,u=t.x+n*X,c=t.y+n*Y;v!==s.length-1?(h.push(`L${r},${f}`),h.push(`Q${t.x},${t.y}`),p.push({x:r,y:f}),u&&c&&(h.push(`${u},${c}`),p.push({x:u,y:c})),x.push(`M${r},${f}`),x.push(`Q${t.x},${t.y}`),y.push(r,f,t.x,t.y),u&&c&&(x.push(`${u},${c}`),y.push(u,c))):(h.push(`L${t.x},${t.y}`),p.push({x:t.x,y:t.y}))}}}return{path:h.join(" "),cornerPath:x.join(" "),rectPath:p,cornerPathArr:y}}function vt(s,n){return n.backgroundColor&&(s.fill=n.backgroundColor||"none"),n.gradientColor&&s.fill!==n.gradientColor&&(s.fillGradient=n.gradientColor),n.borderColor&&(s.stroke=n.borderColor),n.borderWidth&&(s["stroke-width"]=n.borderWidth),n.strokeLineCap&&(s["stroke-linecap"]=n.strokeLineCap),n.borderStyle&&(n.borderStyle==="solid"&&(s["stroke-dash-array"]="0",s["stroke-dasharray"]="0"),n.borderStyle==="dashed"&&(s["stroke-dash-array"]=`${n.strokeDashWidth},${n.strokeDashSpace}`,s["stroke-dasharray"]=`${n.strokeDashWidth},${n.strokeDashSpace}`),n.borderStyle==="dotted"&&(s["stroke-dash-array"]=`${n.strokeDashWidth},${n.strokeDashSpace}`,s["stroke-dasharray"]=`${n.strokeDashWidth},${n.strokeDashSpace}`),n.borderStyle==="hidden"&&(s.stroke=s.fill)),n.strokeDashoffset&&(s["stroke-dashoffset"]=n.strokeDashoffset),s}const pt=R({__name:"DragPoint",props:{lineId:null,point:null,pointIndex:null,points:null},emits:["updatePoint","deletePoint","pointDragEnd"],setup(s,{emit:n}){const h=s,x=n,y=Q("canvasRef"),p=C(()=>y.value.getBoundingClientRect()),v=Q("scaleRatio"),t=H(null),S=H("transform: translate(0px, 0px)"),b=H("30px"),_=H(!1),w={x:0,y:0};function l(r){const f=Number.parseInt(b.value),u=`${r.x-f/2}`,c=`${r.y-f/2}`;S.value=`transform: translate(${u}px, ${c}px)`,w.x=u,w.y=c,_.value=!0}J(()=>h.point,r=>{l(r)},{immediate:!0});let k=!1;function L(r){const{clientX:f,clientY:u}=r,c=(f-p.value.left)/(v.value/100),P=(u-p.value.top)/(v.value/100);x("updatePoint",{x:c,y:P,index:h.pointIndex})}function A(r){r.preventDefault()}function I(r){L(r)}function M(r){if(t.value){if(t.value.removeEventListener("drag",L),t.value.removeEventListener("dragover",A),t.value.removeEventListener("drop",I),t.value.removeEventListener("dragend",M),L(r),k){const f=[0,45,90,180,270,360],u=h.points[h.pointIndex-1],c=h.points[h.pointIndex];if(u){const P=c.x-u.x,W=c.y-u.y;let $=Math.atan2(W,P)*180/Math.PI;$<0&&($+=360);let D=0;for(const d of f)(!D||Math.abs($-d)<Math.abs($-D))&&(D=d);const o=Math.sqrt(P*P+W*W),i=D*Math.PI/180;c.x=u.x+o*Math.cos(i),c.y=u.y+o*Math.sin(i);const a=r.target.closest(".line-container");x("updatePoint",{x:c.x+a.offsetLeft,y:c.y+a.offsetTop,index:h.pointIndex})}}x("pointDragEnd")}}function E(r){k=r.ctrlKey,t.value&&(t.value.addEventListener("drag",L),t.value.addEventListener("dragover",A),t.value.addEventListener("drop",I),t.value.addEventListener("dragend",M))}function X(){x("deletePoint",h.pointIndex)}function Y(r){var $,D;const f=r.target.closest(".line-container"),{clientX:u,clientY:c}=r,P=(u-p.value.left)/(v.value/100)-f.offsetLeft,W=(c-p.value.top)/(v.value/100)-f.offsetTop;P-Number(w.x)<=20&&W-Number(w.y)<=20?($=t.value)==null||$.classList.add("hover-on"):(D=t.value)==null||D.classList.remove("hover-on")}return ot(()=>{t.value&&(t.value.addEventListener("mousemove",Y,!0),t.value.addEventListener("dragstart",E),t.value.addEventListener("dblclick",X))}),at(()=>{t.value&&(t.value.removeEventListener("mousemove",Y,!0),t.value.removeEventListener("dragstart",E),t.value.removeEventListener("dblclick",X))}),(r,f)=>it((m(),g("div",{ref_key:"el