Skip to content

Commit

Permalink
fix: antd curd template
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Nov 4, 2023
1 parent 2ef4767 commit a1cef86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 11 additions & 11 deletions AbpProjectTools/Commands/FontendCrudCodeGeneratorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ public override Command GetCommand()
var command = new Command("crud", "Generate crud page code base on swagger json document");

command.AddOption(new Option<string>("--swagger-url", "The swagger api json document url") { IsRequired = true, });
command.AddOption(new Option<string>(new[] { "--root", "-o" }, "") { IsRequired = true, });
command.AddOption(new Option<string>("--name", "") { IsRequired = true, });
command.AddOption(new Option<string>(new string[] { "--default-model", "-dm" }, ""));
command.AddOption(new Option<string>(new[] { "--edit-model", "-em" }, ""));
command.AddOption(new Option<string>(new[] { "--project-root", "-o" }, "The project root directory path") { IsRequired = true, });
command.AddOption(new Option<string>("--name", "The page name") { IsRequired = true, });
command.AddOption(new Option<string>(new string[] { "--default-model", "-dm" }, "The page default model name for list"));
command.AddOption(new Option<string>(new[] { "--edit-model", "-em" }, "The page edit model name"));
command.AddOption(new Option<string>("--templates", ""));
command.AddOption(new Option<bool>("--overwrite", () => false));
command.AddOption(new Option<bool>(new[] { "--gen-create-or-update", "-cu" }, () => true));
command.AddOption(new Option<bool>(new[] { "--gen-create-or-update", "-cu" }, () => true, "Can generte create or update content"));


var helper = new OpenApiDocumentService();
Expand All @@ -38,7 +37,9 @@ public override Command GetCommand()

Console.WriteLine("🎉 Loading successful. ");

var rootPath = options.Root;
Console.WriteLine("👍 The project root path: " + options.ProjectRoot);

var rootPath = options.ProjectRoot;

string defaultSchameName = options.DefaultModel ?? options.Name;
string editSchameName = options.EditModel ?? options.Name;
Expand Down Expand Up @@ -70,7 +71,7 @@ public override Command GetCommand()
EditFields = editFields,
GenCreateOrUpdate = options.GenCreateOrUpdate,
});
WriteFileContent(Path.Combine(rootPath, "src", ".tmp", "pages", RenderHelperFunctions.ToKebaberize(options.Name) + ".tsx"), crudContent, options.Overwrite);
WriteFileContent(Path.Combine(rootPath, "src", ".tmp", "pages", RenderHelperFunctions.ToKebaberize(options.Name) + ".tsx"), crudContent, true);

// locale
var localeContent = templateService.Render("AntdCrudLocale", new FontendCrudCodeGenerateOptions
Expand All @@ -83,7 +84,7 @@ public override Command GetCommand()
EditFields = editFields,
GenCreateOrUpdate = options.GenCreateOrUpdate,
});
WriteFileContent(Path.Combine(rootPath, "src", ".tmp", "locales", $"pages.{RenderHelperFunctions.ToCamelize(options.Name)}.ts"), localeContent, options.Overwrite);
WriteFileContent(Path.Combine(rootPath, "src", ".tmp", "locales", $"pages.{RenderHelperFunctions.ToCamelize(options.Name)}.ts"), localeContent, true);

Console.WriteLine("🎉 Done. ");
});
Expand Down Expand Up @@ -123,12 +124,11 @@ void FillNestedObejct(ApiParamItem item)
public class FontendCrudCodeGeneratorCommandOptions
{
public string SwaggerUrl { get; set; }
public string Root { get; set; }
public string ProjectRoot { get; set; }
public string Templates { get; set; }
public string Name { get; set; }
public string DefaultModel { get; set; }
public string EditModel { get; set; }
public bool Overwrite { get; set; }
public bool GenCreateOrUpdate { get; set; }
}

Expand Down
8 changes: 6 additions & 2 deletions AbpProjectTools/Tpl/AntdCrud.sbn
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const handle{{name | to_pascalize }}Edit = async (id: string, data: any) => {

const handle{{name | to_pascalize }}Delete = async (id: string) => {
const response = await delete{{name | to_pascalize }}(id);
if (response) {
if (response?.ok) {
message.success(formatMessage({ id: 'common.dict.deleted.success' }));
return true;
}
Expand Down Expand Up @@ -186,6 +186,8 @@ const {{name | to_pascalize }}: React.FC = () => {
<ProFormDatePicker
{{~else if schame.type == 4 ~}}
<ProFormSwitch
{{~else if schame.type == 1 && schame.max_length == null ~}}
<ProFormTextArea
{{~else~}}
<ProFormText
{{~end~}}
Expand All @@ -197,8 +199,10 @@ const {{name | to_pascalize }}: React.FC = () => {
]}
name={['{{schame.name}}']}
label={intl.formatMessage({ id: 'page.{{name | camel_case}}.field.{{schame.name | camel_case}}' })}
{{~ if schame.type == 1 && schame.max_length == null ~}}
fieldProps={%{{{ rows: 2 }}}%}
{{~end~}}
/>

{{~ if schame.object_definition != null ~}}
{{~ output_params names schame.object_definition.params ~}}
{{~end~}}
Expand Down

0 comments on commit a1cef86

Please sign in to comment.