import{c as e,r as a,o as s,q as l,H as r,v as d,x as o,I as t,y as u,N as m,B as n,e as i,F as p,b0 as b,J as c,R as h,ak as f,al as w,ab as g,bc as _,a9 as V}from"./base-lib.js?v=1761009159";import{c4 as v,c8 as y,M as q,P as U,k as j}from"./utils-lib.js?v=1761009159";import{getDatabasesList as x,addUser as k}from"./database.js?v=1761009159";import"./__commonjsHelpers__.js?v=1761009159";const D={class:"p-[24px]"},F=e({__name:"add-user",props:{compData:{default:()=>{}}},setup(e,{expose:F}){const C=e,E=a([]),H=a(null),R=a(C.compData.serverList),B=s({sid:0,username:"",password:v(),host:"127.0.0.1",dbname:"*",tbname:"*",address:"",access:"",disabled:!1,selected:[1,6,21,22],loading:!1}),I={username:[{required:!0,message:"请输入用户名",trigger:["blur"]}],password:[{required:!0,message:"请输入密码",trigger:["blur"]}],address:[{required:!0,validator:(e,a,s)=>{y(a)||"ip"!==B.host?s():s(new Error("请输入正确的ip地址"))},trigger:["blur"]}],tbname:[{required:!0,validator:(e,a,s)=>{""===a&&"*"!==B.dbname?s(new Error("请选择数据库表")):s()},trigger:["blur"]}]},J=async()=>{try{B.loading=!0;const e=await x({sid:B.sid});E.value=e.data}catch(e){q.error(e)}finally{B.loading=!1}};return F({onConfirm:async e=>{try{await H.value.validate();const a=("ip"===B.host&&(B.host=B.address),"*"===B.dbname&&(B.tbname="*"),{sid:B.sid,username:B.username,password:B.password,host:B.host,db_name:B.dbname,tb_name:B.tbname});await U({loading:"正在添加用户,请稍后...",request:k(a),message:!0,success:a=>{a.status&&(C.compData.refreshFn&&C.compData.refreshFn(),e())}})}catch(a){}}}),l(J),(e,a)=>{const s=f,l=w,v=g,y=j,q=_,U=V,x=r("bt-loading");return d(),o("div",D,[t((d(),m(U,{"label-width":"90px",model:u(B),ref_key:"addUserFormRef",ref:H,rules:I,onSubmit:a[5]||(a[5]=h(()=>{},["prevent"]))},{default:n(()=>[i(v,{label:"服务器",prop:"password"},{default:n(()=>[i(l,{modelValue:u(B).sid,"onUpdate:modelValue":a[0]||(a[0]=e=>u(B).sid=e),class:"mr-[1.5rem] !w-[16rem]",placeholder:"请选择",onChange:J},{default:n(()=>[(d(!0),o(p,null,b(u(R),e=>(d(),m(s,{key:e.id,label:e.ps,value:e.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),i(v,{label:"用户名",prop:"username"},{default:n(()=>[i(y,{width:"38rem",placeholder:"请填写用户名",modelValue:u(B).username,"onUpdate:modelValue":a[1]||(a[1]=e=>u(B).username=e)},null,8,["modelValue"])]),_:1}),i(v,{label:"密码",prop:"password"},{default:n(()=>[i(y,{width:"38rem",iconType:"refresh",modelValue:u(B).password,"onUpdate:modelValue":a[2]||(a[2]=e=>u(B).password=e),"is-null":!0},null,8,["modelValue"])]),_:1}),i(v,{label:"访问权限",prop:"host"},{default:n(()=>[i(q,{span:8},{default:n(()=>[i(l,{modelValue:u(B).host,"onUpdate:modelValue":a[3]||(a[3]=e=>u(B).host=e),class:"!w-[16rem]"},{default:n(()=>[i(s,{label:"所有人",value:"%"}),i(s,{label:"本地服务器",value:"127.0.0.1"}),i(s,{label:"指定ip",value:"ip"})]),_:1},8,["modelValue"])]),_:1}),t(i(v,{prop:"address"},{default:n(()=>[i(y,{placeholder:"请输入指定ip",modelValue:u(B).address,"onUpdate:modelValue":a[4]||(a[4]=e=>u(B).address=e),width:"22.3rem",class:"ml-[1rem]"},null,8,["modelValue"])]),_:1},512),[[c,"ip"===u(B).host]])]),_:1})]),_:1},8,["model"])),[[x,u(B).loading]])])}}});export{F as default};
