import{l as e,K as s,N as a,cN as l,t,x as r,a0 as u}from"./utils-lib.js?v=20260328163632";import{B as i}from"./index85.js?v=20260328163632";import{n as p,s as d,o,k as n}from"./useMethod2.js?v=20260328163632";import{p as c}from"./database.js?v=20260328163632";import{u as b}from"./store.js?v=20260328163632";import{r as m,O as v,c as y,k as _,J as h,V as g,_ as f,Y as w}from"./base-lib.js?v=20260328163632";import"./naive-ui.js?v=20260328163632";import"./__commonjsHelpers__.js?v=20260328163632";import"./env-lib.js?v=20260328163632";import"./service.vue_vue_type_style_index_0_scoped_073b5b46_lang.js?v=20260328163632";const{isRefreshList:x}=b(),k=m(!1),j=m([]),I={labelStyle:"min-width: 100px"},K=m({label:e("数据库名"),attrs:I,ruleKey:"name",rules:[s({message:e("请输入数据库名"),trigger:["blur","input"]})],children:[{type:"input",key:"name",attrs:{class:"!w-240px mr-10px",placeholder:e("新的数据库名称"),onInput:e=>{O.value.db_user=e,O.value.ps=e}}},{type:"select",key:"codeing",attrs:{class:"!w-130px",placeholder:e("请选择"),options:[{label:"utf8",value:"utf8"},{label:"utf8mb4",value:"utf8mb4"},{label:"gbk",value:"gbk"},{label:"big5",value:"big5"}]}}]}),P=m({label:e("用户名"),attrs:I,ruleKey:"db_user",rules:[s({message:e("请输入数据库用户名"),trigger:["blur","input"]})],children:[{type:"input",key:"db_user",attrs:{class:"!w-380px",placeholder:e("请输入数据库用户名")}}]}),q=m({label:e("密码"),attrs:I,ruleKey:"db_password",rules:[s({message:e("请输入密码"),trigger:["blur","input"]})],children:[{type:"custom",key:"db_password",render:()=>v(i,{width:"340px",icon:"el-refresh",modelValue:O.value.db_password,"onUpdate:modelValue":e=>O.value.db_password=e,onIconClick:()=>O.value.db_password=a(16),isActive:!0},null)}]}),C=y((()=>({label:e("关联网站"),attrs:I,children:[{type:"select",key:"pid",attrs:{class:"!w-380px",options:j.value,placeholder:e("请选择")}}]}))),E=y((()=>{let s=[{type:"select",key:"db_access",attrs:{class:"!w-380px",options:p,placeholder:e("请选择"),"onUpdate:value":e=>{k.value="ip"===e}}}];return k.value&&s.push({type:"input",key:"address",attrs:{type:"textarea",rows:4,class:"!w-380px mt-20px",placeholder:e("如需填写多个IP，请换行填写，每行一个IP")}}),{label:e("访问权限"),attrs:I,ruleKey:"address",rules:[{validator:(s,a,t)=>"ip"!==O.value.db_access||(""===a?new Error(e("请输入IP地址")):(a.split("\n").forEach((s=>{if(""!==s&&!l(s))return new Error(e("请输入正确的IP地址"))})),!0)),trigger:["blur","change"]}],style:{display:"block"},children:s}})),N=y((()=>({label:e("添加至"),attrs:I,style:{"align-items":"center",width:"100%"},children:[{type:"select",key:"sid",attrs:{consistentMenuWidth:!1,placeholder:e("请选择"),options:d.value}},{type:"custom",key:"",render:()=>v("span",{class:"bt-link ml-10px",onClick:o},[e("管理远程数据库")])}]}))),V=m({formAttrs:{labelWidth:"auto"},formItems:[]}),A=y((()=>(V.value.formItems=[K.value,P.value,q.value,C.value,E.value,N.value],V.value))),[M,O,U]=t(A),W=async()=>{var s;const{db_access:a,address:l,pid:t,...u}=O.value;let i={...u,db_access:"ip"===a?null==(s=null==l?void 0:l.split("\n"))?void 0:s.join(","):a,db_type:"mysql"};""!==t&&(i.pid=t);const p=await r({loading:e("正在添加数据库"),request:c(i),message:!0,data:{status:Number}});return 0===p.status&&(x.value=!0),0===p.status},B=async()=>{var s;await n(),r({request:u({table:"sites"}),success:s=>{let a=s.data.data.map((e=>({...e,label:e.name,value:e.id})));a.unshift({label:e("不关联"),value:""}),j.value=a}}),Object.assign(O.value,{name:"",db_user:"",db_password:a(16),codeing:"utf8",pid:"",db_access:"127.0.0.1",address:"",sid:d.value.length&&(null==(s=d.value[0])?void 0:s.value)||0}),k.value=!1},H=()=>{j.value=[]},J=_({__name:"index",setup:(e,{expose:s})=>(B(),h(H),s({onConfirm:W}),(e,s)=>(g(),f(w(M),{class:"p-24px"})))});export{J as default};
