zova-module-a-router 5.0.35 → 5.0.38
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/package.json +2 -2
- package/src/api/index.ts +2 -0
- package/src/api/interface/index.ts +1 -0
- package/src/api/service/index.ts +1 -0
- package/src/bean/{store.router.ts → bean.router.ts} +6 -6
- package/src/bean/virtual.router.ts +2 -2
- package/src/index.ts +1 -0
- package/src/monkey.ts +33 -29
- package/src/resource/beans.ts +3 -3
- package/src/resource/events.ts +2 -2
- package/src/resource/injects.ts +2 -2
- package/src/resource/scope.ts +3 -1
- package/src/types.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zova-module-a-router",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.38",
|
|
4
4
|
"title": "a-router",
|
|
5
5
|
"zovaModule": {
|
|
6
6
|
"capabilities": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"vue-router": "^4.3.2"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "90bb78df182aa8db862d6b44e86d23aa33b195fa"
|
|
41
41
|
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const services = {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { BeanBase, Cast, IModule, IPageNameRecord, IPagePathRecord,
|
|
1
|
+
import { Bean, BeanBase, Cast, IModule, IPageNameRecord, IPagePathRecord, TypeEventOff } from 'zova';
|
|
2
2
|
import { Router } from 'vue-router';
|
|
3
3
|
import * as ModuleInfo from '@cabloy/module-info';
|
|
4
4
|
import { IModuleRoute, IModuleRouteComponent } from '../types.js';
|
|
5
5
|
|
|
6
6
|
const SymbolRouter = Symbol('SymbolRouter');
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type BeanRouterLike = BeanRouter & Router;
|
|
9
9
|
|
|
10
|
-
@
|
|
11
|
-
export class
|
|
10
|
+
@Bean({ scene: 'bean', name: 'router', containerScope: 'ctx' })
|
|
11
|
+
export class BeanRouter extends BeanBase {
|
|
12
12
|
[SymbolRouter]: Router;
|
|
13
13
|
eventRouterGuards: TypeEventOff;
|
|
14
14
|
|
|
@@ -27,7 +27,7 @@ export class StoreRouter extends BeanBase {
|
|
|
27
27
|
if (!router) {
|
|
28
28
|
throw new Error('Should provide router');
|
|
29
29
|
}
|
|
30
|
-
this.bean.provide('a-router:router', Cast<
|
|
30
|
+
this.bean.provide('a-router:router', Cast<BeanRouterLike>(this));
|
|
31
31
|
// event
|
|
32
32
|
this.eventRouterGuards = this.app.meta.event.on('a-router:routerGuards', async (context, next) => {
|
|
33
33
|
this._routerGuards(context.data);
|
|
@@ -98,7 +98,7 @@ export class StoreRouter extends BeanBase {
|
|
|
98
98
|
return `${fullPath}${join}${query2str}`;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
private _routerGuards(router:
|
|
101
|
+
private _routerGuards(router: BeanRouterLike) {
|
|
102
102
|
router.beforeEach(async to => {
|
|
103
103
|
// fullPath
|
|
104
104
|
const fullPath = to.fullPath;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BeanBase, TypeEventOff, Virtual } from 'zova';
|
|
2
|
-
import {
|
|
2
|
+
import { BeanRouterLike } from './bean.router.js';
|
|
3
3
|
|
|
4
4
|
@Virtual()
|
|
5
5
|
export class BeanRouterBase<TScopeModule = unknown> extends BeanBase<TScopeModule> {
|
|
@@ -18,5 +18,5 @@ export class BeanRouterBase<TScopeModule = unknown> extends BeanBase<TScopeModul
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
protected onRouterGuards(_router:
|
|
21
|
+
protected onRouterGuards(_router: BeanRouterLike) {}
|
|
22
22
|
}
|
package/src/index.ts
CHANGED
package/src/monkey.ts
CHANGED
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
} from 'zova';
|
|
14
14
|
import * as ModuleInfo from '@cabloy/module-info';
|
|
15
15
|
import { useRoute } from 'vue-router';
|
|
16
|
-
import {
|
|
16
|
+
import { BeanRouterLike } from './bean/bean.router.js';
|
|
17
17
|
|
|
18
18
|
export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule, IMonkeyController {
|
|
19
|
-
private
|
|
19
|
+
private _beanRouter: BeanRouterLike;
|
|
20
20
|
private _moduleSelf: IModule;
|
|
21
21
|
|
|
22
22
|
constructor(moduleSelf: IModule) {
|
|
@@ -24,15 +24,15 @@ export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule,
|
|
|
24
24
|
this._moduleSelf = moduleSelf;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
async
|
|
28
|
-
if (!this.
|
|
29
|
-
this.
|
|
27
|
+
async getBeanRouter() {
|
|
28
|
+
if (!this._beanRouter) {
|
|
29
|
+
this._beanRouter = (await this.bean._getBean('a-router.bean.router', false)) as BeanRouterLike;
|
|
30
30
|
}
|
|
31
|
-
return this.
|
|
31
|
+
return this._beanRouter;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
async appInitialize() {}
|
|
35
|
-
async appInitialized() {
|
|
34
|
+
async appInitialize(_bean: BeanContainerLike) {}
|
|
35
|
+
async appInitialized(_bean: BeanContainerLike) {
|
|
36
36
|
// emit event
|
|
37
37
|
const router = this.bean.inject('a-router:router');
|
|
38
38
|
await this.app.meta.event.emit('a-router:routerGuards', router);
|
|
@@ -51,8 +51,8 @@ export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule,
|
|
|
51
51
|
beanDisposed(_bean: BeanContainerLike, _beanInstance: BeanBase) {}
|
|
52
52
|
async moduleLoading(module: IModule) {
|
|
53
53
|
if (this._moduleSelf === module) return;
|
|
54
|
-
const
|
|
55
|
-
|
|
54
|
+
const beanRouter = await this.getBeanRouter();
|
|
55
|
+
beanRouter._registerRoutes(module);
|
|
56
56
|
}
|
|
57
57
|
async moduleLoaded(_module: IModule) {}
|
|
58
58
|
async configLoaded(_module: IModule, _config) {}
|
|
@@ -61,25 +61,29 @@ export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule,
|
|
|
61
61
|
}
|
|
62
62
|
controllerDataInit(controllerData: IControllerData, controller: BeanBase) {
|
|
63
63
|
// only for controller page
|
|
64
|
-
if (controller instanceof BeanControllerPageBase)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
schemas = module.resource.pagePathSchemas?.[schemaKey];
|
|
74
|
-
}
|
|
75
|
-
controller.$params = useComputed(() => {
|
|
76
|
-
if (!schemas?.params) throw new Error(`page params schema not found: ${schemaKey}`);
|
|
77
|
-
return schemas.params.parse(route.params);
|
|
78
|
-
});
|
|
79
|
-
controller.$query = useComputed(() => {
|
|
80
|
-
if (!schemas?.query) throw new Error(`page query schema not found: ${schemaKey}`);
|
|
81
|
-
return schemas.query.parse(route.query);
|
|
82
|
-
});
|
|
64
|
+
if (!(controller instanceof BeanControllerPageBase)) return;
|
|
65
|
+
const route = controllerData.context.route;
|
|
66
|
+
if (!route) return;
|
|
67
|
+
const schemaKey = String(route.name || route.path);
|
|
68
|
+
let schemas: TypePageSchema | undefined;
|
|
69
|
+
const moduleInfo = ModuleInfo.parseInfo(ModuleInfo.parseName(schemaKey));
|
|
70
|
+
if (!moduleInfo) {
|
|
71
|
+
// do nothing
|
|
72
|
+
return;
|
|
83
73
|
}
|
|
74
|
+
const module = this.app.meta.module.get(moduleInfo.relativeName)!;
|
|
75
|
+
if (route.name) {
|
|
76
|
+
schemas = module.resource.pageNameSchemas?.[schemaKey];
|
|
77
|
+
} else {
|
|
78
|
+
schemas = module.resource.pagePathSchemas?.[schemaKey];
|
|
79
|
+
}
|
|
80
|
+
controller.$params = useComputed(() => {
|
|
81
|
+
if (!schemas?.params) throw new Error(`page params schema not found: ${schemaKey}`);
|
|
82
|
+
return schemas.params.parse(route.params);
|
|
83
|
+
});
|
|
84
|
+
controller.$query = useComputed(() => {
|
|
85
|
+
if (!schemas?.query) throw new Error(`page query schema not found: ${schemaKey}`);
|
|
86
|
+
return schemas.query.parse(route.query);
|
|
87
|
+
});
|
|
84
88
|
}
|
|
85
89
|
}
|
package/src/resource/beans.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from '../bean/
|
|
1
|
+
export * from '../bean/bean.router.js';
|
|
2
2
|
export * from '../bean/virtual.router.js';
|
|
3
|
-
import {
|
|
3
|
+
import { BeanRouter } from '../bean/bean.router.js';
|
|
4
4
|
import 'zova';
|
|
5
5
|
declare module 'zova' {
|
|
6
6
|
export interface IBeanRecord {
|
|
7
|
-
'a-router.
|
|
7
|
+
'a-router.bean.router': BeanRouter;
|
|
8
8
|
}
|
|
9
9
|
}
|
package/src/resource/events.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BeanRouterLike } from './beans.js';
|
|
2
2
|
|
|
3
3
|
import 'zova';
|
|
4
4
|
declare module 'zova' {
|
|
5
5
|
export interface IEventRecord {
|
|
6
|
-
'a-router:routerGuards':
|
|
6
|
+
'a-router:routerGuards': BeanRouterLike;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface IEventResultRecord {
|
package/src/resource/injects.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Router } from 'vue-router';
|
|
2
|
-
import {
|
|
2
|
+
import { BeanRouterLike } from '../bean/bean.router.js';
|
|
3
3
|
|
|
4
4
|
import 'zova';
|
|
5
5
|
declare module 'zova' {
|
|
6
6
|
export interface IInjectRecord {
|
|
7
7
|
'a-router:appRouter': Router;
|
|
8
|
-
'a-router:router':
|
|
8
|
+
'a-router:router': BeanRouterLike;
|
|
9
9
|
}
|
|
10
10
|
}
|
package/src/resource/scope.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BeanScopeBase, Scope, TypeLocaleBase, TypeModuleResource } from 'zova';
|
|
2
2
|
import { config, Errors, locales, constants } from '../config/index.js';
|
|
3
3
|
import { components } from './components.js';
|
|
4
|
+
import { services } from '../api/service/index.js';
|
|
4
5
|
|
|
5
6
|
@Scope()
|
|
6
7
|
export class ScopeModuleARouter extends BeanScopeBase {}
|
|
@@ -11,7 +12,8 @@ export interface ScopeModuleARouter
|
|
|
11
12
|
typeof config,
|
|
12
13
|
typeof Errors,
|
|
13
14
|
(typeof locales)[TypeLocaleBase],
|
|
14
|
-
typeof constants
|
|
15
|
+
typeof constants,
|
|
16
|
+
typeof services
|
|
15
17
|
> {}
|
|
16
18
|
|
|
17
19
|
import 'zova';
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IComponentLayoutRecord, TypePageSchemas } from 'zova';
|
|
2
2
|
import { RouteComponent, RouteLocationNormalizedLoaded, RouteRecordRaw } from 'vue-router';
|
|
3
|
-
import {
|
|
3
|
+
import { BeanRouterLike } from './bean/bean.router.js';
|
|
4
4
|
|
|
5
5
|
export type Lazy<T> = () => Promise<T>;
|
|
6
6
|
export type IModuleRouteComponent = RouteComponent | Lazy<RouteComponent>;
|
|
@@ -17,7 +17,7 @@ declare module 'vue-router' {
|
|
|
17
17
|
|
|
18
18
|
declare module 'zova' {
|
|
19
19
|
export interface BeanBase {
|
|
20
|
-
$router:
|
|
20
|
+
$router: BeanRouterLike;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface IModuleResource {
|