Skip to content

Commit 5a7cef4

Browse files
author
23233
committed
1.修改的时候对模型传入自增值
1 parent e47eff0 commit 5a7cef4

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/mailru/easyjson v0.7.6 // indirect
2424
github.com/mattn/go-colorable v0.1.7 // indirect
2525
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
26-
github.com/pkg/errors v0.8.1
26+
github.com/pkg/errors v0.9.1
2727
github.com/smartystreets/goconvey v1.6.4 // indirect
2828
github.com/tdewolff/minify/v2 v2.9.4 // indirect
2929
github.com/yudai/pp v2.0.1+incompatible // indirect

simple_admin.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func (lib *SpAdmin) addData(routerName string, data reflect.Value) error {
387387

388388
// 数据修改
389389
func (lib *SpAdmin) editData(routerName string, id uint64, data reflect.Value) error {
390-
singleData := data.Interface()
390+
singleData := lib.incrSetValue(data, routerName, id).Interface()
391391

392392
// 更新之前的事件
393393
if processor, ok := singleData.(SpUpdateBeforeProcess); ok {
@@ -526,7 +526,7 @@ func (lib *SpAdmin) getCtxValues(routerName string, ctx iris.Context) (reflect.V
526526
}
527527
if len(cb.FieldList.Created) >= 1 {
528528
var equal = false
529-
for k, _ := range cb.FieldList.Created {
529+
for k := range cb.FieldList.Created {
530530
if column.MapName == k {
531531
equal = true
532532
break
@@ -595,6 +595,25 @@ func (lib *SpAdmin) getCtxValues(routerName string, ctx iris.Context) (reflect.V
595595
return newInstance, nil
596596
}
597597

598+
// id赋值
599+
func (lib *SpAdmin) incrSetValue(data reflect.Value, routerName string, id uint64) reflect.Value {
600+
cb, _ := lib.config.tableNameGetModelInfo(routerName)
601+
for _, column := range cb.FieldList.Fields {
602+
if column.MapName == cb.FieldList.AutoIncrement {
603+
switch column.Types {
604+
case "int", "int8", "int16", "int32", "int64":
605+
data.Elem().FieldByName(column.Name).SetInt(int64(id))
606+
return data
607+
case "uint", "uint8", "uint16", "uint32", "uint64":
608+
data.Elem().FieldByName(column.Name).SetUint(id)
609+
return data
610+
}
611+
612+
}
613+
}
614+
return data
615+
}
616+
598617
// 变更用户密码
599618
func (lib *SpAdmin) changeUserPassword(id uint64, password string) error {
600619
ps, salt := lib.config.passwordSalt(password)

0 commit comments

Comments
 (0)