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

部件服务基类调整

上级 d8cc6ffa
...@@ -19,17 +19,6 @@ export class ControlServiceBase { ...@@ -19,17 +19,6 @@ export class ControlServiceBase {
*/ */
protected model: any = null; protected model: any = null;
/**
* 是否正在加载状态
*
* @protected
* @type {boolean}
* @memberof ControlServiceBase
*/
protected $isLoading: boolean = false;
public get isLoading(): boolean {
return this.$isLoading;
}
/** /**
* 应用实体名称 * 应用实体名称
...@@ -109,9 +98,6 @@ export class ControlServiceBase { ...@@ -109,9 +98,6 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
protected async onBeforeAction(action?: string, context: any = {}, data: any = {}, isLoading: boolean = true): Promise<any> { protected async onBeforeAction(action?: string, context: any = {}, data: any = {}, isLoading: boolean = true): Promise<any> {
if (isLoading) {
// this.showLoading();
}
if (!this.service) { if (!this.service) {
this.service = await this.getService(this.appDEName); this.service = await this.getService(this.appDEName);
} }
...@@ -130,32 +116,6 @@ export class ControlServiceBase { ...@@ -130,32 +116,6 @@ export class ControlServiceBase {
*/ */
protected async beforeAction(action?: string, context: any = {}, data: any = {}): Promise<any> { } protected async beforeAction(action?: string, context: any = {}, data: any = {}): Promise<any> { }
/**
* 行为处理之后
*
* @protected
* @param {string} [action]
* @param {*} [context={}]
* @param {*} [response]
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async onAfterAction(action?: string, context: any = {}, response?: any): Promise<any> {
// this.hiddenLoading();
this.afterAction(action, context, response);
}
/**
* 行为处理之后
*
* @protected
* @param {string} [action]
* @param {*} [context={}]
* @param {*} [response]
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async afterAction(action?: string, context: any = {}, response?: any): Promise<any> { }
/** /**
* 添加数据 * 添加数据
...@@ -168,10 +128,9 @@ export class ControlServiceBase { ...@@ -168,10 +128,9 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async add(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async add(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
try{
data = this.handleRequestData(action, context, data); data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) { if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data, isLoading); response = await this.service[action](context, data, isLoading);
} else { } else {
...@@ -180,11 +139,6 @@ export class ControlServiceBase { ...@@ -180,11 +139,6 @@ export class ControlServiceBase {
if (!response.isError()) { if (!response.isError()) {
response = this.handleResponse(action, response); response = this.handleResponse(action, response);
} }
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
}
return response; return response;
} }
...@@ -199,10 +153,9 @@ export class ControlServiceBase { ...@@ -199,10 +153,9 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async delete(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async delete(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
try{
data = this.handleRequestData(action, context, data); data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) { if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data, isLoading); response = await this.service[action](context, data, isLoading);
} else { } else {
...@@ -211,11 +164,6 @@ export class ControlServiceBase { ...@@ -211,11 +164,6 @@ export class ControlServiceBase {
if (!response.isError()) { if (!response.isError()) {
response = this.handleResponse(action, response); response = this.handleResponse(action, response);
} }
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
}
return response; return response;
} }
...@@ -230,10 +178,9 @@ export class ControlServiceBase { ...@@ -230,10 +178,9 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async update(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async update(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
try{
data = this.handleRequestData(action, context, data); data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) { if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data, isLoading); response = await this.service[action](context, data, isLoading);
} else { } else {
...@@ -242,11 +189,6 @@ export class ControlServiceBase { ...@@ -242,11 +189,6 @@ export class ControlServiceBase {
if (!response.isError()) { if (!response.isError()) {
response = this.handleResponse(action, response); response = this.handleResponse(action, response);
} }
}catch(error){
console.error(error)
}finally{
await this.onAfterAction(action, context, response);
}
return response; return response;
} }
...@@ -261,10 +203,9 @@ export class ControlServiceBase { ...@@ -261,10 +203,9 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async get(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async get(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
try{
data = this.handleRequestData(action, context, data); data = this.handleRequestData(action, context, data);
let response: HttpResponse;
if (Util.isFunction(this.service[action])) { if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data, isLoading); response = await this.service[action](context, data, isLoading);
} else { } else {
...@@ -273,11 +214,6 @@ export class ControlServiceBase { ...@@ -273,11 +214,6 @@ export class ControlServiceBase {
if (!response.isError()) { if (!response.isError()) {
response = this.handleResponse(action, response); response = this.handleResponse(action, response);
} }
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
}
return response; return response;
} }
...@@ -292,11 +228,9 @@ export class ControlServiceBase { ...@@ -292,11 +228,9 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async loadDraft(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async loadDraft(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
try{
data = this.handleRequestData(action, context, data); data = this.handleRequestData(action, context, data);
let response: HttpResponse;
let PrimaryKey = Util.createUUID(); let PrimaryKey = Util.createUUID();
//仿真主键数据 //仿真主键数据
data[this.appDeKey] = PrimaryKey; data[this.appDeKey] = PrimaryKey;
...@@ -311,11 +245,6 @@ export class ControlServiceBase { ...@@ -311,11 +245,6 @@ export class ControlServiceBase {
this.mergeDefaults(response); this.mergeDefaults(response);
} }
response.data[this.appDeKey] = PrimaryKey; response.data[this.appDeKey] = PrimaryKey;
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
}
return response; return response;
} }
...@@ -330,9 +259,7 @@ export class ControlServiceBase { ...@@ -330,9 +259,7 @@ export class ControlServiceBase {
* @memberof EditServiceBase * @memberof EditServiceBase
*/ */
public async frontLogic(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async frontLogic(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
try{
data = this.handleRequestData(action, context, data); data = this.handleRequestData(action, context, data);
let response: HttpResponse; let response: HttpResponse;
if (Util.isFunction(this.service[action])) { if (Util.isFunction(this.service[action])) {
...@@ -343,11 +270,6 @@ export class ControlServiceBase { ...@@ -343,11 +270,6 @@ export class ControlServiceBase {
if (!response.isError()) { if (!response.isError()) {
response = this.handleResponse(action, response, true); response = this.handleResponse(action, response, true);
} }
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
}
return response; return response;
} }
...@@ -436,32 +358,5 @@ export class ControlServiceBase { ...@@ -436,32 +358,5 @@ export class ControlServiceBase {
*/ */
protected mergeDefaults(response: any = {}): void { } protected mergeDefaults(response: any = {}): void { }
/**
* 开启加载动画
*
* @protected
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async showLoading(): Promise<any> {
if (this.$isLoading === false) {
this.$isLoading = true;
Loading.show();
}
}
/**
* 结束加载动画
*
* @protected
* @returns {Promise<any>}
* @memberof ControlServiceBase
*/
protected async hiddenLoading(): Promise<any> {
if (this.$isLoading === true) {
Loading.hidden();
this.$isLoading = false;
}
}
} }
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册