import{c as s,r as e,g as a,e as l,T as r,G as t,C as o,a6 as p,v as d,x as u,y as i}from"./base-lib.js?v=1761009159";import{K as c,ar as n,M as m,je as w,P as y}from"./utils-lib.js?v=1761009159";import{b as _,i as v,h as f}from"./form-item.js?v=1761009159";import{u as h}from"./useStore9.js?v=1761009159";import"./__commonjsHelpers__.js?v=1761009159";import"./index106.js?v=1761009159";const k={class:"p-[2rem] node-ssh-edit-form"},g=s({__name:"ssh-edit",props:{compData:{default:()=>({node_id:0,server_ip:"",ssh_conf:{},callback:()=>{}})}},setup(s,{expose:g}){const{setNodeSSHisSet:b,setNodeInfo:S,isRefreshNodeList:x,sshTerminalVisible:j}=h(),H=s,C=e(H.compData||{}),N=e(!1),{BtForm:V,submit:q}=c({data:()=>({node_id:C.value.node_id||"",port:22,password_type:0,pkey:"",pkey_passwd:"",test_case:1}),options:s=>a(()=>[_("端口","port",{attrs:{placeholder:"请输入 SSH 端口",class:"!w-[8rem]"},rules:[n()]}),v("认证方式","password_type",[{label:"密码",value:0},{label:"私钥",value:1}],{attrs:{onChange:s=>{}},rules:[{required:!0,message:"请选择认证方式",trigger:["blur","change"]}]}),1===s.value.password_type&&f("私钥",()=>l("div",{class:"flex items-end w-full"},[l(r,{modelValue:s.value.pkey,"onUpdate:modelValue":e=>s.value.pkey=e,type:"textarea",placeholder:"请输入 SSH 私钥",class:"!w-[320px]",rows:4},null),l(t,{class:"ml-[8px]",type:"default",loading:N.value,onClick:()=>D(s)},{default:()=>[o("测试连接")]})]),"pkey",{rules:[{required:!0,message:"SSH 私钥不能为空",trigger:["blur","change"]}]}),1===s.value.password_type&&_("私钥密码","pkey_passwd",{attrs:{type:"password","show-password":!0,placeholder:"请输入 SSH 私钥密码",class:"!w-[320px]"}}),0==s.value.password_type&&f("密码",()=>l("div",{class:"flex items-center w-full"},[l(r,{modelValue:s.value.password,"onUpdate:modelValue":e=>s.value.password=e,type:"password","show-password":!0,placeholder:"请输入密码",class:"!w-[320px]"},null),l(t,{class:"ml-[8px]",type:"default",loading:N.value,onClick:()=>D(s)},{default:()=>[o("测试连接")]})]),"password",{rules:[{required:!0,message:"密码不能为空",trigger:["blur","change"]}]})]),submit:async(s,e,a)=>{const l=m.load("正在保存中，请稍后...");try{await e();const a={...s.value},{port:l,password:r,pkey:t,pkey_passwd:o}=a;0==a.password_type?(a.pkey_passwd="",a.pkey=""):a.password="",delete a.password_type,a.test_case=0;const p=await w(a);return p.status?(S.value.ssh_conf={host:C.value.server_ip,port:Number(l),password:r,pkey:t,pkey_passwd:o,username:"root"},b.value=!0,x.value=!0,j.value=!1,m.success("SSH 信息保存成功")):m.error(p.msg||"保存失败"),p.status}catch(r){return!1}finally{null==l||l.close()}}}),D=async s=>{try{N.value=!0;const{node_id:e,port:a,password:l,pkey:r,pkey_passwd:t}=s.value,o={port:Number(a),password:l,pkey:r,pkey_passwd:t,node_id:e,test_case:1};await y({request:w(o),message:!0})}catch(e){}finally{N.value=!1}};return p(()=>{var s,e;null==(e=(s=H.compData).callback)||e.call(s)}),g({onConfirm:q}),(s,e)=>(d(),u("div",k,[l(i(V))]))}});export{g as default};
