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

工具服务类

上级 55ed56b8
<#ibiztemplate>
TARGET=PSAPPUTIL
</#ibiztemplate>
import UtilService from '../util-service';
<#if item.getStoagePSAppDataEntity()??>
<#assign stoageDataEntity = item.getStoagePSAppDataEntity() />
import ${srfclassname('${stoageDataEntity.getCodeName()}')}Service from '@/service/${srffilepath2(stoageDataEntity.getCodeName())}/${srffilepath2(stoageDataEntity.getCodeName())}-service';
</#if>
/**
* ${item.getName()}功能服务对象基类
*
* @export
* @class ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
export default class ${srfclassname('${item.getCodeName()}')}UtilServiceBase extends UtilService {
<#if item.getStoagePSAppDataEntity()??>
<#assign stoageDataEntity = item.getStoagePSAppDataEntity() />
/**
* 存储数据服务
*
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
public stoageDataService: ${srfclassname('${stoageDataEntity.getCodeName()}')}Service = new ${srfclassname('${stoageDataEntity.getCodeName()}')}Service();
</#if>
/**
* 获取数据行为
*
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
public loadAction: string = "${item.getGetPSAppDEAction().getCodeName()}";
/**
* 建立数据行为
*
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
public createAction: string = "${item.getCreatePSAppDEAction().getCodeName()}";
/**
* 更新数据行为
*
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
public updateAction: string = "${item.getUpdatePSAppDEAction().getCodeName()}";
/**
* 删除数据行为
*
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
public removeAction: string = "${item.getRemovePSAppDEAction().getCodeName()}";
/**
* Creates an instance of ${srfclassname('${item.getCodeName()}')}UtilServiceBase.
*
* @param {*} [opts={}]
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
constructor(opts: any = {}) {
super(opts);
}
/**
* 初始化基础参数
*
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
public initBasicParam(){
<#if item.getModelIdPSAppDEField()??>this.modelIdField = "${item.getModelIdPSAppDEField().getCodeName()?lower_case}";</#if>
<#if item.getModelPSAppDEField()??>this.modelField = "${item.getModelPSAppDEField().getCodeName()?lower_case}";</#if>
<#if item.getAppIdPSAppDEField()??>this.appIdField = "${item.getAppIdPSAppDEField().getCodeName()?lower_case}";</#if>
<#if item.getUserIdPSAppDEField()??>this.userIdField = "${item.getUserIdPSAppDEField().getCodeName()?lower_case}";</#if>
<#if item.getStoagePSAppDataEntity()??>
<#assign stoageDataEntity = item.getStoagePSAppDataEntity() />
this.stoageEntityName ="${stoageDataEntity.getCodeName()?lower_case}";
this.stoageEntityKey ="${stoageDataEntity.getKeyPSAppDEField().getCodeName()?lower_case}";
</#if>
}
/**
* 获取模型数据
*
* @param context 应用上下文
* @param data 传入模型数据
* @param isloading 是否加载
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
public loadModelData(context: any = {},data: any = {}, isloading?: boolean): Promise<any>{
return new Promise((resolve: any, reject: any) => {
//从接口加载
if(data && data.utilServiceName){
const requestParam:any ={configType:data.utilServiceName,targetType:data.modelid};
this.stoageDataService.getDynaModel(context,requestParam).then((res:any) =>{
if(res && res.status === 200){
const data: any = res.data;
resolve({status:200,data:(data && data.model)?data.model:[]});
}
}).catch((error:any) =>{
reject(error);
})
}else{
let dataStr = window.localStorage.getItem(data.modelid);
if(dataStr) {
const data: any = JSON.parse(dataStr);
resolve({status:200,data:data.model});
} else {
resolve({status:200,data:[]});
}
}
});
}
/**
* 保存模型数据
*
* @param context 应用上下文
* @param action 操作行为 Update|Create
* @param data 传入模型数据
* @param isloading 是否加载
* @memberof ${srfclassname('${item.getCodeName()}')}UtilServiceBase
*/
public saveModelData(context: any = {},action:string,data: any = {}, isloading?: boolean):Promise<any>{
return new Promise((resolve: any, reject: any) => {
// 存储到数据库
if(data && data.utilServiceName){
const requestParam:any ={configType:data.utilServiceName,targetType:data.modelid,model:data.model};
this.stoageDataService.setDynaModel(context,requestParam).then((res:any) =>{
if(res && res.status === 200){
resolve({status:200,data:data.model});
}
}).catch((error:any) =>{
reject(error);
})
}else{
window.localStorage.setItem(data.modelid, JSON.stringify(data));
resolve({status:200,data:data.model});
}
});
}
}
\ No newline at end of file
<#ibiztemplate>
TARGET=PSAPPUTIL
</#ibiztemplate>
import ${srfclassname('${item.getCodeName()}')}UtilServiceBase from './${srffilepath2(item.getCodeName())}-util-service-base';
/**
* ${item.getName()}功能服务对象
*
* @export
* @class ${item.getCodeName()}UtilService
*/
export default class ${srfclassname('${item.getCodeName()}')}UtilService extends ${srfclassname('${item.getCodeName()}')}UtilServiceBase {
/**
* Creates an instance of ${srfclassname('${item.getCodeName()}')}UtilService.
*
* @param {*} [opts={}]
* @memberof ${srfclassname('${item.getCodeName()}')}UtilService
*/
constructor(opts: any = {}) {
super(opts);
}
}
\ No newline at end of file
<#ibiztemplate>
TARGET=PSSYSAPP
</#ibiztemplate>
/**
* 功能服务注册中心
*
* @export
* @class UtilServiceRegister
*/
export class UtilServiceRegister {
/**
* 所有功能服务Map
*
* @protected
* @type {*}
* @memberof UtilServiceRegister
*/
protected allUtilService: Map<string, () => Promise<any>> = new Map();
/**
* 已加载功能服务Map缓存
*
* @protected
* @type {Map<string, any>}
* @memberof UtilServiceRegister
*/
protected serviceCache: Map<string, any> = new Map();
/**
* Creates an instance of UtilServiceRegister.
* @memberof UtilServiceRegister
*/
constructor() {
this.init();
}
/**
* 初始化
*
* @protected
* @memberof UtilServiceRegister
*/
protected init(): void {
<#if app.getAllPSAppUtils?? && app.getAllPSAppUtils()?? >
<#list app.getAllPSAppUtils() as appUtil>
this.allUtilService.set('${appUtil.getCodeName()?lower_case}', () => import('@/utilservice/${srffilepath2(appUtil.getCodeName())}/${srffilepath2(appUtil.getCodeName())}-util-service'));
</#list>
</#if>
}
/**
* 加载服务实体
*
* @protected
* @param {string} serviceName
* @returns {Promise<any>}
* @memberof UtilServiceRegister
*/
protected async loadService(serviceName: string): Promise<any> {
const service = this.allUtilService.get(serviceName);
if (service) {
return service();
}
}
/**
* 获取应用实体服务
*
* @param {string} name
* @returns {Promise<any>}
* @memberof UtilServiceRegister
*/
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 utilServiceRegister: UtilServiceRegister = new UtilServiceRegister();
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册