feat✨ apis路径简化

This commit is contained in:
wenjianzhang committed 2021-05-14 12:19:22 +08:00
1 parent 8adc79a5f7
commit dfd460c50b
56 files changed
+471 -665

No files matched your search

@@ -1,4 +1,4 @@
package system
package models
//sys_casbin_rule
type CasbinRule struct {
@@ -13,4 +13,4 @@ type CasbinRule struct {
func (CasbinRule) TableName() string {
return "sys_casbin_rule"
}
}
@@ -1,4 +1,4 @@
package system
package models
import (
"errors"
@@ -78,4 +78,4 @@ func DataScopes(tableName string, userId int) func(db *gorm.DB) *gorm.DB {
}
return db
}
}
}
+26 -207
View File
@@ -6,34 +6,33 @@ import (
"go-admin/common/models"
"gorm.io/gorm"
"go-admin/app/admin/models/system"
)
type Menu struct {
MenuId int `json:"menuId" gorm:"primaryKey;autoIncrement"`
MenuName string `json:"menuName" gorm:"size:128;"`
Title string `json:"title" gorm:"size:128;"`
Icon string `json:"icon" gorm:"size:128;"`
Path string `json:"path" gorm:"size:128;"`
Paths string `json:"paths" gorm:"size:128;"`
MenuType string `json:"menuType" gorm:"size:1;"`
Action string `json:"action" gorm:"size:16;"`
Permission string `json:"permission" gorm:"size:255;"`
ParentId int `json:"parentId" gorm:"size:11;"`
NoCache bool `json:"noCache" gorm:"size:8;"`
Breadcrumb string `json:"breadcrumb" gorm:"size:255;"`
Component string `json:"component" gorm:"size:255;"`
Sort int `json:"sort" gorm:"size:4;"`
Visible string `json:"visible" gorm:"size:1;"`
CreateBy string `json:"createBy" gorm:"size:128;"`
UpdateBy string `json:"updateBy" gorm:"size:128;"`
IsFrame string `json:"isFrame" gorm:"size:1;DEFAULT:0;"`
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
RoleId int `gorm:"-"`
Children []Menu `json:"children" gorm:"-"`
IsSelect bool `json:"is_select" gorm:"-"`
MenuId int `json:"menuId" gorm:"primaryKey;autoIncrement"`
MenuName string `json:"menuName" gorm:"size:128;"`
Title string `json:"title" gorm:"size:128;"`
Icon string `json:"icon" gorm:"size:128;"`
Path string `json:"path" gorm:"size:128;"`
Paths string `json:"paths" gorm:"size:128;"`
MenuType string `json:"menuType" gorm:"size:1;"`
Action string `json:"action" gorm:"size:16;"`
Permission string `json:"permission" gorm:"size:255;"`
ParentId int `json:"parentId" gorm:"size:11;"`
NoCache bool `json:"noCache" gorm:"size:8;"`
Breadcrumb string `json:"breadcrumb" gorm:"size:255;"`
Component string `json:"component" gorm:"size:255;"`
Sort int `json:"sort" gorm:"size:4;"`
Visible string `json:"visible" gorm:"size:1;"`
CreateBy string `json:"createBy" gorm:"size:128;"`
UpdateBy string `json:"updateBy" gorm:"size:128;"`
IsFrame string `json:"isFrame" gorm:"size:1;DEFAULT:0;"`
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
RoleId int `gorm:"-"`
Children []Menu `json:"children" gorm:"-"`
IsSelect bool `json:"is_select" gorm:"-"`
models.ModelTime
}
@@ -83,160 +82,6 @@ type MenuRole struct {
type MS []Menu
//func (e *Menu) GetByMenuId() (Menu Menu, err error) {
//
// table := orm.Eloquent.Table(e.TableName())
// table = table.Where("menu_id = ?", e.MenuId)
// if err = table.Find(&Menu).Error; err != nil {
// return
// }
// return
//}
//func (e *Menu) SetMenu() (m []Menu, err error) {
// menulist, err := e.GetPage()
//
// m = make([]Menu, 0)
// for i := 0; i < len(menulist); i++ {
// if menulist[i].ParentId != 0 {
// continue
// }
// menusInfo := DiguiMenu(&menulist, menulist[i])
//
// m = append(m, menusInfo)
// }
// return
//}
//func DiguiMenu(menulist *[]Menu, menu Menu) Menu {
// list := *menulist
//
// min := make([]Menu, 0)
// for j := 0; j < len(list); j++ {
//
// if menu.MenuId != list[j].ParentId {
// continue
// }
// mi := Menu{}
// mi.MenuId = list[j].MenuId
// mi.MenuName = list[j].MenuName
// mi.Title = list[j].Title
// mi.Icon = list[j].Icon
// mi.Path = list[j].Path
// mi.MenuType = list[j].MenuType
// mi.Action = list[j].Action
// mi.Permission = list[j].Permission
// mi.ParentId = list[j].ParentId
// mi.NoCache = list[j].NoCache
// mi.Breadcrumb = list[j].Breadcrumb
// mi.Component = list[j].Component
// mi.Sort = list[j].Sort
// mi.Visible = list[j].Visible
// mi.CreatedAt = list[j].CreatedAt
// mi.Children = []Menu{}
//
// if mi.MenuType != "F" {
// ms := DiguiMenu(menulist, mi)
// min = append(min, ms)
//
// } else {
// min = append(min, mi)
// }
//
// }
// menu.Children = min
// return menu
//}
//func (e *Menu) SetMenuLabel() (m *[]MenuLable, err error) {
// menulist, err := e.Get()
//
// ml := make([]MenuLable, 0)
// for i := 0; i < len(menulist); i++ {
// if menulist[i].ParentId != 0 {
// continue
// }
// e := MenuLable{}
// e.Id = menulist[i].MenuId
// e.Label = menulist[i].Title
// menusInfo := MenuLabelCall(&menulist, e)
//
// ml = append(ml, menusInfo)
// }
// return &ml, err
//}
//func MenuLabelCall(menulist *[]Menu, menu MenuLable) MenuLable {
// list := *menulist
//
// min := make([]MenuLable, 0)
// for j := 0; j < len(list); j++ {
//
// if menu.Id != list[j].ParentId {
// continue
// }
// mi := MenuLable{}
// mi.Id = list[j].MenuId
// mi.Label = list[j].Title
// mi.Children = []MenuLable{}
// if list[j].MenuType != "F" {
// ms := MenuLabelCall(menulist, mi)
// min = append(min, ms)
// } else {
// min = append(min, mi)
// }
//
// }
// if len(min) > 0 {
// menu.Children = min
// } else {
// menu.Children = nil
// }
// return menu
//}
//func (e *Menu) SetMenuRole(roleName string) (m []Menu, err error) {
//
// menus, err := e.GetByRoleName(roleName)
//
// m = make([]Menu, 0)
// for i := 0; i < len(menus); i++ {
// if menus[i].ParentId != 0 {
// continue
// }
// menusInfo := DiguiMenu(&menus, menus[i])
//
// m = append(m, menusInfo)
// }
// return
//}
//func (e *MenuRole) Get(tx *gorm.DB) (Menus []MenuRole, err error) {
// table := tx.Table(e.TableName())
// if e.MenuName != "" {
// table = table.Where("menu_name = ?", e.MenuName)
// }
// if err = table.Order("sort").Find(&Menus).Error; err != nil {
// return
// }
// return
//}
//func (e *Menu) GetByRoleName(roleName string) (Menus []Menu, err error) {
// var table *gorm.DB
// if roleName == "admin" {
// table = orm.Eloquent.Table(e.TableName()).Select("sys_menu.*")
// table = table.Where(" menu_type in ('M','C')")
// } else {
// table = orm.Eloquent.Table(e.TableName()).Select("sys_menu.*").Joins("left join sys_role_menu on sys_role_menu.menu_id=sys_menu.menu_id")
// table = table.Where("sys_role_menu.role_name=? and menu_type in ('M','C')", roleName)
// }
// if err = table.Order("sort").Find(&Menus).Error; err != nil {
// return
// }
// return
//}
func (e *Menu) Get(tx *gorm.DB) (Menus []Menu, err error) {
table := tx.Table(e.TableName())
if e.MenuName != "" {
@@ -274,7 +119,7 @@ func (e *Menu) GetPage(tx *gorm.DB) (Menus []Menu, err error) {
}
// 数据权限控制
dataPermission := new(system.DataPermission)
dataPermission := new(DataPermission)
dataPermission.UserId, _ = pkg.StringToInt(e.DataScope)
table, err = dataPermission.GetDataScope("sys_menu", table)
if err != nil {
@@ -314,30 +159,4 @@ func InitPaths(tx *gorm.DB, menu *Menu) (err error) {
}
tx.Table("sys_menu").Where("menu_id = ?", menu.MenuId).Update("paths", menu.Paths)
return
}
//func (e *Menu) Update(tx *gorm.DB, id int) (update Menu, err error) {
// if err = tx.Table(e.TableName()).First(&update, id).Error; err != nil {
// return
// }
//
// //参数1:是要修改的数据
// //参数2:是修改的数据
// if err = tx.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
// return
// }
// err = InitPaths(tx, e)
// if err != nil {
// return
// }
// return
//}
//func (e *Menu) Delete(tx *gorm.DB, id int) (success bool, err error) {
// if err = tx.Table(e.TableName()).Where("menu_id = ?", id).Delete(&Menu{}).Error; err != nil {
// success = false
// return
// }
// success = true
// return
//}
}
+22 -24
View File
@@ -1,28 +1,26 @@
package models
import "go-admin/common/models"
type SysRole struct {
RoleId int `json:"roleId" gorm:"primaryKey;autoIncrement"` // 角色编码
RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
Status string `json:"status" gorm:"size:4;"` //
RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
RoleSort int `json:"roleSort" gorm:""` //角色排序
Flag string `json:"flag" gorm:"size:128;"` //
Remark string `json:"remark" gorm:"size:255;"` //备注
Admin bool `json:"admin" gorm:"size:4;"`
DataScope string `json:"dataScope" gorm:"size:128;"`
models.ModelTime
models.ControlBy
Params string `json:"params" gorm:"-"`
MenuIds []int `json:"menuIds" gorm:"-"`
DeptIds []int `json:"deptIds" gorm:"-"`
}
func (SysRole) TableName() string {
return "sys_role"
}
//type SysRole struct {
// RoleId int `json:"roleId" gorm:"primaryKey;autoIncrement"` // 角色编码
// RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
// Status string `json:"status" gorm:"size:4;"` //
// RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
// RoleSort int `json:"roleSort" gorm:""` //角色排序
// Flag string `json:"flag" gorm:"size:128;"` //
// Remark string `json:"remark" gorm:"size:255;"` //备注
// Admin bool `json:"admin" gorm:"size:4;"`
// DataScope string `json:"dataScope" gorm:"size:128;"`
// models.ModelTime
// models.ControlBy
//
// Params string `json:"params" gorm:"-"`
// MenuIds []int `json:"menuIds" gorm:"-"`
// DeptIds []int `json:"deptIds" gorm:"-"`
//}
//
//func (SysRole) TableName() string {
// return "sys_role"
//}
type MenuIdList struct {
MenuId int `json:"menuId"`
@@ -240,4 +238,4 @@ type MenuIdList struct {
// }
//
// return true, nil
//}
//}
@@ -1,4 +1,4 @@
package system
package models
//sys_role_dept
type SysRoleDept struct {
@@ -8,4 +8,4 @@ type SysRoleDept struct {
func (SysRoleDept) TableName() string {
return "sys_role_dept"
}
}
@@ -1,8 +1,7 @@
package system
package models
import (
"fmt"
"github.com/casbin/casbin/v2"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
@@ -169,4 +168,4 @@ func (rm *RoleMenu) Delete(tx *gorm.DB, RoleId string, MenuID string) (bool, err
}
return true, nil
}
}
+9 -8
View File
@@ -7,14 +7,15 @@ import (
)
type SysApi struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement;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:"comment:按钮id"`
Sort int `json:"sort" gorm:"type:tinyint(4);comment:排序"`
Id int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"`
Handle string `json:"handle" gorm:"type:varchar(128);comment:handle"`
Title string `json:"title" gorm:"type:varchar(128);comment:标题"`
Permission string `json:"permission" gorm:"size:255;"`
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:"comment:按钮id"`
Sort int `json:"sort" gorm:"type:tinyint(4);comment:排序"`
models.ModelTime
models.ControlBy
}
@@ -1,4 +1,4 @@
package system
package models
import (
"go-admin/common/models"
@@ -27,4 +27,4 @@ func (e *SysConfig) Generate() models.ActiveRecord {
func (e *SysConfig) GetId() interface{} {
return e.Id
}
}
@@ -1,4 +1,4 @@
package system
package models
import "go-admin/common/models"
@@ -30,4 +30,4 @@ func (e *SysDept) Generate() models.ActiveRecord {
func (e *SysDept) GetId() interface{} {
return e.DeptId
}
}
@@ -1,4 +1,4 @@
package system
package models
import (
"go-admin/common/models"
@@ -32,4 +32,4 @@ func (e *SysDictData) Generate() models.ActiveRecord {
func (e *SysDictData) GetId() interface{} {
return e.DictCode
}
}
@@ -1,4 +1,4 @@
package system
package models
import (
"go-admin/common/models"
@@ -26,4 +26,4 @@ func (e *SysDictType) Generate() models.ActiveRecord {
func (e *SysDictType) GetId() interface{} {
return e.ID
}
}
@@ -1,4 +1,4 @@
package system
package models
import (
"encoding/json"
@@ -69,4 +69,4 @@ func SaveLoginLog(message storage.Messager) (err error) {
return err
}
return nil
}
}
@@ -1,4 +1,4 @@
package system
package models
import "go-admin/common/models"
@@ -19,6 +19,8 @@ type SysMenu struct {
Sort int `json:"sort" gorm:"size:4;"`
Visible string `json:"visible" gorm:"size:1;"`
IsFrame string `json:"isFrame" gorm:"size:1;DEFAULT:0;"`
SysApi []SysApi `json:"sysApi" gorm:"many2many:sys_menu_api_rule"`
Apis []int `json:"apis" gorm:"-"`
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
RoleId int `gorm:"-"`
@@ -28,27 +30,27 @@ type SysMenu struct {
models.ModelTime
}
type SysMenus struct {
MenuId int `json:"menuId" gorm:"column:menu_id;primaryKey;autoIncrement;"`
MenuName string `json:"menuName" gorm:"column:menu_name"`
Title string `json:"title" gorm:"column:title"`
Icon string `json:"icon" gorm:"column:icon"`
Path string `json:"path" gorm:"column:path"`
MenuType string `json:"menuType" gorm:"column:menu_type"`
Action string `json:"action" gorm:"column:action"`
Permission string `json:"permission" gorm:"column:permission"`
ParentId int `json:"parentId" gorm:"column:parent_id"`
NoCache bool `json:"noCache" gorm:"column:no_cache"`
Breadcrumb string `json:"breadcrumb" gorm:"column:breadcrumb"`
Component string `json:"component" gorm:"column:component"`
Sort int `json:"sort" gorm:"column:sort"`
Visible string `json:"visible" gorm:"column:visible"`
Children []SysMenu `json:"children" gorm:"-"`
models.ControlBy
models.ModelTime
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
}
//type SysMenus struct {
// MenuId int `json:"menuId" gorm:"column:menu_id;primaryKey;autoIncrement;"`
// MenuName string `json:"menuName" gorm:"column:menu_name"`
// Title string `json:"title" gorm:"column:title"`
// Icon string `json:"icon" gorm:"column:icon"`
// Path string `json:"path" gorm:"column:path"`
// MenuType string `json:"menuType" gorm:"column:menu_type"`
// Action string `json:"action" gorm:"column:action"`
// Permission string `json:"permission" gorm:"column:permission"`
// ParentId int `json:"parentId" gorm:"column:parent_id"`
// NoCache bool `json:"noCache" gorm:"column:no_cache"`
// Breadcrumb string `json:"breadcrumb" gorm:"column:breadcrumb"`
// Component string `json:"component" gorm:"column:component"`
// Sort int `json:"sort" gorm:"column:sort"`
// Visible string `json:"visible" gorm:"column:visible"`
// Children []SysMenu `json:"children" gorm:"-"`
// models.ControlBy
// models.ModelTime
// DataScope string `json:"dataScope" gorm:"-"`
// Params string `json:"params" gorm:"-"`
//}
func (SysMenu) TableName() string {
return "sys_menu"
@@ -61,4 +63,4 @@ func (e *SysMenu) Generate() models.ActiveRecord {
func (e *SysMenu) GetId() interface{} {
return e.MenuId
}
}
@@ -1,4 +1,4 @@
package system
package models
import (
"encoding/json"
@@ -82,4 +82,4 @@ func SaveOperaLog(message storage.Messager) (err error) {
return err
}
return nil
}
}
@@ -1,4 +1,4 @@
package system
package models
import "go-admin/common/models"
@@ -27,4 +27,4 @@ func (e *SysPost) Generate() models.ActiveRecord {
func (e *SysPost) GetId() interface{} {
return e.PostId
}
}
@@ -1,4 +1,4 @@
package system
package models
import "go-admin/common/models"
@@ -30,4 +30,4 @@ func (e *SysRole) Generate() models.ActiveRecord {
func (e *SysRole) GetId() interface{} {
return e.RoleId
}
}
@@ -1,4 +1,4 @@
package system
package models
import (
"go-admin/common/models"
@@ -74,4 +74,4 @@ func (e *SysUser) AfterFind(_ *gorm.DB) error {
e.PostIds = []int{e.PostId}
e.RoleIds = []int{e.RoleId}
return nil
}
}