diff --git a/admin/apps/game/domain/entity/project.go b/admin/apps/game/domain/entity/project.go
index cef1ad7..87d39ed 100644
--- a/admin/apps/game/domain/entity/project.go
+++ b/admin/apps/game/domain/entity/project.go
@@ -26,16 +26,16 @@ func FromProjectPo(po *model.Project) *Project {
}
}
-func FromProjectDto(dto *dto.CommonDtoValues) *Project {
+func FromProjectDto(dto dto.CommonDtoValues) *Project {
et := DefaultProject()
po := et.po
//to := reflect.TypeOf(po)
vo := reflect.ValueOf(po)
- for _, f := range dto.Values {
- fo := vo.FieldByName(f.FieldName)
- fo.Set(reflect.ValueOf(f.Value))
+ for k, v := range dto {
+ fo := vo.FieldByName(k)
+ fo.Set(reflect.ValueOf(v))
}
return et
@@ -45,8 +45,8 @@ func (et *Project) ToPo() *model.Project {
return et.po
}
-func (et *Project) ToCommonDto() *dto.CommonDtoValues {
- obj := &dto.CommonDtoValues{}
+func (et *Project) ToCommonDto() dto.CommonDtoValues {
+ obj := make(dto.CommonDtoValues)
to := reflect.TypeOf(et.po).Elem()
vo := reflect.ValueOf(et.po).Elem()
@@ -54,12 +54,7 @@ func (et *Project) ToCommonDto() *dto.CommonDtoValues {
ft := to.Field(i)
fo := vo.Field(i)
- f1 := &dto.CommonDtoValue{
- FieldName: ft.Name,
- Value: fo.Interface(),
- }
-
- obj.Values = append(obj.Values, f1)
+ obj[ft.Name] = fo.Interface()
}
return obj
diff --git a/admin/apps/game/domain/entity/server.go b/admin/apps/game/domain/entity/server.go
index 9a817a1..0e321a4 100644
--- a/admin/apps/game/domain/entity/server.go
+++ b/admin/apps/game/domain/entity/server.go
@@ -26,16 +26,16 @@ func FromServerPo(po *model.Server) *Server {
}
}
-func FromServerDto(dto *dto.CommonDtoValues) *Server {
+func FromServerDto(dto dto.CommonDtoValues) *Server {
et := DefaultServer()
po := et.po
//to := reflect.TypeOf(po)
vo := reflect.ValueOf(po)
- for _, f := range dto.Values {
- fo := vo.FieldByName(f.FieldName)
- fo.Set(reflect.ValueOf(f.Value))
+ for k, v := range dto {
+ fo := vo.FieldByName(k)
+ fo.Set(reflect.ValueOf(v))
}
return et
@@ -45,8 +45,8 @@ func (et *Server) ToPo() *model.Server {
return et.po
}
-func (et *Server) ToCommonDto() *dto.CommonDtoValues {
- obj := &dto.CommonDtoValues{}
+func (et *Server) ToCommonDto() dto.CommonDtoValues {
+ obj := make(dto.CommonDtoValues)
to := reflect.TypeOf(et.po).Elem()
vo := reflect.ValueOf(et.po).Elem()
@@ -54,12 +54,7 @@ func (et *Server) ToCommonDto() *dto.CommonDtoValues {
ft := to.Field(i)
fo := vo.Field(i)
- f1 := &dto.CommonDtoValue{
- FieldName: ft.Name,
- Value: fo.Interface(),
- }
-
- obj.Values = append(obj.Values, f1)
+ obj[ft.Name] = fo.Interface()
}
return obj
diff --git a/admin/apps/game/domain/irestfull.go b/admin/apps/game/domain/irestfull.go
index c35e957..c02d018 100644
--- a/admin/apps/game/domain/irestfull.go
+++ b/admin/apps/game/domain/irestfull.go
@@ -6,13 +6,13 @@ import (
)
type IRestfulEntity interface {
- ToCommonDto() *dto.CommonDtoValues
+ ToCommonDto() dto.CommonDtoValues
}
type IRestfulResourceSvc interface {
List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []IRestfulEntity, error)
- Post(obj *dto.CommonDtoValues) (IRestfulEntity, error)
- Put(obj *dto.CommonDtoValues) (IRestfulEntity, error)
+ Post(obj dto.CommonDtoValues) (IRestfulEntity, error)
+ Put(obj dto.CommonDtoValues) (IRestfulEntity, error)
Delete(id int) error
}
diff --git a/admin/apps/game/domain/project.go b/admin/apps/game/domain/project.go
index 0cc64bf..1fd16dd 100644
--- a/admin/apps/game/domain/project.go
+++ b/admin/apps/game/domain/project.go
@@ -31,13 +31,13 @@ func (svc *ProjectSvc) List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []I
return entity.ProjectDtoFieldsDescInfo, iList, nil
}
-func (svc *ProjectSvc) Post(obj *dto.CommonDtoValues) (IRestfulEntity, error) {
+func (svc *ProjectSvc) Post(obj dto.CommonDtoValues) (IRestfulEntity, error) {
et := entity.FromProjectDto(obj)
err := svc.proRepo.Create(et)
return et, err
}
-func (svc *ProjectSvc) Put(obj *dto.CommonDtoValues) (IRestfulEntity, error) {
+func (svc *ProjectSvc) Put(obj dto.CommonDtoValues) (IRestfulEntity, error) {
et := entity.FromProjectDto(obj)
err := svc.proRepo.Edit(et)
return et, err
diff --git a/admin/apps/game/domain/server.go b/admin/apps/game/domain/server.go
index 398c24b..03aecd5 100644
--- a/admin/apps/game/domain/server.go
+++ b/admin/apps/game/domain/server.go
@@ -31,13 +31,13 @@ func (svc *ServerSvc) List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []IR
return entity.ServerDtoFieldsDescInfo, iList, nil
}
-func (svc *ServerSvc) Post(obj *dto.CommonDtoValues) (IRestfulEntity, error) {
+func (svc *ServerSvc) Post(obj dto.CommonDtoValues) (IRestfulEntity, error) {
et := entity.FromServerDto(obj)
err := svc.serverRepo.Create(et)
return et, err
}
-func (svc *ServerSvc) Put(obj *dto.CommonDtoValues) (IRestfulEntity, error) {
+func (svc *ServerSvc) Put(obj dto.CommonDtoValues) (IRestfulEntity, error) {
et := entity.FromServerDto(obj)
err := svc.serverRepo.Edit(et)
return et, err
diff --git a/admin/apps/game/model/dto/common.go b/admin/apps/game/model/dto/common.go
index 5acad08..6f994f5 100644
--- a/admin/apps/game/model/dto/common.go
+++ b/admin/apps/game/model/dto/common.go
@@ -20,16 +20,14 @@ type CommonDtoFieldDesc struct {
MultiChoice bool `json:"multi_choice"` // 是否多选
}
-type CommonDtoValue struct {
- FieldName string `json:"field_name"`
- Value any `json:"value"`
-}
+//type CommonDtoValue struct {
+// FieldName string `json:"field_name"`
+// Value any `json:"value"`
+//}
-type CommonDtoValues struct {
- Values []*CommonDtoValue `json:"values"`
-}
+type CommonDtoValues map[string]any
type CommonDtoList struct {
FieldsDesc []*CommonDtoFieldDesc `json:"fields_desc"` // 数据字段描述信息
- Rows []*CommonDtoValues `json:"rows"` // 数据行
+ Rows []CommonDtoValues `json:"rows"` // 数据行
}
diff --git a/admin/apps/game/server/ctl_common_rest.go b/admin/apps/game/server/ctl_common_rest.go
index 24b255e..90e8f59 100644
--- a/admin/apps/game/server/ctl_common_rest.go
+++ b/admin/apps/game/server/ctl_common_rest.go
@@ -15,7 +15,7 @@ func (ctl *controller) CommonList(ctx *context.WebContext, restfulResourceName s
}
func (ctl *controller) CommonPost(ctx *context.WebContext, restfulResourceName string, params *dto.CommonDtoValues) {
- newObj, err := ctl.svc.CommonPost(ctx, restfulResourceName, params)
+ newObj, err := ctl.svc.CommonPost(ctx, restfulResourceName, *params)
if err != nil {
ctx.Fail(err)
return
@@ -24,7 +24,7 @@ func (ctl *controller) CommonPost(ctx *context.WebContext, restfulResourceName s
}
func (ctl *controller) CommonPut(ctx *context.WebContext, restfulResourceName string, params *dto.CommonDtoValues) {
- newObj, err := ctl.svc.CommonPut(ctx, restfulResourceName, params)
+ newObj, err := ctl.svc.CommonPut(ctx, restfulResourceName, *params)
if err != nil {
ctx.Fail(err)
return
diff --git a/admin/apps/game/service/service.go b/admin/apps/game/service/service.go
index acc1cc0..cfa5cf6 100644
--- a/admin/apps/game/service/service.go
+++ b/admin/apps/game/service/service.go
@@ -30,14 +30,14 @@ func (svc *Service) CommonList(ctx context.Context, resourceName string, params
if err != nil {
return nil, err
}
- retList := make([]*dto.CommonDtoValues, 0, len(list))
+ retList := make([]dto.CommonDtoValues, 0, len(list))
for _, v := range list {
retList = append(retList, v.ToCommonDto())
}
return &dto.CommonDtoList{FieldsDesc: dtoFieldsDescInfo, Rows: retList}, nil
}
-func (svc *Service) CommonPost(ctx context.Context, resourceName string, params *dto.CommonDtoValues) (*dto.CommonDtoValues, error) {
+func (svc *Service) CommonPost(ctx context.Context, resourceName string, params dto.CommonDtoValues) (dto.CommonDtoValues, error) {
restfulDomainSvc, err := domain.FindRestfulResourceSvc(resourceName)
if err != nil {
return nil, err
@@ -48,7 +48,7 @@ func (svc *Service) CommonPost(ctx context.Context, resourceName string, params
}
return et.ToCommonDto(), nil
}
-func (svc *Service) CommonPut(ctx context.Context, resourceName string, params *dto.CommonDtoValues) (*dto.CommonDtoValues, error) {
+func (svc *Service) CommonPut(ctx context.Context, resourceName string, params dto.CommonDtoValues) (dto.CommonDtoValues, error) {
restfulDomainSvc, err := domain.FindRestfulResourceSvc(resourceName)
if err != nil {
return nil, err
diff --git a/ui/src/components/restful/table.vue b/ui/src/components/restful/table.vue
index 9d662bd..ec10b93 100644
--- a/ui/src/components/restful/table.vue
+++ b/ui/src/components/restful/table.vue
@@ -2,6 +2,11 @@
const props = defineProps({
rows: {}
})
+
+const fieldsDescInfo = props.rows.fields_desc
+const rows = props.rows.rows
+
+console.log("fields desc:", fieldsDescInfo)
console.log("rows:", props.rows)
@@ -15,7 +20,16 @@ console.log("rows:", props.rows)
添加
-
+
+ /
+
+
+
+
+
+
+