优化代码生成C#属性生成
This commit is contained in:
parent
d9abc2b60e
commit
2f132a33e1
@ -144,5 +144,89 @@ namespace Infrastructure.Extensions
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为Pascal风格-每一个单词的首字母大写
|
||||
/// </summary>
|
||||
/// <param name="fieldName">字段名</param>
|
||||
/// <param name="fieldDelimiter">分隔符</param>
|
||||
/// <returns></returns>
|
||||
public static string ConvertToPascal(this string fieldName, string fieldDelimiter)
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (fieldName.Contains(fieldDelimiter))
|
||||
{
|
||||
//全部小写
|
||||
string[] array = fieldName.ToLower().Split(fieldDelimiter.ToCharArray());
|
||||
foreach (var t in array)
|
||||
{
|
||||
//首字母大写
|
||||
result += t.Substring(0, 1).ToUpper() + t[1..];
|
||||
}
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(fieldName))
|
||||
{
|
||||
result = fieldName;
|
||||
}
|
||||
else if (fieldName.Length == 1)
|
||||
{
|
||||
result = fieldName.ToUpper();
|
||||
}
|
||||
else if (fieldName.Length == CountUpper(fieldName))
|
||||
{
|
||||
result = fieldName.Substring(0, 1).ToUpper() + fieldName[1..].ToLower();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = fieldName.Substring(0, 1).ToUpper() + fieldName[1..];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 大写字母个数
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static int CountUpper(this string str)
|
||||
{
|
||||
int count1 = 0;
|
||||
char[] chars = str.ToCharArray();
|
||||
foreach (char num in chars)
|
||||
{
|
||||
if (num >= 'A' && num <= 'Z')
|
||||
{
|
||||
count1++;
|
||||
}
|
||||
//else if (num >= 'a' && num <= 'z')
|
||||
//{
|
||||
// count2++;
|
||||
//}
|
||||
}
|
||||
return count1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为Camel风格-第一个单词小写,其后每个单词首字母大写
|
||||
/// </summary>
|
||||
/// <param name="fieldName">字段名</param>
|
||||
/// <param name="fieldDelimiter">分隔符</param>
|
||||
/// <returns></returns>
|
||||
public static string ConvertToCamel(this string fieldName, string fieldDelimiter)
|
||||
{
|
||||
//先Pascal
|
||||
string result = ConvertToPascal(fieldName, fieldDelimiter);
|
||||
//然后首字母小写
|
||||
if (result.Length == 1)
|
||||
{
|
||||
result = result.ToLower();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result.Substring(0, 1).ToLower() + result[1..];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ $if(column.HtmlType == "datetime")
|
||||
$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 ${column.DictType}" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
|
||||
<el-option v-for="item in $if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
$else
|
||||
@ -119,9 +119,9 @@ $elseif(column.HtmlType == "checkbox" || column.HtmlType == "select" || column.H
|
||||
<el-table-column prop="${columnName}" label="${labelName}" align="center">
|
||||
<template #default="scope">
|
||||
$if(column.HtmlType == "checkbox")
|
||||
<dict-tag :options="${column.DictType}" :value="scope.row.${columnName} ? scope.row.${columnName}.split(',') : []" />
|
||||
<dict-tag :options="$if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :value="scope.row.${columnName} ? scope.row.${columnName}.split(',') : []" />
|
||||
$else
|
||||
<dict-tag :options="${column.DictType}" :value="scope.row.${columnName}" />
|
||||
<dict-tag :options="$if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :value="scope.row.${columnName}" />
|
||||
$end
|
||||
</template>
|
||||
</el-table-column>
|
||||
@ -227,7 +227,7 @@ $elseif(column.HtmlType == "radio")
|
||||
<el-col :lg="12">
|
||||
<el-form-item label="${labelName}" prop="${columnName}">
|
||||
<el-radio-group v-model="form.${columnName}">
|
||||
<el-radio v-for="item in ${column.DictType}" :key="item.dictValue" :label="${value}">{{item.dictLabel}}</el-radio>
|
||||
<el-radio v-for="item in $if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :key="item.dictValue" :label="${value}">{{item.dictLabel}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -247,7 +247,7 @@ $elseif(column.HtmlType == "select")
|
||||
<el-col :lg="12">
|
||||
<el-form-item label="${labelName}" prop="${columnName}">
|
||||
<el-select v-model="form.${columnName}" placeholder="请选择${labelName}">
|
||||
<el-option v-for="item in ${column.DictType}" :key="item.dictValue" :label="item.dictLabel" :value="${value}"></el-option>
|
||||
<el-option v-for="item in $if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :key="item.dictValue" :label="item.dictLabel" :value="${value}"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -255,7 +255,7 @@ $elseif(column.HtmlType == "checkbox")
|
||||
<el-col :lg="24">
|
||||
<el-form-item label="${labelName}" prop="${columnName}">
|
||||
<el-checkbox-group v-model="form.${columnName}Checked">
|
||||
<el-checkbox v-for="item in ${column.DictType}" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-checkbox>
|
||||
<el-checkbox v-for="item in $if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -349,7 +349,7 @@ const formRef = ref()
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.HtmlType == "radio" || item.HtmlType == "select" || item.HtmlType == "checkbox"))
|
||||
// ${item.ColumnComment}选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
|
||||
const ${item.DictType} = ref([])
|
||||
const $if(item.DictType != "") ${item.DictType} $else ${item.CsharpFieldFl}Options$end = ref([])
|
||||
$elseif(item.HtmlType == "datetime" && item.IsQuery == true)
|
||||
// ${item.ColumnComment}时间范围
|
||||
const dateRange${item.CsharpField} = ref([])
|
||||
|
||||
@ -34,7 +34,7 @@ $if(column.HtmlType == "datetime")
|
||||
$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 ${column.DictType}" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
|
||||
<el-option v-for="item in $if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
$else
|
||||
@ -112,9 +112,9 @@ $elseif(column.HtmlType == "checkbox" || column.HtmlType == "select" || column.H
|
||||
<el-table-column prop="${columnName}" label="${labelName}" align="center">
|
||||
<template #default="scope">
|
||||
$if(column.HtmlType == "checkbox")
|
||||
<dict-tag :options="${column.DictType}" :value="scope.row.${columnName} ? scope.row.${columnName}.split(',') : []" />
|
||||
<dict-tag :options="$if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :value="scope.row.${columnName} ? scope.row.${columnName}.split(',') : []" />
|
||||
$else
|
||||
<dict-tag :options="${column.DictType}" :value="scope.row.${columnName}" />
|
||||
<dict-tag :options="$if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :value="scope.row.${columnName}" />
|
||||
$end
|
||||
</template>
|
||||
</el-table-column>
|
||||
@ -203,7 +203,7 @@ $elseif(column.HtmlType == "radio")
|
||||
<el-col :lg="12">
|
||||
<el-form-item label="${labelName}" prop="${columnName}">
|
||||
<el-radio-group v-model="form.${columnName}">
|
||||
<el-radio v-for="item in ${column.DictType}" :key="item.dictValue" :label="${value}">{{item.dictLabel}}</el-radio>
|
||||
<el-radio v-for="item in $if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :key="item.dictValue" :label="${value}">{{item.dictLabel}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -223,7 +223,7 @@ $elseif(column.HtmlType == "select")
|
||||
<el-col :lg="12">
|
||||
<el-form-item label="${labelName}" prop="${columnName}">
|
||||
<el-select v-model="form.${columnName}" placeholder="请选择${labelName}">
|
||||
<el-option v-for="item in ${column.DictType}" :key="item.dictValue" :label="item.dictLabel" :value="${value}"></el-option>
|
||||
<el-option v-for="item in $if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :key="item.dictValue" :label="item.dictLabel" :value="${value}"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -231,7 +231,7 @@ $elseif(column.HtmlType == "checkbox")
|
||||
<el-col :lg="24">
|
||||
<el-form-item label="${labelName}" prop="${columnName}">
|
||||
<el-checkbox-group v-model="form.${columnName}Checked">
|
||||
<el-checkbox v-for="item in ${column.DictType}" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-checkbox>
|
||||
<el-checkbox v-for="item in $if(column.DictType != "") ${column.DictType} $else ${column.CsharpFieldFl}Options$end" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -295,12 +295,10 @@ const open = ref(false)
|
||||
const state = reactive({
|
||||
form: {},
|
||||
rules: {
|
||||
$foreach(column in genTable.Columns)
|
||||
$foreach(column in genTable.Columns)
|
||||
$if(column.IsRequired && column.IsIncrement == false)
|
||||
${column.CsharpFieldFl}: [
|
||||
{ required: true, message: "${column.ColumnComment}不能为空", trigger: $if(column.htmlType == "select")"change"$else"blur"$end
|
||||
$if(column.CsharpType == "int" || column.CsharpType == "long"), type: "number"$end }
|
||||
],
|
||||
${column.CsharpFieldFl}: [{ required: true, message: "${column.ColumnComment}不能为空", trigger: $if(column.htmlType == "select")"change"$else"blur"$end
|
||||
$if(column.CsharpType == "int" || column.CsharpType == "long"), type: "number"$end }],
|
||||
$end
|
||||
$end
|
||||
}
|
||||
@ -315,7 +313,7 @@ const formRef = ref()
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.HtmlType == "radio" || item.HtmlType == "select" || item.HtmlType == "checkbox"))
|
||||
// ${item.ColumnComment}选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
|
||||
const ${item.DictType} = ref([])
|
||||
const $if(item.DictType != "")${item.DictType}$else${item.CsharpFieldFl}Options$end = ref([])
|
||||
$elseif(item.HtmlType == "datetime" && item.IsQuery == true)
|
||||
// ${item.ColumnComment}时间范围
|
||||
const dateRange${item.CsharpField} = ref([])
|
||||
|
||||
@ -452,7 +452,7 @@ namespace ZR.CodeGenerator
|
||||
TableId = genTable.TableId,
|
||||
TableName = genTable.TableName,
|
||||
CsharpType = GetCSharpDatatype(column.DataType),
|
||||
CsharpField = column.DbColumnName.UnderScoreToCamelCase().FirstUpperCase(),
|
||||
CsharpField = column.DbColumnName.ConvertToPascal("_"),
|
||||
IsRequired = !column.IsNullable,
|
||||
IsIncrement = column.IsIdentity,
|
||||
Create_by = genTable.Create_by,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user