optimize
This commit is contained in:
parent
c882f04529
commit
dafa58a5d0
@ -26,16 +26,16 @@ func FromProjectPo(po *model.Project) *Project {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromProjectDto(dto *dto.CommonDtoValues) *Project {
|
func FromProjectDto(dto dto.CommonDtoValues) *Project {
|
||||||
et := DefaultProject()
|
et := DefaultProject()
|
||||||
po := et.po
|
po := et.po
|
||||||
|
|
||||||
//to := reflect.TypeOf(po)
|
//to := reflect.TypeOf(po)
|
||||||
vo := reflect.ValueOf(po)
|
vo := reflect.ValueOf(po)
|
||||||
|
|
||||||
for _, f := range dto.Values {
|
for k, v := range dto {
|
||||||
fo := vo.FieldByName(f.FieldName)
|
fo := vo.FieldByName(k)
|
||||||
fo.Set(reflect.ValueOf(f.Value))
|
fo.Set(reflect.ValueOf(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
return et
|
return et
|
||||||
@ -45,8 +45,8 @@ func (et *Project) ToPo() *model.Project {
|
|||||||
return et.po
|
return et.po
|
||||||
}
|
}
|
||||||
|
|
||||||
func (et *Project) ToCommonDto() *dto.CommonDtoValues {
|
func (et *Project) ToCommonDto() dto.CommonDtoValues {
|
||||||
obj := &dto.CommonDtoValues{}
|
obj := make(dto.CommonDtoValues)
|
||||||
|
|
||||||
to := reflect.TypeOf(et.po).Elem()
|
to := reflect.TypeOf(et.po).Elem()
|
||||||
vo := reflect.ValueOf(et.po).Elem()
|
vo := reflect.ValueOf(et.po).Elem()
|
||||||
@ -54,12 +54,7 @@ func (et *Project) ToCommonDto() *dto.CommonDtoValues {
|
|||||||
ft := to.Field(i)
|
ft := to.Field(i)
|
||||||
fo := vo.Field(i)
|
fo := vo.Field(i)
|
||||||
|
|
||||||
f1 := &dto.CommonDtoValue{
|
obj[ft.Name] = fo.Interface()
|
||||||
FieldName: ft.Name,
|
|
||||||
Value: fo.Interface(),
|
|
||||||
}
|
|
||||||
|
|
||||||
obj.Values = append(obj.Values, f1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
@ -26,16 +26,16 @@ func FromServerPo(po *model.Server) *Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromServerDto(dto *dto.CommonDtoValues) *Server {
|
func FromServerDto(dto dto.CommonDtoValues) *Server {
|
||||||
et := DefaultServer()
|
et := DefaultServer()
|
||||||
po := et.po
|
po := et.po
|
||||||
|
|
||||||
//to := reflect.TypeOf(po)
|
//to := reflect.TypeOf(po)
|
||||||
vo := reflect.ValueOf(po)
|
vo := reflect.ValueOf(po)
|
||||||
|
|
||||||
for _, f := range dto.Values {
|
for k, v := range dto {
|
||||||
fo := vo.FieldByName(f.FieldName)
|
fo := vo.FieldByName(k)
|
||||||
fo.Set(reflect.ValueOf(f.Value))
|
fo.Set(reflect.ValueOf(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
return et
|
return et
|
||||||
@ -45,8 +45,8 @@ func (et *Server) ToPo() *model.Server {
|
|||||||
return et.po
|
return et.po
|
||||||
}
|
}
|
||||||
|
|
||||||
func (et *Server) ToCommonDto() *dto.CommonDtoValues {
|
func (et *Server) ToCommonDto() dto.CommonDtoValues {
|
||||||
obj := &dto.CommonDtoValues{}
|
obj := make(dto.CommonDtoValues)
|
||||||
|
|
||||||
to := reflect.TypeOf(et.po).Elem()
|
to := reflect.TypeOf(et.po).Elem()
|
||||||
vo := reflect.ValueOf(et.po).Elem()
|
vo := reflect.ValueOf(et.po).Elem()
|
||||||
@ -54,12 +54,7 @@ func (et *Server) ToCommonDto() *dto.CommonDtoValues {
|
|||||||
ft := to.Field(i)
|
ft := to.Field(i)
|
||||||
fo := vo.Field(i)
|
fo := vo.Field(i)
|
||||||
|
|
||||||
f1 := &dto.CommonDtoValue{
|
obj[ft.Name] = fo.Interface()
|
||||||
FieldName: ft.Name,
|
|
||||||
Value: fo.Interface(),
|
|
||||||
}
|
|
||||||
|
|
||||||
obj.Values = append(obj.Values, f1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
@ -6,13 +6,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type IRestfulEntity interface {
|
type IRestfulEntity interface {
|
||||||
ToCommonDto() *dto.CommonDtoValues
|
ToCommonDto() dto.CommonDtoValues
|
||||||
}
|
}
|
||||||
|
|
||||||
type IRestfulResourceSvc interface {
|
type IRestfulResourceSvc interface {
|
||||||
List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []IRestfulEntity, error)
|
List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []IRestfulEntity, error)
|
||||||
Post(obj *dto.CommonDtoValues) (IRestfulEntity, error)
|
Post(obj dto.CommonDtoValues) (IRestfulEntity, error)
|
||||||
Put(obj *dto.CommonDtoValues) (IRestfulEntity, error)
|
Put(obj dto.CommonDtoValues) (IRestfulEntity, error)
|
||||||
Delete(id int) error
|
Delete(id int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,13 +31,13 @@ func (svc *ProjectSvc) List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []I
|
|||||||
return entity.ProjectDtoFieldsDescInfo, iList, nil
|
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)
|
et := entity.FromProjectDto(obj)
|
||||||
err := svc.proRepo.Create(et)
|
err := svc.proRepo.Create(et)
|
||||||
return et, err
|
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)
|
et := entity.FromProjectDto(obj)
|
||||||
err := svc.proRepo.Edit(et)
|
err := svc.proRepo.Edit(et)
|
||||||
return et, err
|
return et, err
|
||||||
|
@ -31,13 +31,13 @@ func (svc *ServerSvc) List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []IR
|
|||||||
return entity.ServerDtoFieldsDescInfo, iList, nil
|
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)
|
et := entity.FromServerDto(obj)
|
||||||
err := svc.serverRepo.Create(et)
|
err := svc.serverRepo.Create(et)
|
||||||
return et, err
|
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)
|
et := entity.FromServerDto(obj)
|
||||||
err := svc.serverRepo.Edit(et)
|
err := svc.serverRepo.Edit(et)
|
||||||
return et, err
|
return et, err
|
||||||
|
@ -20,16 +20,14 @@ type CommonDtoFieldDesc struct {
|
|||||||
MultiChoice bool `json:"multi_choice"` // 是否多选
|
MultiChoice bool `json:"multi_choice"` // 是否多选
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommonDtoValue struct {
|
//type CommonDtoValue struct {
|
||||||
FieldName string `json:"field_name"`
|
// FieldName string `json:"field_name"`
|
||||||
Value any `json:"value"`
|
// Value any `json:"value"`
|
||||||
}
|
//}
|
||||||
|
|
||||||
type CommonDtoValues struct {
|
type CommonDtoValues map[string]any
|
||||||
Values []*CommonDtoValue `json:"values"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommonDtoList struct {
|
type CommonDtoList struct {
|
||||||
FieldsDesc []*CommonDtoFieldDesc `json:"fields_desc"` // 数据字段描述信息
|
FieldsDesc []*CommonDtoFieldDesc `json:"fields_desc"` // 数据字段描述信息
|
||||||
Rows []*CommonDtoValues `json:"rows"` // 数据行
|
Rows []CommonDtoValues `json:"rows"` // 数据行
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
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 {
|
if err != nil {
|
||||||
ctx.Fail(err)
|
ctx.Fail(err)
|
||||||
return
|
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) {
|
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 {
|
if err != nil {
|
||||||
ctx.Fail(err)
|
ctx.Fail(err)
|
||||||
return
|
return
|
||||||
|
@ -30,14 +30,14 @@ func (svc *Service) CommonList(ctx context.Context, resourceName string, params
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
retList := make([]*dto.CommonDtoValues, 0, len(list))
|
retList := make([]dto.CommonDtoValues, 0, len(list))
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
retList = append(retList, v.ToCommonDto())
|
retList = append(retList, v.ToCommonDto())
|
||||||
}
|
}
|
||||||
return &dto.CommonDtoList{FieldsDesc: dtoFieldsDescInfo, Rows: retList}, nil
|
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)
|
restfulDomainSvc, err := domain.FindRestfulResourceSvc(resourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -48,7 +48,7 @@ func (svc *Service) CommonPost(ctx context.Context, resourceName string, params
|
|||||||
}
|
}
|
||||||
return et.ToCommonDto(), nil
|
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)
|
restfulDomainSvc, err := domain.FindRestfulResourceSvc(resourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
rows: {}
|
rows: {}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const fieldsDescInfo = props.rows.fields_desc
|
||||||
|
const rows = props.rows.rows
|
||||||
|
|
||||||
|
console.log("fields desc:", fieldsDescInfo)
|
||||||
console.log("rows:", props.rows)
|
console.log("rows:", props.rows)
|
||||||
|
|
||||||
|
|
||||||
@ -15,7 +20,16 @@ console.log("rows:", props.rows)
|
|||||||
<el-button size="large" type="primary">添加</el-button>
|
<el-button size="large" type="primary">添加</el-button>
|
||||||
</el-header>
|
</el-header>
|
||||||
<el-main>
|
<el-main>
|
||||||
<el-table v-for="rows"
|
<el-table :data="rows" style="width: 100%" table-layout="auto" stripe>
|
||||||
|
<template v-for="fieldDescInfo in fieldsDescInfo">
|
||||||
|
<el-table-column :prop="fieldDescInfo.key" :label="fieldDescInfo.name"></el-table-column>/
|
||||||
|
</template>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<el-dialog v-model="addvisible" title="添加" modal="true" :before-close="handleCloseAdd" destroy-on-close>
|
||||||
|
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
</el-main>
|
</el-main>
|
||||||
</el-container>
|
</el-container>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user