import{aP as e,E as a,K as t,P as s,hi as r,hj as o,b as n,hk as m,fF as l,_ as i}from"./utils-lib.js?v=1761009159";import{c as d,r as c,g as p,aD as v,e as u,q as h,H as f,I as y,y as g,v as w,x as b}from"./base-lib.js?v=1761009159";import{b as k,d as _,l as j,g as x,h as D}from"./form-item.js?v=1761009159";import{f as W}from"./validator.js?v=1761009159";import{B as O}from"./index115.js?v=1761009159";import"./__commonjsHelpers__.js?v=1761009159";import"./index106.js?v=1761009159";import"./column.js?v=1761009159";import"./ace.js?v=1761009159";const S={class:"flex flex-col lib-box p-2rem"},q=i(d({__name:"add-compose-template",props:{compData:{default:()=>({})}},emits:["close","complate"],setup(i,{expose:d,emit:q}){const C=n(),{refs:{isRefreshTemplateList:E}}=e(),F=i,T=q,V=c(!1),I={mode:"ace/mode/nginx",theme:a.value?"ace/theme/clouds_midnight":"ace/theme/chrome",wrap:!0,showInvisibles:!1,showFoldWidgets:!1,useSoftTabs:!0,tabSize:2,showPrintMargin:!1,readOnly:!1,fontSize:"12px"},{BtForm:J,submit:N}=t({data:async()=>{var e;return(null==(e=F.compData.row)?void 0:e.id)?(async()=>{const e={name:"",remark:"",data:"",env:""};e.name=F.compData.row.name,e.remark=F.compData.row.remark;const a=await s({request:m({data:JSON.stringify({template_id:F.compData.row.id})}),loading:V});return a.status?(e.data=a.data.compose_data,e.env=a.data.env_data):C.error(a.msg),e})():{name:"",remark:"",data:"",env:"",path:"",envpath:""}},options:e=>p(()=>[k("创建模板","name",{attrs:{class:"!w-[35rem]",placeholder:"请输入模板名"},rules:[{required:!0,message:"请输入模板名",trigger:"blur"}]}),k("备注","remark",{attrs:{class:"!w-[35rem]",placeholder:"备注"}}),_([j(" ","path",{attrs:{class:"!w-[30rem]",placeholder:"请选择compose文件"}},()=>P(e,"compose")),x("本地上传",{attrs:{class:"!ml-[1rem]",onClick:()=>{B(e,"compose")}}})]),D("compose内容",()=>v(O,{id:"templateEditor",class:"max-h-[30rem] h-[30rem] !w-[43rem]",modelValue:e.value.data,"onUpdate:modelValue":a=>e.value.data=a,editorOption:I}),"data",{rules:[{required:!0,message:"请输入内容",trigger:"blur"}]}),_([j(" ","envpath",{attrs:{class:"!w-[30rem]",placeholder:"请选择.env文件"}},()=>P(e,"env")),x("本地上传",{attrs:{class:"!ml-[1rem]",onClick:()=>{B(e,"env")}}})]),D(".env内容",()=>u(O,{key:"editer2",class:"w-full h-[10rem]",modelValue:e.value.env,"onUpdate:modelValue":a=>e.value.env=a,editorOption:I},null),"data")]),submit:async(e,a,t)=>{var n;await a(),s({request:(null==(n=F.compData.row)?void 0:n.id)?r({data:JSON.stringify({id:F.compData.row.id,name:e.value.name,remark:e.value.remark,data:e.value.data,env:e.value.env})}):o({data:JSON.stringify({name:e.value.name,remark:e.value.remark,data:e.value.data,env:e.value.env})}),loading:"提交中...",message:!0,success:e=>{e.status&&(T("complate",e),E.value=!0,T("close"))}})}}),P=(e,a)=>{W({type:"file",change:t=>{t&&("compose"==a&&(e.value.path=t),"env"==a&&(e.value.envpath=t),t.endsWith(".yml")||t.endsWith(".yaml")||"compose"!=a?t.endsWith(".env")||"env"!=a?z(t,e,a):C.error("请选择.env文件"):C.error("请选择compose文件"))}})},z=async(e,a,t)=>{try{const{data:s}=await l({path:e});"object"==typeof s&&("compose"==t&&(a.value.data=s.data||""),"env"==t&&(a.value.env=s.data||""))}catch(s){}},B=(e,a)=>{const t=document.createElement("input");t.type="file",t.style.display="none","compose"===a&&(t.accept=".yml,.yaml"),t.addEventListener("change",t=>{var s;const r=null==(s=t.target.files)?void 0:s[0];if(!r)return;if("compose"===a&&!r.name.endsWith(".yml")&&!r.name.endsWith(".yaml"))return void C.error("请选择compose文件");if("env"===a&&!r.name.endsWith("env"))return void C.error("请选择env文件");const o=new FileReader;o.onload=t=>{var s;const o=null==(s=t.target)?void 0:s.result;"compose"===a?(e.value.path=r.name,e.value.data=o):"env"===a&&(e.value.envpath=r.name,e.value.env=o)},o.onerror=()=>{C.error("读取文件内容失败")},o.readAsText(r)}),document.body.appendChild(t),t.click(),setTimeout(()=>{document.body.removeChild(t)},0)};return h(async()=>{}),d({onConfirm:N}),(e,a)=>{const t=f("bt-loading");return y((w(),b("div",S,[u(g(J))])),[[t,g(V)],[t,"正在获取模板消息，请稍候...","title"]])}}}),[["__scopeId","data-v-196b1e12"]]);export{q as default};
