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 Ls,a4 as js,p as Vs,o as Cs,c as bs,j as W,k as ys,a5 as Us,a6 as Ms,t as Ks,h as Gs,_ as Hs,a3 as gs,E as zs}from"./chunks/framework.D8G7yXPy.js";import{i as Js}from"./chunks/manifest.DM6n3IJf.js";const Xs={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function ws(i){return Xs}let as;function Zs(i){return as==null?void 0:as.get(i)}let ns;function Ws(i){return ns==null?void 0:ns.get(i)}let ts;function Ys(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??Ys(i.reference,l.lang)??(d?Ws(l.lang):null)??a.message??Zs(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 Qs(i,e){return i===e||Number.isNaN(i)&&Number.isNaN(e)}function si(i,e){return Object.prototype.hasOwnProperty.call(i,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function As(i,e){const s=[...new Set(i)];return s.length>1?`(${s.join(` ${e} `)})`:s[0]??"never"}function F(i){return i["~standard"]={version:1,vendor:"valibot",validate:e=>i["~run"]({value:e},ws())},i}function ii(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 Bs(i,e){return{kind:"validation",type:"check",reference:Bs,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 Ds(i){return{kind:"validation",type:"finite",reference:Ds,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 _s(i){return{kind:"metadata",type:"metadata",reference:_s,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 xs(i){return{kind:"metadata",type:"title",reference:xs,title:i}}function ei(i,e,s){return typeof i.fallback=="function"?i.fallback(e,s):i.fallback}function Rs(i,e,s){return typeof i.default=="function"?i.default(e,s):i.default}function V(i,e){return F({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 O(i){return F({kind:"schema",type:"boolean",reference:O,expects:"boolean",async:!1,message:i,"~run"(e,s){return typeof e.value=="boolean"?e.typed=!0:u(this,"type",e,s),e}})}function Ps(i){return F({kind:"schema",type:"lazy",reference:Ps,expects:"unknown",async:!1,getter:i,"~run"(e,s){return this.getter(e.value)["~run"](e,s)}})}function qs(i,e){return F({kind:"schema",type:"literal",reference:qs,expects:ps(i),async:!1,literal:i,message:e,"~run"(s,a){return Qs(s.value,this.literal)?s.typed=!0:u(this,"type",s,a),s}})}function Ss(i){return F({kind:"schema",type:"number",reference:Ss,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 F({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=Rs(this,s,a)),s.value===void 0)?(s.typed=!0,s):this.wrapped["~run"](s,a)}})}function Os(i,e){return F({kind:"schema",type:"picklist",reference:Os,expects:As(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 Ns(i,e,s){return F({kind:"schema",type:"record",reference:Ns,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(si(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 v=this.value["~run"]({value:d},n);if(v.issues){const N={type:"object",origin:"value",input:r,key:l,value:d};for(const b of v.issues)b.path?b.path.unshift(N):b.path=[N],(h=a.issues)==null||h.push(b);if(a.issues||(a.issues=v.issues),n.abortEarly){a.typed=!1;break}}(!o.typed||!v.typed)&&(a.typed=!1),o.typed&&(a.value[o.value]=v.value)}}else u(this,"type",a,n);return a}})}function H(i,e){return F({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]:Rs(h),d=h["~run"]({value:l},a);if(d.issues){const o={type:"object",origin:"value",input:n,key:t,value:l};for(const v of d.issues)v.path?v.path.unshift(o):v.path=[o],(r=s.issues)==null||r.push(v);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]=ei(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 F({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 fs(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 F({kind:"schema",type:"union",reference:G,expects:As(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:fs(r)}),s.typed=!0}else{if((t==null?void 0:t.length)===1)return t[0];u(this,"type",s,a,{issues:fs(t)})}return s}})}function Ts(){return F({kind:"schema",type:"unknown",reference:Ts,expects:"unknown",async:!1,"~run"(i){return i.typed=!0,i}})}function p(...i){return F({...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 ai(i,e,s){const a=i["~run"]({value:e},ws());return{typed:a.typed,success:!a.issues,output:a.value,issues:a.issues}}const _=p(ss(),Q(1),P(256)),$s=p(Ss(),Ds()),ls=G([_,$s]),ms=p(_,j(/^[\w-]+\/[\w-]+$/)),Y="(?:[\\w~.-]+|:[A-Za-z_]\\w*\\??)",rs=p(_,j(new RegExp(`^/${Y}(?:/${Y})*$`))),Fs=/^(?:[oO][nN]|innerHTML$|outerHTML$|srcdoc$|__proto__$|constructor$|prototype$)/,ni=p(Ns(ss(),Ts()),Bs(i=>Object.keys(i).every(e=>!Fs.test(e)),"Unsafe view prop."),_s({propertyNames:{not:{pattern:Fs.source}}})),ti={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([O(),ni]),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(ms,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(O(),E("Hide from the menu. Direct navigation still uses the role guard."))),sameLevel:k(p(O(),E("Append a breadcrumb without replacing the current tab."))),order:k(p($s,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(O(),E("Keep the content scroll position on navigation."))),keepAlive:k(p(O(),E("Keep the view mounted. name must match the registered view name."))),extra:k(p(H({label:k(ls),i18nLabel:k(_),icon:k(ms),show:k(O()),type:k(Os(["default","primary","info","success","warning","error"]))}),E("Optional menu badge.")))})},Is=H({...ti,children:k(p(V(Ps(()=>Is)),Q(1),P(300)))}),li=p(H({version:qs(1),routes:p(V(Is),P(300))}),xs("Ray Template route configuration")),ri=(i,e)=>e.startsWith("/")?e:`${i.replace(/\/$/,"")}/${e}`,pi=new Map([["action/export_excel","action/download"],["logo/office","navigation/table"],["illustration/login_bg","navigation/other"]]),vs=i=>pi.get(i)??i;function hi(i){var b;const{layout:e,findRouteView:s,findRouteViewId:a,managementPath:n,homePath:r}=i,t=y=>y==="/"||y===n||y.startsWith(`${n}/`),h=new Set((b=i.reservedNames)==null?void 0:b.map(y=>y.toLowerCase())),l=256*1024,d=y=>typeof y=="string"?[y]:y??[];function o(y){if(y.length>l)throw new Error("Route configuration exceeds 256 KiB.");const w=JSON.parse(y);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 m of B)x(m==null?void 0:m.children,$+1)}};x(w==null?void 0:w.routes,1);const q=ai(li,w);if(!q.success)throw new Error(q.issues.slice(0,20).map(B=>`${ii(B)??"config"}: ${B.message}`).join(`
|
|
`));const R=q.output,C=new Map,z=new Set(h),J=new Set,T=new Set,U=(B,$="",m=!1)=>{var M,I,hs,ks;for(const is of B){const{name:X,component:S,children:Z,alias:os,redirect:Es,props:ds,meta:c}=is,D=ri($,is.path),g=f=>{throw new Error(`${D}: ${f}`)},es=D.toLowerCase();if((J.has(es)||t(es))&&g("Duplicate or reserved menu path."),J.add(es),c.windowOpen&&!URL.canParse(c.windowOpen)&&g("Invalid external URL."),X){const f=X.toLowerCase();z.has(f)&&g(`Duplicate or reserved name "${X}".`),z.add(f)}c.icon&&(c.icon=vs(c.icon)),(M=c.extra)!=null&&M.icon&&(c.extra.icon=vs(c.extra.icon));for(const f of[c.icon,(I=c.extra)==null?void 0:I.icon])f&&!Js(f)&&g(`Unknown icon "${f}".`);if(Z!=null&&Z.length){(S&&S!=="layout"||os||Es||ds!==void 0||c.windowOpen)&&g("Groups accept layout, children and menu metadata."),D.includes(":")&&g("Use static paths for menu groups."),U(Z,D,m||!!((hs=c.role)!=null&&hs.length));continue}const K=S&&s(S);S&&!K&&g(`Unknown view "${S}".`),+!!S+ +!!Es+ +!!c.windowOpen!=1&&g("Specify exactly one view, redirect or external URL."),ds!==void 0&&!K&&g("Props require a view."),c.keepAlive&&(!K||X!==K.name)&&g("keepAlive requires the registered component name."),D.includes(":")&&!c.hidden&&!c.sameLevel&&g("Parameterized paths must be hidden or sameLevel.");for(const f of[D,...d(os)]){const L=f.toLowerCase();L.split("/").some(us=>us==="."||us==="..")&&g(`Invalid path "${f}".`),(t(L)||C.has(L))&&g(`Duplicate or reserved path "${f}".`),L===r&&(f!==D||D!==r||!K||m||(ks=c.role)!=null&&ks.length)&&g("/dashboard must be a view accessible to all authenticated roles."),f!==D&&(f.includes(":")||D.includes(":"))&&g("Aliases require a static page path.");const cs=L.replace(/:[a-z_]\w*/g,":param");T.has(cs)&&g(`Conflicting parameter pattern "${f}".`),T.add(cs),C.set(L,is)}}};U(R.routes);for(const[B,$]of C){let m=$;const M=new Set;for(;m.redirect;){const I=C.get(m.redirect.toLowerCase());if(M.has(m)||!I||I.meta.windowOpen||m.redirect.includes(":"))throw new Error(`${B}: Redirects must reach a configured page without a cycle.`);M.add(m),m=I}}return R}function v(y){const w=({component:A,children:x,meta:q,...R})=>{var C;return{...R,meta:q,component:A==="layout"?e:A?(C=s(A))==null?void 0:C.load:void 0,children:x==null?void 0:x.map(w)}};return y.routes.map(w)}function N(y){const w=({path:A,name:x,meta:q,component:R,children:C,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:C==null?void 0:C.map(w)}};return o(JSON.stringify({version:1,routes:y.map(w)}))}return{parseRouteConfig:o,toRuntimeRoutes:v,exportRouteConfig:N}}const ki={class:"ray-demo ray-demo-fields"},oi=["for"],Ei=["id","aria-invalid"],di={class:"ray-demo-result"},ci=Ls({__name:"RouteConfigDemo",setup(i){const e=async()=>({}),{parseRouteConfig:s}=hi({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=js(),n=Vs(JSON.stringify({version:1,routes:[{path:"/overview",component:"overview",name:"Overview",meta:{}}]},null,2)),r=Gs(()=>{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)=>(Cs(),bs("div",ki,[W("div",null,[W("label",{for:ys(a)},"路由配置 / Route configuration",8,oi),Us(W("textarea",{id:ys(a),"onUpdate:modelValue":h[0]||(h[0]=l=>n.value=l),rows:"8",spellcheck:"false","aria-invalid":r.value.invalid},null,8,Ei),[[Ms,n.value]]),W("output",di,Ks(r.value.message),1)])]))}}),ui=Hs(ci,[["__scopeId","data-v-e6a3014a"]]),mi=JSON.parse('{"title":"路由、菜单与权限","description":"","frontmatter":{},"headers":[],"relativePath":"guide/routing.md","filePath":"guide/routing.md"}'),yi={name:"guide/routing.md"},Fi=Object.assign(yi,{setup(i){return(e,s)=>(Cs(),bs("div",null,[s[0]||(s[0]=gs("",4)),zs(ui),s[1]||(s[1]=gs("",9))]))}});export{mi as __pageData,Fi as default};
|