system

package
v0.0.0-...-bcd2c7c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NotAdminRole = 0
	AdminRole    = 1
)
View Source
const (
	BindRoleMenuTableName = "bind_role_menu"
)
View Source
const MenuTableName = "menu"
View Source
const RoleTableName = "role"

Variables

View Source
var (
	ErrUpdateRoleNameNotAllowed = errors.New("角色名称不允许修改!")
	ErrUpdateRoleKeyNotAllowed  = errors.New("角色标识不允许修改!")
)

Functions

func BatchDelete

func BatchDelete(ctx context.Context, ids []int) (ok bool, err error)

BatchDelete batch delete role by given id list and return result

func InitPaths

func InitPaths(ctx context.Context, m *Menu) error

InitPaths init menu path when a menu is created. menu.path = parentMenu.path + "/" + menu.id

Types

type BindRoleMenu

type BindRoleMenu struct {
	RoleID   int    `gorm:"column:role_id" json:"role_id"`
	MenuID   int    `gorm:"column:menu_id" json:"menu_id"`
	RoleName string `gorm:"column:role_name" json:"role_name"`
	CreateBy string `gorm:"column:create_by" json:"create_by"`
	UpdateBy string `gorm:"column:update_by" json:"update_by"`
	ID       int    `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"`
}

func (*BindRoleMenu) Delete

func (rm *BindRoleMenu) Delete(ctx context.Context, roleId, menuId string) (err error)

func (*BindRoleMenu) Get

func (rm *BindRoleMenu) Get(ctx context.Context) (rms []*BindRoleMenu, err error)

Get find bindRoleMenu models by give id, if id == 0, then find all

type IsAdmin

type IsAdmin int
type Menu struct {
	MenuID     int        `gorm:"column:menu_id;primary_key;AUTO_INCREMENT" json:"menu_id"`
	MenuName   string     `gorm:"column:menu_name" json:"menu_name"`
	Title      string     `gorm:"column:title" json:"title"`
	Icon       string     `gorm:"column:icon" json:"icon"`
	Path       string     `gorm:"column:path" json:"path"`           // vue router
	Paths      string     `gorm:"column:paths" json:"paths"`         // router from parent to current node
	MenuType   string     `gorm:"column:menu_type" json:"menu_type"` // C: 菜单, M: 目录, F: 按钮, A: 接口
	Action     string     `gorm:"column:action" json:"action"`
	Permission string     `gorm:"column:permission" json:"permission"` // vue permission
	ParentID   int        `gorm:"column:parent_id" json:"parent_id"`
	NoCache    string     `gorm:"column:no_cache" json:"no_cache"`
	Breadcrumb string     `gorm:"column:breadcrumb" json:"breadcrumb"` // FIXME 未知
	Component  string     `gorm:"column:component" json:"component"`   // 组件路径
	Sort       int        `gorm:"column:sort" json:"sort"`
	Visible    string     `gorm:"column:visible" json:"visible"` // 可见性
	CreateBy   string     `gorm:"column:create_by" json:"create_by"`
	UpdateBy   string     `gorm:"column:update_by" json:"update_by"` // 是否外链
	IsFrame    int        `gorm:"column:is_frame;default:0" json:"is_frame"`
	CreateTime *time.Time `gorm:"column:create_time" json:"create_time"`
	UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"`
	DeleteTime *time.Time `gorm:"column:delete_time" json:"delete_time"`
	Children   []*Menu    `json:"children"`
}

func RecursiveMenu

func RecursiveMenu(ctx context.Context, menulist []*Menu, menu *Menu) *Menu

RecursiveMenu find child menu from params menulist for params menu

func (m *Menu) Create(ctx context.Context) (id int, err error)

Create creates a menu object, return its id and an error if it exists

func (m *Menu) DeleteMenu(ctx context.Context, id int) error

DeleteMenu delete menu by given menu_id

func (e *Menu) Get(ctx context.Context) (menus []*Menu, err error)

GetPages find menu list by (menu_name, path, action, menu_type)

func (m *Menu) GetMenuById(ctx context.Context, id int) (menu *Menu, err error)

GetMenuById get menu by given menu_id

func (m *Menu) GetPage(ctx context.Context) (menus []*Menu, err error)

GetPages find menu list by (menu_name, title, visible, menu_type)

func (m *Menu) SetMenu(ctx context.Context) (menus []*Menu, err error)

SetMenu find menu list by given condition and set children menu for each menu

func (m *Menu) SetMenuLabel(ctx context.Context) (mls []*MenuLabel, err error)

SetMenuLabel set menulabel list by give menu

func (m *Menu) Update(ctx context.Context, id int) (menu *Menu, err error)

Update select a menu by id for update TODO: transaction update

type MenuLabel struct {
	Id       int          `json:"id" gorm:"-"`
	Label    string       `json:"label" gorm:"-"`
	Children []*MenuLabel `json:"children" gorm:"-"`
}

func RecursiveMenuLabel

func RecursiveMenuLabel(ctx context.Context, menulist []*Menu, menu *MenuLabel) *MenuLabel

RecursiveMenuLabel find router tree for given menulabel

type Role

type Role struct {
	RoleID     int        `gorm:"primary_key;AUTO_INCREMENT" json:"role_id"`
	RoleName   string     `gorm:"column:role_name" json:"role_name"`
	Status     string     `gorm:"column:status" json:"status"`
	RoleKey    string     `gorm:"column:role_key" json:"role_key"`
	RoleSort   int        `gorm:"column:role_sort" json:"role_sort"`
	Flag       string     `gorm:"column:flag" json:"flag"`
	CreateBy   string     `gorm:"column:create_by" json:"create_by"`
	UpdateBy   string     `gorm:"column:update_by" json:"update_by"`
	Remark     string     `gorm:"column:remark" json:"remark"`
	Admin      int        `gorm:"column:admin" json:"admin"`
	CreateTime *time.Time `gorm:"column:create_time" json:"create_time" default:"2000-01-01 00:00:00"`
	UpdateTime *time.Time `gorm:"column:update_time" json:"update_time" default:"2000-01-01 00:00:00"`
	DeleteTime *time.Time `gorm:"column:delete_time" json:"delete_time" default:"2000-01-01 00:00:00"`
	Params     string     `json:"params" gorm:"-"`
	MenuIds    []int      `json:"menuIds" gorm:"-"`
	DeptIds    []int      `json:"deptIds" gorm:"-"`
}

func NewRole

func NewRole(rolename string, remark string, admin IsAdmin, createBy string) *Role

func (*Role) Get

func (r *Role) Get(ctx context.Context) (role *Role, err error)

Get get a role by (role_id, role_name)

func (*Role) GetList

func (r *Role) GetList(ctx context.Context) (roles []*Role, err error)

GetList get role list by (role_id, role_name)

func (*Role) GetPage

func (r *Role) GetPage(ctx context.Context, limit, offset int) (roles []*Role, count int64, err error)

GetPage get role list page by (role_id, role_name, status, role_key), return list, list length and an error

func (*Role) Insert

func (r *Role) Insert(ctx context.Context) (id int, err error)

Insert create a new role and return its id

func (*Role) Update

func (r *Role) Update(ctx context.Context, id int) (updated *Role, err error)

Update update a role by id

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL