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