index-ea1b5625.js 6.4 KB

12
  1. import{d as Y,c as u,bq as le,h as O,f as re,Z as c,$ as w,a0 as i,T as s,a7 as x,n as r,br as D,a8 as _,a5 as f,bs as ie,aQ as N,M as ue,a4 as E,aD as P,a1 as g,a3 as ce,a6 as fe,a2 as M,a9 as T,bt as R,b4 as de,bu as me,bc as v,bv as pe,b0 as ve,bw as ye,bx as ge,by as be,bz as he,at as xe}from"./index-a8341fa1.js";import"./dayjs-919e6097.js";import{M as _e}from"./index-93635277.js";const ke={class:"flex flex-col h-full"},we={class:"flex justify-between items-center p-8px mb-12px",style:{background:"var(--layout-background)","border-radius":"4px"}},Se={class:"flex items-center gap-2"},Ce={class:"flex flex-1 overflow-hidden"},Fe={class:"plugin-list h-full overflow-y-auto overflow-x-hidden relative flex-1 p-16px"},Ie={key:1,class:"absolute top-40% left-50%"},Ne={key:0,class:"yaml-editor-container"},Me={key:1,class:"absolute top-40% left-50%"},Te=Y({name:"Config"}),Ve=Y({...Te,setup(je){const d=u("form");function $(t,e){return t===e?!0:t==null||e==null?t==e:typeof t!=typeof e?!1:typeof t=="object"?JSON.stringify(t)===JSON.stringify(e):!1}function q(t){const e={};for(const o of t)o&&typeof o=="object"&&"mkey"in o&&"mvalue"in o&&(e[o.mkey]=o.mvalue);return e}function J(t){return!Array.isArray(t)||t.length===0?!1:t.every(e=>e&&typeof e=="object"&&"mkey"in e&&"mvalue"in e)}function U(t,e){if(!t)return;const o=e.split(".");let a=t;for(const l of o){if(!a)return;if(a.properties&&a.properties[l])a=a.properties[l],a?.title||a?.type;else{Object.keys(a.properties||{});return}}return a?.["x-default-value"],a?.["x-value-source"],{defaultValue:a?.["x-default-value"],valueSource:a?.["x-value-source"]||"default",isDefault:a?.["x-is-default"]??!0}}function G(t,e){const o={};e?.properties;let a=0;return t.query("*").forEach(l=>{if(a++,!l)return;const n=l;if(`${a}`,n.path?.toString(),n.address?.toString(),n.value,n.modified,n.displayName,n.componentType,n.value===void 0)return;const m=n.path.toString(),h=n.address?.toString()||m,A=Z(h);if(!A)return;const L=U(e,h);let y=n.value;J(y)&&(y=q(y));const z=n.modified===!0;if(L){const{valueSource:B,defaultValue:K}=L;if((B==="default"||B==="global")&&!z||z&&K!==void 0&&$(y,K))return}Q(y)||H(o,A,y)}),o}function Q(t){return!!(t==null||t===""||Array.isArray(t)&&t.length===0||typeof t=="object"&&Object.keys(t).length===0)}function Z(t){const e=t.split("."),o=new Set(["layout","tabs","pluginTab","commonTab","pluginInnerTabs","commonInnerTabs"]);let a=[];for(let l=0;l<e.length;l++){const n=e[l];if(o.has(n))continue;const m=n.match(/^(plugin_|common_|all_)(.+)$/);if(m){const h=m[2];h!=="basic"&&a.push(h);continue}a.push(n)}return a.length>0?a.join("."):null}function H(t,e,o){const a=e.split(".");let l=t;for(let n=0;n<a.length-1;n++){const m=a[n];m in l||(l[m]={}),l=l[m]}l[a[a.length-1]]=o}const V=u([]);le().then(t=>{t?.plugins?.length&&(V.value=t.plugins.map(e=>({name:e.name,version:`版本: ${e.name}`,disabled:e.disabled})))});const S=u(null),k=u(),j=u(null),C=u(!1),W=u(["global-sub","plugin-sub"]),p=u(["global"]),F=async t=>{C.value=!0;try{const e=await pe({name:t});let o=e;if(e?.merged)try{o=JSON.parse(e.merged)}catch(n){console.error("解析配置 schema 失败",n),o=e}o?.properties,j.value=o;const{FormilyForm:a,form:l}=ve({schema:o});S.value=a,k.value=l}finally{C.value=!1}};O(p,t=>{d.value==="form"&&F(t[0])},{immediate:!0});const X=async()=>{if(!k.value.modified)return v.warning("您尚未修改过任何配置,无需保存!");await k.value.submit();const t=G(k.value,j.value);await ye({name:p.value[0]},t),v.success("保存成功"),await F(p.value[0])},b=u(""),I=u(!1),ee=async()=>{I.value=!0;try{b.value=await ge()}catch(t){v.error("获取配置文件失败:"+t.message)}finally{I.value=!1}},te=async()=>{try{be.parse(b.value),await he(b.value),v.success("保存成功")}catch(t){v.error("配置文件格式错误:"+t.message)}};O(d,t=>{t==="yaml"?ee():t==="form"&&F(p.value[0])});const oe=()=>{const t=d.value==="yaml"?"https://monibuca.com/develop/config.html":"https://monibuca.com/docs/guide/plugins/"+p.value[0].toLowerCase()+".html";window.open(t,"_blank")},ae=async()=>{try{await me(),v.success("热重启成功")}catch(t){v.error("热重启失败:"+t.message)}},ne=re(()=>d.value==="form"),se=()=>{d.value==="form"?X():te()};return(t,e)=>(c(),w(s(de),{class:"h-100% overflow-hidden",bodyStyle:{height:"100%",padding:"12px"}},{default:i(()=>[x("div",ke,[x("div",we,[x("div",Se,[r(s(ie),{value:d.value,"onUpdate:value":e[0]||(e[0]=o=>d.value=o),size:"small"},{default:i(()=>[r(s(D),{value:"form"},{default:i(()=>[r(s(_),{icon:"mdi:form-select",class:"v-text-bottom mr-1"}),e[3]||(e[3]=f(" 可视化 "))]),_:1}),r(s(D),{value:"yaml"},{default:i(()=>[r(s(_),{icon:"mdi:code-braces",class:"v-text-bottom mr-1"}),e[4]||(e[4]=f(" YAML "))]),_:1})]),_:1},8,["value"]),r(s(N),{type:"link",onClick:se},{default:i(()=>[r(s(_),{icon:"tabler:hand-click",class:"v-text-bottom"}),e[5]||(e[5]=f(" 点我保存配置 "))]),_:1}),r(s(N),{type:"link",onClick:ae},{default:i(()=>[r(s(_),{icon:"mdi:restart",class:"v-text-bottom"}),e[6]||(e[6]=f(" 热重启 "))]),_:1})]),r(s(N),{type:"link",onClick:oe},{default:i(()=>[e[7]||(e[7]=f(" 配置文档 ")),r(s(_),{icon:"fluent:window-new-16-filled",class:"v-text-bottom"})]),_:1})]),x("div",Ce,[ne.value?(c(),w(s(ue),{key:0,selectedKeys:p.value,openKeys:W.value,mode:"inline",inlineCollapsed:!1,onSelect:e[1]||(e[1]=({key:o})=>p.value=[o]),class:"w-180px h-100% overflow-y-auto overflow-x-hidden flex-shrink-0"},{default:i(()=>[r(s(P),{key:"global-sub"},{title:i(()=>e[8]||(e[8]=[f("全局配置")])),default:i(()=>[r(s(E),{key:"global"},{default:i(()=>e[9]||(e[9]=[f(" global ")])),_:1})]),_:1}),r(s(P),{key:"plugin-sub"},{title:i(()=>e[10]||(e[10]=[f("插件配置")])),default:i(()=>[(c(!0),g(M,null,ce(V.value,o=>(c(),w(s(E),{key:o.name,disabled:o.disabled},{default:i(()=>[f(fe(o.name),1)]),_:2},1032,["disabled"]))),128))]),_:1})]),_:1},8,["selectedKeys","openKeys"])):T("",!0),x("div",Fe,[d.value==="form"?(c(),g(M,{key:0},[S.value?(c(),w(s(S),{key:0})):T("",!0),C.value?(c(),g("div",Ie,[r(s(R),{class:"zIndex-100",size:"large"})])):T("",!0)],64)):(c(),g(M,{key:1},[I.value?(c(),g("div",Me,[r(s(R),{class:"zIndex-100",size:"large"})])):(c(),g("div",Ne,[r(_e,{class:"yaml-editor",value:b.value,"onUpdate:value":e[2]||(e[2]=o=>b.value=o),language:"yaml",options:{minimap:{enabled:!1},lineNumbers:"on",automaticLayout:!0}},null,8,["value"])]))],64))])])])]),_:1}))}});const Be=xe(Ve,[["__scopeId","data-v-83b9643a"]]);export{Be as default};
  2. //# sourceMappingURL=index-ea1b5625.js.map