import{d as R,r as V,H as L,e as c,f as C,o as _,h as s,T as K,g as E,w as u,F as S,v as q,j as U,U as T,S as $,B as j,_ as z,u as F,c as H,D as v,i as x,q as B,p as o,P as M}from"./index-5k_MqT6o.js";import{u as A,E as D,C as N}from"./index-Cl9RbTBn.js";import"./index-BHx7dntQ.js";import"./index-CAzgmO3A.js";const G={class:"ip-input-container"},J={class:"ip-segment-group"},O={key:0,class:"ip-dot"},Q={class:"ip-btn-group"},W=R({__name:"index",props:{initIp:{type:String,default:""}},emits:["confirm","cancel"],setup(k,{emit:d}){const f=e=>{const t=Number(e);return!isNaN(t)&&t>=0&&t<=255&&e===t.toString()},i=e=>/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/.test(e),n=k,g=d,p=V(["","","",""]);L(()=>n.initIp,e=>{if(e){const t=e.split(".");t.length===4&&i(e)&&(p.value=t)}},{immediate:!0});const y=e=>{let t=p.value[e].trim();t=t.replace(/\D/g,""),t.length>3&&(t=t.slice(0,3)),Number(t)>255&&(t="255"),p.value[e]=t,t.length===3&&e<3&&document.querySelectorAll(".ip-segment-input")[e+1]?.focus()},b=e=>{e<3&&document.querySelectorAll(".ip-segment-input")[e+1]?.focus()},I=e=>{const t=p.value[e];t&&f(t)},a=()=>{p.value=["","","",""],g("cancel")},l=()=>{const e=p.value.join(".");if(!i(e)){j.error("请输入合法的 IP 地址");return}g("confirm",e)};return(e,t)=>{const h=c("el-input"),w=c("el-form-item");return _(),C("div",G,[s(w,{label:e.$t("IP地址"),"label-position":"top"},{default:u(()=>[E("div",J,[(_(!0),C(S,null,q(p.value,(P,m)=>(_(),C(S,{key:m},[s(h,{modelValue:p.value[m],"onUpdate:modelValue":r=>p.value[m]=r,class:"ip-segment-input",size:"large",type:"number",max:255,min:0,onInput:r=>y(m),onKeyup:T(r=>b(m),["enter"]),onBlur:r=>I(m)},null,8,["modelValue","onUpdate:modelValue","onInput","onKeyup","onBlur"]),m<3?(_(),C("span",O,".")):U("",!0)],64))),128))])]),_:1},8,["label"]),K(e.$slots,"default",{},void 0,!0),E("div",Q,[s($,{onClick:a,value:"取消",type:"default"}),s($,{type:"primary",onClick:l,value:"确定"})])])}}}),X=z(W,[["__scopeId","data-v-478b35a9"]]),ne=R({__name:"index",setup(k){const{t:d}=F(),f=V(0),i=V(!1),n=H({status:1,type:1,ip:"",id:null}),{register:g,tableActions:p}=A({showIndex:!0,showSelection:!1,showExport:!1,api:v.ipConfigList,immediate:!0,apiParams:{type:1},columns:[{label:"地址",prop:"ip"},{label:"添加时间",prop:"created_at"},{label:"编辑人",prop:"operator_name"},{label:"状态",prop:"status",tagEnums:D}],schema:[{label:"关键词",prop:"keyword",type:"input"}],showAction:!0,actionProps:{btnList:[{label:"编辑",click(a){n.id=a.row.id,n.status=a.row.status,n.ip=a.row.ip,i.value=!0}},{label:"删除",isPopConfirm:!0,popConfirmEmits:{confirm({row:a}){return v.ipConfigDelete({id:a.id}).then(()=>{p.reload()}),!0}},type:"danger"}]}}),{register:y,tableActions:b}=A({showIndex:!0,showSelection:!1,showExport:!1,api:v.ipConfigList,immediate:!0,apiParams:{type:2},columns:[{label:"地址",prop:"ip"},{label:"添加时间",prop:"created_at"},{label:"编辑人",prop:"operator_name"},{label:"状态",prop:"status",tagEnums:D}],schema:[{label:"关键词",prop:"keyword",type:"input"}],showAction:!0,actionProps:{btnList:[{label:"编辑",click(a){n.id=a.row.id,n.status=a.row.status,n.ip=a.row.ip,i.value=!0}},{label:"删除",isPopConfirm:!0,popConfirmEmits:{confirm({row:a}){return v.ipConfigDelete({id:a.id}).then(()=>{b.reload()}),!0}},type:"danger"}]}}),I=a=>{n.ip=a,f.value===0?n.type=1:n.type=2,v.ipConfigUpdate(n).then(()=>{i.value=!1,f.value===0?p.reload():b.reload(),n.id=null,n.status=1,n.ip=""})};return(a,l)=>{const e=c("CButton"),t=c("el-tab-pane"),h=c("el-tabs"),w=c("el-switch"),P=c("el-form-item"),m=c("el-dialog");return _(),x(M,{bgColor:"none"},{default:u(()=>[s(h,{type:"border-card",modelValue:o(f),"onUpdate:modelValue":l[2]||(l[2]=r=>B(f)?f.value=r:null)},{default:u(()=>[s(t,{label:o(d)("访问黑名单"),name:0},{default:u(()=>[s(o(N),{onRegister:o(g)},{searchRight:u(()=>[s(e,{onClick:l[0]||(l[0]=r=>i.value=!0),value:"添加IP地址"})]),_:1},8,["onRegister"])]),_:1},8,["label"]),s(t,{label:o(d)("访问白名单"),name:1},{default:u(()=>[s(o(N),{onRegister:o(y)},{searchRight:u(()=>[s(e,{onClick:l[1]||(l[1]=r=>i.value=!0),value:"添加IP地址"})]),_:1},8,["onRegister"])]),_:1},8,["label"])]),_:1},8,["modelValue"]),o(i)?(_(),x(m,{key:0,title:"添加IP地址",modelValue:o(i),"onUpdate:modelValue":l[5]||(l[5]=r=>B(i)?i.value=r:null),width:"400px"},{default:u(()=>[s(X,{"init-ip":o(n).ip,onConfirm:I,onCancel:l[4]||(l[4]=r=>i.value=!1)},{default:u(()=>[s(P,{label:o(d)("状态"),"label-position":"top"},{default:u(()=>[s(w,{modelValue:o(n).status,"onUpdate:modelValue":l[3]||(l[3]=r=>o(n).status=r),"inactive-value":0,"inactive-text":o(d)("禁用"),"active-value":1,"active-text":o(d)("启用"),"inline-prompt":"",size:"large"},null,8,["modelValue","inactive-text","active-text"])]),_:1},8,["label"])]),_:1},8,["init-ip"])]),_:1},8,["modelValue"])):U("",!0)]),_:1})}}});export{ne as default};
