提交 e08efb29 编写于 作者: KK's avatar KK

权限服务调整

上级 6cc60809
<#ibiztemplate>
TARGET=PSSYSAPP
</#ibiztemplate>
import { ServiceConstructorBase } from '@/ibiz-core/service/service-constructor-base';
/**
* 实体权限服务注册中心
*
* @export
* @class AuthServiceRegister
*/
export class AuthServiceRegister {
/**
* 所有实体权限服务Map
*
* @protected
* @type {*}
* @memberof AuthServiceRegister
*/
protected allAuthService: Map<string, () => Promise<any>> = new Map();
/**
* 已加载实体权限服务Map缓存
*
* @protected
* @type {Map<string, any>}
* @memberof AuthServiceRegister
*/
protected serviceCache: Map<string, any> = new Map();
/**
* Creates an instance of AuthServiceRegister.
* @memberof AuthServiceRegister
*/
constructor() {
this.init();
}
export class AuthServiceRegister extends ServiceConstructorBase {
/**
* 初始化
......@@ -44,44 +19,11 @@ export class AuthServiceRegister {
protected init(): void {
<#if app.getAllPSAppDataEntities()??>
<#list app.getAllPSAppDataEntities() as curAppEntity>
this.allAuthService.set('${curAppEntity.getCodeName()?lower_case}', () => import('@app-core/auth-service/${srffilepath2(curAppEntity.getCodeName())}/${srffilepath2(curAppEntity.getCodeName())}-auth-service'));
this.allService.set('${curAppEntity.getCodeName()?lower_case}', () => import('@/app-core/auth-service/${srffilepath2(curAppEntity.getCodeName())}/${srffilepath2(curAppEntity.getCodeName())}-auth-service'));
</#list>
</#if>
}
/**
* 加载实体权限服务
*
* @protected
* @param {string} serviceName
* @returns {Promise<any>}
* @memberof AuthServiceRegister
*/
protected async loadService(serviceName: string): Promise<any> {
const service = this.allAuthService.get(serviceName);
if (service) {
return service();
}
}
/**
* 获取应用实体权限服务
*
* @param {string} name
* @returns {Promise<any>}
* @memberof AuthServiceRegister
*/
public async getService(name: string): Promise<any> {
if (this.serviceCache.has(name)) {
return this.serviceCache.get(name);
}
const authService: any = await this.loadService(name);
if (authService && authService.default) {
const instance: any = new authService.default();
this.serviceCache.set(name, instance);
return instance;
}
}
}
export const authServiceRegister: AuthServiceRegister = new AuthServiceRegister();
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册