@spacego/fe-components 0.0.1-alpha.7 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/router/permission.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { message as o } from "antd";
|
|
2
2
|
import { redirect as e } from "react-router-dom";
|
|
3
3
|
function h(i) {
|
|
4
|
-
const { getToken: r, setToken: a, removeToken:
|
|
5
|
-
function
|
|
4
|
+
const { getToken: r, setToken: a, removeToken: u } = i;
|
|
5
|
+
function s() {
|
|
6
6
|
return { token: r() };
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function l({ request: n }) {
|
|
9
9
|
if (!r()) {
|
|
10
|
-
const
|
|
11
|
-
return
|
|
10
|
+
const t = new URLSearchParams();
|
|
11
|
+
return t.set("from", new URL(n.url).pathname), e("/auth/login?" + t.toString());
|
|
12
12
|
}
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
|
-
async function
|
|
15
|
+
async function m() {
|
|
16
16
|
return r() ? e("/") : null;
|
|
17
17
|
}
|
|
18
|
-
async function
|
|
19
|
-
const c = await
|
|
20
|
-
if (!
|
|
21
|
-
return o.warning("You must provide a token to log in");
|
|
18
|
+
async function f({ request: n }) {
|
|
19
|
+
const c = await n.formData(), t = c.get("token");
|
|
20
|
+
if (!t)
|
|
21
|
+
return o.warning("You must provide a token to log in"), null;
|
|
22
22
|
try {
|
|
23
|
-
a(
|
|
23
|
+
a(t), o.success("登录成功");
|
|
24
24
|
} catch {
|
|
25
|
-
return o.warning("Invalid login attempt");
|
|
25
|
+
return o.warning("Invalid login attempt"), null;
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
return e(
|
|
27
|
+
const k = c.get("redirectTo");
|
|
28
|
+
return e(k || "/");
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
return
|
|
30
|
+
function g() {
|
|
31
|
+
return u(), o.success("退出成功"), e("/auth/login");
|
|
32
32
|
}
|
|
33
33
|
return {
|
|
34
|
-
RootLoader:
|
|
35
|
-
ProtectedLoader:
|
|
36
|
-
LoginLoader:
|
|
37
|
-
LoginAction:
|
|
38
|
-
LogoutAction:
|
|
34
|
+
RootLoader: s,
|
|
35
|
+
ProtectedLoader: l,
|
|
36
|
+
LoginLoader: m,
|
|
37
|
+
LoginAction: f,
|
|
38
|
+
LogoutAction: g
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
export {
|
package/lib/router/utils.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import { lazy as
|
|
2
|
-
function
|
|
1
|
+
import { lazy as y, createElement as C } from "react";
|
|
2
|
+
function R(o) {
|
|
3
3
|
return `/src/pages/${o.replace(/^\/+/, "")}/index.tsx`;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
const d =
|
|
7
|
-
|
|
8
|
-
console.warn(`Module not found for path: ${o}`);
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
return g(d);
|
|
5
|
+
function v(o, i) {
|
|
6
|
+
const d = i[R(o)];
|
|
7
|
+
return d ? y(d) : (console.warn(`Module not found for path: ${o}`), y(() => Promise.resolve({ default: () => C("div", null, `Module not found: ${o}`) })));
|
|
12
8
|
}
|
|
13
9
|
function w(o) {
|
|
14
10
|
if (o)
|
|
15
11
|
return o.startsWith("/") ? o : `/${o}`;
|
|
16
12
|
}
|
|
17
|
-
function
|
|
18
|
-
return (o.sort ?? 0) - (
|
|
13
|
+
function T(o, i) {
|
|
14
|
+
return (o.sort ?? 0) - (i.sort ?? 0);
|
|
19
15
|
}
|
|
20
|
-
function
|
|
21
|
-
const p = [...o].sort(
|
|
16
|
+
function N(o, i, d) {
|
|
17
|
+
const p = [...o].sort(T).reduce((e, t) => {
|
|
22
18
|
const n = t.menuType || 2;
|
|
23
19
|
return e[n] || (e[n] = []), e[n].push(t), e;
|
|
24
|
-
}, {}),
|
|
20
|
+
}, {}), g = (p[3] || []).filter((e) => e.menuCode).map((e) => e.menuCode), l = [
|
|
25
21
|
...p[1] || [],
|
|
26
22
|
...p[2] || []
|
|
27
|
-
].sort(
|
|
23
|
+
].sort(T), c = /* @__PURE__ */ new Map(), f = [];
|
|
28
24
|
l.forEach((e) => {
|
|
29
25
|
const t = e.parentId || "/", n = w(e.path), s = {
|
|
30
26
|
id: e.menuId,
|
|
@@ -40,22 +36,22 @@ function E(o, r, d) {
|
|
|
40
36
|
}
|
|
41
37
|
};
|
|
42
38
|
if (e.menuType === 2 && e.menuCode) {
|
|
43
|
-
const
|
|
44
|
-
|
|
39
|
+
const r = v(e.menuCode, i);
|
|
40
|
+
r && (s.Component = r), e.index && (s.index = !0, delete s.path), e.protected !== !1 && d && (s.loader = d);
|
|
45
41
|
}
|
|
46
|
-
|
|
42
|
+
c.set(e.menuId, s);
|
|
47
43
|
}), l.forEach((e) => {
|
|
48
|
-
const t =
|
|
44
|
+
const t = c.get(e.menuId), n = e.parentId;
|
|
49
45
|
if (n && n !== "/") {
|
|
50
|
-
const s =
|
|
46
|
+
const s = c.get(n);
|
|
51
47
|
s ? (s.children || (s.children = []), s.children.push(t)) : f.push(t);
|
|
52
48
|
} else
|
|
53
49
|
f.push(t);
|
|
54
50
|
});
|
|
55
|
-
const
|
|
51
|
+
const a = /* @__PURE__ */ new Map(), h = [], I = l.filter((e) => e.isShowMenu !== !1);
|
|
56
52
|
I.forEach((e) => {
|
|
57
|
-
const t =
|
|
58
|
-
const { children:
|
|
53
|
+
const t = c.get(e.menuId), n = t ? (() => {
|
|
54
|
+
const { children: r, ...m } = t;
|
|
59
55
|
return m;
|
|
60
56
|
})() : void 0, s = {
|
|
61
57
|
key: e.menuId,
|
|
@@ -65,27 +61,27 @@ function E(o, r, d) {
|
|
|
65
61
|
menuType: e.menuType,
|
|
66
62
|
isIndependentMenu: e.isIndependentMenu
|
|
67
63
|
};
|
|
68
|
-
|
|
64
|
+
a.set(e.menuId, s);
|
|
69
65
|
}), I.forEach((e) => {
|
|
70
|
-
const t =
|
|
66
|
+
const t = a.get(e.menuId), n = e.parentId;
|
|
71
67
|
if (n && n !== "/") {
|
|
72
|
-
const s =
|
|
73
|
-
s ? (s.children || (s.children = []), s.children.push(t)) :
|
|
68
|
+
const s = a.get(n);
|
|
69
|
+
s ? (s.children || (s.children = []), s.children.push(t)) : h.push(t);
|
|
74
70
|
} else
|
|
75
|
-
|
|
71
|
+
h.push(t);
|
|
76
72
|
});
|
|
77
73
|
function M(e) {
|
|
78
74
|
const t = [];
|
|
79
75
|
return e.forEach((n) => {
|
|
80
76
|
if (n.children && n.children.length > 0 && (n.children = M(n.children)), n.menuType === 1 && n.children && n.children.length > 0) {
|
|
81
|
-
const s = n.children.filter((
|
|
77
|
+
const s = n.children.filter((r) => r.isIndependentMenu === !0 && r.menuType === 2 && !r.customType);
|
|
82
78
|
if (s.length > 0) {
|
|
83
|
-
const
|
|
84
|
-
...
|
|
79
|
+
const r = s.map((u) => ({
|
|
80
|
+
...u,
|
|
85
81
|
customType: "menu-promoted"
|
|
86
82
|
// 内部标识,表示这个菜单是被提升的
|
|
87
|
-
})), m = n.children.filter((
|
|
88
|
-
t.push(...
|
|
83
|
+
})), m = n.children.filter((u) => !(u.isIndependentMenu === !0 && u.menuType === 2 && !u.customType));
|
|
84
|
+
t.push(...r, ...m);
|
|
89
85
|
} else
|
|
90
86
|
t.push(n);
|
|
91
87
|
} else
|
|
@@ -94,12 +90,12 @@ function E(o, r, d) {
|
|
|
94
90
|
}
|
|
95
91
|
return {
|
|
96
92
|
routes: f,
|
|
97
|
-
menus: M(
|
|
98
|
-
permissions:
|
|
93
|
+
menus: M(h),
|
|
94
|
+
permissions: g
|
|
99
95
|
};
|
|
100
96
|
}
|
|
101
97
|
export {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
v as createLazyComponent,
|
|
99
|
+
R as getPath,
|
|
100
|
+
N as processRoutes
|
|
105
101
|
};
|
|
@@ -25,7 +25,7 @@ export declare function createRouter(options: CreateRouterOptions): {
|
|
|
25
25
|
RootLoader: () => import('./permission').AuthStatus;
|
|
26
26
|
ProtectedLoader: ({ request }: import('react-router-dom').LoaderFunctionArgs) => Response | null;
|
|
27
27
|
LoginLoader: () => Promise<Response | null>;
|
|
28
|
-
LoginAction: ({ request }: import('react-router-dom').LoaderFunctionArgs) => Promise<
|
|
28
|
+
LoginAction: ({ request }: import('react-router-dom').LoaderFunctionArgs) => Promise<Response | null>;
|
|
29
29
|
LogoutAction: () => Response;
|
|
30
30
|
};
|
|
31
31
|
};
|
|
@@ -18,6 +18,6 @@ export declare function createPermissionHelpers(tokenHelpers: TokenHelpers): {
|
|
|
18
18
|
RootLoader: () => AuthStatus;
|
|
19
19
|
ProtectedLoader: ({ request }: LoaderFunctionArgs) => Response | null;
|
|
20
20
|
LoginLoader: () => Promise<Response | null>;
|
|
21
|
-
LoginAction: ({ request }: LoaderFunctionArgs) => Promise<
|
|
21
|
+
LoginAction: ({ request }: LoaderFunctionArgs) => Promise<Response | null>;
|
|
22
22
|
LogoutAction: () => Response;
|
|
23
23
|
};
|
|
@@ -18,7 +18,7 @@ export declare function getPath(name: string): string;
|
|
|
18
18
|
* @param modules
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
|
-
export declare function createLazyComponent(name: string, modules: TModule): import('react').LazyExoticComponent<ComponentType<any>> |
|
|
21
|
+
export declare function createLazyComponent(name: string, modules: TModule): import('react').LazyExoticComponent<ComponentType<any>> | import('react').LazyExoticComponent<() => import('react').DetailedReactHTMLElement<import('react').HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
22
22
|
/** 路由节点类型 */
|
|
23
23
|
type RouteNode = RouteObject & {
|
|
24
24
|
parentId: string;
|