import{c as e,r as a,g as l,q as s,v as d,x as r,e as u,B as o,y as t,N as i,D as m,F as n,b0 as p,C as c,R as b,T as _,bc as v,ak as f,al as g,ab as h,a9 as V}from"./base-lib.js?v=1761009159";import{y as w,c8 as y,P as j,M as x,k,e as A,_ as I}from"./utils-lib.js?v=1761009159";import{_ as U}from"./index103.js?v=1761009159";import{a as C,m as q}from"./useMethod4.js?v=1761009159";import{g as P}from"./useStore2.js?v=1761009159";import{addDatabase as M}from"./database.js?v=1761009159";import{_ as S}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 D={class:"p-[24px]"},E=I(e({__name:"index",props:{compData:{default:()=>({refresh:async()=>[]})}},setup(e,{expose:I}){const E=e,{refreshTableList:F}=P(),L=a(),R=a(!1),T=a([]),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"]}],db_user:[{required:!0,message:"请输入用户名",trigger:["blur","change"]}],password:[{required:!0,message:"请输入密码",trigger:["blur","change"]}],address:[{validator:(e,a,l)=>{"ip"===B.value.dataAccess&&(""===a?l(new Error("请输入IP地址")):(a.split("\n").forEach(e=>{""===e||y(e)||l(new Error("请输入正确的IP地址"))}),l())),l()},trigger:["blur","change"]}]},N=l(()=>{var e;return(null==(e=T.value.find(e=>e.id===B.value.sid))?void 0:e.db_host)||""}),Q=e=>{B.value.db_user=e,B.value.ps=e},z=()=>{L.value.clearValidate("address")},G=async()=>{const e=x.load("正在连接服务器，请稍后...");try{const{status:e,msg:a,err_msg:l}=await q(B.value.sid);return!!e||(x.error(l),!1)}catch(a){}finally{e.close()}};return s(async()=>{var e;T.value=await E.compData.refresh(),B.value.sid=null==(e=T.value[0])?void 0:e.id}),I({onConfirm:async e=>{await L.value.validate(),await G(),"ip"===B.value.dataAccess&&(B.value.address=B.value.address.replace(/\n/g,",")),await j({request:M({...B.value,sid:String(B.value.sid),address:"ip"===B.value.dataAccess?B.value.address:B.value.dataAccess}),loading:"正在添加数据库，请稍后...",message:!0}),F(),e()}}),(e,a)=>{const l=_,s=v,y=f,j=g,x=h,I=k,q=U,P=A,M=V;return d(),r("div",D,[u(M,{disabled:t(R),model:t(B),ref_key:"addFormRef",ref:L,rules:H,onSubmit:a[8]||(a[8]=b(()=>{},["prevent"]))},{default:o(()=>[u(x,{label:"数据库名",prop:"name"},{default:o(()=>[u(s,{span:14},{default:o(()=>[u(l,{placeholder:"新的数据库名称",modelValue:t(B).name,"onUpdate:modelValue":a[0]||(a[0]=e=>t(B).name=e),onInput:Q},null,8,["modelValue"])]),_:1}),u(s,{span:10},{default:o(()=>[u(x,null,{default:o(()=>[u(j,{modelValue:t(B).codeing,"onUpdate:modelValue":a[1]||(a[1]=e=>t(B).codeing=e),class:"ml-8px !w-[13.2rem]"},{default:o(()=>[u(y,{label:"utf8",value:"utf8"}),u(y,{label:"utf8mb4",value:"utf8mb4"}),u(y,{label:"gbk",value:"gbk"}),u(y,{label:"big5",value:"big5"})]),_:1},8,["modelValue"])]),_:1})]),_:1})]),_:1}),u(x,{label:"用户名",prop:"db_user"},{default:o(()=>[u(I,{width:"38rem",placeholder:"数据库用户",modelValue:t(B).db_user,"onUpdate:modelValue":a[2]||(a[2]=e=>t(B).db_user=e)},null,8,["modelValue"])]),_:1}),u(x,{label:"密码",prop:"password"},{default:o(()=>[u(q,{width:"38rem",icon:"el-refresh",modelValue:t(B).password,"onUpdate:modelValue":a[3]||(a[3]=e=>t(B).password=e),modelModifiers:{sync:!0},onIconClick:a[4]||(a[4]=()=>t(B).password=t(w)(16)),isActive:!0},null,8,["modelValue"])]),_:1}),u(x,{label:"访问权限",prop:"dataAccess"},{default:o(()=>[u(j,{class:"!w-[38rem]",modelValue:t(B).dataAccess,"onUpdate:modelValue":a[5]||(a[5]=e=>t(B).dataAccess=e),onChange:z},{default:o(()=>[u(y,{label:"所有人",value:"%"}),u(y,{label:"本地服务器",value:"127.0.0.1"}),u(y,{label:"指定ip",value:"ip"})]),_:1},8,["modelValue"]),u(x,{prop:"address"},{default:o(()=>["ip"===t(B).dataAccess?(d(),i(I,{key:0,type:"textarea",rows:4,placeholder:"如需填写多个IP，请换行填写，每行一个IP",modelValue:t(B).address,"onUpdate:modelValue":a[6]||(a[6]=e=>t(B).address=e),width:"38rem",class:"mt-[8px] w-full"},null,8,["modelValue"])):m("",!0)]),_:1})]),_:1}),u(x,{label:"添加至",prop:"sid",class:"!mb-0"},{default:o(()=>[u(j,{class:"!w-[24rem]",modelValue:t(B).sid,"onUpdate:modelValue":a[7]||(a[7]=e=>t(B).sid=e)},{default:o(()=>[(d(!0),r(n,null,p(t(T),(e,a)=>(d(),i(y,{key:a,label:e.ps+(e.db_host?"（"+e.db_host+"）":""),value:e.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"]),u(P,{class:"ml-[8px]",onClick:t(C)},{default:o(()=>a[9]||(a[9]=[c("管理远程数据库",-1)])),_:1,__:[9]},8,["onClick"])]),_:1}),u(x,{label:" ",class:"!mb-0"},{default:o(()=>[u(S,{server:{sid:t(B).sid,ip:t(N)}},null,8,["server"])]),_:1})]),_:1},8,["disabled","model"])])}}}),[["__scopeId","data-v-b34e8314"]]);export{E as default};
