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