feat✨ 添加api管理

This commit is contained in:
wenjianzhang committed 2021-05-12 18:48:01 +08:00
1 parent 70998c424d
commit d0b2e8d03f
6 files changed
+395 -53

No files matched your search

+3 -36
View File
@@ -3,20 +3,17 @@ package models
import (
// "gorm.io/gorm"
"errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"go-admin/common/models"
"gorm.io/gorm"
)
type SysApi struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"`
Name string `json:"name" gorm:"type:varchar(128);comment:名称"`
Handle string `json:"handle" gorm:"type:varchar(128);comment:handle"`
Title string `json:"title" gorm:"type:varchar(128);comment:标题"`
Path string `json:"path" gorm:"type:varchar(128);comment:地址"`
Paths string `json:"paths" gorm:"type:varchar(128);comment:Paths"`
Action string `json:"action" gorm:"type:varchar(16);comment:类型"`
ParentId int `json:"parentId" gorm:"type:smallint(6);comment:按钮id"`
ParentId int `json:"parentId" gorm:"comment:按钮id"`
Sort int `json:"sort" gorm:"type:tinyint(4);comment:排序"`
models.ModelTime
models.ControlBy
@@ -33,34 +30,4 @@ func (e *SysApi) Generate() models.ActiveRecord {
func (e *SysApi) GetId() interface{} {
return e.Id
}
func (e *SysApi) Create(tx *gorm.DB) (id int, err error) {
result := tx.Table(e.TableName()).Create(&e)
if result.Error != nil {
err = result.Error
return
}
err = e.InitPaths(tx)
if err != nil {
return
}
id = e.Id
return
}
func (e *SysApi) InitPaths(tx *gorm.DB) (err error) {
parentMenu := new(Menu)
if e.ParentId != 0 {
tx.Table("sys_api").Where("id = ?", e.ParentId).First(parentMenu)
if parentMenu.Paths == "" {
err = errors.New("父级paths异常,请尝试对当前节点父级菜单进行更新操作!")
return
}
e.Paths = parentMenu.Paths + "/" + pkg.IntToString(e.Id)
} else {
e.Paths = "/0/" + pkg.IntToString(e.Id)
}
tx.Table("sys_api").Where("id = ?", e.ParentId).Update("paths", e.Paths)
return
}
}