import{uploadFileToJingrow as $}from"./common-fa44b7a0.js";import{d as q,r as B,c as V,e as s,f as o,s as z,g as u,k as p,F as O,B as R,n}from"./index-a0da86f0.js";import{_ as D}from"./_plugin-vue_export-helper-c27b6911.js";const J={class:"field-label"},L={key:0,class:"required"},P={class:"attach-image-container"},G={key:0,class:"attach-line"},H={class:"file-link-wrap"},K=["title"],Q={key:0,class:"actions"},W={key:1,class:"preview-popover"},X=["src"],Y={key:0,class:"actions actions-left"},Z={key:1,class:"field-value"},ee=q({__name:"AttachImage",props:{df:{},record:{},canEdit:{type:Boolean},ctx:{}},setup(S){const e=S,_=B(null),f=B(!1),r=V(()=>{var t;return String(((t=e.record)==null?void 0:t[e.df.fieldname])||"")}),j=V(()=>e.df.label_layout||"vertical");function F(){var t;e.canEdit&&((t=_.value)==null||t.click())}async function M(t){var m,v,g,y,h,b,k,I,A,w,x,C;const a=t.target,c=(m=a.files)==null?void 0:m[0];if(c)try{const d=((v=e.ctx)==null?void 0:v.entity)&&(((g=e.ctx)==null?void 0:g.entity.value)??((y=e.ctx)==null?void 0:y.entity))||((h=e.record)==null?void 0:h.pagetype)||"",E=((b=e.ctx)==null?void 0:b.id)&&(((k=e.ctx)==null?void 0:k.id.value)??((I=e.ctx)==null?void 0:I.id))||((A=e.record)==null?void 0:A.name)||"",i=(w=e.df)==null?void 0:w.fieldname,T=(x=e.record)==null?void 0:x[i];console.debug("[AttachImage] upload params",{pagetype:d,docname:E,fieldname:i,file:c.name,oldValue:T});const l=await $(c,d,E,i);if(console.debug("[AttachImage] upload result",l),l.success){if(console.debug("[AttachImage] server returned",{file_url:l.file_url,file_name:l.file_name,local_path:l.local_path}),l.file_url){e.record[i]=l.file_url,console.debug("[AttachImage] set field value locally",{fieldname:i,value:l.file_url});try{typeof((C=e.ctx)==null?void 0:C.save)=="function"&&(await e.ctx.save(),console.debug("[AttachImage] auto save triggered"))}catch(U){console.warn("[AttachImage] auto save failed",U)}}}else alert(l.error||"上传失败"),console.warn("[AttachImage] upload failed",l)}catch(d){alert("上传失败"),console.error("[AttachImage] upload error",d)}finally{a&&(a.value="")}}function N(){e.canEdit&&(e.record[e.df.fieldname]="")}return(t,a)=>(n(),s("div",{class:R(["field-wrapper",`layout-${j.value}`])},[o("label",J,[z(u(t.ctx.t(t.df.label||t.df.fieldname))+" ",1),t.df.reqd?(n(),s("span",L,"*")):p("",!0)]),o("div",P,[r.value?(n(),s("div",G,[a[2]||(a[2]=o("span",{class:"link-icon"},[o("i",{class:"fa-solid fa-link"})],-1)),o("span",H,[o("a",{class:"file-link",title:r.value,href:"javascript:void(0)",onMouseenter:a[0]||(a[0]=c=>f.value=!0),onMouseleave:a[1]||(a[1]=c=>f.value=!1)},u(r.value),41,K)]),t.canEdit?(n(),s("div",Q,[o("button",{class:"action",type:"button",onClick:N},u(t.ctx.t?t.ctx.t("Clear"):"Clear"),1)])):p("",!0),f.value?(n(),s("div",W,[o("img",{src:r.value,alt:"preview"},null,8,X)])):p("",!0)])):(n(),s(O,{key:1},[t.canEdit?(n(),s("div",Y,[o("button",{class:"action",type:"button",onClick:F},u(t.ctx.t?t.ctx.t("Upload"):"Upload"),1)])):(n(),s("span",Z,"—"))],64)),o("input",{ref_key:"inputRef",ref:_,type:"file",accept:"image/*",style:{display:"none"},onChange:M},null,544)])],2))}});const te=D(ee,[["__scopeId","data-v-468818cf"]]),se=Object.freeze(Object.defineProperty({__proto__:null,default:te},Symbol.toStringTag,{value:"Module"}));export{se as _};
