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