@mooljs/plugin-access
Advanced tools
+33
-28
@@ -1,10 +0,10 @@ | ||
| const h = Symbol("access-context"); | ||
| function d(t, o) { | ||
| for (const e of t) { | ||
| if (e.path === o) | ||
| return [null, e]; | ||
| if (e.routes && e.routes.length > 0) { | ||
| const c = d(e.routes, o); | ||
| if (c) | ||
| return [e, c[1]]; | ||
| const d = Symbol("access-context"); | ||
| function h(c, e) { | ||
| for (const s of c) { | ||
| if (s.path === e) | ||
| return [null, s]; | ||
| if (s.routes && s.routes.length > 0) { | ||
| const t = h(s.routes, e); | ||
| if (t) | ||
| return [s, t[1]]; | ||
| } | ||
@@ -14,28 +14,33 @@ } | ||
| } | ||
| function p(t) { | ||
| var m, i; | ||
| const { to: o, routes: e = [], access: c = {}, exclude: u = ["/user"] } = t, s = (n, r) => r && !n[r], a = d(e, o.path); | ||
| if (a) { | ||
| const [n, r] = a; | ||
| return (s(c, (m = n == null ? void 0 : n.meta) == null ? void 0 : m.access) || s(c, (i = r.meta) == null ? void 0 : i.access)) && !u.some((f) => o.path.includes(f)) && o.path !== "/403"; | ||
| function p(c) { | ||
| var m, r; | ||
| const { to: e, routes: s = [], access: t = {}, exclude: i = ["/user"] } = c, o = (n, a) => a && !n[a], u = h(s, e.path); | ||
| if (u) { | ||
| const [n, a] = u; | ||
| return (o(t, (m = n == null ? void 0 : n.meta) == null ? void 0 : m.access) || o(t, (r = a.meta) == null ? void 0 : r.access)) && !i.some((l) => e.path.includes(l)) && e.path !== "/403"; | ||
| } else | ||
| return !1; | ||
| } | ||
| const y = (t, o) => { | ||
| const { access: e = {}, layout: c = {}, routes: u = [], router: s } = o ?? {}; | ||
| t.config.globalProperties.$access = e, t.provide("@@access-key", h), t.provide(h, e), s == null || s.addRoute({ | ||
| const y = async (c) => { | ||
| var o; | ||
| const { getInitialState: e, access: s } = c, t = await (e == null ? void 0 : e()) ?? {}; | ||
| return { access: (o = s.default) == null ? void 0 : o.call(s, t) }; | ||
| }, P = (c, e) => { | ||
| const { access: s = {}, layout: t = {}, routes: i = [], router: o } = e ?? {}; | ||
| c.config.globalProperties.$access = s, c.provide(d, s), o == null || o.addRoute({ | ||
| path: "/403", | ||
| component: c.unAccessible ?? (() => import("@mooljs/plugin-layout/src/layouts/403.vue")) | ||
| }), s == null || s.beforeEach((a, m, i) => { | ||
| var r; | ||
| const n = (r = u.filter((l) => { | ||
| var f; | ||
| return ((f = l.meta) == null ? void 0 : f.layout) === !1; | ||
| })) == null ? void 0 : r.map((l) => l.path); | ||
| p({ to: a, routes: u, access: e, exclude: n }) ? i("/403") : i(); | ||
| component: t.unAccessible ?? (() => import("@mooljs/plugin-layout/src/layouts/403.vue")) | ||
| }), o == null || o.beforeEach((u, m, r) => { | ||
| var a; | ||
| const n = (a = i.filter((f) => { | ||
| var l; | ||
| return ((l = f.meta) == null ? void 0 : l.layout) === !1; | ||
| })) == null ? void 0 : a.map((f) => f.path); | ||
| p({ to: u, routes: i, access: s, exclude: n }) ? r("/403") : r(); | ||
| }); | ||
| }; | ||
| export { | ||
| h as ACCESS_KEY, | ||
| y as useAccess | ||
| d as ACCESS_KEY, | ||
| y as getAccess, | ||
| P as useAccess | ||
| }; |
+5
-1
@@ -11,6 +11,10 @@ const { readFileSync, existsSync } = require('node:fs'); | ||
| injectImports: (opt) => { | ||
| return [`import { useAccess } from 'virtual:access';`,]; | ||
| return [` | ||
| import { useAccess,getAccess } from 'virtual:access'; | ||
| ${existsSync("src/access.ts") ? `import * as accessConfig from '/src/access.ts';` : `const accessConfig = {default:()=>({})};`} | ||
| `]; | ||
| }, | ||
| // 运行时逻辑 | ||
| runtime: (ctx) => ` | ||
| const {access} = await getAccess({config,access:accessConfig}) | ||
| app.use(useAccess, { | ||
@@ -17,0 +21,0 @@ access, |
+1
-1
| { | ||
| "name": "@mooljs/plugin-access", | ||
| "version": "0.3.1", | ||
| "version": "0.3.2", | ||
| "description": "pro layout access for mooljs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5151
9.29%89
11.25%