import{c as e,r as a,V as l,g as s,q as r,v as d,x as o,e as t,B as u,y as i,N as m,D as p,F as n,b0 as _,C as c,R as v,ab as b,ak as f,al as h,a9 as g}from"./base-lib.js?v=1761009159";import{y as w,P as V,M as j,k as y,e as x,_ as k}from"./utils-lib.js?v=1761009159";import{_ as U}from"./index103.js?v=1761009159";import{addModulesDatabase as q}from"./database.js?v=1761009159";import{a as C,m as A}from"./useMethod4.js?v=1761009159";import{g as D}from"./useStore2.js?v=1761009159";import{_ as I}from"./index.vue_vue_type_script_setup_true_lang9.js?v=1761009159";import"./__commonjsHelpers__.js?v=1761009159";import"./column.js?v=1761009159";import"./index106.js?v=1761009159";import"./validator.js?v=1761009159";const M={class:"p-[24px]"},S=k(e({__name:"index",props:{compData:{default:()=>({options:[]})}},setup(e,{expose:k}){const{refs:{tabActive:S},refreshTableList:F}=D(),R=e,B=a(),E=l(!1),H=a([]),L=a({name:"",db_user:"",password:w(16),ps:"",sid:0,listen_ip:"0.0.0.0/0",host:""}),N={name:[{required:!0,message:"请输入数据库名",trigger:["blur","change"]}],db_user:[{required:!0,message:"请输入用户名",trigger:["blur","change"]}],password:[{required:!0,message:"请输入密码",trigger:["blur","change"]}]},P=s(()=>{var e;return(null==(e=H.value.find(e=>e.id===L.value.sid))?void 0:e.db_host)||""}),T=e=>{L.value.db_user=L.value.name,L.value.ps=L.value.name},z=async()=>{try{E.value=!0;const{status:e,msg:a,err_msg:l}=await A(L.value.sid);if(!e)throw j.error(l||a),new Error(l||a);E.value=!1}catch(e){}};return r(async()=>{var e,a;H.value=await(null==(e=R.compData)?void 0:e.refresh()),L.value.sid=null==(a=H.value[0])?void 0:a.id}),k({onConfirm:async e=>{await B.value.validate(),E.value=!0,await z();let a={...L.value,sid:String(L.value.sid)};a.listen_ip="ip"===a.listen_ip?a.host:a.listen_ip,await V({loading:"正在添加数据库,请稍后...",request:q(a,S.value),message:!0}),F(),e()}}),(e,a)=>{const l=y,s=b,r=U,V=f,j=h,k=x,q=g;return d(),o("div",M,[t(q,{disabled:i(E),model:i(L),ref_key:"addFormRef",ref:B,rules:N,onSubmit:a[7]||(a[7]=v(()=>{},["prevent"]))},{default:u(()=>[t(s,{label:"数据库名",prop:"name"},{default:u(()=>[t(l,{width:"38rem",ref:"data_name",placeholder:"新的数据库名称",modelValue:i(L).name,"onUpdate:modelValue":a[0]||(a[0]=e=>i(L).name=e),onInput:T},null,8,["modelValue"])]),_:1}),t(s,{label:"用户名",prop:"db_user"},{default:u(()=>[t(l,{width:"38rem",placeholder:"数据库用户",modelValue:i(L).db_user,"onUpdate:modelValue":a[1]||(a[1]=e=>i(L).db_user=e)},null,8,["modelValue"])]),_:1}),t(s,{label:"密码",prop:"password"},{default:u(()=>[t(r,{width:"38rem",icon:"el-refresh",modelValue:i(L).password,"onUpdate:modelValue":a[2]||(a[2]=e=>i(L).password=e),modelModifiers:{sync:!0},onIconClick:a[3]||(a[3]=()=>i(L).password=i(w)(16)),isActive:!0},null,8,["modelValue"])]),_:1}),t(s,{label:"访问权限",prop:"dataAccess"},{default:u(()=>[t(j,{class:"!w-[38rem]",modelValue:i(L).listen_ip,"onUpdate:modelValue":a[4]||(a[4]=e=>i(L).listen_ip=e)},{default:u(()=>[t(V,{label:"所有人",value:"0.0.0.0/0"}),t(V,{label:"本地服务器",value:"127.0.0.1/32"}),t(V,{label:"指定ip",value:"ip"})]),_:1},8,["modelValue"]),t(s,{prop:"host"},{default:u(()=>["ip"===i(L).listen_ip?(d(),m(l,{key:0,placeholder:"填写格式如：192.168.69.11/24",modelValue:i(L).host,"onUpdate:modelValue":a[5]||(a[5]=e=>i(L).host=e),width:"38rem",class:"mt-8px w-full"},null,8,["modelValue"])):p("",!0)]),_:1})]),_:1}),t(s,{label:"添加至",prop:"sid",class:"!mb-0"},{default:u(()=>[t(j,{class:"!w-[24rem]",modelValue:i(L).sid,"onUpdate:modelValue":a[6]||(a[6]=e=>i(L).sid=e)},{default:u(()=>[(d(!0),o(n,null,_(i(H),(e,a)=>(d(),m(V,{key:a,label:e.ps+(e.db_host?"（"+e.db_host+"）":""),value:e.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"]),t(k,{class:"ml-[8px]",onClick:i(C)},{default:u(()=>a[8]||(a[8]=[c(" 管理远程数据库 ",-1)])),_:1,__:[8]},8,["onClick"])]),_:1}),t(s,{label:" ",class:"!mb-0"},{default:u(()=>[t(I,{server:{sid:i(L).sid,ip:i(P)}},null,8,["server"])]),_:1})]),_:1},8,["disabled","model"])])}}}),[["__scopeId","data-v-1c688efe"]]);export{S as default};
