cosey 0.6.23 → 0.6.25
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/config/index.d.ts +5 -1
- package/package.json +1 -1
- package/store/user.js +10 -4
package/config/index.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export interface LayoutSlots {
|
|
|
44
44
|
authWidget?: () => VNodeChild;
|
|
45
45
|
userMenu?: () => VNodeChild;
|
|
46
46
|
}
|
|
47
|
+
type FilterRouteHandler = (route: RouteRecordRaw) => RouteRecordRaw | void | boolean | undefined | null;
|
|
47
48
|
export type CoseyOptions = {
|
|
48
49
|
router?: CoseyRouterOptions & RouterConfig;
|
|
49
50
|
persist?: PersistConfig;
|
|
@@ -51,7 +52,9 @@ export type CoseyOptions = {
|
|
|
51
52
|
layout?: LayoutConfig;
|
|
52
53
|
site?: SiteConfig;
|
|
53
54
|
api?: ApiConfig;
|
|
54
|
-
filterRoute?:
|
|
55
|
+
filterRoute?: {
|
|
56
|
+
hook: () => FilterRouteHandler;
|
|
57
|
+
} | FilterRouteHandler;
|
|
55
58
|
defineAuthority?: (userInfo: Record<any, any>) => void | Promise<void>;
|
|
56
59
|
components?: LayoutComponents;
|
|
57
60
|
slots?: LayoutSlots;
|
|
@@ -69,3 +72,4 @@ export interface GlobalConfig {
|
|
|
69
72
|
}
|
|
70
73
|
export declare function provideGlobalConfig(app: App, options: CoseyOptions): void;
|
|
71
74
|
export declare function useGlobalConfig(): GlobalConfig;
|
|
75
|
+
export {};
|
package/package.json
CHANGED
package/store/user.js
CHANGED
|
@@ -6,6 +6,7 @@ import { TOKEN_NAME } from '../constant.js';
|
|
|
6
6
|
import { useGlobalConfig } from '../config/index.js';
|
|
7
7
|
import { NOT_FOUND_ROUTE_NAME, NotFoundRoute } from '../router/not-found.js';
|
|
8
8
|
import { usePersist } from '../hooks/usePersist.js';
|
|
9
|
+
import { isFunction } from '../utils/is.js';
|
|
9
10
|
import { warningOnce } from '../utils/warning.js';
|
|
10
11
|
|
|
11
12
|
const useUserStore = defineStore("cosey-user", () => {
|
|
@@ -18,6 +19,7 @@ const useUserStore = defineStore("cosey-user", () => {
|
|
|
18
19
|
filterRoute,
|
|
19
20
|
defineAuthority
|
|
20
21
|
} = useGlobalConfig() || {};
|
|
22
|
+
const filterRouteHandler = isFunction(filterRoute) ? filterRoute : filterRoute.hook();
|
|
21
23
|
if (!apiConfig?.login) {
|
|
22
24
|
warningOnce(!!apiConfig?.login, 'The "login" api is required.');
|
|
23
25
|
}
|
|
@@ -59,7 +61,7 @@ const useUserStore = defineStore("cosey-user", () => {
|
|
|
59
61
|
};
|
|
60
62
|
const mapRoute = (routes) => {
|
|
61
63
|
return routes.map((route2) => {
|
|
62
|
-
const result =
|
|
64
|
+
const result = filterRouteHandler(route2);
|
|
63
65
|
const node = result === true ? route2 : result;
|
|
64
66
|
if (node && node.children && node.children.length) {
|
|
65
67
|
node.children = mapRoute(node.children);
|
|
@@ -79,20 +81,24 @@ const useUserStore = defineStore("cosey-user", () => {
|
|
|
79
81
|
router.addRoute("Exception", NotFoundRoute);
|
|
80
82
|
dynamicRoutes.value = filteredRoutes;
|
|
81
83
|
};
|
|
82
|
-
const flush = (lastPath) => {
|
|
84
|
+
const flush = async (lastPath) => {
|
|
83
85
|
persist.remove(TOKEN_NAME);
|
|
84
86
|
userInfo.value = void 0;
|
|
85
87
|
requestedUserInfo.value = false;
|
|
86
|
-
router.push({
|
|
88
|
+
await router.push({
|
|
87
89
|
path: routerConfig.loginPath,
|
|
88
90
|
query: {
|
|
89
91
|
redirect: lastPath
|
|
90
92
|
}
|
|
91
93
|
});
|
|
94
|
+
dynamicRoutes.value.forEach((route2) => {
|
|
95
|
+
router.removeRoute(route2.name);
|
|
96
|
+
});
|
|
97
|
+
dynamicRoutes.value = [];
|
|
92
98
|
};
|
|
93
99
|
const logout = async (lastPath) => {
|
|
94
100
|
await logoutApi?.();
|
|
95
|
-
flush(lastPath);
|
|
101
|
+
await flush(lastPath);
|
|
96
102
|
};
|
|
97
103
|
return {
|
|
98
104
|
dynamicRoutes,
|