@go-wind/admin-react 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +74 -2
- package/dist/access/access-control.d.ts +39 -0
- package/dist/access/field-permission.d.ts +11 -0
- package/dist/access/index.d.ts +4 -0
- package/dist/access/use-access.d.ts +50 -0
- package/dist/admin-react.css +2 -0
- package/dist/admin-react.js +5432 -0
- package/dist/admin-react.js.map +1 -0
- package/dist/auth-gateway.d.ts +54 -0
- package/dist/components/Loading/index.d.ts +22 -0
- package/dist/env.d.ts +5 -0
- package/dist/hooks/useProTableScrollY.d.ts +22 -0
- package/dist/hooks/useTime.d.ts +6 -0
- package/dist/hooks/useTitle.d.ts +1 -0
- package/dist/hooks/useTokenRefresh.d.ts +26 -0
- package/dist/i18n/components/LocaleSwitcher/index.d.ts +1 -0
- package/dist/i18n/components/index.d.ts +1 -0
- package/dist/i18n/config/i18n.d.ts +18 -0
- package/dist/i18n/hooks/index.d.ts +2 -0
- package/dist/i18n/hooks/useI18n.d.ts +96 -0
- package/dist/i18n/hooks/useLocaleSync.d.ts +4 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/utils/detector.d.ts +26 -0
- package/dist/i18n/utils/formatter.d.ts +38 -0
- package/dist/i18n/utils/index.d.ts +3 -0
- package/dist/i18n/utils/sync.d.ts +27 -0
- package/dist/index.d.ts +34 -0
- package/dist/locales/en-US/index.d.ts +2 -0
- package/dist/locales/index.d.ts +10 -0
- package/dist/locales/zh-CN/index.d.ts +2 -0
- package/dist/nprogress-CwfUlis6.js +159 -0
- package/dist/nprogress-CwfUlis6.js.map +1 -0
- package/dist/preferences/components/PreferencesPanel/AppearancePanel.d.ts +3 -0
- package/dist/preferences/components/PreferencesPanel/GeneralPanel.d.ts +3 -0
- package/dist/preferences/components/PreferencesPanel/LayoutPanel.d.ts +3 -0
- package/dist/preferences/components/PreferencesPanel/ShortcutKeyPanel.d.ts +3 -0
- package/dist/preferences/components/PreferencesPanel/index.d.ts +8 -0
- package/dist/preferences/components/ThemeProvider/index.d.ts +9 -0
- package/dist/preferences/components/index.d.ts +2 -0
- package/dist/preferences/config/constants.d.ts +24 -0
- package/dist/preferences/config/darkTheme.d.ts +32 -0
- package/dist/preferences/config/default.d.ts +3 -0
- package/dist/preferences/config/index.d.ts +4 -0
- package/dist/preferences/config/lightTheme.d.ts +33 -0
- package/dist/preferences/hooks/index.d.ts +3 -0
- package/dist/preferences/hooks/useLocale.d.ts +23 -0
- package/dist/preferences/hooks/usePreferences.d.ts +31 -0
- package/dist/preferences/hooks/useThemeConfig.d.ts +2 -0
- package/dist/preferences/index.d.ts +5 -0
- package/dist/preferences/store/index.d.ts +24 -0
- package/dist/preferences/theme-transition.d.ts +17 -0
- package/dist/preferences/types/app.d.ts +238 -0
- package/dist/preferences/types/index.d.ts +4 -0
- package/dist/preferences/types/layout.d.ts +78 -0
- package/dist/preferences/types/preferences-root.d.ts +48 -0
- package/dist/preferences/types/theme.d.ts +29 -0
- package/dist/preferences/utils/diff.d.ts +7 -0
- package/dist/preferences/utils/merge.d.ts +9 -0
- package/dist/query-client.d.ts +9 -0
- package/dist/rolldown-runtime-BbCBk-LD.js +19 -0
- package/dist/router/factory.d.ts +7 -0
- package/dist/router/generators/generate-menus.d.ts +13 -0
- package/dist/router/generators/generate-routes-backend.d.ts +12 -0
- package/dist/router/generators/generate-routes-frontend.d.ts +17 -0
- package/dist/router/generators/index.d.ts +3 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/routes-context.d.ts +8 -0
- package/dist/router/types/index.d.ts +207 -0
- package/dist/router/utils/index.d.ts +8 -0
- package/dist/router/utils/inject-redirect.d.ts +6 -0
- package/dist/router/utils/lazy.d.ts +11 -0
- package/dist/router/utils/loader.d.ts +14 -0
- package/dist/router/utils/menu.d.ts +5 -0
- package/dist/router/utils/merge-route-modules.d.ts +23 -0
- package/dist/router/utils/reset-routes.d.ts +18 -0
- package/dist/router/utils/sort-routes.d.ts +5 -0
- package/dist/router/utils/transform-meta-to-handle.d.ts +11 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/storage.class.d.ts +125 -0
- package/dist/storage/storage.types.d.ts +199 -0
- package/dist/stores/auth.d.ts +56 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/stores/user.d.ts +32 -0
- package/dist/transport/rest/captcha-headers.d.ts +2 -0
- package/dist/transport/rest/index.d.ts +8 -0
- package/dist/transport/rest/modules/downloader.d.ts +9 -0
- package/dist/transport/rest/modules/interceptor.d.ts +9 -0
- package/dist/transport/rest/modules/uploader.d.ts +10 -0
- package/dist/transport/rest/pagination.d.ts +73 -0
- package/dist/transport/rest/preset-interceptors.d.ts +25 -0
- package/dist/transport/rest/request-api.d.ts +6 -0
- package/dist/transport/rest/request-client.d.ts +87 -0
- package/dist/transport/rest/types.d.ts +38 -0
- package/dist/transport/rest/utils.d.ts +16 -0
- package/dist/transport/sse/event.d.ts +44 -0
- package/dist/transport/sse/index.d.ts +5 -0
- package/dist/transport/sse/sse_client.d.ts +76 -0
- package/dist/transport/sse/types.d.ts +27 -0
- package/dist/types.d.ts +44 -0
- package/dist/utils/color.d.ts +27 -0
- package/dist/utils/date.d.ts +5 -0
- package/dist/utils/diff.d.ts +6 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/inference.d.ts +111 -0
- package/dist/utils/merge.d.ts +17 -0
- package/dist/utils/nprogress.d.ts +11 -0
- package/dist/utils/tree.d.ts +27 -0
- package/dist/utils/url.d.ts +11 -0
- package/dist/utils/utils.d.ts +37 -0
- package/package.json +70 -3
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AppPreferences, BreadcrumbPreferences, CopyrightPreferences, FooterPreferences, HeaderPreferences, LogoPreferences, NavigationPreferences, ShortcutKeyPreferences, SidebarPreferences, TabbarPreferences, ThemePreferences, TransitionPreferences, WidgetPreferences } from "./app";
|
|
2
|
+
/**
|
|
3
|
+
* 偏好设置总接口
|
|
4
|
+
*/
|
|
5
|
+
export interface Preferences {
|
|
6
|
+
/** 全局配置 */
|
|
7
|
+
app: AppPreferences;
|
|
8
|
+
/** 顶栏配置 */
|
|
9
|
+
breadcrumb: BreadcrumbPreferences;
|
|
10
|
+
/** 版权配置 */
|
|
11
|
+
copyright: CopyrightPreferences;
|
|
12
|
+
/** 底栏配置 */
|
|
13
|
+
footer: FooterPreferences;
|
|
14
|
+
/** 面包屑配置 */
|
|
15
|
+
header: HeaderPreferences;
|
|
16
|
+
/** logo配置 */
|
|
17
|
+
logo: LogoPreferences;
|
|
18
|
+
/** 导航配置 */
|
|
19
|
+
navigation: NavigationPreferences;
|
|
20
|
+
/** 快捷键配置 */
|
|
21
|
+
shortcutKeys: ShortcutKeyPreferences;
|
|
22
|
+
/** 侧边栏配置 */
|
|
23
|
+
sidebar: SidebarPreferences;
|
|
24
|
+
/** 标签页配置 */
|
|
25
|
+
tabbar: TabbarPreferences;
|
|
26
|
+
/** 主题配置 */
|
|
27
|
+
theme: ThemePreferences;
|
|
28
|
+
/** 动画配置 */
|
|
29
|
+
transition: TransitionPreferences;
|
|
30
|
+
/** 功能配置 */
|
|
31
|
+
widget: WidgetPreferences;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 偏好设置接口
|
|
35
|
+
*/
|
|
36
|
+
export type PreferencesKeys = keyof Preferences;
|
|
37
|
+
export type DeepPartial<T> = {
|
|
38
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* 偏好设置初始化参数
|
|
42
|
+
*/
|
|
43
|
+
export interface InitialOptions {
|
|
44
|
+
/** 命名空间 */
|
|
45
|
+
namespace: string;
|
|
46
|
+
/** 覆盖默认偏好设置 */
|
|
47
|
+
overrides?: DeepPartial<Preferences>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 主题模式
|
|
3
|
+
* auto 自动
|
|
4
|
+
* dark 暗色
|
|
5
|
+
* light 亮色
|
|
6
|
+
*/
|
|
7
|
+
export type ThemeModeType = "auto" | "dark" | "light";
|
|
8
|
+
/**
|
|
9
|
+
* 内置主题名称
|
|
10
|
+
* custom 自定义
|
|
11
|
+
* deep-blue 深蓝
|
|
12
|
+
* deep-green 深绿
|
|
13
|
+
* default 默认
|
|
14
|
+
* gray 灰色
|
|
15
|
+
* green 绿色
|
|
16
|
+
* neutral 中性色
|
|
17
|
+
* orange 橙色
|
|
18
|
+
* pink 粉色
|
|
19
|
+
* red 红色
|
|
20
|
+
* rose 玫红色
|
|
21
|
+
* sky-blue 天蓝色
|
|
22
|
+
* slate 石板灰色
|
|
23
|
+
* stone 石灰色
|
|
24
|
+
* violet 紫罗兰色
|
|
25
|
+
* yellow 黄色
|
|
26
|
+
* zinc 锌色
|
|
27
|
+
* (Record<never, never> & string) 自定义主题
|
|
28
|
+
*/
|
|
29
|
+
export type BuiltinThemeType = "custom" | "deep-blue" | "deep-green" | "default" | "gray" | "green" | "neutral" | "orange" | "pink" | "red" | "rose" | "sky-blue" | "slate" | "stone" | "violet" | "yellow" | "zinc" | (Record<never, never> & string);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DeepPartial } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* 深度比较 initial 与 current,产出「与出厂默认的增量」对象(只含被改过的叶子值)。
|
|
4
|
+
* 与 vben 的 diffPreference 同语义:复制偏好设置时导出的是增量 overrides,
|
|
5
|
+
* 不是全量快照(对齐 framework/effects/layouts/widgets/preferences/preferences-drawer.vue 的 handleCopy)。
|
|
6
|
+
*/
|
|
7
|
+
export declare function diffDeep<T extends object>(initial: T, current: DeepPartial<T>): DeepPartial<T>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DeepPartial } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* 深度合并对象
|
|
4
|
+
*/
|
|
5
|
+
export declare function mergeDeep<T extends object>(target: T, source: DeepPartial<T>): T;
|
|
6
|
+
/**
|
|
7
|
+
* 判断是否为普通对象
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPlainObject(value: any): value is Record<string, any>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
export declare const queryClient: QueryClient;
|
|
3
|
+
/**
|
|
4
|
+
* 宿主在 bootstrap 阶段调整 query 行为。
|
|
5
|
+
* @param options.isDev 开发环境姿态:任何查询错误重试 3 次(默认仅网络错误重试 1 次)
|
|
6
|
+
*/
|
|
7
|
+
export declare function configureQueryClient(options?: {
|
|
8
|
+
isDev?: boolean;
|
|
9
|
+
}): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), s = (e, n) => {
|
|
3
|
+
let r = {};
|
|
4
|
+
for (var i in e) t(r, i, {
|
|
5
|
+
get: e[i],
|
|
6
|
+
enumerable: !0
|
|
7
|
+
});
|
|
8
|
+
return n || t(r, Symbol.toStringTag, { value: "Module" }), r;
|
|
9
|
+
}, c = (e, i, o, s) => {
|
|
10
|
+
if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
|
|
11
|
+
get: ((e) => i[e]).bind(null, d),
|
|
12
|
+
enumerable: !(s = n(i, d)) || s.enumerable
|
|
13
|
+
});
|
|
14
|
+
return e;
|
|
15
|
+
}, l = (e, t, n) => (c(e, t, "default"), n && c(n, t, "default")), u = (n, r, o) => (o = n == null ? {} : e(i(n)), c(r || !n || !n.__esModule || !a.call(n, "default") ? t(o, "default", {
|
|
16
|
+
value: n,
|
|
17
|
+
enumerable: !0
|
|
18
|
+
}) : o, n));
|
|
19
|
+
export { u as i, s as n, l as r, o as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createBrowserRouter } from 'react-router-dom';
|
|
2
|
+
import type { GenerateMenuAndRoutesOptions, AppRouteObject } from './types';
|
|
3
|
+
import type { AccessModeType } from '../preferences';
|
|
4
|
+
export declare const createAccessibleRouter: (mode: AccessModeType, options: GenerateMenuAndRoutesOptions) => Promise<{
|
|
5
|
+
router: ReturnType<typeof createBrowserRouter>;
|
|
6
|
+
routes: AppRouteObject[];
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AppMenu, AppRouteObject } from "../../router/types";
|
|
2
|
+
/**
|
|
3
|
+
* 根据路由配置生成菜单列表
|
|
4
|
+
* @param routes - 路由配置数组(AppRouteObject[],含 meta)
|
|
5
|
+
* @param getAllRoutes - 获取完整路由树的函数(用于解析动态路径)
|
|
6
|
+
* @returns 菜单树数组(AppMenu[]),可直接传给 ProLayout
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateMenus(routes: AppRouteObject[], getAllRoutes: () => AppRouteObject[]): Promise<AppMenu[]>;
|
|
9
|
+
/**
|
|
10
|
+
* 工具:判断菜单是否应该显示(权限 + 配置)
|
|
11
|
+
* 可用于二次过滤
|
|
12
|
+
*/
|
|
13
|
+
export declare const shouldShowMenu: (menu: AppMenu, permissions: string[]) => boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AppRouteObject, GenerateRoutesOptions } from "../../router/types";
|
|
2
|
+
/**
|
|
3
|
+
* 动态生成路由 - 后端方式(React 版本)
|
|
4
|
+
* @param options - 配置选项
|
|
5
|
+
* @returns 转换后的路由树(AppRouteObject[]),可直接传入 createBrowserRouter
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateRoutesByBackend(options: GenerateRoutesOptions): Promise<AppRouteObject[]>;
|
|
8
|
+
/**
|
|
9
|
+
* 标准化视图路径(适配 React 目录结构)
|
|
10
|
+
* @param path - 后端返回的组件路径,如 "./views/system/user" 或 "/views/dashboard"
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeViewPath(path: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { AppRouteObject } from "../../router/types";
|
|
3
|
+
/**
|
|
4
|
+
* 动态生成路由 - 前端权限过滤方式
|
|
5
|
+
* @param routes - 静态路由表(AppRouteObject[],含 meta)
|
|
6
|
+
* @param permissions - 用户权限码列表
|
|
7
|
+
* @param forbiddenElement - 无权限时渲染的元素(<Forbidden />)
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateRoutesByFrontend(routes: AppRouteObject[], permissions: string[], forbiddenElement?: ReactNode): Promise<AppRouteObject[]>;
|
|
10
|
+
/**
|
|
11
|
+
* 判断路由是否有权限访问
|
|
12
|
+
* @param route - 路由对象
|
|
13
|
+
* @param permissions - 用户权限码列表
|
|
14
|
+
* @returns 是否允许访问
|
|
15
|
+
*/
|
|
16
|
+
declare function hasPermission(route: AppRouteObject, permissions: string[]): boolean;
|
|
17
|
+
export { hasPermission };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AppRouteObject } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* 当前实际挂载的路由树(createAccessibleRouter 的产物):
|
|
4
|
+
* 后端模式=后端下发路由;前端模式=权限过滤后的静态路由。
|
|
5
|
+
* 侧栏等消费方必须镜像此树保证"菜单即路由"——后端模式下若回退静态全量表,
|
|
6
|
+
* 会出现未授权菜单可见、点击 404 的越权观感。
|
|
7
|
+
*/
|
|
8
|
+
export declare const AccessibleRoutesContext: import("react").Context<AppRouteObject[] | null>;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { RouteObject } from "react-router-dom";
|
|
2
|
+
import React, { type ComponentType } from "react";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
export type IconName = string;
|
|
5
|
+
export type IconType = IconName | ComponentType<{
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
}>;
|
|
9
|
+
export type BadgeVariant = 'default' | 'primary' | 'success' | 'warning' | 'destructive' | string;
|
|
10
|
+
export type BadgeType = 'dot' | 'normal';
|
|
11
|
+
export type { AccessModeType } from '../../preferences/types/layout';
|
|
12
|
+
/**
|
|
13
|
+
* 后端返回的路由对象(组件路径为字符串)
|
|
14
|
+
*/
|
|
15
|
+
export interface BackendRoute extends Omit<AppRouteObject, 'element' | 'children'> {
|
|
16
|
+
component?: string;
|
|
17
|
+
children?: BackendRoute[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* generateRoutesByBackend 的选项。只声明后端生成器实际消费的字段——
|
|
21
|
+
* 此前这里的 staticRoutes/mode 等字段从未被消费,形成"传了也没用"的误导性签名。
|
|
22
|
+
*/
|
|
23
|
+
export interface GenerateRoutesOptions {
|
|
24
|
+
/** 从后端拉取菜单路由树(component 为字符串路径) */
|
|
25
|
+
fetchMenuListAsync?: () => Promise<BackendRoute[]>;
|
|
26
|
+
/** 布局组件映射(component 字符串 → React 组件) */
|
|
27
|
+
layoutMap?: ComponentRecord;
|
|
28
|
+
/** 页面组件映射(view 路径 → React 组件) */
|
|
29
|
+
pageMap?: ComponentRecord;
|
|
30
|
+
}
|
|
31
|
+
export interface GenerateRoutesResult {
|
|
32
|
+
routes: AppRouteObject[];
|
|
33
|
+
menus: AppMenu[];
|
|
34
|
+
}
|
|
35
|
+
export interface RouteMeta {
|
|
36
|
+
title?: string;
|
|
37
|
+
icon?: IconType;
|
|
38
|
+
activeIcon?: IconType;
|
|
39
|
+
authority?: string[];
|
|
40
|
+
ignoreAccess?: boolean;
|
|
41
|
+
hideInMenu?: boolean;
|
|
42
|
+
hideInTab?: boolean;
|
|
43
|
+
hideInBreadcrumb?: boolean;
|
|
44
|
+
hideChildrenInMenu?: boolean;
|
|
45
|
+
menuVisibleWithForbidden?: boolean;
|
|
46
|
+
activePath?: string;
|
|
47
|
+
affixTab?: boolean;
|
|
48
|
+
affixTabOrder?: number;
|
|
49
|
+
keepAlive?: boolean;
|
|
50
|
+
loaded?: boolean;
|
|
51
|
+
link?: string;
|
|
52
|
+
iframeSrc?: string;
|
|
53
|
+
openInNewWindow?: boolean;
|
|
54
|
+
order?: number;
|
|
55
|
+
query?: Record<string, any>;
|
|
56
|
+
maxNumOfOpenTab?: number;
|
|
57
|
+
badge?: string;
|
|
58
|
+
badgeType?: 'dot' | 'normal';
|
|
59
|
+
badgeVariants?: BadgeVariant;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
export interface AppRoute extends Omit<RouteObject, 'meta' | 'children' | 'element'> {
|
|
63
|
+
name: string;
|
|
64
|
+
path: string;
|
|
65
|
+
redirect?: string;
|
|
66
|
+
index?: boolean;
|
|
67
|
+
meta?: RouteMeta;
|
|
68
|
+
children?: AppRoute[];
|
|
69
|
+
element?: ReactNode;
|
|
70
|
+
componentPath?: string;
|
|
71
|
+
parent?: string;
|
|
72
|
+
parents?: string[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* AppRouteObject = RouteObject + meta + 业务字段
|
|
76
|
+
* 用于替代原生的 RouteObject,携带业务元数据
|
|
77
|
+
*/
|
|
78
|
+
export interface AppRouteObject extends Omit<RouteObject, 'children'> {
|
|
79
|
+
name?: string;
|
|
80
|
+
path?: string;
|
|
81
|
+
meta?: RouteMeta;
|
|
82
|
+
redirect?: string;
|
|
83
|
+
icon?: IconType;
|
|
84
|
+
activeIcon?: IconType;
|
|
85
|
+
disabled?: boolean;
|
|
86
|
+
show?: boolean;
|
|
87
|
+
order?: number;
|
|
88
|
+
children?: AppRouteObject[];
|
|
89
|
+
parent?: string;
|
|
90
|
+
parents?: string[];
|
|
91
|
+
componentPath?: string;
|
|
92
|
+
element?: ReactNode;
|
|
93
|
+
}
|
|
94
|
+
export interface AppMenuBadge {
|
|
95
|
+
badge?: string;
|
|
96
|
+
badgeType?: BadgeType;
|
|
97
|
+
badgeVariants?: BadgeVariant;
|
|
98
|
+
}
|
|
99
|
+
export interface AppMenu extends AppMenuBadge {
|
|
100
|
+
name: string;
|
|
101
|
+
path: string;
|
|
102
|
+
label: string;
|
|
103
|
+
icon?: IconType;
|
|
104
|
+
activeIcon?: IconType;
|
|
105
|
+
order?: number;
|
|
106
|
+
badge?: string;
|
|
107
|
+
badgeType?: 'dot' | 'normal';
|
|
108
|
+
badgeVariants?: BadgeVariant;
|
|
109
|
+
disabled?: boolean;
|
|
110
|
+
show?: boolean;
|
|
111
|
+
parent?: string;
|
|
112
|
+
parents?: string[];
|
|
113
|
+
children?: AppMenu[];
|
|
114
|
+
authority?: string[];
|
|
115
|
+
menuVisibleWithForbidden?: boolean;
|
|
116
|
+
meta?: RouteMeta;
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
}
|
|
119
|
+
export type ComponentRecordType = Record<string, ComponentType<any>>;
|
|
120
|
+
export type ComponentRecord = Record<string, ComponentType<any>>;
|
|
121
|
+
export interface GenerateMenuAndRoutesOptions {
|
|
122
|
+
fetchMenuListAsync?: () => Promise<BackendRoute[]>;
|
|
123
|
+
forbiddenElement?: React.ReactNode;
|
|
124
|
+
layoutMap?: ComponentRecordType;
|
|
125
|
+
pageMap?: ComponentRecordType;
|
|
126
|
+
permissions?: string[];
|
|
127
|
+
roles?: string[];
|
|
128
|
+
routes: AppRouteObject[];
|
|
129
|
+
autoInjectRedirect?: boolean;
|
|
130
|
+
autoSort?: boolean;
|
|
131
|
+
/** 登录落地兜底路径(宿主注入,如 ROUTES.DEFAULT_HOME);后端模式下无可见菜单时使用 */
|
|
132
|
+
defaultHomePath?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 路由模块的默认导出类型
|
|
136
|
+
* 每个动态导入的路由文件应默认导出 AppRouteObject[]
|
|
137
|
+
*/
|
|
138
|
+
export interface RouteModuleType {
|
|
139
|
+
default: AppRouteObject[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Vite glob 导入的动态模块类型
|
|
143
|
+
* 兼容 .tsx/.ts 文件 + 默认导出
|
|
144
|
+
*/
|
|
145
|
+
export type RouteModuleRecord = Record<string, RouteModuleType | AppRouteObject[] | (() => Promise<RouteModuleType>)>;
|
|
146
|
+
export declare const isAppRoute: (route: any) => route is AppRouteObject;
|
|
147
|
+
export interface MenuRecordBadgeRaw {
|
|
148
|
+
/**
|
|
149
|
+
* 徽标
|
|
150
|
+
*/
|
|
151
|
+
badge?: string;
|
|
152
|
+
/**
|
|
153
|
+
* 徽标类型
|
|
154
|
+
*/
|
|
155
|
+
badgeType?: "dot" | "normal";
|
|
156
|
+
/**
|
|
157
|
+
* 徽标颜色
|
|
158
|
+
*/
|
|
159
|
+
badgeVariants?: "destructive" | "primary" | string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 菜单原始对象
|
|
163
|
+
*/
|
|
164
|
+
export interface MenuRecordRaw extends MenuRecordBadgeRaw {
|
|
165
|
+
/**
|
|
166
|
+
* 激活时的图标名
|
|
167
|
+
*/
|
|
168
|
+
activeIcon?: string;
|
|
169
|
+
/**
|
|
170
|
+
* 子菜单
|
|
171
|
+
*/
|
|
172
|
+
children?: MenuRecordRaw[];
|
|
173
|
+
/**
|
|
174
|
+
* 是否禁用菜单
|
|
175
|
+
* @default false
|
|
176
|
+
*/
|
|
177
|
+
disabled?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* 图标名
|
|
180
|
+
*/
|
|
181
|
+
icon?: IconType;
|
|
182
|
+
/**
|
|
183
|
+
* 菜单名
|
|
184
|
+
*/
|
|
185
|
+
name: string;
|
|
186
|
+
/**
|
|
187
|
+
* 排序号
|
|
188
|
+
*/
|
|
189
|
+
order?: number;
|
|
190
|
+
/**
|
|
191
|
+
* 父级路径
|
|
192
|
+
*/
|
|
193
|
+
parent?: string;
|
|
194
|
+
/**
|
|
195
|
+
* 所有父级路径
|
|
196
|
+
*/
|
|
197
|
+
parents?: string[];
|
|
198
|
+
/**
|
|
199
|
+
* 菜单路径,唯一,可当作key
|
|
200
|
+
*/
|
|
201
|
+
path: string;
|
|
202
|
+
/**
|
|
203
|
+
* 是否显示菜单
|
|
204
|
+
* @default true
|
|
205
|
+
*/
|
|
206
|
+
show?: boolean;
|
|
207
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './inject-redirect';
|
|
2
|
+
export * from './lazy';
|
|
3
|
+
export * from './loader';
|
|
4
|
+
export * from './menu';
|
|
5
|
+
export * from './merge-route-modules';
|
|
6
|
+
export * from './reset-routes';
|
|
7
|
+
export * from './sort-routes';
|
|
8
|
+
export * from './transform-meta-to-handle';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ComponentType } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 创建懒加载路由元素
|
|
4
|
+
* 自动包裹 Suspense + Spin fallback
|
|
5
|
+
*
|
|
6
|
+
* @param loader Vite 动态导入函数,如 () => import('@/pages/dashboard')
|
|
7
|
+
* @returns 可直接赋值给 route.element 的 ReactNode
|
|
8
|
+
*/
|
|
9
|
+
export declare const createLazyRoute: (loader: () => Promise<{
|
|
10
|
+
default: ComponentType<any>;
|
|
11
|
+
}>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AppRouteObject } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 展平模块导出(兼容 default / 具名导出)
|
|
4
|
+
* 纯函数,无副作用,可单元测试
|
|
5
|
+
*/
|
|
6
|
+
export declare const extractRoutes: (module: any) => AppRouteObject[];
|
|
7
|
+
/**
|
|
8
|
+
* 过滤无效路由(开发环境调试用)
|
|
9
|
+
*/
|
|
10
|
+
export declare const filterValidRoutes: (routes: AppRouteObject[]) => AppRouteObject[];
|
|
11
|
+
/**
|
|
12
|
+
* 根据权限过滤路由树
|
|
13
|
+
*/
|
|
14
|
+
export declare const filterRoutesByPermission: (routes: AppRouteObject[], permissions: string[]) => AppRouteObject[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ProLayoutProps } from '@ant-design/pro-components';
|
|
2
|
+
import type { AppRouteObject } from '../../router/types';
|
|
3
|
+
type MenuRoute = AppRouteObject;
|
|
4
|
+
export declare const transformRoutesToMenu: (routes: MenuRoute[], permissions: string[], parentPath?: string) => NonNullable<ProLayoutProps["route"]>["routes"];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AppRouteObject, RouteModuleRecord, RouteModuleType } from "../../router";
|
|
2
|
+
/**
|
|
3
|
+
* 合并动态路由模块的默认导出
|
|
4
|
+
*
|
|
5
|
+
* @param routeModules - Vite import.meta.glob 返回的模块对象
|
|
6
|
+
* @param options - 可选配置
|
|
7
|
+
* @returns 合并后的路由配置数组(AppRouteObject[])
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare function mergeRouteModules(routeModules: RouteModuleRecord, options?: {
|
|
13
|
+
/** 是否过滤空模块 */
|
|
14
|
+
filterEmpty?: boolean;
|
|
15
|
+
/** 是否按路径排序 */
|
|
16
|
+
sortByPath?: boolean;
|
|
17
|
+
}): AppRouteObject[];
|
|
18
|
+
/**
|
|
19
|
+
* 异步合并动态路由模块(用于 lazy 加载)
|
|
20
|
+
* @param routeModules - Vite import.meta.glob 返回的异步模块对象
|
|
21
|
+
* @returns Promise<AppRouteObject[]>
|
|
22
|
+
*/
|
|
23
|
+
export declare function mergeRouteModulesAsync(routeModules: Record<string, () => Promise<RouteModuleType | AppRouteObject[]>>): Promise<AppRouteObject[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AppRouteObject } from "../../router/types";
|
|
2
|
+
/**
|
|
3
|
+
* 重置可访问路由(保留白名单)
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ React Router v6+ 不支持运行时修改路由,
|
|
6
|
+
* 此函数返回过滤后的路由树,需配合 createBrowserRouter 重新创建 router
|
|
7
|
+
*
|
|
8
|
+
* @param allRoutes - 当前完整路由树(含动态路由)
|
|
9
|
+
* @param staticRouteNames - 静态路由白名单(保留这些路由)
|
|
10
|
+
* @returns 过滤后的路由树(仅含白名单路由)
|
|
11
|
+
*/
|
|
12
|
+
export declare function resetAccessibleRoutes(allRoutes: AppRouteObject[], staticRouteNames: string[]): AppRouteObject[];
|
|
13
|
+
/**
|
|
14
|
+
* 提取路由树中所有有效的 name(用于生成白名单)
|
|
15
|
+
* @param routes - 路由树
|
|
16
|
+
* @returns 有效的路由 name 数组
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractRouteNames(routes: AppRouteObject[]): string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AppRouteObject, RouteMeta } from '../types';
|
|
2
|
+
import type { RouteHandle } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* 将 meta 转换为 React Router 的 handle
|
|
5
|
+
* 这样 useMatches() 就能获取到路由元数据
|
|
6
|
+
*/
|
|
7
|
+
export declare function transformMetaToHandle(meta?: RouteMeta): RouteHandle | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* 递归转换路由配置,将 meta 映射到 handle
|
|
10
|
+
*/
|
|
11
|
+
export declare function transformRoutesWithHandle(routes: AppRouteObject[]): AppRouteObject[];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { BatchGetOptions, BatchProgressCallback, BatchResult, BatchSetItem, IStorageCache, StorageManagerOptions, StorageMetrics, SyncMessage } from "./storage.types";
|
|
2
|
+
declare class StorageManager implements IStorageCache {
|
|
3
|
+
private readonly prefix;
|
|
4
|
+
private readonly storage;
|
|
5
|
+
private readonly options;
|
|
6
|
+
private readonly defaultTTL?;
|
|
7
|
+
private readonly tabId;
|
|
8
|
+
private channel;
|
|
9
|
+
private metrics;
|
|
10
|
+
private metricsDebounceTimer;
|
|
11
|
+
private readonly onMetricsCallback?;
|
|
12
|
+
private onSyncCallback?;
|
|
13
|
+
constructor(options?: StorageManagerOptions);
|
|
14
|
+
/**
|
|
15
|
+
* 获取完整存储键(安全添加前缀)
|
|
16
|
+
*/
|
|
17
|
+
private getFullKey;
|
|
18
|
+
private getMetaKey;
|
|
19
|
+
private readMeta;
|
|
20
|
+
private writeMeta;
|
|
21
|
+
/**
|
|
22
|
+
* 访问时更新元数据(访问次数和最后访问时间)
|
|
23
|
+
*/
|
|
24
|
+
private updateMetaOnAccess;
|
|
25
|
+
/**
|
|
26
|
+
* 设置时更新元数据
|
|
27
|
+
*/
|
|
28
|
+
private updateMetaOnSet;
|
|
29
|
+
/**
|
|
30
|
+
* 移除元数据
|
|
31
|
+
*/
|
|
32
|
+
private removeMeta;
|
|
33
|
+
private getAllMeta;
|
|
34
|
+
/**
|
|
35
|
+
* 安全解析存储值
|
|
36
|
+
*/
|
|
37
|
+
private parseValue;
|
|
38
|
+
/**
|
|
39
|
+
* 序列化存储值
|
|
40
|
+
*/
|
|
41
|
+
private serializeValue;
|
|
42
|
+
/**
|
|
43
|
+
* 获取存储项
|
|
44
|
+
*/
|
|
45
|
+
getItem<T>(key: string, defaultValue?: T | null): T | null;
|
|
46
|
+
/**
|
|
47
|
+
* 设置存储项
|
|
48
|
+
*/
|
|
49
|
+
setItem<T>(key: string, value: T, ttl?: number | null): void;
|
|
50
|
+
/**
|
|
51
|
+
* 移除存储项
|
|
52
|
+
*/
|
|
53
|
+
removeItem(key: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* 检查键是否存在且未过期
|
|
56
|
+
*/
|
|
57
|
+
hasItem(key: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* 清除所有带前缀的项(使用倒序遍历避免索引错位)
|
|
60
|
+
*/
|
|
61
|
+
clear(): void;
|
|
62
|
+
/**
|
|
63
|
+
* 清除所有过期项
|
|
64
|
+
*/
|
|
65
|
+
clearExpiredItems(): void;
|
|
66
|
+
/**
|
|
67
|
+
* 获取存储键(带前缀过滤)
|
|
68
|
+
*/
|
|
69
|
+
key(index: number): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* 获取有效存储项数量(带前缀过滤)
|
|
72
|
+
*/
|
|
73
|
+
length(): number;
|
|
74
|
+
/**
|
|
75
|
+
* 获取底层 Storage 实例(用于高级操作)
|
|
76
|
+
*/
|
|
77
|
+
getRawStorage(): Storage | null;
|
|
78
|
+
/**
|
|
79
|
+
* 批量获取存储项
|
|
80
|
+
* @param keys 要获取的键数组
|
|
81
|
+
* @param options 获取选项
|
|
82
|
+
* @param onProgress 进度回调(每处理完一个项触发)
|
|
83
|
+
* @returns Promise<Record<string, T | null>> 键值映射
|
|
84
|
+
*/
|
|
85
|
+
getItems<T>(keys: string[], options?: BatchGetOptions, onProgress?: BatchProgressCallback): Promise<Record<string, T | null>>;
|
|
86
|
+
/**
|
|
87
|
+
* 批量设置存储项
|
|
88
|
+
* @param items 键值对映射,值可以是普通值或 BatchSetItem 配置
|
|
89
|
+
* @param onProgress 进度回调
|
|
90
|
+
* @returns Promise<BatchResult<T>> 操作结果统计
|
|
91
|
+
*/
|
|
92
|
+
setItems<T>(items: Record<string, T | BatchSetItem<T>>, onProgress?: BatchProgressCallback): Promise<BatchResult<T>>;
|
|
93
|
+
/**
|
|
94
|
+
* 批量移除存储项
|
|
95
|
+
* @param keys 要移除的键数组
|
|
96
|
+
* @returns Promise<{ removed: string[]; failed: Record<string, Error> }>
|
|
97
|
+
*/
|
|
98
|
+
removeItems(keys: string[]): Promise<{
|
|
99
|
+
removed: string[];
|
|
100
|
+
failed: Record<string, Error>;
|
|
101
|
+
}>;
|
|
102
|
+
/**
|
|
103
|
+
* 批量检查键是否存在(且未过期)
|
|
104
|
+
* @param keys 要检查的键数组
|
|
105
|
+
* @returns Promise<Record<string, boolean>>
|
|
106
|
+
*/
|
|
107
|
+
hasItems(keys: string[]): Promise<Record<string, boolean>>;
|
|
108
|
+
/**
|
|
109
|
+
* 内部方法:标准化批量设置的值配置
|
|
110
|
+
*/
|
|
111
|
+
private _normalizeBatchValue;
|
|
112
|
+
private checkAndEvict;
|
|
113
|
+
private sortByEvictionPriority;
|
|
114
|
+
private initSync;
|
|
115
|
+
private handleSyncMessage;
|
|
116
|
+
private broadcast;
|
|
117
|
+
onSync(callback: (event: SyncMessage) => void): () => void;
|
|
118
|
+
private trackMetric;
|
|
119
|
+
private updateHitRate;
|
|
120
|
+
private debounceReportMetrics;
|
|
121
|
+
private updateQuotaUsage;
|
|
122
|
+
getMetrics(): StorageMetrics;
|
|
123
|
+
resetMetrics(): void;
|
|
124
|
+
}
|
|
125
|
+
export { StorageManager };
|