From a1cef866cacb96fadecf3173e5080030c743e7bc Mon Sep 17 00:00:00 2001 From: jxnkwlp Date: Sat, 4 Nov 2023 19:55:57 +0800 Subject: [PATCH] fix: antd curd template --- .../FontendCrudCodeGeneratorCommand.cs | 22 +++++++++---------- AbpProjectTools/Tpl/AntdCrud.sbn | 8 +++++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/AbpProjectTools/Commands/FontendCrudCodeGeneratorCommand.cs b/AbpProjectTools/Commands/FontendCrudCodeGeneratorCommand.cs index 5f7ecdc..91d0c20 100644 --- a/AbpProjectTools/Commands/FontendCrudCodeGeneratorCommand.cs +++ b/AbpProjectTools/Commands/FontendCrudCodeGeneratorCommand.cs @@ -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("--swagger-url", "The swagger api json document url") { IsRequired = true, }); - command.AddOption(new Option(new[] { "--root", "-o" }, "") { IsRequired = true, }); - command.AddOption(new Option("--name", "") { IsRequired = true, }); - command.AddOption(new Option(new string[] { "--default-model", "-dm" }, "")); - command.AddOption(new Option(new[] { "--edit-model", "-em" }, "")); + command.AddOption(new Option(new[] { "--project-root", "-o" }, "The project root directory path") { IsRequired = true, }); + command.AddOption(new Option("--name", "The page name") { IsRequired = true, }); + command.AddOption(new Option(new string[] { "--default-model", "-dm" }, "The page default model name for list")); + command.AddOption(new Option(new[] { "--edit-model", "-em" }, "The page edit model name")); command.AddOption(new Option("--templates", "")); - command.AddOption(new Option("--overwrite", () => false)); - command.AddOption(new Option(new[] { "--gen-create-or-update", "-cu" }, () => true)); + command.AddOption(new Option(new[] { "--gen-create-or-update", "-cu" }, () => true, "Can generte create or update content")); var helper = new OpenApiDocumentService(); @@ -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; @@ -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 @@ -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. "); }); @@ -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; } } diff --git a/AbpProjectTools/Tpl/AntdCrud.sbn b/AbpProjectTools/Tpl/AntdCrud.sbn index 23dd56e..a2af3a7 100644 --- a/AbpProjectTools/Tpl/AntdCrud.sbn +++ b/AbpProjectTools/Tpl/AntdCrud.sbn @@ -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; } @@ -186,6 +186,8 @@ 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~}}