提交 3ae8a5b3 编写于 作者: Mosher's avatar Mosher

update:更新表单事件

上级 2daa1904
...@@ -1164,33 +1164,45 @@ import { Environment } from '@/environments/environment'; ...@@ -1164,33 +1164,45 @@ import { Environment } from '@/environments/environment';
* @param {*} [opt={}] * @param {*} [opt={}]
* @memberof ${srfclassname('${ctrl.codeName}')}Base * @memberof ${srfclassname('${ctrl.codeName}')}Base
*/ */
public load(opt: any = {}): void { public async load(opt: any = {}): Promise<any> {
if(!this.loadAction){ if(!this.loadAction){
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.loadaction') as string) }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.loadaction') as string) });
return; return;
} }
const arg: any = { ...opt }; const arg: any = { ...opt };
let viewparamResult:any = Object.assign(arg,this.viewparams); let viewparamResult:any = Object.assign(arg, this.viewparams);
const get: Promise<any> = this.service.get(this.loadAction,JSON.parse(JSON.stringify(this.context)),{viewparams:viewparamResult}, this.showBusyIndicator); const tempContext = Util.deepCopy(this.context);
get.then((response: any) => { if (!(await this.handleCtrlEvents('onbeforeload', { context: tempContext, viewparams: viewparamResult, data: arg }))) {
return;
}
const get: Promise<any> = this.service.get(this.loadAction, tempContext,{ viewparams: viewparamResult }, this.showBusyIndicator);
try {
if (response && response.status === 200) { if (response && response.status === 200) {
if (!(await this.handleCtrlEvents('onloadsuccess', { data: response.data }))) {
return;
}
const data = response.data; const data = response.data;
this.onFormLoad(data,'load'); this.onFormLoad(data,'load');
this.$emit('load', data); this.$emit('load', data);
this.$nextTick(() => { this.$nextTick(() => {
this.formState.next({ type: 'load', data: data }); this.formState.next({ type: 'load', data: data });
}); });
} else {
if (!(await this.handleCtrlEvents('onloaderror', { data: response.data }))) {
return;
}
}
return response;
} catch (response: any) {
if (!(await this.handleCtrlEvents('onloaderror', { context: tempContext, viewparams: viewparamResult, data: response && response.data ? response.data : arg }))) {
return;
} }
}).catch((response: any) => {
if (response && response.status && response.data) { if (response && response.status && response.data) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
return; return;
} }
if (!response || !response.status || !response.data) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
return;
} }
});
} }
/** /**
...@@ -1199,22 +1211,30 @@ import { Environment } from '@/environments/environment'; ...@@ -1199,22 +1211,30 @@ import { Environment } from '@/environments/environment';
* @param {*} [opt={}] * @param {*} [opt={}]
* @memberof ${srfclassname('${ctrl.codeName}')}Base * @memberof ${srfclassname('${ctrl.codeName}')}Base
*/ */
public loadDraft(opt: any = {}): void { public async loadDraft(opt: any = {}): Promise<any> {
if(!this.loaddraftAction){ if (!this.loaddraftAction) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.loaddraftaction') as string) }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.loaddraftaction') as string) });
return; return;
} }
const arg: any = { ...opt } ; const arg: any = { ...opt } ;
let viewparamResult:any = Object.assign(arg,this.viewparams); let viewparamResult:any = Object.assign(arg, this.viewparams);
let post: Promise<any> = this.service.loadDraft(this.loaddraftAction,JSON.parse(JSON.stringify(this.context)),{viewparams:viewparamResult}, this.showBusyIndicator); try {
post.then((response: any) => { if (!(await this.handleCtrlEvents('onbeforeloaddraft', { data: arg }))) {
return;
}
const response: any = this.service.loadDraft(this.loaddraftAction,JSON.parse(JSON.stringify(this.context)),{viewparams:viewparamResult}, this.showBusyIndicator);
if (!response.status || response.status !== 200) { if (!response.status || response.status !== 200) {
if (!(await this.handleCtrlEvents('onloaddrafterror', { data: response.data ? response.data : arg }))) {
return;
}
if (response.data) { if (response.data) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
} }
return; return;
} }
if (!(await this.handleCtrlEvents('onloaddraftsuccess', { data: response.data }))) {
return;
}
const data = response.data; const data = response.data;
this.resetDraftFormStates(); this.resetDraftFormStates();
this.onFormLoad(data,'loadDraft'); this.onFormLoad(data,'loadDraft');
...@@ -1240,16 +1260,17 @@ import { Environment } from '@/environments/environment'; ...@@ -1240,16 +1260,17 @@ import { Environment } from '@/environments/environment';
}); });
} }
}); });
}).catch((response: any) => { return response;
} catch (response: any) {
if (!(await this.handleCtrlEvents('onloaddrafterror', { data: response.data ? response.data : arg }))) {
return;
}
if (response && response.status && response.data) { if (response && response.status && response.data) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
return; return response;
} }
if (!response || !response.status || !response.data) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
return;
} }
});
} }
/** /**
...@@ -1344,7 +1365,7 @@ import { Environment } from '@/environments/environment'; ...@@ -1344,7 +1365,7 @@ import { Environment } from '@/environments/environment';
* @returns {Promise<any>} * @returns {Promise<any>}
* @memberof ${srfclassname('${ctrl.codeName}')}Base * @memberof ${srfclassname('${ctrl.codeName}')}Base
*/ */
public async save(opt: any = {}, showResultInfo?: boolean, ifStateNext: boolean = true): Promise<any> { public save(opt: any = {}, showResultInfo?: boolean, ifStateNext: boolean = true): Promise<any> {
return new Promise((resolve: any, reject: any) => { return new Promise((resolve: any, reject: any) => {
showResultInfo = showResultInfo === undefined ? true : false; showResultInfo = showResultInfo === undefined ? true : false;
if (!this.formValidateStatus()) { if (!this.formValidateStatus()) {
...@@ -1388,15 +1409,26 @@ import { Environment } from '@/environments/environment'; ...@@ -1388,15 +1409,26 @@ import { Environment } from '@/environments/environment';
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.actionname') as string) }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.actionname') as string) });
return; return;
} }
Object.assign(arg,{viewparams:this.viewparams}); Object.assign(arg, { viewparams: this.viewparams });
const post: Promise<any> = Object.is(data.srfuf, '1')?this.service.update(action, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator):this.service.add(action,JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator); this.handleCtrlEvents('onbeforesave', { data: arg }).then((beforeSaveResult: boolean) => {
if (!beforeSaveResult) {
return;
}
const post: Promise<any> = Object.is(data.srfuf, '1') ? this.service.update(action, JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator):this.service.add(action,JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator);
post.then((response: any) => { post.then((response: any) => {
if (!response.status || response.status !== 200) { if (!response.status || response.status !== 200) {
this.handleCtrlEvents('onsaverror', { data: response && response.data ? response.data : arg }).then((saveErrorResult: boolean) => {
// 保存失败处理
})
if (response.data) { if (response.data) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
} }
return; return;
} }
this.handleCtrlEvents('onsavesuccess', { data: response.data }).then((saveSuccessResult: boolean) => {
if (!saveSuccessResult) {
return;
}
this.viewparams.copymode = false; this.viewparams.copymode = false;
const data = response.data; const data = response.data;
this.onFormLoad(data,'save'); this.onFormLoad(data,'save');
...@@ -1413,7 +1445,12 @@ import { Environment } from '@/environments/environment'; ...@@ -1413,7 +1445,12 @@ import { Environment } from '@/environments/environment';
} }
</#if> </#if>
resolve(response); resolve(response);
})
}).catch((response: any) => { }).catch((response: any) => {
this.handleCtrlEvents('onsaveerror', { data: response && response.data ? response.data : {} }).then((saveErrorResult: boolean) => {
if (!saveErrorResult) {
return;
}
if (response && response.status && response.data) { if (response && response.status && response.data) {
if (response.data.errorKey) { if (response.data.errorKey) {
if(Object.is(response.data.errorKey, "versionCheck")) { if(Object.is(response.data.errorKey, "versionCheck")) {
...@@ -1452,8 +1489,10 @@ import { Environment } from '@/environments/environment'; ...@@ -1452,8 +1489,10 @@ import { Environment } from '@/environments/environment';
reject(response); reject(response);
} }
reject(response); reject(response);
})
}); });
}) })
})
} }
/** /**
...@@ -1471,9 +1510,14 @@ import { Environment } from '@/environments/environment'; ...@@ -1471,9 +1510,14 @@ import { Environment } from '@/environments/environment';
} }
const arg: any = opt[0]; const arg: any = opt[0];
const _this: any = this; const _this: any = this;
Object.assign(arg,{viewparams:this.viewparams}); Object.assign(arg, { viewparams: this.viewparams });
this.service.delete(_this.removeAction, JSON.parse(JSON.stringify(this.context)),arg, showResultInfo).then((response: any) => { this.handleCtrlEvents('onbeforeremove', { data: arg }).then((beforeRemoveResult: boolean) => {
if (response) { if (!beforeRemoveResult) {
return;
}
this.service.delete(_this.removeAction, JSON.parse(JSON.stringify(this.context)), arg, showResultInfo).then((response: any) => {
if (response && response.status === 200) {
this.handleCtrlEvents('onremovesuccess', { data: response.data }).then((removeSuccessResult: boolean) => {
const data = response.data; const data = response.data;
this.$emit('remove',data); this.$emit('remove',data);
this.formState.next({ type: 'remove', data: data }); this.formState.next({ type: 'remove', data: data });
...@@ -1483,12 +1527,20 @@ import { Environment } from '@/environments/environment'; ...@@ -1483,12 +1527,20 @@ import { Environment } from '@/environments/environment';
AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data}); AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
</#if> </#if>
resolve(response); resolve(response);
})
} else {
this.handleCtrlEvents('onremoveerror', { data: response && response.data ? response.data : arg });
} }
}).catch((error: any) => { }).catch((error: any) => {
this.handleCtrlEvents('onremoveerror', { data: error && error.data ? error.data : arg }).then((removeErrorResult) => {
if (!removeErrorResult) {
const { data: _data } = error; const { data: _data } = error;
this.$Notice.error({ title: _data.title, desc: _data.message }); this.$Notice.error({ title: _data.title, desc: _data.message });
reject(error); reject(error);
}
})
}); });
})
}); });
} }
<#if ctrl.getControlType() == 'FORM'> <#if ctrl.getControlType() == 'FORM'>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册