component.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package model
  2. import (
  3. "Panel_development/global"
  4. "errors"
  5. "gorm.io/gorm"
  6. )
  7. type ComponentList struct {
  8. gorm.Model
  9. Name string `gorm:"type:varchar(255);not null;unique;comment:组件名称"`
  10. Image string `gorm:"type:varchar(255);not null;comment:组件图片"`
  11. UserId uint `gorm:"type:int;not null;comment:用户id"`
  12. Data string `gorm:"type:longtext;comment:组件数据"`
  13. ClassifyId uint `gorm:"type:int;not null;comment:组件分类id"`
  14. }
  15. func (c ComponentList) TableName() string {
  16. return "component_list"
  17. }
  18. type ComponentClassify struct {
  19. gorm.Model
  20. Name string `gorm:"type:varchar(255);not null;unique;comment:组件分类名称" json:"name" validate:"required"`
  21. ParentId uint `gorm:"type:int;not null;comment:父组件id" json:"parentId"`
  22. ComponentClass []ComponentClassify `gorm:"foreignKey:ParentId;references:ID" json:"componentClass"`
  23. }
  24. func (cc ComponentClassify) TableName() string {
  25. return "component_classify"
  26. }
  27. func (cc ComponentClassify) AddComponentClassify(ComponentClassify) (ComponentClassify, error) {
  28. //TODO implement me
  29. tx := global.DBLink.Create(&ComponentClassify{})
  30. if tx.RowsAffected > 0 {
  31. return ComponentClassify{}, nil
  32. }
  33. return ComponentClassify{}, errors.New("添加失败")
  34. }