@melt-js/libs-vben 0.0.0-stage → 2026.11.8-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/LICENSE +10 -0
- package/README.md +86 -2
- package/package.json +98 -3
- package/src/access/access-control.vue +47 -0
- package/src/access/accessible.ts +236 -0
- package/src/access/directive.ts +42 -0
- package/src/access/index.ts +4 -0
- package/src/access/use-access.ts +53 -0
- package/src/composables/index.ts +14 -0
- package/src/composables/use-is-mobile.ts +7 -0
- package/src/composables/use-layout-style.ts +51 -0
- package/src/composables/use-layout-viewport-height.ts +71 -0
- package/src/composables/use-namespace.ts +106 -0
- package/src/composables/use-priority-value.ts +96 -0
- package/src/composables/use-scroll-lock.ts +151 -0
- package/src/composables/use-simple-locale/README.md +3 -0
- package/src/composables/use-simple-locale/index.ts +27 -0
- package/src/composables/use-simple-locale/messages.ts +31 -0
- package/src/composables/use-sortable.ts +32 -0
- package/src/constants/core.ts +76 -0
- package/src/constants/index.ts +2 -0
- package/src/core-icons/create-icon.ts +14 -0
- package/src/core-icons/index.ts +11 -0
- package/src/core-icons/lucide.ts +95 -0
- package/src/core-preferences/config.ts +172 -0
- package/src/core-preferences/constants.ts +116 -0
- package/src/core-preferences/index.ts +24 -0
- package/src/core-preferences/preferences.ts +503 -0
- package/src/core-preferences/types.ts +471 -0
- package/src/core-preferences/update-css-variables.ts +129 -0
- package/src/core-preferences/use-preferences.ts +282 -0
- package/src/design/css/global.css +1 -0
- package/src/design/css/nprogress.css +61 -0
- package/src/design/css/transition.css +238 -0
- package/src/design/css/ui.css +101 -0
- package/src/design/design-tokens/dark.css +446 -0
- package/src/design/design-tokens/default.css +491 -0
- package/src/design/design-tokens/index.ts +2 -0
- package/src/design/index.ts +6 -0
- package/src/design/scss-bem/bem.scss +34 -0
- package/src/design/scss-bem/constants.scss +5 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/use-app-config.ts +39 -0
- package/src/hooks/use-content-maximize.ts +24 -0
- package/src/hooks/use-design-tokens.ts +421 -0
- package/src/hooks/use-hover-toggle.ts +163 -0
- package/src/hooks/use-pagination.ts +72 -0
- package/src/hooks/use-refresh.ts +16 -0
- package/src/hooks/use-tabs.ts +143 -0
- package/src/hooks/use-watermark.ts +84 -0
- package/src/icons/iconify/index.ts +5 -0
- package/src/icons/icons/empty-icon.vue +27 -0
- package/src/icons/index.ts +3 -0
- package/src/icons/svg/icons/antdv-logo.svg +29 -0
- package/src/icons/svg/icons/antdv-next-logo.svg +1 -0
- package/src/icons/svg/icons/avatar-1.svg +1 -0
- package/src/icons/svg/icons/avatar-2.svg +1 -0
- package/src/icons/svg/icons/avatar-3.svg +1 -0
- package/src/icons/svg/icons/avatar-4.svg +1 -0
- package/src/icons/svg/icons/bell.svg +1 -0
- package/src/icons/svg/icons/cake.svg +1 -0
- package/src/icons/svg/icons/card.svg +1 -0
- package/src/icons/svg/icons/dingding.svg +1 -0
- package/src/icons/svg/icons/download.svg +1 -0
- package/src/icons/svg/icons/github.svg +1 -0
- package/src/icons/svg/icons/google.svg +1 -0
- package/src/icons/svg/icons/qqchat.svg +1 -0
- package/src/icons/svg/icons/tdesign-logo.svg +39 -0
- package/src/icons/svg/icons/wechat.svg +1 -0
- package/src/icons/svg/index.ts +39 -0
- package/src/icons/svg/load.ts +81 -0
- package/src/locales/i18n.ts +147 -0
- package/src/locales/index.ts +30 -0
- package/src/locales/langs/en-US/authentication.json +65 -0
- package/src/locales/langs/en-US/common.json +27 -0
- package/src/locales/langs/en-US/preferences.json +245 -0
- package/src/locales/langs/en-US/profile.json +4 -0
- package/src/locales/langs/en-US/ui.json +165 -0
- package/src/locales/langs/zh-CN/authentication.json +65 -0
- package/src/locales/langs/zh-CN/common.json +27 -0
- package/src/locales/langs/zh-CN/preferences.json +245 -0
- package/src/locales/langs/zh-CN/profile.json +4 -0
- package/src/locales/langs/zh-CN/ui.json +165 -0
- package/src/locales/langs/zh-TW/authentication.json +65 -0
- package/src/locales/langs/zh-TW/common.json +27 -0
- package/src/locales/langs/zh-TW/preferences.json +245 -0
- package/src/locales/langs/zh-TW/profile.json +4 -0
- package/src/locales/langs/zh-TW/ui.json +165 -0
- package/src/locales/typing.ts +27 -0
- package/src/preferences/index.ts +42 -0
- package/src/request/index.ts +2 -0
- package/src/request/request-client/index.ts +3 -0
- package/src/request/request-client/modules/downloader.ts +60 -0
- package/src/request/request-client/modules/interceptor.ts +40 -0
- package/src/request/request-client/modules/sse.ts +134 -0
- package/src/request/request-client/modules/uploader.ts +79 -0
- package/src/request/request-client/preset-interceptors.ts +178 -0
- package/src/request/request-client/request-client.ts +163 -0
- package/src/request/request-client/types.ts +90 -0
- package/src/shared/cache/README.md +418 -0
- package/src/shared/cache/index.ts +5 -0
- package/src/shared/cache/indexeddb-driver.ts +137 -0
- package/src/shared/cache/local-storage-driver.ts +70 -0
- package/src/shared/cache/memory-storage-driver.ts +32 -0
- package/src/shared/cache/storage-manager.ts +146 -0
- package/src/shared/cache/types.ts +39 -0
- package/src/shared/color/color.ts +9 -0
- package/src/shared/color/convert.ts +62 -0
- package/src/shared/color/generator.ts +45 -0
- package/src/shared/color/index.ts +3 -0
- package/src/shared/constants/globals.ts +20 -0
- package/src/shared/constants/index.ts +2 -0
- package/src/shared/constants/vben.ts +30 -0
- package/src/shared/global-state.ts +45 -0
- package/src/shared/store.ts +1 -0
- package/src/shared/utils/cn.ts +10 -0
- package/src/shared/utils/date.ts +80 -0
- package/src/shared/utils/diff.ts +114 -0
- package/src/shared/utils/dom.ts +126 -0
- package/src/shared/utils/download.ts +186 -0
- package/src/shared/utils/error.ts +19 -0
- package/src/shared/utils/index.ts +22 -0
- package/src/shared/utils/inference.ts +164 -0
- package/src/shared/utils/letter.ts +47 -0
- package/src/shared/utils/merge.ts +11 -0
- package/src/shared/utils/nprogress.ts +52 -0
- package/src/shared/utils/resources.ts +21 -0
- package/src/shared/utils/stack.ts +103 -0
- package/src/shared/utils/state-handler.ts +61 -0
- package/src/shared/utils/to.ts +21 -0
- package/src/shared/utils/tree.ts +159 -0
- package/src/shared/utils/unique.ts +15 -0
- package/src/shared/utils/update-css-variables.ts +47 -0
- package/src/shared/utils/util.ts +50 -0
- package/src/shared/utils/window.ts +37 -0
- package/src/stores/index.ts +3 -0
- package/src/stores/modules/access.ts +130 -0
- package/src/stores/modules/dict.ts +244 -0
- package/src/stores/modules/index.ts +5 -0
- package/src/stores/modules/tabbar.ts +797 -0
- package/src/stores/modules/timezone.ts +132 -0
- package/src/stores/modules/user.ts +42 -0
- package/src/stores/setup.ts +79 -0
- package/src/stores/shim-pinia.d.ts +11 -0
- package/src/styles/antd/index.css +78 -0
- package/src/styles/antdv-next/index.css +90 -0
- package/src/styles/ele/index.css +44 -0
- package/src/styles/global/index.scss +1 -0
- package/src/styles/index.ts +1 -0
- package/src/styles/naive/index.css +26 -0
- package/src/styles/style-exports.d.ts +3 -0
- package/src/theme.css +592 -0
- package/src/types/global.d.ts +28 -0
- package/src/types/index.ts +2 -0
- package/src/types/shims.d.ts +1 -0
- package/src/types/user.ts +20 -0
- package/src/typings/app.d.ts +128 -0
- package/src/typings/basic.d.ts +42 -0
- package/src/typings/helper.d.ts +147 -0
- package/src/typings/index.ts +16 -0
- package/src/typings/languages.ts +28 -0
- package/src/typings/menu-record.ts +82 -0
- package/src/typings/tabs.ts +8 -0
- package/src/typings/vue-router.d.ts +169 -0
- package/src/utils/helpers/find-menu-by-path.ts +37 -0
- package/src/utils/helpers/generate-menus.ts +89 -0
- package/src/utils/helpers/generate-routes-backend.ts +108 -0
- package/src/utils/helpers/generate-routes-frontend.ts +58 -0
- package/src/utils/helpers/get-popup-container.ts +10 -0
- package/src/utils/helpers/index.ts +8 -0
- package/src/utils/helpers/merge-route-modules.ts +28 -0
- package/src/utils/helpers/reset-routes.ts +30 -0
- package/src/utils/helpers/unmount-global-loading.ts +31 -0
- package/src/utils/index.ts +4 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Router, RouteRecordRaw } from 'vue-router';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ExRouteRecordRaw,
|
|
5
|
+
MenuRecordRaw,
|
|
6
|
+
RouteMeta,
|
|
7
|
+
} from '@melt-js/libs-vben/typings';
|
|
8
|
+
|
|
9
|
+
import { filterTree, mapTree, sortTree } from '@melt-js/libs-vben/shared/utils';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 根据 routes 生成菜单列表
|
|
13
|
+
* @param routes - 路由配置列表
|
|
14
|
+
* @param router - Vue Router 实例
|
|
15
|
+
* @returns 生成的菜单列表
|
|
16
|
+
*/
|
|
17
|
+
function generateMenus(
|
|
18
|
+
routes: RouteRecordRaw[],
|
|
19
|
+
router: Router,
|
|
20
|
+
): MenuRecordRaw[] {
|
|
21
|
+
// 将路由列表转换为一个以 name 为键的对象映射
|
|
22
|
+
const finalRoutesMap: { [key: string]: string } = Object.fromEntries(
|
|
23
|
+
router.getRoutes().map(({ name, path }) => [name, path]),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
let menus = mapTree<ExRouteRecordRaw, MenuRecordRaw>(routes, (route) => {
|
|
27
|
+
// 获取最终的路由路径
|
|
28
|
+
const path = finalRoutesMap[route.name as string] ?? route.path ?? '';
|
|
29
|
+
|
|
30
|
+
const { meta, name: routeName, redirect, children = [] } = route;
|
|
31
|
+
// vue-router 的 RouteMeta 是宽松索引类型,这里收窄为带字段名的类型再解构。
|
|
32
|
+
const metaRecord = (meta ?? {}) as RouteMeta;
|
|
33
|
+
const {
|
|
34
|
+
activeIcon,
|
|
35
|
+
badge,
|
|
36
|
+
badgeType,
|
|
37
|
+
badgeVariants,
|
|
38
|
+
hideChildrenInMenu = false,
|
|
39
|
+
icon,
|
|
40
|
+
link,
|
|
41
|
+
order,
|
|
42
|
+
title,
|
|
43
|
+
query,
|
|
44
|
+
} = metaRecord;
|
|
45
|
+
|
|
46
|
+
// 确保菜单名称不为空
|
|
47
|
+
const name = (title || routeName || '') as string;
|
|
48
|
+
|
|
49
|
+
// 处理子菜单
|
|
50
|
+
const resultChildren = hideChildrenInMenu
|
|
51
|
+
? []
|
|
52
|
+
: ((children as MenuRecordRaw[]) ?? []);
|
|
53
|
+
|
|
54
|
+
// 设置子菜单的父子关系
|
|
55
|
+
if (resultChildren.length > 0) {
|
|
56
|
+
resultChildren.forEach((child) => {
|
|
57
|
+
child.parents = [...(route.parents ?? []), path];
|
|
58
|
+
child.parent = path;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 确定最终路径
|
|
63
|
+
const resultPath = hideChildrenInMenu ? redirect || path : link || path;
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
activeIcon,
|
|
67
|
+
badge,
|
|
68
|
+
badgeType,
|
|
69
|
+
badgeVariants,
|
|
70
|
+
icon,
|
|
71
|
+
name,
|
|
72
|
+
query,
|
|
73
|
+
order,
|
|
74
|
+
parent: route.parent,
|
|
75
|
+
parents: route.parents,
|
|
76
|
+
path: resultPath,
|
|
77
|
+
show: !metaRecord.hideInMenu,
|
|
78
|
+
children: resultChildren,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// 对菜单进行排序,避免order=0时被替换成999的问题
|
|
83
|
+
menus = sortTree(menus, (a, b) => (a?.order ?? 999) - (b?.order ?? 999));
|
|
84
|
+
|
|
85
|
+
// 过滤掉隐藏的菜单项
|
|
86
|
+
return filterTree(menus, (menu) => !!menu.show);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { generateMenus };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { RouteRecordRaw } from 'vue-router';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ComponentRecordType,
|
|
5
|
+
GenerateMenuAndRoutesOptions,
|
|
6
|
+
RouteRecordStringComponent,
|
|
7
|
+
} from '@melt-js/libs-vben/typings';
|
|
8
|
+
|
|
9
|
+
import { mapTree } from '@melt-js/libs-vben/shared/utils';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 判断路由是否在菜单中显示但访问时展示 403(让用户知悉功能并申请权限)
|
|
13
|
+
*/
|
|
14
|
+
function menuHasVisibleWithForbidden(route: RouteRecordRaw): boolean {
|
|
15
|
+
return !!route.meta?.menuVisibleWithForbidden;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 动态生成路由 - 后端方式
|
|
20
|
+
* 对 meta.menuVisibleWithForbidden 为 true 的项直接替换为 403 组件,让用户知悉功能并申请权限。
|
|
21
|
+
*/
|
|
22
|
+
async function generateRoutesByBackend(
|
|
23
|
+
options: GenerateMenuAndRoutesOptions,
|
|
24
|
+
): Promise<RouteRecordRaw[]> {
|
|
25
|
+
const {
|
|
26
|
+
fetchMenuListAsync,
|
|
27
|
+
layoutMap = {},
|
|
28
|
+
pageMap = {},
|
|
29
|
+
forbiddenComponent,
|
|
30
|
+
} = options;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const menuRoutes = await fetchMenuListAsync?.();
|
|
34
|
+
if (!menuRoutes) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const normalizePageMap: ComponentRecordType = {};
|
|
39
|
+
|
|
40
|
+
for (const [key, value] of Object.entries(pageMap)) {
|
|
41
|
+
normalizePageMap[normalizeViewPath(key)] = value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let routes = convertRoutes(menuRoutes, layoutMap, normalizePageMap);
|
|
45
|
+
|
|
46
|
+
if (forbiddenComponent) {
|
|
47
|
+
routes = mapTree(routes, (route) => {
|
|
48
|
+
if (menuHasVisibleWithForbidden(route)) {
|
|
49
|
+
route.component = forbiddenComponent;
|
|
50
|
+
}
|
|
51
|
+
return route;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return routes;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(error);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function convertRoutes(
|
|
63
|
+
routes: RouteRecordStringComponent[],
|
|
64
|
+
layoutMap: ComponentRecordType,
|
|
65
|
+
pageMap: ComponentRecordType,
|
|
66
|
+
): RouteRecordRaw[] {
|
|
67
|
+
return mapTree(routes, (node) => {
|
|
68
|
+
const route = node as unknown as RouteRecordRaw;
|
|
69
|
+
const { component, name } = node;
|
|
70
|
+
|
|
71
|
+
if (!name) {
|
|
72
|
+
console.error('route name is required', route);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// layout转换
|
|
76
|
+
if (component && layoutMap[component]) {
|
|
77
|
+
route.component = layoutMap[component];
|
|
78
|
+
// 页面组件转换
|
|
79
|
+
} else if (component) {
|
|
80
|
+
const normalizePath = normalizeViewPath(component);
|
|
81
|
+
const pageKey = normalizePath.endsWith('.vue')
|
|
82
|
+
? normalizePath
|
|
83
|
+
: `${normalizePath}.vue`;
|
|
84
|
+
if (pageMap[pageKey]) {
|
|
85
|
+
route.component = pageMap[pageKey];
|
|
86
|
+
} else {
|
|
87
|
+
console.error(`route component is invalid: ${pageKey}`, route);
|
|
88
|
+
route.component = pageMap['/_core/fallback/not-found.vue'];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return route;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function normalizeViewPath(path: string): string {
|
|
97
|
+
// 去除相对路径前缀
|
|
98
|
+
const normalizedPath = path.replace(/^(\.\/|\.\.\/)+/, '');
|
|
99
|
+
|
|
100
|
+
// 确保路径以 '/' 开头
|
|
101
|
+
const viewPath = normalizedPath.startsWith('/')
|
|
102
|
+
? normalizedPath
|
|
103
|
+
: `/${normalizedPath}`;
|
|
104
|
+
|
|
105
|
+
// 这里耦合了vben-admin的目录结构
|
|
106
|
+
return viewPath.replace(/^\/views/, '');
|
|
107
|
+
}
|
|
108
|
+
export { generateRoutesByBackend };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { RouteRecordRaw } from 'vue-router';
|
|
2
|
+
|
|
3
|
+
import { filterTree, mapTree } from '@melt-js/libs-vben/shared/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 动态生成路由 - 前端方式
|
|
7
|
+
*/
|
|
8
|
+
async function generateRoutesByFrontend(
|
|
9
|
+
routes: RouteRecordRaw[],
|
|
10
|
+
roles: string[],
|
|
11
|
+
forbiddenComponent?: RouteRecordRaw['component'],
|
|
12
|
+
): Promise<RouteRecordRaw[]> {
|
|
13
|
+
// 根据角色标识过滤路由表,判断当前用户是否拥有指定权限
|
|
14
|
+
const finalRoutes = filterTree(routes, (route) => {
|
|
15
|
+
return hasAuthority(route, roles);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (!forbiddenComponent) {
|
|
19
|
+
return finalRoutes;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 如果有禁止访问的页面,将禁止访问的页面替换为403页面
|
|
23
|
+
return mapTree(finalRoutes, (route) => {
|
|
24
|
+
if (menuHasVisibleWithForbidden(route)) {
|
|
25
|
+
route.component = forbiddenComponent;
|
|
26
|
+
}
|
|
27
|
+
return route;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 判断路由是否有权限访问
|
|
33
|
+
* @param route
|
|
34
|
+
* @param access
|
|
35
|
+
*/
|
|
36
|
+
function hasAuthority(route: RouteRecordRaw, access: string[]) {
|
|
37
|
+
const authority = route.meta?.authority;
|
|
38
|
+
if (!authority) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
const canAccess = access.some((value) => authority.includes(value));
|
|
42
|
+
|
|
43
|
+
return canAccess || (!canAccess && menuHasVisibleWithForbidden(route));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 判断路由是否在菜单中显示,但是访问会被重定向到403
|
|
48
|
+
* @param route
|
|
49
|
+
*/
|
|
50
|
+
function menuHasVisibleWithForbidden(route: RouteRecordRaw) {
|
|
51
|
+
return (
|
|
52
|
+
!!route.meta?.authority &&
|
|
53
|
+
Reflect.has(route.meta || {}, 'menuVisibleWithForbidden') &&
|
|
54
|
+
!!route.meta?.menuVisibleWithForbidden
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { generateRoutesByFrontend, hasAuthority };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* If the node is holding inside a form, return the form element,
|
|
3
|
+
* otherwise return the parent node of the given element or
|
|
4
|
+
* the document body if the element is not provided.
|
|
5
|
+
*/
|
|
6
|
+
export function getPopupContainer(node?: HTMLElement): HTMLElement {
|
|
7
|
+
return (
|
|
8
|
+
node?.closest('form') ?? (node?.parentNode as HTMLElement) ?? document.body
|
|
9
|
+
);
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './find-menu-by-path';
|
|
2
|
+
export * from './generate-menus';
|
|
3
|
+
export * from './generate-routes-backend';
|
|
4
|
+
export * from './generate-routes-frontend';
|
|
5
|
+
export * from './get-popup-container';
|
|
6
|
+
export * from './merge-route-modules';
|
|
7
|
+
export * from './reset-routes';
|
|
8
|
+
export * from './unmount-global-loading';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RouteRecordRaw } from 'vue-router';
|
|
2
|
+
|
|
3
|
+
// 定义模块类型
|
|
4
|
+
interface RouteModuleType {
|
|
5
|
+
default: RouteRecordRaw[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 合并动态路由模块的默认导出
|
|
10
|
+
* @param routeModules 动态导入的路由模块对象
|
|
11
|
+
* @returns 合并后的路由配置数组
|
|
12
|
+
*/
|
|
13
|
+
function mergeRouteModules(
|
|
14
|
+
routeModules: Record<string, unknown>,
|
|
15
|
+
): RouteRecordRaw[] {
|
|
16
|
+
const mergedRoutes: RouteRecordRaw[] = [];
|
|
17
|
+
|
|
18
|
+
for (const routeModule of Object.values(routeModules)) {
|
|
19
|
+
const moduleRoutes = (routeModule as RouteModuleType)?.default ?? [];
|
|
20
|
+
mergedRoutes.push(...moduleRoutes);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return mergedRoutes;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { mergeRouteModules };
|
|
27
|
+
|
|
28
|
+
export type { RouteModuleType };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Router, RouteRecordName, RouteRecordRaw } from 'vue-router';
|
|
2
|
+
|
|
3
|
+
import { traverseTreeValues } from '@melt-js/libs-vben/shared/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @zh_CN 重置所有路由,如有指定白名单除外
|
|
7
|
+
*/
|
|
8
|
+
export function resetStaticRoutes(router: Router, routes: RouteRecordRaw[]) {
|
|
9
|
+
// 获取静态路由所有节点包含子节点的 name,并排除不存在 name 字段的路由
|
|
10
|
+
const staticRouteNames = traverseTreeValues<
|
|
11
|
+
RouteRecordRaw,
|
|
12
|
+
RouteRecordName | undefined
|
|
13
|
+
>(routes, (route) => {
|
|
14
|
+
// 这些路由需要指定 name,防止在路由重置时,不能删除没有指定 name 的路由
|
|
15
|
+
if (!route.name) {
|
|
16
|
+
console.warn(
|
|
17
|
+
`The route with the path ${route.path} needs to have the field name specified.`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return route.name;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const allRoutes = router.getRoutes();
|
|
24
|
+
allRoutes.forEach(({ name }) => {
|
|
25
|
+
// 存在于路由表且非白名单才需要删除
|
|
26
|
+
if (name && !staticRouteNames.includes(name) && router.hasRoute(name)) {
|
|
27
|
+
router.removeRoute(name);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 移除并销毁loading
|
|
3
|
+
* 放在这里是而不是放在 index.html 的app标签内,是因为这样比较不会生硬,渲染过快可能会有闪烁
|
|
4
|
+
* 通过先添加css动画隐藏,在动画结束后在移除loading节点来改善体验
|
|
5
|
+
* 不好的地方是会增加一些代码量
|
|
6
|
+
* 自定义loading可以见:https://doc.vben.pro/guide/in-depth/loading.html
|
|
7
|
+
*/
|
|
8
|
+
export function unmountGlobalLoading() {
|
|
9
|
+
// 查找全局 loading 元素
|
|
10
|
+
const loadingElement = document.querySelector('#__app-loading__');
|
|
11
|
+
|
|
12
|
+
if (loadingElement) {
|
|
13
|
+
// 添加隐藏类,触发过渡动画
|
|
14
|
+
loadingElement.classList.add('hidden');
|
|
15
|
+
|
|
16
|
+
// 查找所有需要移除的注入 loading 元素
|
|
17
|
+
const injectLoadingElements = document.querySelectorAll(
|
|
18
|
+
'[data-app-loading^="inject"]',
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// 当过渡动画结束时,移除 loading 元素和所有注入的 loading 元素
|
|
22
|
+
loadingElement.addEventListener(
|
|
23
|
+
'transitionend',
|
|
24
|
+
() => {
|
|
25
|
+
loadingElement.remove(); // 移除 loading 元素
|
|
26
|
+
injectLoadingElements.forEach((el) => el.remove()); // 移除所有注入的 loading 元素
|
|
27
|
+
},
|
|
28
|
+
{ once: true },
|
|
29
|
+
); // 确保事件只触发一次
|
|
30
|
+
}
|
|
31
|
+
}
|