提交 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;
}
} }
}).catch((response: any) => { return response;
if (response && response.status && response.data) { } catch (response: any) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message }); if (!(await this.handleCtrlEvents('onloaderror', { context: tempContext, viewparams: viewparamResult, data: response && response.data ? response.data : arg }))) {
return; 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: (this.$t('app.commonWords.sysException') as string) }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
return; return;
} }
}); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
}
} }
/** /**
...@@ -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;
if (response && response.status && response.data) { } catch (response: any) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message }); if (!(await this.handleCtrlEvents('onloaddrafterror', { data: response.data ? response.data : arg }))) {
return; 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: (this.$t('app.commonWords.sysException') as string) }); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
return; return response;
} }
}); this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
}
} }
/** /**
...@@ -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,71 +1409,89 @@ import { Environment } from '@/environments/environment'; ...@@ -1388,71 +1409,89 @@ 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) => {
post.then((response: any) => { if (!beforeSaveResult) {
if (!response.status || response.status !== 200) {
if (response.data) {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
}
return; return;
} }
this.viewparams.copymode = false; 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);
const data = response.data; post.then((response: any) => {
this.onFormLoad(data,'save'); if (!response.status || response.status !== 200) {
this.$emit('save', data); this.handleCtrlEvents('onsaverror', { data: response && response.data ? response.data : arg }).then((saveErrorResult: boolean) => {
<#if ctrl.getControlType() == 'FORM'> // 保存失败处理
AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data}); })
</#if> if (response.data) {
this.$nextTick(() => { this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
this.formState.next({ type: 'save', data: data }); }
}); return;
<#if ctrl.getFormFuncMode()?lower_case != 'wizardform'> }
if (showResultInfo) { this.handleCtrlEvents('onsavesuccess', { data: response.data }).then((saveSuccessResult: boolean) => {
this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;'+ (this.$t('app.formpage.savesuccess') as string) }); if (!saveSuccessResult) {
} return;
</#if> }
resolve(response); this.viewparams.copymode = false;
}).catch((response: any) => { const data = response.data;
if (response && response.status && response.data) { this.onFormLoad(data,'save');
if (response.data.errorKey) { this.$emit('save', data);
if(Object.is(response.data.errorKey, "versionCheck")) { <#if ctrl.getControlType() == 'FORM'>
this.$Modal.confirm({ AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
title: (this.$t('app.formpage.saveerror') as string), </#if>
content: (this.$t('app.formpage.savecontent') as string), this.$nextTick(() => {
onOk: () => { this.formState.next({ type: 'save', data: data });
this.refresh([]); });
}, <#if ctrl.getFormFuncMode()?lower_case != 'wizardform'>
onCancel: () => { } if (showResultInfo) {
}); this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;'+ (this.$t('app.formpage.savesuccess') as string) });
} else if(Object.is(response.data.errorKey, 'DupCheck')) { }
let errorProp: string = response.data.message.match(/\[[a-zA-Z]*\]/)[0]; </#if>
let name: string = this.service.getNameByProp(errorProp.substr(1, errorProp.length-2)); resolve(response);
if(name) { })
this.$Notice.error({ }).catch((response: any) => {
title: (this.$t('app.commonWords.createFailed') as string), this.handleCtrlEvents('onsaveerror', { data: response && response.data ? response.data : {} }).then((saveErrorResult: boolean) => {
desc: this.detailsModel[name].caption + " : " + arg[name] + (this.$t('app.commonWords.isExist') as string) + '!', if (!saveErrorResult) {
}); return;
}
if (response && response.status && response.data) {
if (response.data.errorKey) {
if(Object.is(response.data.errorKey, "versionCheck")) {
this.$Modal.confirm({
title: (this.$t('app.formpage.saveerror') as string),
content: (this.$t('app.formpage.savecontent') as string),
onOk: () => {
this.refresh([]);
},
onCancel: () => { }
});
} else if(Object.is(response.data.errorKey, 'DupCheck')) {
let errorProp: string = response.data.message.match(/\[[a-zA-Z]*\]/)[0];
let name: string = this.service.getNameByProp(errorProp.substr(1, errorProp.length-2));
if(name) {
this.$Notice.error({
title: (this.$t('app.commonWords.createFailed') as string),
desc: this.detailsModel[name].caption + " : " + arg[name] + (this.$t('app.commonWords.isExist') as string) + '!',
});
} else {
this.$Notice.error({
title: (this.$t('app.commonWords.createFailed') as string),
desc: response.data.message,
})
}
} else {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
}
} else { } else {
this.$Notice.error({ this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
title: (this.$t('app.commonWords.createFailed') as string), reject(response);
desc: response.data.message,
})
} }
return;
} else { } else {
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: (this.$t('app.commonWords.sysException') as string) });
} reject(response);
} else { }
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
reject(response); reject(response);
} })
return; });
} else { })
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
reject(response);
}
reject(response);
});
}) })
} }
...@@ -1471,24 +1510,37 @@ import { Environment } from '@/environments/environment'; ...@@ -1471,24 +1510,37 @@ 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) {
const data = response.data; return;
this.$emit('remove',data);
this.formState.next({ type: 'remove', data: data });
this.data.ismodify = false;
this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;' + (this.$t('app.formpage.deletesuccess') as string) });
<#if ctrl.getControlType() == 'FORM'>
AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
</#if>
resolve(response);
} }
}).catch((error: any) => { this.service.delete(_this.removeAction, JSON.parse(JSON.stringify(this.context)), arg, showResultInfo).then((response: any) => {
const { data: _data } = error; if (response && response.status === 200) {
this.$Notice.error({ title: _data.title, desc: _data.message }); this.handleCtrlEvents('onremovesuccess', { data: response.data }).then((removeSuccessResult: boolean) => {
reject(error); const data = response.data;
}); this.$emit('remove',data);
this.formState.next({ type: 'remove', data: data });
this.data.ismodify = false;
this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;' + (this.$t('app.formpage.deletesuccess') as string) });
<#if ctrl.getControlType() == 'FORM'>
AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
</#if>
resolve(response);
})
} else {
this.handleCtrlEvents('onremoveerror', { data: response && response.data ? response.data : arg });
}
}).catch((error: any) => {
this.handleCtrlEvents('onremoveerror', { data: error && error.data ? error.data : arg }).then((removeErrorResult) => {
if (!removeErrorResult) {
const { data: _data } = error;
this.$Notice.error({ title: _data.title, desc: _data.message });
reject(error);
}
})
});
})
}); });
} }
<#if ctrl.getControlType() == 'FORM'> <#if ctrl.getControlType() == 'FORM'>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册