@vlian/framework 1.2.59 → 1.2.60
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/dist/analytics/index.cjs +1 -22
- package/dist/analytics.umd.js +1 -1
- package/dist/components/LocaleSwitch.cjs +1 -116
- package/dist/components/ThemeSwitch.cjs +1 -115
- package/dist/components/index.cjs +1 -20
- package/dist/components/persistence.cjs +1 -58
- package/dist/core/Test.cjs +1 -64
- package/dist/core/app/AppContext.cjs +1 -348
- package/dist/core/app/AppContext.types.cjs +1 -4
- package/dist/core/app/BasicLayout.cjs +1 -122
- package/dist/core/app/DefaultApp.cjs +1 -150
- package/dist/core/app/index.cjs +1 -41
- package/dist/core/config/AppConfig.cjs +1 -139
- package/dist/core/config/ConfigLoader.cjs +1 -323
- package/dist/core/config/ConfigValidator.cjs +2 -133
- package/dist/core/config/index.cjs +1 -28
- package/dist/core/dev/DevTools.cjs +1 -226
- package/dist/core/error/ErrorBoundary.cjs +1 -401
- package/dist/core/error/ErrorHandler.cjs +1 -275
- package/dist/core/error/index.cjs +1 -34
- package/dist/core/event/AppEventBus.cjs +1 -444
- package/dist/core/event/frameworkEvents.cjs +1 -141
- package/dist/core/event/hooks.cjs +1 -69
- package/dist/core/event/index.cjs +1 -41
- package/dist/core/event/types.cjs +1 -62
- package/dist/core/event/useEventBus.cjs +1 -25
- package/dist/core/index.cjs +1 -140
- package/dist/core/initialization/InitializationErrorThrower.cjs +1 -75
- package/dist/core/initialization/index.cjs +1 -26
- package/dist/core/initialization/initialization.cjs +1 -64
- package/dist/core/initialization/initializationErrorState.cjs +1 -66
- package/dist/core/kernel/defaultAdapters.cjs +1 -184
- package/dist/core/kernel/errors.cjs +1 -69
- package/dist/core/kernel/index.cjs +1 -20
- package/dist/core/kernel/startKernel.cjs +1 -200
- package/dist/core/kernel/types.cjs +1 -4
- package/dist/core/middleware.cjs +1 -73
- package/dist/core/plugin/PluginEventBus.cjs +1 -298
- package/dist/core/plugin/PluginSandbox.cjs +1 -137
- package/dist/core/plugin.cjs +1 -494
- package/dist/core/router/RouterManager.cjs +1 -286
- package/dist/core/router/adapter/AdapterManager.cjs +1 -235
- package/dist/core/router/adapter/index.cjs +1 -22
- package/dist/core/router/adapter/react-router/ReactRouterAdapter.cjs +1 -128
- package/dist/core/router/adapter/react-router/index.cjs +1 -20
- package/dist/core/router/adapter/types.cjs +1 -6
- package/dist/core/router/dev/RouterDevTools.cjs +1 -260
- package/dist/core/router/dev/index.cjs +1 -20
- package/dist/core/router/dynamic/DynamicRouteManager.cjs +1 -193
- package/dist/core/router/dynamic/index.cjs +1 -20
- package/dist/core/router/errors/RouterError.cjs +1 -61
- package/dist/core/router/errors/index.cjs +1 -20
- package/dist/core/router/index.cjs +1 -36
- package/dist/core/router/lifecycle/RouterLifecycleManager.cjs +1 -144
- package/dist/core/router/lifecycle/index.cjs +1 -20
- package/dist/core/router/middleware/RouterMiddlewareManager.cjs +1 -193
- package/dist/core/router/middleware/auth.cjs +1 -66
- package/dist/core/router/middleware/index.cjs +1 -22
- package/dist/core/router/middleware/types.cjs +1 -6
- package/dist/core/router/monitoring/RouterMonitoring.cjs +1 -227
- package/dist/core/router/monitoring/index.cjs +1 -20
- package/dist/core/router/navigation/RouterNavigation.cjs +1 -239
- package/dist/core/router/navigation/index.cjs +1 -20
- package/dist/core/router/performance/RouteCache.cjs +1 -305
- package/dist/core/router/performance/RoutePreloader.cjs +1 -292
- package/dist/core/router/performance/index.cjs +1 -21
- package/dist/core/router/plugin/RouterPluginManager.cjs +1 -262
- package/dist/core/router/plugin/index.cjs +1 -21
- package/dist/core/router/plugin/types.cjs +1 -39
- package/dist/core/router/types.cjs +1 -4
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +1 -129
- package/dist/core/router/utils/adapters/react-router/transform.cjs +1 -250
- package/dist/core/router/utils/transform.cjs +1 -780
- package/dist/core/router/validation/RouterConfigValidator.cjs +2 -83
- package/dist/core/router/validation/index.cjs +1 -21
- package/dist/core/router/validation/schema.cjs +1 -159
- package/dist/core/router/version/RouteVersionManager.cjs +1 -205
- package/dist/core/router/version/index.cjs +1 -20
- package/dist/core/splash/SplashScreen.cjs +1 -341
- package/dist/core/splash/index.cjs +1 -22
- package/dist/core/splash/splashScreenUtils.cjs +1 -38
- package/dist/core/startup/AppInstance.cjs +1 -239
- package/dist/core/startup/environment.cjs +1 -169
- package/dist/core/startup/index.cjs +1 -23
- package/dist/core/startup/initializeServices.cjs +1 -226
- package/dist/core/startup/performanceTracker.cjs +1 -179
- package/dist/core/startup/renderApp.cjs +1 -314
- package/dist/core/startup/startApp.cjs +1 -317
- package/dist/core/types.cjs +1 -4
- package/dist/index.cjs +1 -52
- package/dist/index.umd.cjs +1 -27
- package/dist/index.umd.js +1 -1
- package/dist/kernel/constants.cjs +1 -65
- package/dist/kernel/index.cjs +1 -38
- package/dist/kernel/kernel.cjs +1 -295
- package/dist/kernel/manager/cacheManager.cjs +1 -46
- package/dist/kernel/manager/i18n/I18nManager.cjs +1 -91
- package/dist/kernel/manager/i18n/i18n.persistence.cjs +1 -60
- package/dist/kernel/manager/i18n/i18n.schema.cjs +1 -86
- package/dist/kernel/manager/i18n/index.cjs +1 -11
- package/dist/kernel/manager/i18nManager.cjs +1 -11
- package/dist/kernel/manager/index.cjs +1 -28
- package/dist/kernel/manager/logger/LoggerManager.cjs +1 -107
- package/dist/kernel/manager/logger/index.cjs +1 -11
- package/dist/kernel/manager/logger/logger.persistence.cjs +1 -62
- package/dist/kernel/manager/logger/logger.schema.cjs +1 -74
- package/dist/kernel/manager/loggerManager.cjs +1 -11
- package/dist/kernel/manager/theme/ThemeManager.cjs +1 -84
- package/dist/kernel/manager/theme/index.cjs +1 -11
- package/dist/kernel/manager/theme/theme.dom.cjs +1 -61
- package/dist/kernel/manager/theme/theme.persistence.cjs +1 -57
- package/dist/kernel/manager/theme/theme.schema.cjs +1 -122
- package/dist/kernel/manager/themeManager.cjs +1 -11
- package/dist/kernel/types.cjs +1 -4
- package/dist/library/index.cjs +1 -19
- package/dist/library/locale/index.cjs +1 -39
- package/dist/library/locale/langs/en-us/index.cjs +1 -32
- package/dist/library/locale/langs/zh-cn/index.cjs +1 -32
- package/dist/library/locale/types.cjs +1 -4
- package/dist/library/storage/cache.cjs +1 -243
- package/dist/library/storage/encryption.cjs +1 -147
- package/dist/library/storage/index.cjs +1 -124
- package/dist/state/StateManager.cjs +1 -166
- package/dist/state/adapters/AdapterFactory.cjs +1 -89
- package/dist/state/adapters/DefaultAdapter.cjs +1 -75
- package/dist/state/adapters/ReduxAdapter.cjs +1 -443
- package/dist/state/adapters/ZustandAdapter.cjs +1 -69
- package/dist/state/adapters/index.cjs +1 -44
- package/dist/state/adapters/types.cjs +1 -20
- package/dist/state/core/DerivedStateInstance.cjs +1 -174
- package/dist/state/core/StateInstance.cjs +1 -170
- package/dist/state/core/StateRegistry.cjs +1 -110
- package/dist/state/core/StateScope.cjs +1 -137
- package/dist/state/core/index.cjs +1 -30
- package/dist/state/index.cjs +1 -30
- package/dist/state/types.cjs +1 -12
- package/dist/state.umd.js +1 -1
- package/dist/types.cjs +1 -4
- package/dist/utils/analytics.cjs +1 -217
- package/dist/utils/configSecurity.cjs +3 -182
- package/dist/utils/csrf.cjs +1 -18
- package/dist/utils/errors/ErrorCodes.cjs +1 -25
- package/dist/utils/errors.cjs +1 -111
- package/dist/utils/index.cjs +1 -135
- package/dist/utils/logger.cjs +1 -25
- package/dist/utils/logger.types.cjs +1 -11
- package/dist/utils/monitoring.cjs +1 -18
- package/dist/utils/performance.cjs +1 -22
- package/dist/utils/resourceLoader.cjs +1 -22
- package/dist/utils/runtimeSecurity.cjs +1 -11
- package/dist/utils/security.cjs +1 -19
- package/dist/utils/traceId.cjs +1 -37
- package/dist/utils/validation.cjs +1 -19
- package/package.json +7 -3
|
@@ -1,128 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* React Router 适配器实现
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
function _export(target, all) {
|
|
8
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
_export(exports, {
|
|
14
|
-
get ReactRouterAdapter () {
|
|
15
|
-
return ReactRouterAdapter;
|
|
16
|
-
},
|
|
17
|
-
get createReactRouterAdapter () {
|
|
18
|
-
return createReactRouterAdapter;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
const _reactrouterdom = require("react-router-dom");
|
|
22
|
-
const _transform = require("../../utils/adapters/react-router/transform");
|
|
23
|
-
const _transform1 = require("../../utils/transform");
|
|
24
|
-
const _logger = require("@vlian/logger");
|
|
25
|
-
function _define_property(obj, key, value) {
|
|
26
|
-
if (key in obj) {
|
|
27
|
-
Object.defineProperty(obj, key, {
|
|
28
|
-
value: value,
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
obj[key] = value;
|
|
35
|
-
}
|
|
36
|
-
return obj;
|
|
37
|
-
}
|
|
38
|
-
let ReactRouterAdapter = class ReactRouterAdapter {
|
|
39
|
-
/**
|
|
40
|
-
* 初始化适配器
|
|
41
|
-
*/ async initialize(config) {
|
|
42
|
-
// 转换路由配置
|
|
43
|
-
const transformResult = await (0, _transform1.transformRoutes)(config.routes);
|
|
44
|
-
const reactRoutes = await (0, _transform.transformRoutesToReactRoutes)(transformResult.routes, transformResult, config.defaultRouteErrorComponent, config.defaultRouteLoadingComponent, Boolean(config.options?.hydrationData));
|
|
45
|
-
// 创建路由实例
|
|
46
|
-
const mode = config.mode || 'browser';
|
|
47
|
-
if (mode === 'browser') {
|
|
48
|
-
this.router = (0, _reactrouterdom.createBrowserRouter)(reactRoutes, config.options);
|
|
49
|
-
} else if (mode === 'hash') {
|
|
50
|
-
this.router = (0, _reactrouterdom.createHashRouter)(reactRoutes, config.options);
|
|
51
|
-
} else if (mode === 'memory') {
|
|
52
|
-
this.router = (0, _reactrouterdom.createMemoryRouter)(reactRoutes, config.options);
|
|
53
|
-
} else {
|
|
54
|
-
throw new Error(`不支持的路由模式: ${mode}`);
|
|
55
|
-
}
|
|
56
|
-
_logger.logger.debug('React Router 适配器初始化完成');
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* 挂载到应用实例
|
|
60
|
-
*/ mount(_app) {
|
|
61
|
-
if (!this.router) {
|
|
62
|
-
throw new Error('适配器未初始化');
|
|
63
|
-
}
|
|
64
|
-
// React Router 适配器通过 RouterProvider 挂载
|
|
65
|
-
// 实际的挂载逻辑在 renderApp 中处理
|
|
66
|
-
_logger.logger.debug('React Router 适配器已挂载');
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* 导航到指定路径
|
|
70
|
-
*/ navigate(to, options) {
|
|
71
|
-
if (!this.router) {
|
|
72
|
-
throw new Error('适配器未初始化');
|
|
73
|
-
}
|
|
74
|
-
if (options?.replace) {
|
|
75
|
-
this.router.navigate(to, {
|
|
76
|
-
replace: true,
|
|
77
|
-
state: options.state
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
this.router.navigate(to, {
|
|
81
|
-
state: options?.state
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* 获取当前路由信息
|
|
87
|
-
*/ getCurrentRoute() {
|
|
88
|
-
if (!this.router) {
|
|
89
|
-
throw new Error('适配器未初始化');
|
|
90
|
-
}
|
|
91
|
-
const state = this.router.state;
|
|
92
|
-
const location = state.location;
|
|
93
|
-
// 解析查询参数
|
|
94
|
-
const query = {};
|
|
95
|
-
if (location.search) {
|
|
96
|
-
const params = new URLSearchParams(location.search);
|
|
97
|
-
params.forEach((value, key)=>{
|
|
98
|
-
query[key] = value;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
path: location.pathname + location.hash,
|
|
103
|
-
query,
|
|
104
|
-
params: location.state
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 获取路由实例(用于 RouterProvider)
|
|
109
|
-
*/ getRouter() {
|
|
110
|
-
return this.router;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* 销毁适配器
|
|
114
|
-
*/ destroy() {
|
|
115
|
-
this.router = null;
|
|
116
|
-
_logger.logger.debug('React Router 适配器已销毁');
|
|
117
|
-
}
|
|
118
|
-
constructor(){
|
|
119
|
-
_define_property(this, "name", 'react-router');
|
|
120
|
-
_define_property(this, "version", '6.0.0');
|
|
121
|
-
_define_property(this, "router", null);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
function createReactRouterAdapter() {
|
|
125
|
-
return (_config)=>{
|
|
126
|
-
return new ReactRouterAdapter();
|
|
127
|
-
};
|
|
128
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get ReactRouterAdapter(){return ReactRouterAdapter},get createReactRouterAdapter(){return createReactRouterAdapter}});const _reactrouterdom=require("react-router-dom");const _transform=require("../../utils/adapters/react-router/transform");const _transform1=require("../../utils/transform");const _logger=require("@vlian/logger");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let ReactRouterAdapter=class ReactRouterAdapter{async initialize(config){const transformResult=await (0,_transform1.transformRoutes)(config.routes);const reactRoutes=await (0,_transform.transformRoutesToReactRoutes)(transformResult.routes,transformResult,config.defaultRouteErrorComponent,config.defaultRouteLoadingComponent,Boolean(config.options?.hydrationData));const mode=config.mode||"browser";if(mode==="browser"){this.router=(0,_reactrouterdom.createBrowserRouter)(reactRoutes,config.options)}else if(mode==="hash"){this.router=(0,_reactrouterdom.createHashRouter)(reactRoutes,config.options)}else if(mode==="memory"){this.router=(0,_reactrouterdom.createMemoryRouter)(reactRoutes,config.options)}else{throw new Error(`不支持的路由模式: ${mode}`)}_logger.logger.debug("React Router 适配器初始化完成")}mount(_app){if(!this.router){throw new Error("适配器未初始化")}_logger.logger.debug("React Router 适配器已挂载")}navigate(to,options){if(!this.router){throw new Error("适配器未初始化")}if(options?.replace){this.router.navigate(to,{replace:true,state:options.state})}else{this.router.navigate(to,{state:options?.state})}}getCurrentRoute(){if(!this.router){throw new Error("适配器未初始化")}const state=this.router.state;const location=state.location;const query={};if(location.search){const params=new URLSearchParams(location.search);params.forEach((value,key)=>{query[key]=value})}return{path:location.pathname+location.hash,query,params:location.state}}getRouter(){return this.router}destroy(){this.router=null;_logger.logger.debug("React Router 适配器已销毁")}constructor(){_define_property(this,"name","react-router");_define_property(this,"version","6.0.0");_define_property(this,"router",null)}};function createReactRouterAdapter(){return _config=>{return new ReactRouterAdapter}}
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* React Router 适配器模块入口
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
_export_star(require("./ReactRouterAdapter"), exports);
|
|
8
|
-
function _export_star(from, to) {
|
|
9
|
-
Object.keys(from).forEach(function(k) {
|
|
10
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
-
Object.defineProperty(to, k, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function() {
|
|
14
|
-
return from[k];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return from;
|
|
20
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("./ReactRouterAdapter"),exports);function _export_star(from,to){Object.keys(from).forEach(function(k){if(k!=="default"&&!Object.prototype.hasOwnProperty.call(to,k)){Object.defineProperty(to,k,{enumerable:true,get:function(){return from[k]}})}});return from}
|
|
@@ -1,260 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 路由调试工具(开发环境,无 UI 框架依赖)
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
Object.defineProperty(exports, "RouterDevTools", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function() {
|
|
10
|
-
return RouterDevTools;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
14
|
-
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
15
|
-
const _RouterManager = require("../RouterManager");
|
|
16
|
-
const _lifecycle = require("../lifecycle");
|
|
17
|
-
const _middleware = require("../middleware");
|
|
18
|
-
const _navigation = require("../navigation");
|
|
19
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
20
|
-
if (typeof WeakMap !== "function") return null;
|
|
21
|
-
var cacheBabelInterop = new WeakMap();
|
|
22
|
-
var cacheNodeInterop = new WeakMap();
|
|
23
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
24
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
25
|
-
})(nodeInterop);
|
|
26
|
-
}
|
|
27
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
28
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
32
|
-
return {
|
|
33
|
-
default: obj
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
37
|
-
if (cache && cache.has(obj)) {
|
|
38
|
-
return cache.get(obj);
|
|
39
|
-
}
|
|
40
|
-
var newObj = {
|
|
41
|
-
__proto__: null
|
|
42
|
-
};
|
|
43
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
44
|
-
for(var key in obj){
|
|
45
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
46
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
47
|
-
if (desc && (desc.get || desc.set)) {
|
|
48
|
-
Object.defineProperty(newObj, key, desc);
|
|
49
|
-
} else {
|
|
50
|
-
newObj[key] = obj[key];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
newObj.default = obj;
|
|
55
|
-
if (cache) {
|
|
56
|
-
cache.set(obj, newObj);
|
|
57
|
-
}
|
|
58
|
-
return newObj;
|
|
59
|
-
}
|
|
60
|
-
function pretty(value) {
|
|
61
|
-
try {
|
|
62
|
-
return JSON.stringify(value, null, 2);
|
|
63
|
-
} catch {
|
|
64
|
-
return String(value);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function RouterDevTools() {
|
|
68
|
-
if (process.env.NODE_ENV !== 'development') {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
const [visible, setVisible] = (0, _react.useState)(false);
|
|
72
|
-
const [currentRoute, setCurrentRoute] = (0, _react.useState)(null);
|
|
73
|
-
const [routeState, setRouteState] = (0, _react.useState)({});
|
|
74
|
-
const [lifecycleHooks, setLifecycleHooks] = (0, _react.useState)([]);
|
|
75
|
-
const [middlewares, setMiddlewares] = (0, _react.useState)([]);
|
|
76
|
-
const updateRouteInfo = ()=>{
|
|
77
|
-
try {
|
|
78
|
-
const route = _navigation.RouterNavigation.getCurrentRoute();
|
|
79
|
-
setCurrentRoute(route);
|
|
80
|
-
const router = (0, _RouterManager.getRouterManager)().getRouter();
|
|
81
|
-
if (router) {
|
|
82
|
-
const state = router.state;
|
|
83
|
-
setRouteState({
|
|
84
|
-
pathname: state.location.pathname,
|
|
85
|
-
search: state.location.search || '',
|
|
86
|
-
hash: state.location.hash || '',
|
|
87
|
-
state: state.location.state || {}
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
90
|
-
setRouteState({});
|
|
91
|
-
}
|
|
92
|
-
const hooks = (0, _lifecycle.getRouterLifecycleManager)().getAll();
|
|
93
|
-
setLifecycleHooks(hooks.map((hook, index)=>({
|
|
94
|
-
key: index,
|
|
95
|
-
hasBeforeEach: !!hook.beforeEach,
|
|
96
|
-
hasAfterEach: !!hook.afterEach
|
|
97
|
-
})));
|
|
98
|
-
const middlewareList = (0, _middleware.getRouterMiddlewareManager)().getAll();
|
|
99
|
-
setMiddlewares(middlewareList.map((m, index)=>({
|
|
100
|
-
key: index,
|
|
101
|
-
name: m.name || `middleware-${index}`,
|
|
102
|
-
priority: m.priority || 100,
|
|
103
|
-
enabled: m.enabled !== false
|
|
104
|
-
})));
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error('更新路由信息失败', error);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
(0, _react.useEffect)(()=>{
|
|
110
|
-
if (!visible) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
updateRouteInfo();
|
|
114
|
-
const timer = setInterval(updateRouteInfo, 1000);
|
|
115
|
-
return ()=>clearInterval(timer);
|
|
116
|
-
}, [
|
|
117
|
-
visible
|
|
118
|
-
]);
|
|
119
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
120
|
-
children: [
|
|
121
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
122
|
-
type: "button",
|
|
123
|
-
onClick: ()=>setVisible(true),
|
|
124
|
-
style: {
|
|
125
|
-
position: 'fixed',
|
|
126
|
-
right: 20,
|
|
127
|
-
bottom: 20,
|
|
128
|
-
zIndex: 9999,
|
|
129
|
-
border: 'none',
|
|
130
|
-
background: '#2f80ed',
|
|
131
|
-
color: '#fff',
|
|
132
|
-
borderRadius: 999,
|
|
133
|
-
padding: '8px 12px',
|
|
134
|
-
cursor: 'pointer'
|
|
135
|
-
},
|
|
136
|
-
children: "路由调试"
|
|
137
|
-
}),
|
|
138
|
-
visible && /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
139
|
-
style: {
|
|
140
|
-
position: 'fixed',
|
|
141
|
-
top: 0,
|
|
142
|
-
right: 0,
|
|
143
|
-
width: 'min(800px, 96vw)',
|
|
144
|
-
height: '100vh',
|
|
145
|
-
zIndex: 10000,
|
|
146
|
-
background: '#fff',
|
|
147
|
-
borderLeft: '1px solid #d9e2ec',
|
|
148
|
-
boxShadow: '-8px 0 20px rgba(0, 0, 0, 0.08)',
|
|
149
|
-
padding: 16,
|
|
150
|
-
overflowY: 'auto'
|
|
151
|
-
},
|
|
152
|
-
children: [
|
|
153
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
154
|
-
style: {
|
|
155
|
-
display: 'flex',
|
|
156
|
-
justifyContent: 'space-between',
|
|
157
|
-
alignItems: 'center'
|
|
158
|
-
},
|
|
159
|
-
children: [
|
|
160
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h3", {
|
|
161
|
-
style: {
|
|
162
|
-
margin: 0
|
|
163
|
-
},
|
|
164
|
-
children: "路由调试工具"
|
|
165
|
-
}),
|
|
166
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
167
|
-
style: {
|
|
168
|
-
display: 'flex',
|
|
169
|
-
gap: 8
|
|
170
|
-
},
|
|
171
|
-
children: [
|
|
172
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
173
|
-
onClick: updateRouteInfo,
|
|
174
|
-
children: "刷新"
|
|
175
|
-
}),
|
|
176
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
177
|
-
onClick: ()=>setVisible(false),
|
|
178
|
-
children: "关闭"
|
|
179
|
-
})
|
|
180
|
-
]
|
|
181
|
-
})
|
|
182
|
-
]
|
|
183
|
-
}),
|
|
184
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("section", {
|
|
185
|
-
style: {
|
|
186
|
-
marginTop: 12
|
|
187
|
-
},
|
|
188
|
-
children: [
|
|
189
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h4", {
|
|
190
|
-
children: "当前路由"
|
|
191
|
-
}),
|
|
192
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("pre", {
|
|
193
|
-
style: {
|
|
194
|
-
background: '#f7fafc',
|
|
195
|
-
borderRadius: 8,
|
|
196
|
-
padding: 12
|
|
197
|
-
},
|
|
198
|
-
children: pretty(currentRoute || {})
|
|
199
|
-
})
|
|
200
|
-
]
|
|
201
|
-
}),
|
|
202
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("section", {
|
|
203
|
-
style: {
|
|
204
|
-
marginTop: 12
|
|
205
|
-
},
|
|
206
|
-
children: [
|
|
207
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h4", {
|
|
208
|
-
children: "路由状态"
|
|
209
|
-
}),
|
|
210
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("pre", {
|
|
211
|
-
style: {
|
|
212
|
-
background: '#f7fafc',
|
|
213
|
-
borderRadius: 8,
|
|
214
|
-
padding: 12
|
|
215
|
-
},
|
|
216
|
-
children: pretty(routeState)
|
|
217
|
-
})
|
|
218
|
-
]
|
|
219
|
-
}),
|
|
220
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("section", {
|
|
221
|
-
style: {
|
|
222
|
-
marginTop: 12
|
|
223
|
-
},
|
|
224
|
-
children: [
|
|
225
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h4", {
|
|
226
|
-
children: "生命周期钩子"
|
|
227
|
-
}),
|
|
228
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("pre", {
|
|
229
|
-
style: {
|
|
230
|
-
background: '#f7fafc',
|
|
231
|
-
borderRadius: 8,
|
|
232
|
-
padding: 12
|
|
233
|
-
},
|
|
234
|
-
children: pretty(lifecycleHooks)
|
|
235
|
-
})
|
|
236
|
-
]
|
|
237
|
-
}),
|
|
238
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("section", {
|
|
239
|
-
style: {
|
|
240
|
-
marginTop: 12
|
|
241
|
-
},
|
|
242
|
-
children: [
|
|
243
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("h4", {
|
|
244
|
-
children: "中间件"
|
|
245
|
-
}),
|
|
246
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("pre", {
|
|
247
|
-
style: {
|
|
248
|
-
background: '#f7fafc',
|
|
249
|
-
borderRadius: 8,
|
|
250
|
-
padding: 12
|
|
251
|
-
},
|
|
252
|
-
children: pretty(middlewares)
|
|
253
|
-
})
|
|
254
|
-
]
|
|
255
|
-
})
|
|
256
|
-
]
|
|
257
|
-
})
|
|
258
|
-
]
|
|
259
|
-
});
|
|
260
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"RouterDevTools",{enumerable:true,get:function(){return RouterDevTools}});const _jsxruntime=require("react/jsx-runtime");const _react=/*#__PURE__*/_interop_require_wildcard(require("react"));const _RouterManager=require("../RouterManager");const _lifecycle=require("../lifecycle");const _middleware=require("../middleware");const _navigation=require("../navigation");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interop_require_wildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={__proto__:null};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}function pretty(value){try{return JSON.stringify(value,null,2)}catch{return String(value)}}function RouterDevTools(){if(process.env.NODE_ENV!=="development"){return null}const[visible,setVisible]=(0,_react.useState)(false);const[currentRoute,setCurrentRoute]=(0,_react.useState)(null);const[routeState,setRouteState]=(0,_react.useState)({});const[lifecycleHooks,setLifecycleHooks]=(0,_react.useState)([]);const[middlewares,setMiddlewares]=(0,_react.useState)([]);const updateRouteInfo=()=>{try{const route=_navigation.RouterNavigation.getCurrentRoute();setCurrentRoute(route);const router=(0,_RouterManager.getRouterManager)().getRouter();if(router){const state=router.state;setRouteState({pathname:state.location.pathname,search:state.location.search||"",hash:state.location.hash||"",state:state.location.state||{}})}else{setRouteState({})}const hooks=(0,_lifecycle.getRouterLifecycleManager)().getAll();setLifecycleHooks(hooks.map((hook,index)=>({key:index,hasBeforeEach:!!hook.beforeEach,hasAfterEach:!!hook.afterEach})));const middlewareList=(0,_middleware.getRouterMiddlewareManager)().getAll();setMiddlewares(middlewareList.map((m,index)=>({key:index,name:m.name||`middleware-${index}`,priority:m.priority||100,enabled:m.enabled!==false})))}catch(error){console.error("更新路由信息失败",error)}};(0,_react.useEffect)(()=>{if(!visible){return}updateRouteInfo();const timer=setInterval(updateRouteInfo,1e3);return()=>clearInterval(timer)},[visible]);return(0,_jsxruntime.jsxs)(_jsxruntime.Fragment,{children:[(0,_jsxruntime.jsx)("button",{type:"button",onClick:()=>setVisible(true),style:{position:"fixed",right:20,bottom:20,zIndex:9999,border:"none",background:"#2f80ed",color:"#fff",borderRadius:999,padding:"8px 12px",cursor:"pointer"},children:"路由调试"}),visible&&(0,_jsxruntime.jsxs)("div",{style:{position:"fixed",top:0,right:0,width:"min(800px, 96vw)",height:"100vh",zIndex:1e4,background:"#fff",borderLeft:"1px solid #d9e2ec",boxShadow:"-8px 0 20px rgba(0, 0, 0, 0.08)",padding:16,overflowY:"auto"},children:[(0,_jsxruntime.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,_jsxruntime.jsx)("h3",{style:{margin:0},children:"路由调试工具"}),(0,_jsxruntime.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,_jsxruntime.jsx)("button",{onClick:updateRouteInfo,children:"刷新"}),(0,_jsxruntime.jsx)("button",{onClick:()=>setVisible(false),children:"关闭"})]})]}),(0,_jsxruntime.jsxs)("section",{style:{marginTop:12},children:[(0,_jsxruntime.jsx)("h4",{children:"当前路由"}),(0,_jsxruntime.jsx)("pre",{style:{background:"#f7fafc",borderRadius:8,padding:12},children:pretty(currentRoute||{})})]}),(0,_jsxruntime.jsxs)("section",{style:{marginTop:12},children:[(0,_jsxruntime.jsx)("h4",{children:"路由状态"}),(0,_jsxruntime.jsx)("pre",{style:{background:"#f7fafc",borderRadius:8,padding:12},children:pretty(routeState)})]}),(0,_jsxruntime.jsxs)("section",{style:{marginTop:12},children:[(0,_jsxruntime.jsx)("h4",{children:"生命周期钩子"}),(0,_jsxruntime.jsx)("pre",{style:{background:"#f7fafc",borderRadius:8,padding:12},children:pretty(lifecycleHooks)})]}),(0,_jsxruntime.jsxs)("section",{style:{marginTop:12},children:[(0,_jsxruntime.jsx)("h4",{children:"中间件"}),(0,_jsxruntime.jsx)("pre",{style:{background:"#f7fafc",borderRadius:8,padding:12},children:pretty(middlewares)})]})]})]})}
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 路由开发工具模块入口
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
_export_star(require("./RouterDevTools"), exports);
|
|
8
|
-
function _export_star(from, to) {
|
|
9
|
-
Object.keys(from).forEach(function(k) {
|
|
10
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
-
Object.defineProperty(to, k, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function() {
|
|
14
|
-
return from[k];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return from;
|
|
20
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("./RouterDevTools"),exports);function _export_star(from,to){Object.keys(from).forEach(function(k){if(k!=="default"&&!Object.prototype.hasOwnProperty.call(to,k)){Object.defineProperty(to,k,{enumerable:true,get:function(){return from[k]}})}});return from}
|
|
@@ -1,193 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 路由动态注册管理器
|
|
3
|
-
* 支持运行时动态注册和卸载路由
|
|
4
|
-
*/ "use strict";
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
function _export(target, all) {
|
|
9
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
_export(exports, {
|
|
15
|
-
get DynamicRouteManager () {
|
|
16
|
-
return DynamicRouteManager;
|
|
17
|
-
},
|
|
18
|
-
get getDynamicRouteManager () {
|
|
19
|
-
return getDynamicRouteManager;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _logger = require("@vlian/logger");
|
|
23
|
-
const _RouterManager = require("../RouterManager");
|
|
24
|
-
const _transform = require("../utils/transform");
|
|
25
|
-
const _errors = require("../errors");
|
|
26
|
-
function _define_property(obj, key, value) {
|
|
27
|
-
if (key in obj) {
|
|
28
|
-
Object.defineProperty(obj, key, {
|
|
29
|
-
value: value,
|
|
30
|
-
enumerable: true,
|
|
31
|
-
configurable: true,
|
|
32
|
-
writable: true
|
|
33
|
-
});
|
|
34
|
-
} else {
|
|
35
|
-
obj[key] = value;
|
|
36
|
-
}
|
|
37
|
-
return obj;
|
|
38
|
-
}
|
|
39
|
-
let DynamicRouteManager = class DynamicRouteManager {
|
|
40
|
-
/**
|
|
41
|
-
* 注册路由
|
|
42
|
-
*
|
|
43
|
-
* @param routes - 要注册的路由配置
|
|
44
|
-
* @param namespace - 路由命名空间(可选,用于分组管理)
|
|
45
|
-
* @returns 取消注册函数
|
|
46
|
-
*/ async register(routes, namespace) {
|
|
47
|
-
const ns = namespace || 'default';
|
|
48
|
-
// 验证路由配置
|
|
49
|
-
if (!Array.isArray(routes) || routes.length === 0) {
|
|
50
|
-
throw new _errors.RouterError('路由配置必须是非空数组', _errors.RouterErrorCode.ROUTER_CONFIG_ERROR);
|
|
51
|
-
}
|
|
52
|
-
// 检查路由名称是否冲突
|
|
53
|
-
const existingRoutes = this.registeredRoutes.get(ns) || [];
|
|
54
|
-
const existingNames = new Set(existingRoutes.map((r)=>r.name));
|
|
55
|
-
const newNames = routes.map((r)=>r.name);
|
|
56
|
-
const conflicts = newNames.filter((name)=>existingNames.has(name));
|
|
57
|
-
if (conflicts.length > 0) {
|
|
58
|
-
throw new _errors.RouterError(`路由名称冲突: ${conflicts.join(', ')}`, _errors.RouterErrorCode.ROUTER_CONFIG_ERROR, undefined, undefined, {
|
|
59
|
-
conflicts,
|
|
60
|
-
namespace: ns
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
// 添加到注册表
|
|
64
|
-
const currentRoutes = this.registeredRoutes.get(ns) || [];
|
|
65
|
-
this.registeredRoutes.set(ns, [
|
|
66
|
-
...currentRoutes,
|
|
67
|
-
...routes
|
|
68
|
-
]);
|
|
69
|
-
// 更新版本号
|
|
70
|
-
this.routeVersion++;
|
|
71
|
-
_logger.logger.info(`路由已注册: ${routes.length} 个路由到命名空间 "${ns}"`);
|
|
72
|
-
// 返回取消注册函数
|
|
73
|
-
return async ()=>{
|
|
74
|
-
await this.unregister(routes.map((r)=>r.name), ns);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 取消注册路由
|
|
79
|
-
*
|
|
80
|
-
* @param routeNames - 要取消注册的路由名称数组
|
|
81
|
-
* @param namespace - 路由命名空间(可选)
|
|
82
|
-
*/ async unregister(routeNames, namespace) {
|
|
83
|
-
const ns = namespace || 'default';
|
|
84
|
-
const routes = this.registeredRoutes.get(ns) || [];
|
|
85
|
-
// 过滤掉要取消注册的路由
|
|
86
|
-
const filteredRoutes = routes.filter((r)=>!routeNames.includes(r.name));
|
|
87
|
-
if (filteredRoutes.length === routes.length) {
|
|
88
|
-
_logger.logger.warn(`未找到要取消注册的路由: ${routeNames.join(', ')}`);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
// 更新注册表
|
|
92
|
-
if (filteredRoutes.length === 0) {
|
|
93
|
-
this.registeredRoutes.delete(ns);
|
|
94
|
-
} else {
|
|
95
|
-
this.registeredRoutes.set(ns, filteredRoutes);
|
|
96
|
-
}
|
|
97
|
-
// 更新版本号
|
|
98
|
-
this.routeVersion++;
|
|
99
|
-
_logger.logger.info(`路由已取消注册: ${routeNames.length} 个路由从命名空间 "${ns}"`);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 获取指定命名空间的路由
|
|
103
|
-
*
|
|
104
|
-
* @param namespace - 路由命名空间(可选)
|
|
105
|
-
* @returns 路由配置数组
|
|
106
|
-
*/ getRoutes(namespace) {
|
|
107
|
-
const ns = namespace || 'default';
|
|
108
|
-
return [
|
|
109
|
-
...this.registeredRoutes.get(ns) || []
|
|
110
|
-
];
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* 获取所有路由
|
|
114
|
-
*
|
|
115
|
-
* @returns 所有命名空间的路由配置
|
|
116
|
-
*/ getAllRoutes() {
|
|
117
|
-
return new Map(this.registeredRoutes);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 清空指定命名空间的路由
|
|
121
|
-
*
|
|
122
|
-
* @param namespace - 路由命名空间(可选)
|
|
123
|
-
*/ clear(namespace) {
|
|
124
|
-
const ns = namespace || 'default';
|
|
125
|
-
this.registeredRoutes.delete(ns);
|
|
126
|
-
this.routeVersion++;
|
|
127
|
-
_logger.logger.info(`路由命名空间已清空: "${ns}"`);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* 清空所有路由
|
|
131
|
-
*/ clearAll() {
|
|
132
|
-
this.registeredRoutes.clear();
|
|
133
|
-
this.routeVersion++;
|
|
134
|
-
_logger.logger.info('所有路由已清空');
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* 获取路由版本号
|
|
138
|
-
*
|
|
139
|
-
* @returns 路由版本号
|
|
140
|
-
*/ getVersion() {
|
|
141
|
-
return this.routeVersion;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* 检查路由是否已注册
|
|
145
|
-
*
|
|
146
|
-
* @param routeName - 路由名称
|
|
147
|
-
* @param namespace - 路由命名空间(可选)
|
|
148
|
-
* @returns 如果已注册返回 true,否则返回 false
|
|
149
|
-
*/ isRegistered(routeName, namespace) {
|
|
150
|
-
const ns = namespace || 'default';
|
|
151
|
-
const routes = this.registeredRoutes.get(ns) || [];
|
|
152
|
-
return routes.some((r)=>r.name === routeName);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* 重新加载路由
|
|
156
|
-
*
|
|
157
|
-
* 注意:此方法会重新初始化路由管理器,需要谨慎使用
|
|
158
|
-
*/ async reload() {
|
|
159
|
-
const routerManager = (0, _RouterManager.getRouterManager)();
|
|
160
|
-
if (!routerManager.isInitialized()) {
|
|
161
|
-
throw new _errors.RouterError('路由管理器未初始化', _errors.RouterErrorCode.ROUTER_NOT_INITIALIZED);
|
|
162
|
-
}
|
|
163
|
-
// 获取所有路由
|
|
164
|
-
const allRoutes = [];
|
|
165
|
-
this.registeredRoutes.forEach((routes)=>{
|
|
166
|
-
allRoutes.push(...routes);
|
|
167
|
-
});
|
|
168
|
-
if (allRoutes.length === 0) {
|
|
169
|
-
_logger.logger.warn('没有已注册的路由,无法重新加载');
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
// 转换路由
|
|
173
|
-
await (0, _transform.transformRoutes)(allRoutes);
|
|
174
|
-
// const reactRoutes = await transformRoutesToReactRoutes(result.routes, result);
|
|
175
|
-
// 重新创建路由实例
|
|
176
|
-
// 注意:这里需要获取原始配置的模式和选项
|
|
177
|
-
// 由于当前架构限制,这里只是示例实现
|
|
178
|
-
_logger.logger.info('路由重新加载完成');
|
|
179
|
-
}
|
|
180
|
-
constructor(){
|
|
181
|
-
_define_property(this, "registeredRoutes", new Map());
|
|
182
|
-
_define_property(this, "routeVersion", 0);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* 获取动态路由管理器单例
|
|
187
|
-
*/ let dynamicRouteManagerInstance = null;
|
|
188
|
-
function getDynamicRouteManager() {
|
|
189
|
-
if (!dynamicRouteManagerInstance) {
|
|
190
|
-
dynamicRouteManagerInstance = new DynamicRouteManager();
|
|
191
|
-
}
|
|
192
|
-
return dynamicRouteManagerInstance;
|
|
193
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get DynamicRouteManager(){return DynamicRouteManager},get getDynamicRouteManager(){return getDynamicRouteManager}});const _logger=require("@vlian/logger");const _RouterManager=require("../RouterManager");const _transform=require("../utils/transform");const _errors=require("../errors");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let DynamicRouteManager=class DynamicRouteManager{async register(routes,namespace){const ns=namespace||"default";if(!Array.isArray(routes)||routes.length===0){throw new _errors.RouterError("路由配置必须是非空数组",_errors.RouterErrorCode.ROUTER_CONFIG_ERROR)}const existingRoutes=this.registeredRoutes.get(ns)||[];const existingNames=new Set(existingRoutes.map(r=>r.name));const newNames=routes.map(r=>r.name);const conflicts=newNames.filter(name=>existingNames.has(name));if(conflicts.length>0){throw new _errors.RouterError(`路由名称冲突: ${conflicts.join(", ")}`,_errors.RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{conflicts,namespace:ns})}const currentRoutes=this.registeredRoutes.get(ns)||[];this.registeredRoutes.set(ns,[...currentRoutes,...routes]);this.routeVersion++;_logger.logger.info(`路由已注册: ${routes.length} 个路由到命名空间 "${ns}"`);return async()=>{await this.unregister(routes.map(r=>r.name),ns)}}async unregister(routeNames,namespace){const ns=namespace||"default";const routes=this.registeredRoutes.get(ns)||[];const filteredRoutes=routes.filter(r=>!routeNames.includes(r.name));if(filteredRoutes.length===routes.length){_logger.logger.warn(`未找到要取消注册的路由: ${routeNames.join(", ")}`);return}if(filteredRoutes.length===0){this.registeredRoutes.delete(ns)}else{this.registeredRoutes.set(ns,filteredRoutes)}this.routeVersion++;_logger.logger.info(`路由已取消注册: ${routeNames.length} 个路由从命名空间 "${ns}"`)}getRoutes(namespace){const ns=namespace||"default";return[...this.registeredRoutes.get(ns)||[]]}getAllRoutes(){return new Map(this.registeredRoutes)}clear(namespace){const ns=namespace||"default";this.registeredRoutes.delete(ns);this.routeVersion++;_logger.logger.info(`路由命名空间已清空: "${ns}"`)}clearAll(){this.registeredRoutes.clear();this.routeVersion++;_logger.logger.info("所有路由已清空")}getVersion(){return this.routeVersion}isRegistered(routeName,namespace){const ns=namespace||"default";const routes=this.registeredRoutes.get(ns)||[];return routes.some(r=>r.name===routeName)}async reload(){const routerManager=(0,_RouterManager.getRouterManager)();if(!routerManager.isInitialized()){throw new _errors.RouterError("路由管理器未初始化",_errors.RouterErrorCode.ROUTER_NOT_INITIALIZED)}const allRoutes=[];this.registeredRoutes.forEach(routes=>{allRoutes.push(...routes)});if(allRoutes.length===0){_logger.logger.warn("没有已注册的路由,无法重新加载");return}await (0,_transform.transformRoutes)(allRoutes);_logger.logger.info("路由重新加载完成")}constructor(){_define_property(this,"registeredRoutes",new Map);_define_property(this,"routeVersion",0)}};let dynamicRouteManagerInstance=null;function getDynamicRouteManager(){if(!dynamicRouteManagerInstance){dynamicRouteManagerInstance=new DynamicRouteManager}return dynamicRouteManagerInstance}
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 路由动态注册模块入口
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
_export_star(require("./DynamicRouteManager"), exports);
|
|
8
|
-
function _export_star(from, to) {
|
|
9
|
-
Object.keys(from).forEach(function(k) {
|
|
10
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
-
Object.defineProperty(to, k, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function() {
|
|
14
|
-
return from[k];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return from;
|
|
20
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("./DynamicRouteManager"),exports);function _export_star(from,to){Object.keys(from).forEach(function(k){if(k!=="default"&&!Object.prototype.hasOwnProperty.call(to,k)){Object.defineProperty(to,k,{enumerable:true,get:function(){return from[k]}})}});return from}
|