feat: 完成web to code及code to web功能

This commit is contained in:
橙子
2023-09-28 12:59:25 +08:00
parent f095fde5a7
commit fcb0ea9574
4 changed files with 66 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.DirectoryServices.ActiveDirectory;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -11,6 +12,7 @@ using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Mapster.Utils;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Asn1.Ntt;
using SqlSugar;
@@ -78,22 +80,56 @@ namespace Yi.Framework.Module.WebFirstManager.Domain
}
private FieldEntity PropertyMapperToFiled(PropertyInfo propertyInfo)
private FieldEntity PropertyMapperToFiled(PropertyInfo propertyInfo)
{
var fieldEntity = new FieldEntity();
fieldEntity.Name = propertyInfo.Name;
var enumName = typeof(FieldTypeEnum).GetFields(BindingFlags.Static | BindingFlags.Public).Where(x => x.GetCustomAttribute<DisplayAttribute>()?.Name== propertyInfo.PropertyType.Name).FirstOrDefault()?.Name;
if (enumName is null)
//获取数据类型,包括可空类型
Type? fieldType = null;
// 如果字段类型是 Nullable<T> 泛型类型
if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
fieldEntity.FieldType = FieldTypeEnum.String;
Console.Out.WriteLine($"字段类型:{propertyInfo.PropertyType.Name},未定义");
//throw new ApplicationException($"字段类型:{propertyInfo.PropertyType.Name},未定义");
Type nullableType = Nullable.GetUnderlyingType(propertyInfo.PropertyType)!;
fieldType = nullableType;
}
else
{
fieldEntity.FieldType =EasyTool.EnumUtil.Parse<FieldTypeEnum>(enumName);
fieldType = propertyInfo.PropertyType;
}
//判断类型
var enumName = typeof(FieldTypeEnum).GetFields(BindingFlags.Static | BindingFlags.Public).Where(x => x.GetCustomAttribute<DisplayAttribute>()?.Description == fieldType.Name).FirstOrDefault()?.Name;
if (enumName is null)
{
fieldEntity.FieldType = FieldTypeEnum.String;
// App.GetRequiredService<ILogger<WebTemplateManager>>().LogError($"字段类型:{propertyInfo.PropertyType.Name},未定义");
}
else
{
fieldEntity.FieldType = EasyTool.EnumUtil.Parse<FieldTypeEnum>(enumName);
}
//判断是否可空
if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
fieldEntity.IsRequired = false;
}
else
{
fieldEntity.IsRequired = true;
}
//判断是否主键
if (propertyInfo.GetCustomAttribute<SugarColumn>()?.IsPrimaryKey == true)
{
fieldEntity.IsKey = true;
}
//判断长度
var colum = propertyInfo.GetCustomAttribute<SugarColumn>();
if (colum is not null && colum.Length != 0)
{

View File

@@ -19,5 +19,14 @@ namespace Yi.Framework.Module.WebFirstManager.Enums
[Display(Name = "long", Description = "Int64")]
Long,
[Display(Name ="bool",Description = "Boolean")]
Bool,
[Display(Name = "decimal",Description = "Decimal")]
Decimal,
[Display(Name = "DateTime", Description = "DateTime")]
DateTime,
}
}

View File

@@ -53,8 +53,15 @@ namespace Yi.Framework.Module.WebFirstManager.Handler
fieldStrs.AppendLine(lengthStr);
}
//添加可空类型
string nullStr ="";
if (field.IsRequired == false)
{
nullStr = "?";
}
//添加字段
var fieldStr = $"public {typeStr} {nameStr} {{ get; set; }}";
var fieldStr = $"public {typeStr}{nullStr} {nameStr} {{ get; set; }}";
fieldStrs.AppendLine(fieldStr);
}

View File

@@ -41,6 +41,7 @@
v-hasPermi="['system:config:add']"
>新增</el-button
>
<!-- :disabled="props.table.name==null" -->
</el-col>
<el-col :span="1.5">
<el-button
@@ -94,7 +95,11 @@
</template>
</el-table-column>
<el-table-column label="长度" align="center" prop="length" />
<el-table-column label="长度" align="center" prop="length" >
<template #default="scope">
{{ scope.row.length==0?'-':scope.row.length }}
</template>
</el-table-column>
<el-table-column label="是否必填" align="center" prop="isRequired" >
<template #default="scope">