From b051c98dece4684c93e7fa5ff938ca78e0b400a0 Mon Sep 17 00:00:00 2001 From: maxbad <26058031@qq.com> Date: Mon, 8 Jan 2024 17:51:20 +0800 Subject: [PATCH] fix generate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 接口返回list如果是nil,则赋值为空数组 前端State类加构造函数 --- server/internal/controller/admin/common/ems.go | 2 +- .../internal/library/hggen/views/curd_generate_web_model.go | 1 + server/resource/generate/default/curd/controller.go.template | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server/internal/controller/admin/common/ems.go b/server/internal/controller/admin/common/ems.go index d3f29f6..7b63963 100644 --- a/server/internal/controller/admin/common/ems.go +++ b/server/internal/controller/admin/common/ems.go @@ -42,7 +42,7 @@ func (c *cEms) SendTest(ctx context.Context, req *common.SendTestEmailReq) (res } // SendBindEms 发送换绑邮件 -func (c *cSms) SendBindEms(ctx context.Context, _ *common.SendBindEmsReq) (res *common.SendBindEmsRes, err error) { +func (c *cEms) SendBindEms(ctx context.Context, _ *common.SendBindEmsReq) (res *common.SendBindEmsRes, err error) { var ( memberId = contexts.GetUserId(ctx) models *entity.AdminMember diff --git a/server/internal/library/hggen/views/curd_generate_web_model.go b/server/internal/library/hggen/views/curd_generate_web_model.go index 85e37a1..b635690 100644 --- a/server/internal/library/hggen/views/curd_generate_web_model.go +++ b/server/internal/library/hggen/views/curd_generate_web_model.go @@ -46,6 +46,7 @@ func (l *gCurd) generateWebModelState(ctx context.Context, in *CurdPreviewInput) } buffer.WriteString(fmt.Sprintf(" public %s = %v; // %s\n", field.TsName, value, field.Dc)) } + buffer.WriteString("\n constructor(state?: Partial) {\n if (state) {\n Object.assign(this, state);\n }\n }") buffer.WriteString("}") return buffer.String() } diff --git a/server/resource/generate/default/curd/controller.go.template b/server/resource/generate/default/curd/controller.go.template index 34ace6a..de925c6 100644 --- a/server/resource/generate/default/curd/controller.go.template +++ b/server/resource/generate/default/curd/controller.go.template @@ -27,6 +27,10 @@ func (c *c@{.varName}) List(ctx context.Context, req *@{.varName | ToLower}.List if err != nil { return } + + if list == nil { + list = []*@{.templateGroup}in.@{.varName}ListModel{} + } res = new(@{.varName | ToLower}.ListRes) res.List = list