CodeGenerator/Templates/TypeScript.cshtml
owenchen 61714e0a91 ow
2026-05-12 10:43:31 +08:00

116 lines
5.2 KiB
Plaintext

@{
ModelData modelData = Model;
NamespaceObject namespaceObject = modelData.NamespaceObject;
SysTableSchemaViewEntity[] sysTableSchemas = modelData.sysTableSchemas;
ClassInfo classInfo= modelData.ClassInfos.FirstOrDefault();
//ClassInfo classInfo= modelData.ClassInfos.Where(x=>x.ClassName=="SecurityUserSearchCriteria").FirstOrDefault();
}
@{
if(classInfo.Usings!=null && classInfo.Usings.Length>0)
{
for (var i = 0; i < classInfo.Usings.Length; i++)
{
<text>import { @classInfo.Usings[i].StringToProerty() } from "./@classInfo.Usings[i].StringToProtectedProerty()";
</text>
}
}
}
@{
string implementTypeName=string.IsNullOrEmpty(classInfo.ImplementTypeName)?"":" extends "+classInfo.ImplementTypeName;
if(!string.IsNullOrEmpty(implementTypeName))
{
<text>import { @classInfo.ImplementTypeName.StringToProerty() } from "./@classInfo.ImplementTypeName.StringToProtectedProerty()";
</text>
}
}
export class @classInfo.ClassName @implementTypeName
{
@{
if(classInfo.ClassProperties!=null && classInfo.ClassProperties.Length>0)
{
for (var j= 0; j< classInfo.ClassProperties.Length; j++)
{
if(classInfo.ClassProperties[j].PropertyTypeName=="Nullable`1")
{
<text> public @classInfo.ClassProperties[j].PropertyName?: Date= null!;
</text>
}
else if(classInfo.ClassProperties[j].PropertyTypeName.ToLower()=="datetime")
{
<text> public @classInfo.ClassProperties[j].PropertyName: Date = new Date();
</text>
}
else if(classInfo.ClassProperties[j].PropertyTypeName=="Boolean")
{
<text> public @classInfo.ClassProperties[j].PropertyName: boolean =false;
</text>
}
else if(classInfo.ClassProperties[j].PropertyTypeName=="String")
{
<text> public @classInfo.ClassProperties[j].PropertyName: string = "";
</text>
}
else if(classInfo.ClassProperties[j].PropertyTypeName=="Int32" || classInfo.ClassProperties[j].PropertyTypeName=="Int64" || classInfo.ClassProperties[j].PropertyTypeName=="Int16" || classInfo.ClassProperties[j].PropertyTypeName=="Long" || classInfo.ClassProperties[j].PropertyTypeName.ToLower()=="decimal")
{
<text> public @classInfo.ClassProperties[j].PropertyName: number = 0;
</text>
}
else if(classInfo.ClassProperties[j].PropertyTypeName=="Int32[]" || classInfo.ClassProperties[j].PropertyTypeName=="Int64[]" || classInfo.ClassProperties[j].PropertyTypeName=="Int16[]" || classInfo.ClassProperties[j].PropertyTypeName=="Long[]" || classInfo.ClassProperties[j].PropertyTypeName.ToLower()=="decimal[]")
{
<text> public @classInfo.ClassProperties[j].PropertyName: number[] = [];
</text>
}
else if(classInfo.ClassProperties[j].PropertyTypeName.Contains("String[]"))
{
<text> public @classInfo.ClassProperties[j].PropertyName: string[]= [];
</text>
}
else if(!classInfo.ClassProperties[j].IsValueType && classInfo.ClassProperties[j].PropertyTypeName.Contains("[]"))
{
<text> public @classInfo.ClassProperties[j].PropertyName: @classInfo.ClassProperties[j].PropertyTypeName.StringToProerty() = [];
</text>
}
else if(classInfo.ClassProperties[j].PropertyTypeName=="any")
{
<text> public @classInfo.ClassProperties[j].PropertyName: any;
</text>
}
else if(!classInfo.ClassProperties[j].IsValueType)
{
<text> public @classInfo.ClassProperties[j].PropertyName: @classInfo.ClassProperties[j].PropertyTypeName.StringToProerty() = new @{@classInfo.ClassProperties[j].PropertyTypeName.StringToProerty() }();
</text>
}
else
{
<text> public @classInfo.ClassProperties[j].PropertyName: any ={}
</text>
}
}
}
}
@{
if(classInfo.ClassFields!=null && classInfo.ClassFields.Length>0)
{
for (var j= 0; j< classInfo.ClassFields.Length; j++)
{
if(classInfo.ClassFields[j].FieldTypeName =="String")
{
<text> static readonly @classInfo.ClassFields[j].FieldName : string ='@classInfo.ClassFields[j].FieldValue';
</text>
}
if(classInfo.ClassFields[j].FieldTypeName =="Boolean")
{
<text> static readonly @classInfo.ClassFields[j].FieldName : Boolean ='@classInfo.ClassFields[j].FieldValue';
</text>
}
else if(classInfo.ClassFields[j].FieldTypeName =="Int32" || classInfo.ClassFields[j].FieldTypeName =="Int64" || classInfo.ClassFields[j].FieldTypeName =="Int16" || classInfo.ClassFields[j].FieldTypeName =="Long" || classInfo.ClassFields[j].FieldTypeName .ToLower()=="decimal")
{
<text> static readonly @classInfo.ClassFields[j].FieldName: number =@classInfo.ClassFields[j].FieldValue;
</text>
}
}
}
}
}