import{uploadFileToJingrow as F}from"./common-fa44b7a0.js";import{d as M,r as U,c as f,e as s,f as o,s as T,g as d,k as B,F as $,B as j,n as l}from"./index-a0da86f0.js";import{_ as q}from"./_plugin-vue_export-helper-c27b6911.js";const z={class:"field-label"},L={key:0,class:"required"},D={class:"attach-container"},J={class:"file-link-wrap"},P=["title","href"],G={key:0,class:"actions"},H={key:0,class:"actions actions-left"},K={key:1,class:"field-value"},Q=M({__name:"Attach",props:{df:{},record:{},canEdit:{type:Boolean},ctx:{}},setup(I){const t=I,u=U(null),p=U(!1),i=f(()=>{var e;return String(((e=t.record)==null?void 0:e[t.df.fieldname])||"")}),R=f(()=>t.df.label_layout||"vertical"),N=f(()=>{const e=i.value;if(!e)return"";try{const n=new URL(e,window.location.origin).pathname,c=n.substring(n.lastIndexOf("/")+1);return decodeURIComponent(c||e)}catch{const n=e.lastIndexOf("/");return n>=0?decodeURIComponent(e.substring(n+1)):e}});function O(){var e;t.canEdit&&((e=u.value)==null||e.click())}async function S(e){var c,_,y,v,m,g,h,k,b,x,C;const a=e.target,n=(c=a.files)==null?void 0:c[0];if(n)try{const w=((_=t.ctx)==null?void 0:_.entity)&&(((y=t.ctx)==null?void 0:y.entity.value)??((v=t.ctx)==null?void 0:v.entity))||((m=t.record)==null?void 0:m.pagetype)||"",A=((g=t.ctx)==null?void 0:g.id)&&(((h=t.ctx)==null?void 0:h.id.value)??((k=t.ctx)==null?void 0:k.id))||((b=t.record)==null?void 0:b.name)||"",E=(x=t.df)==null?void 0:x.fieldname,r=await F(n,w,A,E);if(r.success){if(r.file_url){t.record[E]=r.file_url;try{typeof((C=t.ctx)==null?void 0:C.save)=="function"&&await t.ctx.save()}catch{}}}else alert(r.error||"上传失败")}catch{alert("上传失败")}finally{a&&(a.value="")}}function V(){t.canEdit&&(t.record[t.df.fieldname]="")}return(e,a)=>(l(),s("div",{class:j(["field-wrapper",`layout-${R.value}`])},[o("label",z,[T(d(e.ctx.t(e.df.label||e.df.fieldname))+" ",1),e.df.reqd?(l(),s("span",L,"*")):B("",!0)]),o("div",D,[i.value?(l(),s("div",{key:0,class:"attach-line",onMouseenter:a[0]||(a[0]=n=>p.value=!0),onMouseleave:a[1]||(a[1]=n=>p.value=!1)},[a[2]||(a[2]=o("span",{class:"link-icon"},[o("i",{class:"fa-regular fa-file"})],-1)),o("span",J,[o("a",{class:"file-link",title:i.value,href:i.value,target:"_blank",rel:"noopener"},d(N.value||i.value),9,P)]),e.canEdit?(l(),s("div",G,[o("button",{class:"action",type:"button",onClick:V},d(e.ctx.t?e.ctx.t("Clear"):"Clear"),1)])):B("",!0)],32)):(l(),s($,{key:1},[e.canEdit?(l(),s("div",H,[o("button",{class:"action",type:"button",onClick:O},d(e.ctx.t?e.ctx.t("Upload"):"Upload"),1)])):(l(),s("span",K,"—"))],64)),o("input",{ref_key:"inputRef",ref:u,type:"file",style:{display:"none"},onChange:S},null,544)])],2))}});const W=q(Q,[["__scopeId","data-v-0249c198"]]),te=Object.freeze(Object.defineProperty({__proto__:null,default:W},Symbol.toStringTag,{value:"Module"}));export{te as _};
