mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-12-03 18:46:25 +08:00
3 lines
15 KiB
JavaScript
3 lines
15 KiB
JavaScript
import{d as Ts,a4 as Is,p as js,o as Fs,c as vs,j as Z,k as Es,a5 as Ls,a6 as Vs,t as Us,h as Ms,_ as Ks,a3 as us,E as Js}from"./chunks/framework.D8G7yXPy.js";import{i as Gs}from"./chunks/manifest.BoLhpUE-.js";const zs={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function bs(i){return zs}let es;function Hs(i){return es==null?void 0:es.get(i)}let as;function Xs(i){return as==null?void 0:as.get(i)}let ns;function Ws(i,e){var s;return(s=ns==null?void 0:ns.get(i))==null?void 0:s.get(e)}function rs(i){var s,a;const e=typeof i;return e==="string"?`"${i}"`:e==="number"||e==="bigint"||e==="boolean"?`${i}`:e==="object"||e==="function"?(i&&((a=(s=Object.getPrototypeOf(i))==null?void 0:s.constructor)==null?void 0:a.name))??"null":e}function u(i,e,s,a,n){const r=n&&"input"in n?n.input:s.value,t=(n==null?void 0:n.expected)??i.expects??null,h=(n==null?void 0:n.received)??rs(r),l={kind:i.kind,type:i.type,input:r,expected:t,received:h,message:`Invalid ${e}: ${t?`Expected ${t} but r`:"R"}eceived ${h}`,requirement:i.requirement,path:n==null?void 0:n.path,issues:n==null?void 0:n.issues,lang:a.lang,abortEarly:a.abortEarly,abortPipeEarly:a.abortPipeEarly},E=i.kind==="schema",o=(n==null?void 0:n.message)??i.message??Ws(i.reference,l.lang)??(E?Xs(l.lang):null)??a.message??Hs(l.lang);o!==void 0&&(l.message=typeof o=="function"?o(l):o),E&&(s.typed=!1),s.issues?s.issues.push(l):s.issues=[l]}function Zs(i,e){return i===e||Number.isNaN(i)&&Number.isNaN(e)}function Ys(i,e){return Object.prototype.hasOwnProperty.call(i,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function Cs(i,e){const s=[...new Set(i)];return s.length>1?`(${s.join(` ${e} `)})`:s[0]??"never"}function v(i){return i["~standard"]={version:1,vendor:"valibot",validate:e=>i["~run"]({value:e},bs())},i}function Qs(i){if(i.path){let e="";for(const s of i.path)if(typeof s.key=="string"||typeof s.key=="number")e?e+=`.${s.key}`:e+=s.key;else return null;return e}return null}function ws(i,e){return{kind:"validation",type:"check",reference:ws,async:!1,expects:null,requirement:i,message:e,"~run"(s,a){return s.typed&&!this.requirement(s.value)&&u(this,"input",s,a),s}}}function c(i){return{kind:"metadata",type:"description",reference:c,description:i}}function As(i){return{kind:"validation",type:"finite",reference:As,async:!1,expects:null,requirement:Number.isFinite,message:i,"~run"(e,s){return e.typed&&!this.requirement(e.value)&&u(this,"finite",e,s),e}}}function q(i,e){return{kind:"validation",type:"max_length",reference:q,async:!1,expects:`<=${i}`,requirement:i,message:e,"~run"(s,a){return s.typed&&s.value.length>this.requirement&&u(this,"length",s,a,{received:`${s.value.length}`}),s}}}function Ds(i){return{kind:"metadata",type:"metadata",reference:Ds,metadata:i}}function Q(i,e){return{kind:"validation",type:"min_length",reference:Q,async:!1,expects:`>=${i}`,requirement:i,message:e,"~run"(s,a){return s.typed&&s.value.length<this.requirement&&u(this,"length",s,a,{received:`${s.value.length}`}),s}}}function j(i,e){return{kind:"validation",type:"regex",reference:j,async:!1,expects:`${i}`,requirement:i,message:e,"~run"(s,a){return s.typed&&!this.requirement.test(s.value)&&u(this,"format",s,a),s}}}function Bs(i){return{kind:"metadata",type:"title",reference:Bs,title:i}}function si(i,e,s){return typeof i.fallback=="function"?i.fallback(e,s):i.fallback}function _s(i,e,s){return typeof i.default=="function"?i.default(e,s):i.default}function L(i,e){return v({kind:"schema",type:"array",reference:L,expects:"Array",async:!1,item:i,message:e,"~run"(s,a){var r;const n=s.value;if(Array.isArray(n)){s.typed=!0,s.value=[];for(let t=0;t<n.length;t++){const h=n[t],l=this.item["~run"]({value:h},a);if(l.issues){const E={type:"array",origin:"value",input:n,key:t,value:h};for(const o of l.issues)o.path?o.path.unshift(E):o.path=[E],(r=s.issues)==null||r.push(o);if(s.issues||(s.issues=l.issues),a.abortEarly){s.typed=!1;break}}l.typed||(s.typed=!1),s.value.push(l.value)}}else u(this,"type",s,a);return s}})}function N(i){return v({kind:"schema",type:"boolean",reference:N,expects:"boolean",async:!1,message:i,"~run"(e,s){return typeof e.value=="boolean"?e.typed=!0:u(this,"type",e,s),e}})}function xs(i){return v({kind:"schema",type:"lazy",reference:xs,expects:"unknown",async:!1,getter:i,"~run"(e,s){return this.getter(e.value)["~run"](e,s)}})}function Rs(i,e){return v({kind:"schema",type:"literal",reference:Rs,expects:rs(i),async:!1,literal:i,message:e,"~run"(s,a){return Zs(s.value,this.literal)?s.typed=!0:u(this,"type",s,a),s}})}function qs(i){return v({kind:"schema",type:"number",reference:qs,expects:"number",async:!1,message:i,"~run"(e,s){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:u(this,"type",e,s),e}})}function k(i,e){return v({kind:"schema",type:"optional",reference:k,expects:`(${i.expects} | undefined)`,async:!1,wrapped:i,default:e,"~run"(s,a){return s.value===void 0&&(this.default!==void 0&&(s.value=_s(this,s,a)),s.value===void 0)?(s.typed=!0,s):this.wrapped["~run"](s,a)}})}function Ps(i,e){return v({kind:"schema",type:"picklist",reference:Ps,expects:Cs(i.map(rs),"|"),async:!1,options:i,message:e,"~run"(s,a){return this.options.includes(s.value)?s.typed=!0:u(this,"type",s,a),s}})}function Ss(i,e,s){return v({kind:"schema",type:"record",reference:Ss,expects:"Object",async:!1,key:i,value:e,message:s,"~run"(a,n){var t,h;const r=a.value;if(r&&typeof r=="object"){a.typed=!0,a.value={};for(const l in r)if(Ys(r,l)){const E=r[l],o=this.key["~run"]({value:l},n);if(o.issues){const $={type:"object",origin:"key",input:r,key:l,value:E};for(const w of o.issues)w.path=[$],(t=a.issues)==null||t.push(w);if(a.issues||(a.issues=o.issues),n.abortEarly){a.typed=!1;break}}const b=this.value["~run"]({value:E},n);if(b.issues){const $={type:"object",origin:"value",input:r,key:l,value:E};for(const w of b.issues)w.path?w.path.unshift($):w.path=[$],(h=a.issues)==null||h.push(w);if(a.issues||(a.issues=b.issues),n.abortEarly){a.typed=!1;break}}(!o.typed||!b.typed)&&(a.typed=!1),o.typed&&(a.value[o.value]=b.value)}}else u(this,"type",a,n);return a}})}function J(i,e){return v({kind:"schema",type:"strict_object",reference:J,expects:"Object",async:!1,entries:i,message:e,"~run"(s,a){var r;const n=s.value;if(n&&typeof n=="object"){s.typed=!0,s.value={};for(const t in this.entries){const h=this.entries[t];if(t in n||(h.type==="exact_optional"||h.type==="optional"||h.type==="nullish")&&h.default!==void 0){const l=t in n?n[t]:_s(h),E=h["~run"]({value:l},a);if(E.issues){const o={type:"object",origin:"value",input:n,key:t,value:l};for(const b of E.issues)b.path?b.path.unshift(o):b.path=[o],(r=s.issues)==null||r.push(b);if(s.issues||(s.issues=E.issues),a.abortEarly){s.typed=!1;break}}E.typed||(s.typed=!1),s.value[t]=E.value}else if(h.fallback!==void 0)s.value[t]=si(h);else if(h.type!=="exact_optional"&&h.type!=="optional"&&h.type!=="nullish"&&(u(this,"key",s,a,{input:void 0,expected:`"${t}"`,path:[{type:"object",origin:"key",input:n,key:t,value:n[t]}]}),a.abortEarly))break}if(!s.issues||!a.abortEarly){for(const t in n)if(!Object.prototype.hasOwnProperty.call(this.entries,t)){u(this,"key",s,a,{input:t,expected:"never",path:[{type:"object",origin:"key",input:n,key:t,value:n[t]}]});break}}}else u(this,"type",s,a);return s}})}function ss(i){return v({kind:"schema",type:"string",reference:ss,expects:"string",async:!1,message:i,"~run"(e,s){return typeof e.value=="string"?e.typed=!0:u(this,"type",e,s),e}})}function ys(i){let e;if(i)for(const s of i)if(e)for(const a of s.issues)e.push(a);else e=s.issues;return e}function K(i,e){return v({kind:"schema",type:"union",reference:K,expects:Cs(i.map(s=>s.expects),"|"),async:!1,options:i,message:e,"~run"(s,a){let n,r,t;for(const h of this.options){const l=h["~run"]({value:s.value},a);if(l.typed)if(l.issues)r?r.push(l):r=[l];else{n=l;break}else t?t.push(l):t=[l]}if(n)return n;if(r){if(r.length===1)return r[0];u(this,"type",s,a,{issues:ys(r)}),s.typed=!0}else{if((t==null?void 0:t.length)===1)return t[0];u(this,"type",s,a,{issues:ys(t)})}return s}})}function Os(){return v({kind:"schema",type:"unknown",reference:Os,expects:"unknown",async:!1,"~run"(i){return i.typed=!0,i}})}function p(...i){return v({...i[0],pipe:i,"~run"(e,s){for(const a of i)if(a.kind!=="metadata"){if(e.issues&&(a.kind==="schema"||a.kind==="transformation")){e.typed=!1;break}(!e.issues||!s.abortEarly&&!s.abortPipeEarly)&&(e=a["~run"](e,s))}return e}})}function ii(i,e,s){const a=i["~run"]({value:e},bs());return{typed:a.typed,success:!a.issues,output:a.value,issues:a.issues}}const B=p(ss(),Q(1),q(256)),Ns=p(qs(),As()),ts=K([B,Ns]),gs=p(B,j(/^[\w-]+\/[\w-]+$/)),Y="(?:[\\w~.-]+|:[A-Za-z_]\\w*\\??)",ls=p(B,j(new RegExp(`^/${Y}(?:/${Y})*$`))),fs=/^(?:[oO][nN]|innerHTML$|outerHTML$|srcdoc$|__proto__$|constructor$|prototype$)/,ei=p(Ss(ss(),Os()),ws(i=>Object.keys(i).every(e=>!fs.test(e)),"Unsafe view prop."),Ds({propertyNames:{not:{pattern:fs.source}}})),ai={path:p(B,j(new RegExp(`^/?${Y}(?:/${Y})*$`)),c("Absolute or relative child path. Supports named and optional parameters.")),name:k(p(B,j(/^[A-Za-z_][\w.-]*$/),c("Unique Vue Router name. Required for keepAlive."))),component:k(p(B,c("Registered view ID. Use layout for a menu group."))),alias:k(p(K([ls,p(L(ls),Q(1),q(16))]),c("Absolute alternative path(s) for a leaf."))),redirect:k(p(ls,c("Absolute path of another configured page."))),props:k(p(K([N(),ei]),c("Pass route params (true) or a JSON object to the view."))),meta:J({i18nKey:k(p(B,c("Translation key for the menu title."))),noLocalTitle:k(p(ts,c("Literal title if i18nKey is absent."))),icon:k(p(gs,c("IconName from src/icons/manifest.ts."))),role:k(p(L(ts),q(32),c("Allowed roles. Omitted or empty means any authenticated role."))),hidden:k(p(N(),c("Hide from the menu. Direct navigation still uses the role guard."))),sameLevel:k(p(N(),c("Append a breadcrumb without replacing the current tab."))),order:k(p(Ns,c("Menu sort order at the top level."))),env:k(p(K([B,p(L(B),q(16))]),c("Vite mode(s) in which the menu item is visible."))),windowOpen:k(p(ss(),q(2048),j(/^[Hh][Tt][Tt][Pp][Ss]?:\/\//),c("Open this HTTP(S) URL in a new tab."))),ignoreAutoResetScroll:k(p(N(),c("Keep the content scroll position on navigation."))),keepAlive:k(p(N(),c("Keep the view mounted. name must match the registered view name."))),extra:k(p(J({label:k(ts),i18nLabel:k(B),icon:k(gs),show:k(N()),type:k(Ps(["default","primary","info","success","warning","error"]))}),c("Optional menu badge.")))})},$s=J({...ai,children:k(p(L(xs(()=>$s)),Q(1),q(300)))}),ni=p(J({version:Rs(1),routes:p(L($s),q(300))}),Bs("Ray Template route configuration")),ti=(i,e)=>e.startsWith("/")?e:`${i.replace(/\/$/,"")}/${e}`,li=new Map([["action/export_excel","action/download"],["logo/office","navigation/table"],["illustration/login_bg","navigation/other"]]),ms=i=>li.get(i)??i;function ri(i){var w,ps;const{layout:e,findRouteView:s,findRouteViewId:a,managementPath:n}=i,r=((w=i.reservedPaths)==null?void 0:w.map(d=>d.toLowerCase()))??[],t=d=>d==="/"||d===n||d.startsWith(`${n}/`)||r.some(m=>d===m||d.startsWith(`${m}/`)),h=new Set((ps=i.reservedNames)==null?void 0:ps.map(d=>d.toLowerCase())),l=256*1024,E=d=>typeof d=="string"?[d]:d??[];function o(d){if(d.length>l)throw new Error("Route configuration exceeds 256 KiB.");const m=JSON.parse(d);let A=0;const _=(D,I)=>{if(Array.isArray(D)){if(A+=D.length,A>300||I>8)throw new Error("Use at most 300 routes and 8 menu levels.");for(const F of D)_(F==null?void 0:F.children,I+1)}};_(m==null?void 0:m.routes,1);const P=ii(ni,m);if(!P.success)throw new Error(P.issues.slice(0,20).map(D=>`${Qs(D)??"config"}: ${D.message}`).join(`
|
|
`));const x=P.output,C=new Map,G=new Set(h),z=new Set,T=new Set,V=(D,I="")=>{var F,U;for(const S of D){const{name:H,component:O,children:X,alias:hs,redirect:ks,props:os,meta:y}=S,R=ti(I,S.path),g=f=>{throw new Error(`${R}: ${f}`)},is=R.toLowerCase();if((z.has(is)||t(is))&&g("Duplicate or reserved menu path."),z.add(is),y.windowOpen&&!URL.canParse(y.windowOpen)&&g("Invalid external URL."),H){const f=H.toLowerCase();G.has(f)&&g(`Duplicate or reserved name "${H}".`),G.add(f)}y.icon&&(y.icon=ms(y.icon)),(F=y.extra)!=null&&F.icon&&(y.extra.icon=ms(y.extra.icon));for(const f of[y.icon,(U=y.extra)==null?void 0:U.icon])f&&!Gs(f)&&g(`Unknown icon "${f}".`);if(X!=null&&X.length){(O&&O!=="layout"||hs||ks||os!==void 0||y.windowOpen)&&g("Groups accept layout, children and menu metadata."),R.includes(":")&&g("Use static paths for menu groups."),V(X,R);continue}const W=O&&s(O);O&&!W&&g(`Unknown view "${O}".`),+!!O+ +!!ks+ +!!y.windowOpen!=1&&g("Specify exactly one view, redirect or external URL."),os!==void 0&&!W&&g("Props require a view."),y.keepAlive&&(!W||H!==W.name)&&g("keepAlive requires the registered component name."),R.includes(":")&&!y.hidden&&!y.sameLevel&&g("Parameterized paths must be hidden or sameLevel.");for(const f of[R,...E(hs)]){const M=f.toLowerCase();M.split("/").some(cs=>cs==="."||cs==="..")&&g(`Invalid path "${f}".`),(t(M)||C.has(M))&&g(`Duplicate or reserved path "${f}".`),f!==R&&(f.includes(":")||R.includes(":"))&&g("Aliases require a static page path.");const ds=M.replace(/:[a-z_]\w*/g,":param");T.has(ds)&&g(`Conflicting parameter pattern "${f}".`),T.add(ds),C.set(M,S)}}};V(x.routes);for(const[D,I]of C){let F=I;const U=new Set;for(;F.redirect;){const S=C.get(F.redirect.toLowerCase());if(U.has(F)||!S||S.meta.windowOpen||F.redirect.includes(":"))throw new Error(`${D}: Redirects must reach a configured page without a cycle.`);U.add(F),F=S}}return x}function b(d){const m=({component:A,children:_,meta:P,...x})=>{var C;return{...x,meta:P,component:A==="layout"?e:A?(C=s(A))==null?void 0:C.load:void 0,children:_==null?void 0:_.map(m)}};return d.routes.map(m)}function $(d){const m=({path:A,name:_,meta:P,component:x,children:C,props:G,alias:z,redirect:T})=>{const V=x===e?"layout":a(x);if(x&&!V)throw new Error(`${A}: Register the view in router/config/views.ts before exporting.`);if(T&&typeof T!="string")throw new Error(`${A}: Export requires a string redirect.`);return{path:A,name:_,meta:P,component:V,alias:z,redirect:T,props:G,children:C==null?void 0:C.map(m)}};return o(JSON.stringify({version:1,routes:d.map(m)}))}return{parseRouteConfig:o,toRuntimeRoutes:b,exportRouteConfig:$}}const pi={class:"ray-demo ray-demo-fields"},hi=["for"],ki=["id","aria-invalid"],oi={class:"ray-demo-result"},di=Ts({__name:"RouteConfigDemo",setup(i){const e=async()=>({}),{parseRouteConfig:s}=ri({layout:e,managementPath:"/route-management",findRouteView:t=>t==="overview"?{name:"Overview",load:e}:void 0,findRouteViewId:t=>t===e?"overview":void 0}),a=Is(),n=js(JSON.stringify({version:1,routes:[{path:"/overview",component:"overview",name:"Overview",meta:{}}]},null,2)),r=Ms(()=>{try{const{routes:t}=s(n.value);return{invalid:!1,message:`有效路由 / Valid routes: ${t.length}`}}catch(t){return{invalid:!0,message:t instanceof Error?t.message:String(t)}}});return(t,h)=>(Fs(),vs("div",pi,[Z("div",null,[Z("label",{for:Es(a)},"路由配置 / Route configuration",8,hi),Ls(Z("textarea",{id:Es(a),"onUpdate:modelValue":h[0]||(h[0]=l=>n.value=l),rows:"8",spellcheck:"false","aria-invalid":r.value.invalid},null,8,ki),[[Vs,n.value]]),Z("output",oi,Us(r.value.message),1)])]))}}),ci=Ks(di,[["__scopeId","data-v-cd34cb20"]]),gi=JSON.parse('{"title":"路由、菜单与权限","description":"","frontmatter":{},"headers":[],"relativePath":"guide/routing.md","filePath":"guide/routing.md"}'),Ei={name:"guide/routing.md"},fi=Object.assign(Ei,{setup(i){return(e,s)=>(Fs(),vs("div",null,[s[0]||(s[0]=us("",4)),Js(ci),s[1]||(s[1]=us("",17))]))}});export{gi as __pageData,fi as default};
|