优化代码生成模板
This commit is contained in:
parent
61038d01a0
commit
c4003e5ca4
36
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/QueryForm.txt
Normal file
36
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/QueryForm.txt
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
$foreach(column in genTable.Columns)
|
||||||
|
$set(labelName = "")
|
||||||
|
$set(columnName = "")
|
||||||
|
$set(numLabel = "")
|
||||||
|
|
||||||
|
$if(column.IsQuery == true)
|
||||||
|
$set(columnName = column.CsharpFieldFl)
|
||||||
|
|
||||||
|
$if(column.ColumnComment != "")
|
||||||
|
$set(labelName = column.ColumnComment)
|
||||||
|
$else
|
||||||
|
$set(labelName = column.CsharpFieldFl)
|
||||||
|
$end
|
||||||
|
$if(column.CsharpType == "int" || column.CsharpType == "long")
|
||||||
|
$set(numLabel = ".number")
|
||||||
|
$end
|
||||||
|
|
||||||
|
$if(column.HtmlType == "datetime")
|
||||||
|
<el-form-item label="$labelName">
|
||||||
|
<el-date-picker v-model="dateRange${column.CsharpField}" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
|
||||||
|
start-placeholder="开始日期" end-placeholder="结束日期" placeholder="请选择$labelName" :picker-options="{ firstDayOfWeek: 1}"></el-date-picker>
|
||||||
|
</el-form-item>
|
||||||
|
$elseif(column.HtmlType == "select" || column.HtmlType == "radio")
|
||||||
|
<el-form-item label="${labelName}" prop="${columnName}">
|
||||||
|
<el-select v-model="queryParams.${columnName}" placeholder="请选择${labelName}">
|
||||||
|
<el-option v-for="item in ${columnName}Options" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
$else
|
||||||
|
<el-form-item label="${labelName}" prop="${columnName}">
|
||||||
|
<el-input v-model${numLabel}="queryParams.${columnName}" placeholder="请输入${labelName}" />
|
||||||
|
</el-form-item>
|
||||||
|
$end
|
||||||
|
|
||||||
|
$end
|
||||||
|
$end
|
||||||
@ -1,7 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
||||||
<el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" @submit.native.prevent>
|
<el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch"
|
||||||
|
@submit.native.prevent>
|
||||||
${vueQueryFormHtml}
|
${vueQueryFormHtml}
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<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>
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
||||||
<el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" @submit.native.prevent>
|
<el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch"
|
||||||
|
@submit.native.prevent>
|
||||||
${vueQueryFormHtml}
|
${vueQueryFormHtml}
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<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>
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
||||||
<el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" @submit.native.prevent>
|
<el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch"
|
||||||
|
@submit.native.prevent>
|
||||||
${vueQueryFormHtml}
|
${vueQueryFormHtml}
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<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>
|
||||||
|
|||||||
@ -166,42 +166,42 @@ namespace ZR.CodeGenerator
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// Vue 查询表单
|
///// Vue 查询表单
|
||||||
/// </summary>
|
///// </summary>
|
||||||
/// <param name="dbFieldInfo"></param>
|
///// <param name="dbFieldInfo"></param>
|
||||||
/// <returns></returns>
|
///// <returns></returns>
|
||||||
public static string TplQueryFormHtml(GenTableColumn dbFieldInfo)
|
//public static string TplQueryFormHtml(GenTableColumn dbFieldInfo)
|
||||||
{
|
//{
|
||||||
StringBuilder sb = new();
|
// StringBuilder sb = new();
|
||||||
string columnName = dbFieldInfo.CsharpFieldFl;
|
// string columnName = dbFieldInfo.CsharpFieldFl;
|
||||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.CsharpField);
|
// string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.CsharpField);
|
||||||
if (!dbFieldInfo.IsQuery) return sb.ToString();
|
// if (!dbFieldInfo.IsQuery) return sb.ToString();
|
||||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
// if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||||
{
|
// {
|
||||||
sb.AppendLine($" <el-form-item label=\"{labelName}\">");
|
// sb.AppendLine($" <el-form-item label=\"{labelName}\">");
|
||||||
sb.AppendLine($" <el-date-picker v-model=\"dateRange{dbFieldInfo.CsharpField}\" style=\"width: 240px\" value-format=\"yyyy-MM-dd\" type=\"daterange\" range-separator=\"-\" start-placeholder=\"开始日期\"");
|
// sb.AppendLine($" <el-date-picker v-model=\"dateRange{dbFieldInfo.CsharpField}\" style=\"width: 240px\" value-format=\"yyyy-MM-dd\" type=\"daterange\" range-separator=\"-\" start-placeholder=\"开始日期\"");
|
||||||
sb.AppendLine($" end-placeholder=\"结束日期\" placeholder=\"请选择{dbFieldInfo.ColumnComment}\" :picker-options=\"{{ firstDayOfWeek: 1}}\"></el-date-picker>");
|
// sb.AppendLine($" end-placeholder=\"结束日期\" placeholder=\"请选择{dbFieldInfo.ColumnComment}\" :picker-options=\"{{ firstDayOfWeek: 1}}\"></el-date-picker>");
|
||||||
sb.AppendLine(" </el-form-item>");
|
// sb.AppendLine(" </el-form-item>");
|
||||||
}
|
// }
|
||||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
|
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
|
||||||
{
|
// {
|
||||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
||||||
sb.AppendLine($" <el-select v-model=\"queryParams.{columnName}\" placeholder=\"请选择{dbFieldInfo.ColumnComment}\" >");
|
// sb.AppendLine($" <el-select v-model=\"queryParams.{columnName}\" placeholder=\"请选择{dbFieldInfo.ColumnComment}\" >");
|
||||||
sb.AppendLine($" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"item.dictValue\"></el-option>");
|
// sb.AppendLine($" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"item.dictValue\"></el-option>");
|
||||||
sb.AppendLine(" </el-select>");
|
// sb.AppendLine(" </el-select>");
|
||||||
sb.AppendLine(" </el-form-item>");
|
// sb.AppendLine(" </el-form-item>");
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
string inputNumTxt = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
// string inputNumTxt = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||||
sb.AppendLine($" <el-form-item label=\"{ labelName}\" prop=\"{columnName}\">");
|
// sb.AppendLine($" <el-form-item label=\"{ labelName}\" prop=\"{columnName}\">");
|
||||||
sb.AppendLine($" <el-input v-model{inputNumTxt}=\"queryParams.{columnName}\" placeholder=\"请输入{dbFieldInfo.ColumnComment}\" />");
|
// sb.AppendLine($" <el-input v-model{inputNumTxt}=\"queryParams.{columnName}\" placeholder=\"请输入{dbFieldInfo.ColumnComment}\" />");
|
||||||
sb.AppendLine(" </el-form-item>");
|
// sb.AppendLine(" </el-form-item>");
|
||||||
}
|
// }
|
||||||
|
|
||||||
return sb.ToString();
|
// return sb.ToString();
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Vue 查询列表
|
/// Vue 查询列表
|
||||||
|
|||||||
@ -68,7 +68,7 @@ namespace ZR.CodeGenerator
|
|||||||
|
|
||||||
replaceDto.VueViewFormHtml += CodeGenerateTemplate.TplVueFormContent(dbFieldInfo, dto.GenTable);
|
replaceDto.VueViewFormHtml += CodeGenerateTemplate.TplVueFormContent(dbFieldInfo, dto.GenTable);
|
||||||
replaceDto.VueViewListHtml += CodeGenerateTemplate.TplTableColumn(dbFieldInfo, dto.GenTable);
|
replaceDto.VueViewListHtml += CodeGenerateTemplate.TplTableColumn(dbFieldInfo, dto.GenTable);
|
||||||
replaceDto.VueQueryFormHtml += CodeGenerateTemplate.TplQueryFormHtml(dbFieldInfo);
|
//replaceDto.VueQueryFormHtml += CodeGenerateTemplate.TplQueryFormHtml(dbFieldInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceDto.PKName = PKName;
|
replaceDto.PKName = PKName;
|
||||||
@ -76,6 +76,7 @@ namespace ZR.CodeGenerator
|
|||||||
replaceDto.FistLowerPk = PKName.FirstLowerCase();
|
replaceDto.FistLowerPk = PKName.FirstLowerCase();
|
||||||
InitJntTemplate(dto, replaceDto);
|
InitJntTemplate(dto, replaceDto);
|
||||||
|
|
||||||
|
replaceDto.VueQueryFormHtml = GenerateVueQueryForm();
|
||||||
GenerateModels(replaceDto, dto);
|
GenerateModels(replaceDto, dto);
|
||||||
GenerateInputDto(replaceDto, dto);
|
GenerateInputDto(replaceDto, dto);
|
||||||
GenerateRepository(replaceDto, dto);
|
GenerateRepository(replaceDto, dto);
|
||||||
@ -241,6 +242,18 @@ namespace ZR.CodeGenerator
|
|||||||
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, result));
|
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成vue页面查询form
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="replaceDto"></param>
|
||||||
|
/// <param name="generateDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GenerateVueQueryForm()
|
||||||
|
{
|
||||||
|
var tpl = FileHelper.ReadJtTemplate("QueryForm.txt");
|
||||||
|
var result = tpl.Render();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 帮助方法
|
#region 帮助方法
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user