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