新增jnt模板引擎
This commit is contained in:
parent
7eadff782e
commit
6772266b95
@ -1,6 +1,7 @@
|
|||||||
using Hei.Captcha;
|
using Hei.Captcha;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Extensions;
|
using Infrastructure.Extensions;
|
||||||
|
using JinianNet.JNTemplate;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
@ -84,6 +85,14 @@ namespace ZR.Admin.WebApi
|
|||||||
c.IncludeXmlComments("ZRAdmin.xml", true);
|
c.IncludeXmlComments("ZRAdmin.xml", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//jnt模板引擎全局变量
|
||||||
|
Engine.Configure((options) =>
|
||||||
|
{
|
||||||
|
options.Data.Set("author", Configuration["gen:author"]);
|
||||||
|
options.Data.Set("time", DateTime.Now.ToString("yyyy-MM-dd"));
|
||||||
|
//...其它数据
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
|||||||
@ -1,24 +1,24 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using {ModelsNamespace}.Dto;
|
using ${ModelsNamespace}.Dto;
|
||||||
using {ModelsNamespace}.Models;
|
using ${ModelsNamespace}.Models;
|
||||||
|
|
||||||
namespace {DtosNamespace}.Dto
|
namespace ${DtosNamespace}.Dto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {FunctionName}输入对象模型
|
/// ${FunctionName}输入对象模型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class {ModelTypeName}Dto
|
public class ${ModelTypeName}Dto
|
||||||
{
|
{
|
||||||
{PropertyName}
|
${PropertyName}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {FunctionName}查询对象模型
|
/// ${FunctionName}查询对象模型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class {ModelTypeName}QueryDto: PagerInfo
|
public class ${ModelTypeName}QueryDto: PagerInfo
|
||||||
{
|
{
|
||||||
{QueryProperty}
|
${QueryProperty}
|
||||||
public DateTime? BeginTime { get; set; }
|
public DateTime? BeginTime { get; set; }
|
||||||
public DateTime? EndTime { get; set; }
|
public DateTime? EndTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
||||||
<el-form :model="queryParams" label-position="left" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" @submit.native.prevent>
|
<el-form :model="queryParams" label-position="left" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" @submit.native.prevent>
|
||||||
{vueQueryFormHtml}
|
${vueQueryFormHtml}
|
||||||
<el-row class="mb8" style="text-align:center">
|
<el-row class="mb8" style="text-align:center">
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||||
@ -12,13 +12,13 @@
|
|||||||
<!-- 工具区域 -->
|
<!-- 工具区域 -->
|
||||||
<el-row :gutter="10" class="mb8">
|
<el-row :gutter="10" class="mb8">
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button type="primary" v-hasPermi="['{Permission}:add']" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
|
<el-button type="primary" v-hasPermi="['${Permission}:add']" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button type="success" :disabled="single" v-hasPermi="['{Permission}:update']" plain icon="el-icon-edit" size="mini" @click="handleUpdate">修改</el-button>
|
<el-button type="success" :disabled="single" v-hasPermi="['${Permission}:update']" plain icon="el-icon-edit" size="mini" @click="handleUpdate">修改</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button type="danger" :disabled="multiple" v-hasPermi="['{Permission}:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
|
<el-button type="danger" :disabled="multiple" v-hasPermi="['${Permission}:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
</el-row>
|
</el-row>
|
||||||
@ -26,12 +26,12 @@
|
|||||||
<!-- 数据区域 -->
|
<!-- 数据区域 -->
|
||||||
<el-table :data="dataList" ref="table" border @selection-change="handleSelectionChange">
|
<el-table :data="dataList" ref="table" border @selection-change="handleSelectionChange">
|
||||||
<el-table-column type="selection" width="50" />
|
<el-table-column type="selection" width="50" />
|
||||||
{VueViewListContent}
|
${VueViewListContent}
|
||||||
<el-table-column label="操作" align="center" width="200">
|
<el-table-column label="操作" align="center" width="200">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button v-hasPermi="['{Permission}:update']" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
|
<el-button v-hasPermi="['${Permission}:update']" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
|
||||||
<el-popconfirm title="确定删除吗?" @confirm="handleDelete(scope.row)" style="margin-left:10px">
|
<el-popconfirm title="确定删除吗?" @confirm="handleDelete(scope.row)" style="margin-left:10px">
|
||||||
<el-button slot="reference" v-hasPermi="['{Permission}:delete']" type="text" icon="el-icon-delete">删除</el-button>
|
<el-button slot="reference" v-hasPermi="['${Permission}:delete']" type="text" icon="el-icon-delete">删除</el-button>
|
||||||
</el-popconfirm>
|
</el-popconfirm>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@ -42,7 +42,7 @@
|
|||||||
<el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
|
<el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
|
||||||
<el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
|
<el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
|
||||||
<el-row>
|
<el-row>
|
||||||
{VueViewFormContent}
|
${VueViewFormContent}
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
<div slot="footer" class="dialog-footer" v-if="btnSubmitVisible">
|
<div slot="footer" class="dialog-footer" v-if="btnSubmitVisible">
|
||||||
@ -55,23 +55,20 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import {
|
import {
|
||||||
list{ModelTypeName},
|
list${ModelTypeName},
|
||||||
add{ModelTypeName},
|
add${ModelTypeName},
|
||||||
del{ModelTypeName},
|
del${ModelTypeName},
|
||||||
update{ModelTypeName},
|
update${ModelTypeName},
|
||||||
get{ModelTypeName}
|
get${ModelTypeName}
|
||||||
} from '@/api/{fileClassName}.js';
|
} from '@/api/${fileClassName}.js';
|
||||||
|
|
||||||
{VueComponentImport}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "{ModelTypeName}",
|
name: "${ModelTypeName}",
|
||||||
components: { {VueComponent} },
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
labelWidth: "100px",
|
labelWidth: "100px",
|
||||||
formLabelWidth:"100px",
|
formLabelWidth:"100px",
|
||||||
// 选中{PrimaryKey}数组
|
// 选中${PrimaryKey}数组
|
||||||
ids: [],
|
ids: [],
|
||||||
// 非单个禁用
|
// 非单个禁用
|
||||||
single: true,
|
single: true,
|
||||||
@ -91,7 +88,7 @@ export default {
|
|||||||
form: {},
|
form: {},
|
||||||
// 时间范围数组
|
// 时间范围数组
|
||||||
timeRange: [],
|
timeRange: [],
|
||||||
{VueDataContent}
|
${VueDataContent}
|
||||||
// 数据列表
|
// 数据列表
|
||||||
dataList: [],
|
dataList: [],
|
||||||
// 总记录数
|
// 总记录数
|
||||||
@ -100,7 +97,7 @@ export default {
|
|||||||
btnSubmitVisible: true,
|
btnSubmitVisible: true,
|
||||||
// 表单校验
|
// 表单校验
|
||||||
rules: {
|
rules: {
|
||||||
{VueViewEditFormRuleContent}
|
${VueViewEditFormRuleContent}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -108,13 +105,13 @@ export default {
|
|||||||
// 列表数据查询
|
// 列表数据查询
|
||||||
this.getList();
|
this.getList();
|
||||||
|
|
||||||
{MountedMethod}
|
${MountedMethod}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 查询数据
|
// 查询数据
|
||||||
getList() {
|
getList() {
|
||||||
console.log(JSON.stringify(this.queryParams));
|
console.log(JSON.stringify(this.queryParams));
|
||||||
list{ModelTypeName}(this.addDateRange(this.queryParams, this.timeRange)).then(res => {
|
list${ModelTypeName}(this.addDateRange(this.queryParams, this.timeRange)).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
this.dataList = res.data.result;
|
this.dataList = res.data.result;
|
||||||
this.total = res.data.totalNum;
|
this.total = res.data.totalNum;
|
||||||
@ -129,7 +126,7 @@ export default {
|
|||||||
// 重置数据表单
|
// 重置数据表单
|
||||||
reset() {
|
reset() {
|
||||||
this.form = {
|
this.form = {
|
||||||
{VueViewFormResetHtml}
|
${VueViewFormResetHtml}
|
||||||
//TODO 根据实际内容调整
|
//TODO 根据实际内容调整
|
||||||
};
|
};
|
||||||
this.resetForm("form");
|
this.resetForm("form");
|
||||||
@ -147,7 +144,7 @@ export default {
|
|||||||
},
|
},
|
||||||
// 多选框选中数据
|
// 多选框选中数据
|
||||||
handleSelectionChange(selection) {
|
handleSelectionChange(selection) {
|
||||||
this.ids = selection.map((item) => item.{PrimaryKey});
|
this.ids = selection.map((item) => item.${PrimaryKey});
|
||||||
this.single = selection.length != 1
|
this.single = selection.length != 1
|
||||||
this.multiple = !selection.length;
|
this.multiple = !selection.length;
|
||||||
},
|
},
|
||||||
@ -163,8 +160,8 @@ export default {
|
|||||||
},
|
},
|
||||||
/** 删除按钮操作 */
|
/** 删除按钮操作 */
|
||||||
handleDelete(row) {
|
handleDelete(row) {
|
||||||
const {PrimaryKey}s = row.{PrimaryKey} || this.ids;
|
const ${PrimaryKey}s = row.${PrimaryKey} || this.ids;
|
||||||
del{ModelTypeName}({PrimaryKey}s.toString()).then((res) => {
|
del${ModelTypeName}(${PrimaryKey}s.toString()).then((res) => {
|
||||||
this.msgSuccess("删除成功");
|
this.msgSuccess("删除成功");
|
||||||
this.handleQuery();
|
this.handleQuery();
|
||||||
});
|
});
|
||||||
@ -172,8 +169,8 @@ export default {
|
|||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
handleUpdate(row) {
|
handleUpdate(row) {
|
||||||
this.reset();
|
this.reset();
|
||||||
const {PrimaryKey} = row.{PrimaryKey} || this.ids;
|
const ${PrimaryKey} = row.${PrimaryKey} || this.ids;
|
||||||
get{ModelTypeName}({PrimaryKey}).then((res) => {
|
get${ModelTypeName}(${PrimaryKey}).then((res) => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
this.form = res.data;
|
this.form = res.data;
|
||||||
this.open = true;
|
this.open = true;
|
||||||
@ -181,15 +178,15 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
{vueJsMethod}
|
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
submitForm: function () {
|
submitForm: function () {
|
||||||
this.$refs["form"].validate((valid) => {
|
this.$refs["form"].validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
console.log(JSON.stringify(this.form));
|
console.log(JSON.stringify(this.form));
|
||||||
|
|
||||||
if (this.form.{PrimaryKey} != undefined || this.title === "修改数据") {
|
if (this.form.${PrimaryKey} != undefined || this.title === "修改数据") {
|
||||||
update{ModelTypeName}(this.form).then((res) => {
|
update${ModelTypeName}(this.form).then((res) => {
|
||||||
if (!res.data) {
|
if (!res.data) {
|
||||||
this.msgError("修改失败");
|
this.msgError("修改失败");
|
||||||
return;
|
return;
|
||||||
@ -199,7 +196,7 @@ export default {
|
|||||||
this.getList();
|
this.getList();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
add{ModelTypeName}(this.form).then((res) => {
|
add${ModelTypeName}(this.form).then((res) => {
|
||||||
if (!res.data) {
|
if (!res.data) {
|
||||||
this.msgError("新增失败");
|
this.msgError("新增失败");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
|
using JinianNet.JNTemplate;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -200,17 +201,18 @@ namespace ZR.CodeGenerator
|
|||||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var content = FileHelper.ReadTemplate("InputDtoTemplate.txt")
|
var tpl = FileHelper.ReadJtTemplate("InputDtoTemplate.txt");
|
||||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
tpl.Set("DtosNamespace", _option.DtosNamespace);
|
||||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
tpl.Set("ModelsNamespace", _option.ModelsNamespace);
|
||||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
tpl.Set("FunctionName", generateDto.GenTable.FunctionName);
|
||||||
.Replace("{PropertyName}", replaceDto.InputDtoProperty)
|
tpl.Set("PropertyName", replaceDto.InputDtoProperty);
|
||||||
.Replace("{QueryProperty}", replaceDto.QueryProperty)
|
tpl.Set("QueryProperty", replaceDto.QueryProperty);
|
||||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
tpl.Set("ModelTypeName", replaceDto.ModelTypeName);
|
||||||
.Replace("{Author}", replaceDto.Author)
|
tpl.Set("Author", replaceDto.Author);
|
||||||
.Replace("{DateTime}", replaceDto.AddTime);
|
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
|
#endregion
|
||||||
|
|
||||||
@ -359,6 +361,27 @@ namespace ZR.CodeGenerator
|
|||||||
.Replace("{VueViewEditFormRuleContent}", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
|
.Replace("{VueViewEditFormRuleContent}", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
|
||||||
|
|
||||||
generateDto.GenCodes.Add(new GenCode(6, "index.vue", fullPath, content));
|
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>
|
/// <summary>
|
||||||
/// 7、生成vue页面api
|
/// 7、生成vue页面api
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using JinianNet.JNTemplate;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
@ -108,6 +109,16 @@ namespace ZR.CodeGenerator
|
|||||||
return str;
|
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>
|
/// <summary>
|
||||||
/// 压缩代码
|
/// 压缩代码
|
||||||
|
|||||||
@ -105,6 +105,7 @@ namespace ZR.CodeGenerator.Model
|
|||||||
/// 上传URL data
|
/// 上传URL data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string VueUploadUrl { get; set; }
|
public string VueUploadUrl { get; set; }
|
||||||
|
public bool UploadImage{ get; set; }
|
||||||
public string Author { get; set; }
|
public string Author { get; set; }
|
||||||
public string AddTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
|
public string AddTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="JinianNet.JNTemplate" Version="2.2.4" />
|
||||||
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.4.3" />
|
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.4.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user