import{c as e,r as s,o as a,q as t,v as l,x as i,e as r,B as o,y as n,F as p,b0 as m,N as u,D as c,ak as d,al as g,ab as f,a9 as b}from"./base-lib.js?v=1761009159";import{p as v,k as y,P as _,M as w}from"./utils-lib.js?v=1761009159";import{getPermission as h,batchSetMysqlAuth as j,setPermission as P,setPgSqlAuth as x}from"./database.js?v=1761009159";import{i as q,h as k}from"./validator.js?v=1761009159";import{x as D}from"./useMethod4.js?v=1761009159";import{g as V}from"./useStore2.js?v=1761009159";import"./__commonjsHelpers__.js?v=1761009159";import"./index106.js?v=1761009159";import"./column.js?v=1761009159";const I={class:"p-20px"},B=e({__name:"index",props:{compData:{default:()=>({type:"single",rowData:{},config:{}})}},setup(e,{expose:B}){const{refs:{tabActive:S},refreshTableList:A}=V(),O=e,{rowData:F,type:M}=O.compData,{enable:N,exclude:U,clearBatch:C}=O.compData.config,H=s(),J=a({permission:"",ip:""}),L={ip:[{required:!0,trigger:["blur","change"],message:"请输入IP地址"}]},R={pgsql:{option:[{label:"所有人",value:"0.0.0.0/0"},{label:"本地服务器",value:"127.0.0.1/32"}],placeholder:"填写格式如：192.168.69.11/24",getPermission:()=>{const e="0.0.0.0/0"!==F.listen_ip&&"127.0.0.1/32"!==F.listen_ip;J.ip=e?F.listen_ip:"",J.permission=e?"ip":F.listen_ip},setPermission:async()=>{const{permission:e,ip:s}=J,a={data_name:F.name,username:F.username,listen_ip:"ip"===e?s:e};return await _({loading:"正在修改权限，请稍后...",request:x({data:JSON.stringify(a)}),success:({data:e})=>{w.request({msg:e.msg||e.data,status:e.status})}})}},mysql:{option:[{label:"所有人",value:"%"},{label:"本地服务器",value:"127.0.0.1"}],placeholder:"如果要允许IP段访问，可以使用%作为通配符，如127.17.%.%，如需要填写多个IP，请换行填写，每行一个IP",getPermission:async()=>{const{msg:e,status:s}=await _({request:h({name:F.username}),data:{msg:String,status:Boolean}});if(!s)return w.error(e);J.permission=e,"%"!==e&&"127.0.0.1"!==e&&(J.permission="ip",J.ip=e.replace(/,/g,"\n"))},setPermission:async()=>{const e=(()=>{const{permission:e,ip:s}=J;let a={name:F.username,dataAccess:e,access:"ip"===e?s:e,address:"ip"===e?s:""};return"multlples"==M?(delete a.name,k(F,U,N,{params:{...a}})):a})();if("multlples"===M){const s=await j(e),{data:a}=q(s.data);return a.length&&D(a,{title:"修改权限"}),C&&C(),s}{const s=await _({loading:"正在修改权限，请稍后...",request:P(e),message:"single"===M,data:{error:[Object,e=>Object.keys(e)],success:Array,status:Boolean,msg:String}});return s.status?s:w.error(s.msg)}}}};return t(()=>{(async()=>{"multlples"!=M?R[S.value].getPermission():J.permission=R[S.value].option.filter(e=>e.label.includes("本地"))[0].value})()}),B({onConfirm:async e=>{await H.value.validate();const{permission:s,ip:a}=J;["%","0.0.0.0/0"].includes(s)&&await v({title:"提示",content:"设置权限为所有人后，将会导致数据库安全性降低，他人可以随意访问数据库，是否继续操作？",icon:"warning-filled"});(await R[S.value].setPermission()).status&&(e(),A())}}),(e,s)=>{const a=d,t=g,v=f,_=y,w=b;return l(),i("div",I,[r(w,{ref_key:"permissionFormRef",ref:H,model:n(J),rules:L,"label-width":"5rem"},{default:o(()=>[r(v,{label:"访问权限",prop:"permission"},{default:o(()=>[r(t,{class:"!w-[22rem]",modelValue:n(J).permission,"onUpdate:modelValue":s[0]||(s[0]=e=>n(J).permission=e)},{default:o(()=>[(l(!0),i(p,null,m(R[n(S)].option,e=>(l(),u(a,{key:e.value,label:e.label,value:e.value},null,8,["label","value"]))),128)),r(a,{label:"指定ip",value:"ip"})]),_:1},8,["modelValue"])]),_:1}),"ip"===n(J).permission?(l(),u(v,{key:0,prop:"ip",label:"IP地址"},{default:o(()=>[r(_,{type:"mysql"===n(S)?"textarea":"text",rows:4,width:"22rem",modelValue:n(J).ip,"onUpdate:modelValue":s[1]||(s[1]=e=>n(J).ip=e),placeholder:R[n(S)].placeholder},null,8,["type","modelValue","placeholder"])]),_:1})):c("",!0)]),_:1},8,["model"])])}}});export{B as default};
