package model import ( "Panel_development/global" "errors" "gorm.io/gorm" ) type ComponentList struct { gorm.Model Name string `gorm:"type:varchar(255);not null;unique;comment:组件名称"` Image string `gorm:"type:varchar(255);not null;comment:组件图片"` UserId uint `gorm:"type:int;not null;comment:用户id"` Data string `gorm:"type:longtext;comment:组件数据"` ClassifyId uint `gorm:"type:int;not null;comment:组件分类id"` } func (c ComponentList) TableName() string { return "component_list" } type ComponentClassify struct { gorm.Model Name string `gorm:"type:varchar(255);not null;unique;comment:组件分类名称" json:"name" validate:"required"` ParentId uint `gorm:"type:int;not null;comment:父组件id" json:"parentId"` ComponentClass []ComponentClassify `gorm:"foreignKey:ParentId;references:ID" json:"componentClass"` } func (cc ComponentClassify) TableName() string { return "component_classify" } func (cc ComponentClassify) AddComponentClassify(ComponentClassify) (ComponentClassify, error) { //TODO implement me tx := global.DBLink.Create(&ComponentClassify{}) if tx.RowsAffected > 0 { return ComponentClassify{}, nil } return ComponentClassify{}, errors.New("添加失败") }