新增jnt模板引擎

This commit is contained in:
不做码农
2021-11-29 21:54:01 +08:00
parent 7eadff782e
commit 6772266b95
7 changed files with 95 additions and 53 deletions

View File

@@ -1,4 +1,5 @@
using Infrastructure;
using JinianNet.JNTemplate;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -200,17 +201,18 @@ namespace ZR.CodeGenerator
if (File.Exists(fullPath) && !generateDto.Coverd)
return;
var content = FileHelper.ReadTemplate("InputDtoTemplate.txt")
.Replace("{DtosNamespace}", _option.DtosNamespace)
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
.Replace("{PropertyName}", replaceDto.InputDtoProperty)
.Replace("{QueryProperty}", replaceDto.QueryProperty)
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
.Replace("{Author}", replaceDto.Author)
.Replace("{DateTime}", replaceDto.AddTime);
var tpl = FileHelper.ReadJtTemplate("InputDtoTemplate.txt");
tpl.Set("DtosNamespace", _option.DtosNamespace);
tpl.Set("ModelsNamespace", _option.ModelsNamespace);
tpl.Set("FunctionName", generateDto.GenTable.FunctionName);
tpl.Set("PropertyName", replaceDto.InputDtoProperty);
tpl.Set("QueryProperty", replaceDto.QueryProperty);
tpl.Set("ModelTypeName", replaceDto.ModelTypeName);
tpl.Set("Author", replaceDto.Author);
tpl.Set("DateTime", replaceDto.AddTime);
generateDto.GenCodes.Add(new GenCode(2, "数据传输实体类", fullPath, content));
var result = tpl.Render();
generateDto.GenCodes.Add(new GenCode(2, "数据传输实体类", fullPath, result));
}
#endregion
@@ -359,6 +361,27 @@ namespace ZR.CodeGenerator
.Replace("{VueViewEditFormRuleContent}", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
generateDto.GenCodes.Add(new GenCode(6, "index.vue", fullPath, content));
//var tpl = FileHelper.ReadJtTemplate("VueTemplate.txt");
//tpl.Set("fileClassName", replaceDto.ViewsFileName);
//tpl.Set("VueViewListContent", replaceDto.VueViewListHtml);//查询 table列
//tpl.Set("VueViewFormContent", replaceDto.VueViewFormHtml);//添加、修改表单
//tpl.Set("ModelTypeName", replaceDto.ModelTypeName);
//tpl.Set("Permission", replaceDto.Permission);
//tpl.Set("VueViewFormResetHtml", replaceDto.VueViewFormResetHtml);
////tpl.Set("vueJsMethod}", replaceDto.VueJsMethod);
////tpl.Set("vueQueryFormHtml", replaceDto.VueQueryFormHtml);
////tpl.Set("VueDataContent", replaceDto.VueDataContent);
////tpl.Set("PrimaryKey", FirstLowerCase(replaceDto.PKName));
////tpl.Set("MountedMethod", replaceDto.MountedMethod);
////tpl.Set("VueComponent", replaceDto.VueComponent.TrimEnd(','));
////tpl.Set("VueComponentImport", replaceDto.VueComponentImport);
////tpl.Set("VueViewEditFormRuleContent", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
//tpl.Set("uploadImage", generateDto.GenTable.Columns.Any(x => x.HtmlType == GenConstants.HTML_IMAGE_UPLOAD));
//var result = tpl.Render();
//generateDto.GenCodes.Add(new GenCode(6, "index.vue", fullPath, result));
}
/// <summary>
/// 7、生成vue页面api

View File

@@ -1,4 +1,5 @@
using System;
using JinianNet.JNTemplate;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
@@ -108,6 +109,16 @@ namespace ZR.CodeGenerator
return str;
}
public static ITemplate ReadJtTemplate(string tplName)
{
string path = Environment.CurrentDirectory;
string fullName = Path.Combine(path, "wwwroot", "CodeGenTemplate", tplName);
if (File.Exists(fullName))
{
return Engine.LoadTemplate(fullName);
}
return null;
}
/// <summary>
/// 压缩代码

View File

@@ -105,6 +105,7 @@ namespace ZR.CodeGenerator.Model
/// 上传URL data
/// </summary>
public string VueUploadUrl { get; set; }
public bool UploadImage{ get; set; }
public string Author { get; set; }
public string AddTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
}

View File

@@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="JinianNet.JNTemplate" Version="2.2.4" />
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.4.3" />
</ItemGroup>