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()
 | 
			
		||||
	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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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"`        // 数据行
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
        <el-button size="large" type="primary">添加</el-button>
 | 
			
		||||
      </el-header>
 | 
			
		||||
      <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-container>
 | 
			
		||||
  </div>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user