Former-commit-id: 4f481d916f06a9813a809a79a96c01df48367961
Former-commit-id: 12b533a0ad5687150857c9ff4505e070751168b7
TSXN
wanggang 5 years ago
parent 9a3f38e2ef
commit 7128bfde22

@ -89,10 +89,20 @@ namespace Infrastructure.Extensions
else if (modelType == typeof(int) || modelType == typeof(long))
{
json.type = "integer";
json.ui = "string";
json.digits = new
{
message = "整数格式错误"
};
}
else if (modelType == typeof(float) || modelType == typeof(double) || modelType == typeof(decimal))
{
json.type = "number";
json.ui = "string";
json.number = new
{
message = "数值格式错误"
};
}
else if (modelType == typeof(bool))
{
@ -130,26 +140,45 @@ namespace Infrastructure.Extensions
json.pattern = new
{
regex = regularExpressionAttribute.Pattern,
message = regularExpressionAttribute.GetErrorMessage(localizer, metadata.DisplayName)
message = regularExpressionAttribute.GetErrorMessage(localizer, metadata.DisplayName,regularExpressionAttribute.Pattern)
};
}
else if (attribute is DataTypeAttribute dataTypeAttribute)
{//format
if (dataTypeAttribute.DataType == DataType.DateTime)
if (dataTypeAttribute.DataType == DataType.EmailAddress)
{
json.format = "date-time";
json.format = "email";
json.ui = "string";
json.email =new {
message = "email格式错误"
};
}
else if (dataTypeAttribute.DataType == DataType.Time)
else if (dataTypeAttribute.DataType == DataType.Url)
{
json.format = "time";
json.format = "url";
json.ui = "string";
json.url = new
{
message = "url格式错误"
};
}
else if (dataTypeAttribute.DataType == DataType.EmailAddress)
else if (dataTypeAttribute.DataType == DataType.DateTime)
{
json.format = "email";
json.format = "date";
json.ui = "string";
json.date = new
{
message = "日期格式错误"
};
}
else if (dataTypeAttribute.DataType == DataType.Url)
else if (dataTypeAttribute.DataType == DataType.CreditCard)
{
json.format = "uri";
json.format = "creditcard";
json.ui = "string";
json.url = new
{
message = "信用卡格式错误"
};
}
else if (dataTypeAttribute.DataType == DataType.Custom)
{//自定义
@ -169,7 +198,7 @@ namespace Infrastructure.Extensions
json.minLength = new
{
min = minLengthAttribute.Length,
message = minLengthAttribute.GetErrorMessage(localizer, metadata.DisplayName)
message = minLengthAttribute.GetErrorMessage(localizer, metadata.DisplayName,minLengthAttribute.Length.ToString())
};
}
else if (attribute is MaxLengthAttribute maxLengthAttribute)
@ -177,12 +206,12 @@ namespace Infrastructure.Extensions
json.maxLength = new
{
max = maxLengthAttribute.Length,
message = maxLengthAttribute.GetErrorMessage(localizer, metadata.DisplayName)
message = maxLengthAttribute.GetErrorMessage(localizer, metadata.DisplayName,maxLengthAttribute.ToString())
};
}
else if (attribute is StringLengthAttribute stringLengthAttribute)
{//minLength,maxLength
json.length = new
json.rangelength = new
{
min = stringLengthAttribute.MinimumLength,
max = stringLengthAttribute.MaximumLength,
@ -195,17 +224,17 @@ namespace Infrastructure.Extensions
{//minimum,maximum
json.range = new
{
minimum = rangeAttribute.Minimum,
maximum = rangeAttribute.Maximum,
min = rangeAttribute.Minimum,
max = rangeAttribute.Maximum,
message = rangeAttribute.GetErrorMessage(localizer, metadata.DisplayName,
rangeAttribute.Minimum.ToString(),
rangeAttribute.Minimum.ToString())
};
rangeAttribute.Maximum.ToString())
};
}
else if (attribute is CompareAttribute compareAttribute)
{//compare 自定义
var compareName = parent.Properties.FirstOrDefault(o => o.PropertyName == compareAttribute.OtherProperty)?.DisplayName;
json.compare = new
json.equalTo = new
{
other = compareAttribute.OtherProperty,
message = compareAttribute.GetErrorMessage(localizer, metadata.DisplayName, compareName)

@ -32,6 +32,7 @@ namespace Application.Models
[Required(ErrorMessage = nameof(RequiredAttribute))]
//for temp test start
//[Remote("Valid", "Ajax", "Admin", AdditionalFields = "CategoryNumber", ErrorMessage = "test ajax valid")]
//[Remote("CronValid", "Ajax", "Admin")]
//for temp test end
public string Name { get; set; }

@ -93,12 +93,23 @@
var value = this.data.model[name];
var property = this.data.schema.properties[name];
this.validInternal(property.required, name, o => value);
this.validInternal(property.pattern, name, o => new RegExp(property.pattern.regex).test(value));
this.validInternal(property.minLength, name, o => value.length >= property.minLength.min);
this.validInternal(property.maxLength, name, o => value.length <= property.maxLength.max);
this.validInternal(property.length, name, o => value.length >= property.length.min && value.length <= property.length.max);
this.validInternal(property.range, name, o => parseFloat(value) >= property.range.minimum && parseFloat(value) <= property.range.maximum);
this.validInternal(property.compare, name, o => o === vm.data.model[vm.camelCased(name)]);
if (value) {
this.validInternal(property.email, name, o => /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(value));
this.validInternal(property.url, name, o => /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value));
this.validInternal(property.date, name, o => !/Invalid|NaN/.test(new Date(value).toString()));
this.validInternal(property.number, name, o => /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value));
this.validInternal(property.digits, name, o => /^\d+$/.test(value));
//dateiso
//creditcard
//accept
this.validInternal(property.pattern, name, o => new RegExp(property.pattern.regex).test(value));
this.validInternal(property.minLength, name, o => value.length >= property.minLength.min);
this.validInternal(property.maxLength, name, o => value.length <= property.maxLength.max);
this.validInternal(property.rangelength, name, o => value.length >= property.length.min && value.length <= property.length.max);
this.validInternal(property.range, name, o => parseFloat(value) >= property.range.min && parseFloat(value) <= property.range.max);
this.validInternal(property.equalTo, name, o => o === vm.data.model[vm.camelCased(name)]);
}
this.validInternal(property.remote, name, o => {
var url = property.remote.url + '?' + name + '=' + value;
if (property.remote.additionalFields) {
@ -109,10 +120,9 @@
}
}
axios.get(url).then(function (response) {
if (response.data === true) {
vm.removeError(name);
}
else {
vm.removeError(name);
if (response.data !== true) {
var message = response.data === false ? property.remote.message : response.data;
vm.updateError(name, message);
}

Loading…
Cancel
Save