From 0e4226fd849da21fce67cb9c954167377f36da6b Mon Sep 17 00:00:00 2001 From: Yavolte Date: Tue, 29 Jul 2025 16:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=AE=E5=92=8C=E5=80=BC?= =?UTF-8?q?=E4=B8=80=E6=A0=B7=E7=9A=84=E6=83=85=E5=86=B5=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E6=B2=A1=E6=9C=89=E6=95=B0=E6=8D=AE=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hook.go | 5 +---- rest.go | 17 +++++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/hook.go b/hook.go index 91c81ad..4b776b8 100644 --- a/hook.go +++ b/hook.go @@ -2,6 +2,7 @@ package rest import ( "context" + "git.nobla.cn/golang/rest/types" "gorm.io/gorm" ) @@ -133,7 +134,6 @@ func (hook *hookManager) afterSave(ctx context.Context, tx *gorm.DB, model any, cb(ctx, tx, model, diff) } } - return } func (hook *hookManager) beforeDelete(ctx context.Context, tx *gorm.DB, model any) (err error) { @@ -161,7 +161,6 @@ func (hook *hookManager) afterDelete(ctx context.Context, tx *gorm.DB, model any cb(ctx, tx, model) } } - return } func (hook *hookManager) afterExport(ctx context.Context, filename string) { @@ -174,7 +173,6 @@ func (hook *hookManager) afterExport(ctx context.Context, filename string) { cb(ctx, filename) } } - return } func (hook *hookManager) afterImport(ctx context.Context, ret *types.ImportResult) { @@ -187,7 +185,6 @@ func (hook *hookManager) afterImport(ctx context.Context, ret *types.ImportResul cb(ctx, ret) } } - return } func (hook *hookManager) BeforeCreate(cb BeforeCreate) { diff --git a/rest.go b/rest.go index cab21ac..13924d2 100644 --- a/rest.go +++ b/rest.go @@ -673,13 +673,12 @@ func ModelTypes[T any](ctx context.Context, db *gorm.DB, model any, domainName, } else { feed.Label = fmt.Sprint(s) } - continue + //这里不直接返回, 有可能key和value是同一个字段 } if k == valueColumn { if p, ok := v.(T); ok { feed.Value = p } - continue } } values = append(values, feed) @@ -703,25 +702,23 @@ func ModelTiers[T comparable](ctx context.Context, db *gorm.DB, model any, domai for _, pairs := range result { feed := &types.TierValue[T]{} for k, v := range pairs { + if k == parentColumn { + if p, ok := v.(T); ok { + feed.Parent = p + } + continue + } if k == labelColumn { if s, ok := v.(string); ok { feed.Label = s } else { feed.Label = fmt.Sprint(s) } - continue } if k == valueColumn { if p, ok := v.(T); ok { feed.Value = p } - continue - } - if k == parentColumn { - if p, ok := v.(T); ok { - feed.Parent = p - } - continue } } values = append(values, feed)