import{c as e,r as s,g as a,I as r,H as l,e as t,C as o,ae as i,U as d,aS as n,aY as u,T as c,G as p,a6 as m,v,x as _,y as f,i as g}from"./base-lib.js?v=1761009159";import{K as x,aq as b,y as w,M as h,jo as j,_ as y}from"./utils-lib.js?v=1761009159";import{u as k,o as C}from"./index63.js?v=1761009159";import{b as q,j as I,h as R,f as P}from"./form-item.js?v=1761009159";import{a as S}from"./useController10.js?v=1761009159";import"./__commonjsHelpers__.js?v=1761009159";import"./index105.js?v=1761009159";import"./column.js?v=1761009159";import"./index106.js?v=1761009159";import"./useController6.js?v=1761009159";import"./site.js?v=1761009159";import"./validator.js?v=1761009159";import"./useStore4.js?v=1761009159";const V={class:"p-[2rem] master-redis-add-form"};const H=y(e({__name:"index",setup(e,{expose:y}){const{redisAvailableNodes:H,openNodesLoading:N}=k(),O=s(!1),{BtForm:U,param:A,submit:B}=x({data:{slave_node_ids:[]},options:e=>a(()=>[q("主从名称","group_name",{attrs:{placeholder:"请输入主从复制组名称",class:"!w-[46rem]"},rules:[{required:!0,message:"主从名称不能为空",trigger:["blur","change"]}]}),I("主节点选择","master_node_id",H.value.nodes||[],{attrs:{placeholder:"请选择主节点",class:"!w-[46rem]",loading:N.value,onChange:s=>{const a=H.value.nodes.find(e=>e.value===s);e.value.master_ip=a.server_ip,e.value.slave_node_ids=(e.value.slave_node_ids||[]).filter(e=>e!==s)}},rules:[{required:!0,message:"请选择主节点",trigger:["blur","change"]}]}),q("主节点IP","master_ip",{attrs:{placeholder:"请输入主节点IP地址",class:"!w-[46rem]"},rules:[{required:!0,...b()}]}),R("可用从节点",()=>{let s;return r(t("div",{class:"slave-checkbox-list border w-full rounded p-[12px] max-h-[42rem] overflow-y-auto",style:{minHeight:N.value?"10rem":"auto"}},[!N.value&&!H.value.row.length&&t("div",{class:"text-small text-tertiary leading-[12px]"},[o("暂无可用Redis从节点，请先在前往 节点管理 -")," ",t("span",{class:"bt-link",onClick:()=>location.href="/node/node-mgt"},[o("添加节点")])]),t(i,{modelValue:e.value.slave_node_ids,"onUpdate:modelValue":s=>e.value.slave_node_ids=s},(a=s=H.value.row.map(s=>{const a=t("span",{class:"text-small flex-1"},[s.server_ip,o(" - "),s.name]);return t("div",{class:"flex justify-between items-center mb-[8px] last:mb-0",key:s.id},[t(d,{value:s.id,class:"mr-[8px]",disabled:s.id===e.value.master_node_id||s.is_in_replication_group},{default:()=>{var e;return[s.is_in_replication_group?t(n,{content:"节点已在主从组 - ".concat(null==(e=s.group_info)?void 0:e.group_name),placement:"top"},{default:()=>a}):a]}}),t("span",{class:"ml-[12px] text-small px-[8px] py-[2px] leading-[22px] rounded",style:{background:1===S(s.redis_version,"7.0.0")?"#f6ffed":"#fff7e6",color:1===S(s.redis_version,"7.0.0")?"#52c41a":"#fa8c16"}},[o("Redis "),s.redis_version])])}),"function"==typeof a||"[object Object]"===Object.prototype.toString.call(a)&&!g(a)?s:{default:()=>[s]}))]),[[l("bt-loading"),N.value]]);var a},"slave_node_ids",{rules:[{required:!0,trigger:["blur","change"],validator:(e,s,a)=>{if(!s||0===s.length)return O.value=!1,void a(new Error("请选择主从节点"));const r=H.value.row.filter(e=>s.includes(e.id)).map(e=>e.redis_version),l=r.every(e=>e===r[0]);O.value=!l,a()}}]}),O.value&&R(" ",()=>t(u,{"show-icon":!0,title:"警告：检测到版本不一致，建议使用相同版本的Redis节点",effect:"light",closable:!1,type:"warning"},null)),R("Redis密码",()=>t("div",{class:"flex items-center w-full"},[t(c,{modelValue:e.value.redis_password,"onUpdate:modelValue":s=>e.value.redis_password=s,placeholder:"请输入Redis密码",class:"!w-[38rem]",type:"password","show-password":!0},null),t(p,{class:"ml-[8px]",type:"default",onClick:()=>e.value.redis_password=w(16)},{default:()=>[o("生成密码")]})]),"redis_password",{rules:[{required:!0,message:"Redis密码不能为空",trigger:["blur","change"]}]}),P(" ",[{content:"设置的密码将会覆盖当前redis密码"},{content:"redis密码建议使用包含字母、数字和特殊字符的复杂密码确保安全性"},{content:"如有安全组，请执行以下两步操作"},{content:"在主节点与从节点设置本机IP为白名单，放行6379端口"},{content:"在主节点机器，设置从节点IP为白名单，放行6379端口"},{content:"只支持通过app/或api添加的节点"}])]),submit:async(e,s,a)=>{let r=null;try{await s(),r=h.load("正在创建主从复制组，请稍候...");const a={...e.value,slave_node_ids:JSON.stringify(e.value.slave_node_ids)},l=await j(a);return l.data.status?(C(l.data.msg.task_id),h.success(l.data.msg.message)):h.error(l.data.msg||"创建主从复制组失败"),l.status}catch(l){return!1}finally{null==r||r.close()}}});return y({onConfirm:B}),m(()=>{H.value={row:[],nodes:[]},N.value=!0}),(e,s)=>(v(),_("div",V,[t(f(U))]))}}),[["__scopeId","data-v-2cb6efdc"]]);export{H as default};
