提交 74b49c90 编写于 作者: tony001's avatar tony001

增加权限服务类

上级 ee7f5a28
<#ibiztemplate>
TARGET=PSAPPDATAENTITY
</#ibiztemplate>
import AuthService from '../auth-service';
/**
* ${de.getLogicName()}权限服务对象基类
*
* @export
* @class ${srfclassname('${item.getCodeName()}')}AuthServiceBase
* @extends {AuthService}
*/
export default class ${srfclassname('${item.getCodeName()}')}AuthServiceBase extends AuthService {
/**
* Creates an instance of ${srfclassname('${item.getCodeName()}')}AuthServiceBase.
*
* @param {*} [opts={}]
* @memberof ${srfclassname('${item.getCodeName()}')}AuthServiceBase
*/
constructor(opts: any = {}) {
super(opts);
}
}
\ No newline at end of file
<#ibiztemplate>
TARGET=PSAPPDATAENTITY
</#ibiztemplate>
import { Http,Util } from '@/utils';
import ${srfclassname('${item.getCodeName()}')}AuthServiceBase from './${srffilepath2(item.getCodeName())}-auth-service-base';
/**
* ${de.getLogicName()}权限服务对象
*
* @export
* @class ${srfclassname('${item.getCodeName()}')}AuthService
* @extends {${srfclassname('${item.getCodeName()}')}AuthServiceBase}
*/
export default class ${srfclassname('${item.getCodeName()}')}AuthService extends ${srfclassname('${item.getCodeName()}')}AuthServiceBase {
/**
* Creates an instance of ${srfclassname('${item.getCodeName()}')}AuthService.
*
* @param {*} [opts={}]
* @memberof ${srfclassname('${item.getCodeName()}')}AuthService
*/
constructor(opts: any = {}) {
super(opts);
}
}
\ No newline at end of file
<#ibiztemplate>
TARGET=PSSYSAPP
</#ibiztemplate>
/**
* 实体数据服务注册中心
*
* @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();
}
/**
* 初始化
*
* @protected
* @memberof AuthServiceRegister
*/
protected init(): void {
<#if app.getAllPSAppDataEntities()??>
<#list app.getAllPSAppDataEntities() as curAppEntity>
this.allAuthService.set('${curAppEntity.getCodeName()?lower_case}', () => import('@/service/${srffilepath2(curAppEntity.getCodeName())}/${srffilepath2(curAppEntity.getCodeName())}-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 entityService: any = await this.loadService(name);
if (entityService && entityService.default) {
const instance: any = new entityService.default();
this.serviceCache.set(name, instance);
return instance;
}
}
}
export const authServiceRegister: AuthServiceRegister = new AuthServiceRegister();
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册