import{y as I,_ as Y}from"./js-yaml-ahJ4l1wK.js";import{d as R,a as P,B as i,y as K,z as q,D as z,l as U,r as N,u as $,c as D,b as a,w as e,J as b,T,L as B,e as d,o as y,j as k,M as G,f as g,m as v,a4 as H,p as Q,h as W,_ as X}from"./index-FX23dEwE.js";import{k as Z,l as aa,m as ea}from"./traffic-3Lpl9nRz.js";import{V as ta}from"./ConfigModel-90Xk7s5k.js";import"./request-dCC5BMJA.js";const F=p=>(Q("data-v-b8c9a84b"),p=p(),W(),p),sa={class:"editorBox"},na=F(()=>k("p",null,"修改时间: 2024/3/20 15:20:31",-1)),oa=F(()=>k("p",null,"版本号: xo842xqpx834",-1)),la=R({__name:"YAMLView",setup(p){const m=P(),C=i(m.params.isEdit==="1"),w=i(!1),f=i(!1),A=i(8),c=K(q.PROVIDE_INJECT_KEY),r=i(),E=i(),O=i("");z(async()=>{await h()}),U(()=>E.value!==JSON.stringify(r.value));const s=N(new ta);async function h(){var t,_,l;if((t=c.dynamicConfigForm)!=null&&t.data)s.fromData(c.dynamicConfigForm.data);else{if(((_=m.params)==null?void 0:_.pathId)==="_tmp")C.value=!0,s.isAdd=!0;else{console.log("666"),s.isAdd=!1;const u=await Z({name:(l=m.params)==null?void 0:l.pathId});s.fromApiOutput(u.data)}c.dynamicConfigForm=N({data:s})}const n=s.toApiInput();O.value=n.ruleName,n.ruleName=void 0;const o=I.dump(n);E.value=JSON.stringify(o),r.value=o}async function S(){f.value=!0;try{c.dynamicConfigForm.data=null,await h(),v.success("config reset success")}finally{f.value=!1}}const M=$();async function j(){var o;f.value=!0;let n=I.load(r.value);try{if(s.isAdd===!0){aa({name:s.basicInfo.key+".configurators"},n).then(t=>{c.dynamicConfigForm.data=null,H(()=>{M.replace("/traffic/dynamicConfig"),v.success("config add success")})}).catch(t=>{v.error("添加失败： "+t.msg)});return}await ea({name:(o=m.params)==null?void 0:o.pathId},n),v.success("config save success"),await new Promise(t=>setTimeout(t,2e3)),c.dynamicConfigForm.data=null,await h()}finally{f.value=!1}}function J(n){s.fromApiOutput(I.load(r.value))}return(n,o)=>{const t=d("a-col"),_=d("a-row"),l=d("a-flex"),u=d("a-button"),x=d("a-card"),L=d("a-spin");return y(),D(B,null,[a(x,null,{default:e(()=>[a(L,{spinning:f.value},{default:e(()=>[a(l,{style:{width:"100%"}},{default:e(()=>[a(t,{span:w.value?24-A.value:24,class:"left"},{default:e(()=>[a(l,{vertical:"",align:"end"},{default:e(()=>[a(_,{style:{width:"100%"},justify:"space-between"},{default:e(()=>[a(t,{span:12}),a(t,{span:12})]),_:1}),k("div",sa,[a(Y,{modelValue:r.value,"onUpdate:modelValue":o[0]||(o[0]=V=>r.value=V),onChange:J,theme:"vs-dark",height:"calc(100vh - 450px)",language:"yaml",readonly:!C.value},null,8,["modelValue","readonly"])])]),_:1})]),_:1},8,["span"]),a(t,{span:w.value?A.value:0,class:"right"},{default:e(()=>[w.value?(y(),b(x,{key:0,class:"sliderBox"},{default:e(()=>[(y(),D(B,null,G(2,V=>a(x,{key:V},{default:e(()=>[na,oa,a(l,{justify:"flex-end"},{default:e(()=>[a(u,{type:"text",style:{color:"#0a90d5"}},{default:e(()=>[g("查看")]),_:1}),a(u,{type:"text",style:{color:"#0a90d5"}},{default:e(()=>[g("回滚")]),_:1})]),_:1})]),_:2},1024)),64))]),_:1})):T("",!0)]),_:1},8,["span"])]),_:1})]),_:1},8,["spinning"])]),_:1}),C.value?(y(),b(l,{key:0,style:{"margin-top":"30px"}},{default:e(()=>[a(u,{type:"primary",onClick:j},{default:e(()=>[g("保存")]),_:1}),a(u,{style:{"margin-left":"30px"},onClick:S},{default:e(()=>[g("重置")]),_:1})]),_:1})):T("",!0)],64)}}}),fa=X(la,[["__scopeId","data-v-b8c9a84b"]]);export{fa as default};
