easyabp / abp.datadictionary Goto Github PK
View Code? Open in Web Editor NEWAbp data dictionary module.
License: MIT License
Abp data dictionary module.
License: MIT License
CacheDataDictionaryValueProvider
在找不到字典数据时直接抛出了404
但个人感觉其实这种情况下,直接返回null,不渲染或者fallback就行了。
能否根据用户的配置进行异常处理?
目前访问这些接口,好像必须是登录的,角色必须是admin的时候才可以访问,请问如何匿名访问这些接口
很常见地,数据对象会有一些非简单类型的成员、列表等也可能含有需要渲染的字典字段。
以目前的方式,只能逐个去手动处理,在试着手动渲染了几处之后,发现非常的麻烦且冗余。
希望能加上自动渲染复杂对象的功能。
我尝试自己扩展,临时实现了一下,方式可能不是太好,供参考。
加了一个特性:DictionaryChildFieldAttribute
,用来标记需要进一步渲染的字段。
扩展了DataDictionaryLoader
的ScanRules
方法:
把标记了DictionaryChildField
的字段记录下来,并且判断一下是否是IEnumerable
,也记录下来
这里借用了 DataDictionaryRule
,临时用自己的方式保存了规则信息
var properties = type
.GetProperties()
.Where(p => p.IsDefined(typeof(DictionaryChildFieldAttribute)))
.ToList();
rules.AddRange(properties.Select(property => new DataDictionaryRule
{
DictionaryCode = property.PropertyType.IsAssignableTo(typeof(IEnumerable)) ? "IEnumerable" : "",
DtoType = type,
RenderFieldProperty = property,
DictionaryCodeProperty = null
}));
在需要的字段加上这个特性作为标记:
public class PlanDto {
[DictionaryCodeField(“Category")]
public string Category { get; set; }
[DictionaryRenderField(“Category")]
public string CategoryName { get; set; }
[DictionaryChildField]
public List<TeamDto> Teams {get;set;}
[DictionaryChildField]
public User Manager {get;set;}
}
扩展了一个非泛型的Render方法,将 Type 作为参数传入: Task RenderAsync(object sourceDto, Type dtoType)
渲染时,增加了对”新规则“的处理:
if (rule.DictionaryCodeProperty == null)
{
var childDto = rule.RenderFieldProperty.GetValue(sourceDto);
if (rule.DictionaryCode == "IEnumerable" && childDto != null)
{
var type = rule.RenderFieldProperty.PropertyType.GenericTypeArguments.FirstOrDefault();
foreach (var item in (IEnumerable) childDto)
{
await RenderAsync(item, type);
}
}
else
{
await RenderAsync(childDto, rule.RenderFieldProperty.PropertyType);
}
continue;
}
目前使用暂无问题,但还是希望用上原生功能
DataDictionaryDbContextModelBuilderExtensions.ConfigureDataDictionary扩展方法应多加Action optionsAction = null,并进行optionsAction?.Invoke(options);
有时候一个 code ,可能会用来渲染多个不同的字段:
比如:
[
{code:1,name:'一级',color:'红色'},
{code:2,name:'二级',color:'蓝色'}
]
根据以上数据分别定义了字典LevelName
和 LevelColor
,略...
[DictionaryCodeField("LevelName")] // <-- Color 怎么办
public string Code {get;set;}
[DictionaryCodeField("LevelName")]
public string Name {get;set;}
[DictionaryCodeField("LevelColor")]
public string Color {get;set;}
DataDictionary
有 IsStatic
DataDictionaryItem
是否也能加上,或者实现一下 IHasExtraProperties
让我们自己扩展。
有时候需要 Seed 一些作为系统内置的字典值,不想让用户删掉
Hi
Can you tell me more about the intent of the data dictionary module?
Will it be possible to use it to document the domain layer, or is it to document the data transfer objects?
Or, am I missing the point.
Thanks
Jamie
abp的EntityFrameworkCore层都是用的netstandard2.1,目前EasyAbp.Abp.DataDictionary.EntityFrameworkCore的目标架构是net5.0应该改为netstandard2.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.