提交 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;
}
/** /**
* 应用实体名称 * 应用实体名称
...@@ -97,7 +86,7 @@ export class ControlServiceBase { ...@@ -97,7 +86,7 @@ export class ControlServiceBase {
return appEntityServiceConstructor.getService(entityName); return appEntityServiceConstructor.getService(entityName);
} }
/** /**
* 行为处理之前 * 行为处理之前
* *
* @protected * @protected
...@@ -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,22 +128,16 @@ export class ControlServiceBase { ...@@ -168,22 +128,16 @@ 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 {
response = await this.service.Create(context, data, isLoading); response = await this.service.Create(context, data, isLoading);
} }
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,22 +153,16 @@ export class ControlServiceBase { ...@@ -199,22 +153,16 @@ 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 {
response = await this.service.Remove(context, data, isLoading); response = await this.service.Remove(context, data, isLoading);
} }
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,22 +178,16 @@ export class ControlServiceBase { ...@@ -230,22 +178,16 @@ 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 {
response = await this.service.Update(context, data, isLoading); response = await this.service.Update(context, data, isLoading);
} }
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,22 +203,16 @@ export class ControlServiceBase { ...@@ -261,22 +203,16 @@ 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 {
response = await this.service.Get(context, data, isLoading); response = await this.service.Get(context, data, isLoading);
} }
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,30 +228,23 @@ export class ControlServiceBase { ...@@ -292,30 +228,23 @@ 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);
let response: HttpResponse;
data = this.handleRequestData(action, context, data); let PrimaryKey = Util.createUUID();
let PrimaryKey = Util.createUUID(); //仿真主键数据
//仿真主键数据 data[this.appDeKey] = PrimaryKey;
data[this.appDeKey] = PrimaryKey; 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); console.log(response);
console.log(response); } else {
} else { response = await this.service.GetDraft(context, data, isLoading);
response = await this.service.GetDraft(context, data, isLoading); }
} if (!response.isError()) {
if (!response.isError()) { response = this.handleResponse(action, response, true);
response = this.handleResponse(action, response, true); this.mergeDefaults(response);
this.mergeDefaults(response);
}
response.data[this.appDeKey] = PrimaryKey;
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
} }
response.data[this.appDeKey] = PrimaryKey;
return response; return response;
} }
...@@ -330,23 +259,16 @@ export class ControlServiceBase { ...@@ -330,23 +259,16 @@ 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])) { response = await this.service[action](context, data, isLoading);
response = await this.service[action](context, data, isLoading); } else {
} else { response = new HttpResponse(200, null, { code: 100, message: `${action}前台逻辑未实现` });
response = new HttpResponse(200, null, { code: 100, message: `${action}前台逻辑未实现` }); }
} 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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册