Skip to content

Commit c358d4e

Browse files
committed
chore: 新增BeforeEditable、BeforeAction回调函数
1 parent d82a571 commit c358d4e

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const (
2323
AppName = "QuarkGo"
2424

2525
// 版本号
26-
Version = "3.9.6"
26+
Version = "3.9.7"
2727

2828
// 包名
2929
PkgName = "github.com/quarkcloudio/quark-go/v3"

template/admin/resource/requests/action.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ func (p *ActionRequest) Handle(ctx *quark.Context) error {
4646
for _, dropdownAction := range dropdownActioner.GetActions() {
4747
uriKey := dropdownActioner.GetUriKey(dropdownAction)
4848
if ctx.Param("uriKey") == uriKey {
49+
// 行为执行完之前回调
50+
err := template.BeforeAction(ctx, uriKey, model)
51+
if err != nil {
52+
return err
53+
}
54+
4955
result = dropdownAction.(interface {
5056
Handle(*quark.Context, *gorm.DB) error
5157
}).Handle(ctx, model)
5258

5359
// 执行完后回调
54-
err := template.AfterAction(ctx, uriKey, model)
60+
err = template.AfterAction(ctx, uriKey, model)
5561
if err != nil {
5662
return err
5763
}
@@ -61,12 +67,18 @@ func (p *ActionRequest) Handle(ctx *quark.Context) error {
6167
}
6268
} else {
6369
if ctx.Param("uriKey") == uriKey {
70+
// 行为执行完之前回调
71+
err := template.BeforeAction(ctx, uriKey, model)
72+
if err != nil {
73+
return err
74+
}
75+
6476
result = v.(interface {
6577
Handle(*quark.Context, *gorm.DB) error
6678
}).Handle(ctx, model)
6779

6880
// 执行完后回调
69-
err := template.AfterAction(ctx, uriKey, model)
81+
err = template.AfterAction(ctx, uriKey, model)
7082
if err != nil {
7183
return err
7284
}

template/admin/resource/requests/editable.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ func (p *EditableRequest) Handle(ctx *quark.Context) error {
5858
return ctx.CJSONError("参数错误")
5959
}
6060

61+
// 表格行内编辑执行完之前回调
62+
result := template.BeforeEditable(ctx, id, field, value)
63+
if result != nil {
64+
return result
65+
}
66+
6167
// 创建表格行内编辑查询
6268
query := template.BuildEditableQuery(ctx, model)
6369

@@ -68,7 +74,7 @@ func (p *EditableRequest) Handle(ctx *quark.Context) error {
6874
}
6975

7076
// 行为执行后回调
71-
result := template.AfterEditable(ctx, id, field, value)
77+
result = template.AfterEditable(ctx, id, field, value)
7278
if result != nil {
7379
return result
7480
}

template/admin/resource/resource.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,21 @@ func (p *Template) BeforeImporting(ctx *quark.Context, list [][]interface{}) [][
289289
return list
290290
}
291291

292-
// 表格行内编辑执行完之后回调
292+
// 行内编辑执行完之前回调
293+
func (p *Template) BeforeEditable(ctx *quark.Context, id interface{}, field string, value interface{}) error {
294+
return nil
295+
}
296+
297+
// 行内编辑执行完之后回调
293298
func (p *Template) AfterEditable(ctx *quark.Context, id interface{}, field string, value interface{}) error {
294299
return nil
295300
}
296301

302+
// 行为执行完之前回调
303+
func (p *Template) BeforeAction(ctx *quark.Context, uriKey string, query *gorm.DB) error {
304+
return nil
305+
}
306+
297307
// 行为执行完之后回调
298308
func (p *Template) AfterAction(ctx *quark.Context, uriKey string, query *gorm.DB) error {
299309
return nil

template/admin/resource/types/resourcer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,15 @@ type Resourcer interface {
8484
// 数据导入前回调
8585
BeforeImporting(ctx *quark.Context, list [][]interface{}) [][]interface{}
8686

87+
// 表格行内编辑执行完之前回调
88+
BeforeEditable(ctx *quark.Context, id interface{}, field string, value interface{}) error
89+
8790
// 表格行内编辑执行完之后回调
8891
AfterEditable(ctx *quark.Context, id interface{}, field string, value interface{}) error
8992

93+
// 行为执行完之前回调
94+
BeforeAction(ctx *quark.Context, uriKey string, query *gorm.DB) error
95+
9096
// 行为执行完之后回调
9197
AfterAction(ctx *quark.Context, uriKey string, query *gorm.DB) error
9298

0 commit comments

Comments
 (0)