提交 938ecd72 编写于 作者: MosYCo's avatar MosYCo

update:更新多数据部件保存错误提示逻辑

上级 d4900644
......@@ -42,7 +42,7 @@ export interface FormControlState extends MainControlState {
* @type {string[]}
* @memberof FormControlState
*/
errorMessage: string[];
errorMessages: string[];
/**
* @description 表单通讯对象
......
......@@ -827,10 +827,10 @@ export class FormControl extends MainControl {
result = false;
if (error.errorFields && error.errorFields.length) {
const { detailsModel } = this.state;
this.state.errorMessage = [];
this.state.errorMessages = [];
error.errorFields.forEach((field: IParam) => {
const caption = detailsModel[field.name[0]]?.caption;
this.state.errorMessage.push(`${caption}: ${field.errors?.join('、')}`);
this.state.errorMessages.push(`${caption}: ${field.errors?.join('、')}`);
});
}
}
......@@ -844,16 +844,16 @@ export class FormControl extends MainControl {
* @memberof FormControl
*/
private showErrorMessage() {
const errorMessage = this.state.errorMessage;
if (errorMessage && errorMessage.length) {
const errorMessages = this.state.errorMessages;
if (errorMessages && errorMessages.length) {
const getMessage = () => {
const messages: any[] = [];
errorMessage.forEach((message: string) => {
messages.push(h('span', {}, message));
errorMessages.forEach((message: string) => {
messages.push(h('p', {}, message));
});
return messages;
}
const content = h('div', { class: 'error-messages', style: { 'display': 'flex', 'flex-direction': 'column' } }, getMessage());
const content = h('div', { class: 'error-messages' }, getMessage());
App.getNotificationService().error({ message: '值规则错误', description: content });
}
}
......
import { DataTypes, dateFormat, deepCopy, GridControlState, IActionParam, IParam, isExistAndNotEmpty, MDControl } from "@core";
import { DataTypes, dateFormat, deepCopy, GridControlState, IActionParam, IParam, isExistAndNotEmpty, MDControl, Verify } from "@core";
import { createUUID } from "qx-util";
import schema, { ErrorList, FieldErrorList } from 'async-validator';
import { Ref } from "vue";
......@@ -175,7 +175,7 @@ export class GridControl extends MDControl {
onResizeColumn,
onGridChange,
onExpandedRowsChange,
formRef:useFormRef()
formRef: useFormRef()
}
}
......@@ -242,21 +242,34 @@ export class GridControl extends MDControl {
* @memberof GridControl
*/
public validateField(name: string, value: any, rowIndex: number): Promise<boolean> {
return new Promise((resolve: any, reject: any) => {
const { rules, gridEditState } = toRefs(this.state);
const fileRule = rules.value[name];
if (!fileRule) {
return new Promise((resolve: any) => {
const { rules, gridEditState, columnsModel } = toRefs(this.state);
const fieldRule = rules.value[name];
if (!fieldRule) {
resolve(true);
return;
}
const validator = new schema({ [name]: fileRule });
const validator = new schema({ [name]: fieldRule });
validator.validate({ [name]: value }, undefined, (errors: ErrorList, fields: FieldErrorList) => {
const error = errors?.find((item: any) => {
return item.field === name;
})
gridEditState.value[name][rowIndex] = error;
});
if (error) {
gridEditState.value[name][rowIndex] = error;
const caption = columnsModel.value.find((model: IParam) => {
return model.dataIndex === name;
})?.title;
const errorMessage = `${caption}: ${error.message}`;
// 多行数据不保存重复错误提示信息
if (this.state.errorMessages.findIndex((m: string) => Object.is(m, errorMessage)) === -1) {
this.state.errorMessages.push(errorMessage);
}
resolve(false);
} else {
resolve(true);
}
})
})
});
}
/**
......@@ -798,7 +811,20 @@ export class GridControl extends MDControl {
* @memberof GridControl
*/
protected async validateAll(): Promise<boolean> {
return true;
const { items } = toRefs(this.state);
let index: number = 0;
let validateStatus: boolean = true;
for (const item of items.value) {
if (item.rowDataState === 'create' || item.rowDataState === 'update') {
for (const property of item.$ownKeys) {
if (!await this.validateField(property, item[property], index)) {
validateStatus = false;
}
}
}
index += 1;
}
return validateStatus;
}
/**
......
import { ControlVOBase, IParam, MainControlState } from '@core';
import { IParam, MainControlState } from '@core';
/**
* @description 多数据部件状态
......@@ -15,12 +15,19 @@ export interface MDControlState extends MainControlState {
*/
exportItems?: IParam[];
/**
* @description 错误信息
* @type {string[]}
* @memberof MDControlState
*/
errorMessages: string[];
/**
* @description 多数据部件数据
* @type {IParam[]}
* @memberof MDControlState
*/
items: ControlVOBase[];
items: IParam[];
/**
* @description 是否多选
......
......@@ -322,6 +322,7 @@ export class MDControl extends MainControl {
isLoading: showBusyIndicator,
});
this.setCreateDefault(response.data);
response.data.rowDataState = 'create';
if (response.status || response.status == 200) {
items.value.push(response.data);
}
......@@ -638,11 +639,11 @@ export class MDControl extends MainControl {
* @memberof MDControl
*/
private showErrorMessages() {
const errorMessage = this.state.errorMessage;
if (errorMessage && errorMessage.length) {
const errorMessages = this.state.errorMessages;
if (errorMessages && errorMessages.length) {
const getMessage = () => {
const messages: any[] = [];
errorMessage.forEach((message: string) => {
errorMessages.forEach((message: string) => {
messages.push(h('p', {}, message));
});
return messages;
......
import { deepCopy, IParam } from '@core';
import { deepCopy } from '@core';
export class ControlVOBase {
/**
......
......@@ -58,7 +58,7 @@ export const ctrlState = {
appDeMajorFieldName: '{{#if ctrl.appEntity.majorPSAppDEField}}{{ctrl.appEntity.majorPSAppDEField.codeName}}{{/if}}',
enableAutoSave: {{ctrl.enableAutoSave}},
// 错误信息
errorMessage: [],
errorMessages: [],
// 关系界面计数器
drCount: 0,
// 新建默认值
......
......@@ -5,6 +5,14 @@ export class ControlVO extends ControlVOBase {
constructor(data: any){
super(data);
// 表格自持属性
this.$ownKeys =
{{~#each ctrl.psDEGridDataItems as | dataItem | ~}}
{{#if @first}}[{{/if~}}
'{{lowerCase dataItem.name}}'{{#unless @last}},{{/unless}}
{{~#if @last}}];{{/if~}}
{{/each}}
}
{{#each ctrl.psDEGridDataItems as | dataItem |}}
{{#if dataItem.psAppDEField}}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册