Merge branch 'gin-vue-admin_v2_dev' of https://github.com/piexlmax/gin-vue-admin into gin-vue-admin_v2_dev

# Conflicts:
#	server/model/sys_authority.go
#	server/model/sys_authority_menu.go
#	server/model/sys_base_menu.go
This commit is contained in:
rainyan
2020-04-06 00:47:46 +08:00
28 changed files with 259 additions and 315 deletions
+23 -33
View File
@@ -1,13 +1,12 @@
package model
import (
"fmt"
"gin-vue-admin/global"
)
type SysMenu struct {
SysBaseMenu
MenuId string `json:"menuId"`
MenuId string `json:"MenuId"`
AuthorityId string `json:"-"`
Children []SysMenu `json:"children"`
}
@@ -15,51 +14,41 @@ type SysMenu struct {
// @title AddMenuAuthority
// @description 为角色增加menu树
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param menus []SysBaseMenu
// @param authorityId string
// @return error
func (m *SysMenu) AddMenuAuthority(menus []SysBaseMenu, authorityId string) (err error) {
var menu SysMenu
global.GVA_DB.Where("authority_id = ? ", authorityId).Unscoped().Delete(&SysMenu{})
for _, v := range menus {
menu.SysBaseMenu = v
menu.AuthorityId = authorityId
menu.MenuId = fmt.Sprintf("%v", v.ID)
menu.ID = 0
err = global.GVA_DB.Create(&menu).Error
if err != nil {
return err
}
}
var auth SysAuthority
auth.AuthorityId = authorityId
auth.SysBaseMenus = menus
auth.SetMuneAuthority()
return nil
err = auth.SetMuneAuthority()
return err
}
// @title GetMenuAuthority
// @description 查看当前角色树
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (m *SysMenu) GetMenuAuthority(authorityId string) (err error, menus []SysMenu) {
err = global.GVA_DB.Where("authority_id = ?", authorityId).Find(&menus).Error
return err, menus
// @param authorityId string
// @return err error
// @return menus []SysBaseMenu
func (m *SysMenu) GetMenuAuthority(authorityId string) (err error, menus []SysBaseMenu) {
var a SysAuthority
err = global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", authorityId).First(&a).Error
return err, a.SysBaseMenus
}
// @title GetMenuTree
// @description 获取动态菜单树
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @param authorityId string
// @return err error
// @return menus []SysMenu
func (m *SysMenu) GetMenuTree(authorityId string) (err error, menus []SysMenu) {
err = global.GVA_DB.Where("authority_id = ? AND parent_id = ?", authorityId, 0).Order("sort", true).Find(&menus).Error
SQLstatement := "SELECT authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? AND authority_menu.parent_id = ?"
err = global.GVA_DB.Raw(SQLstatement, authorityId, 0).Scan(&menus).Error
for i := 0; i < len(menus); i++ {
err = getChildrenList(&menus[i])
err = getChildrenList(&menus[i], SQLstatement)
}
return err, menus
}
@@ -67,12 +56,13 @@ func (m *SysMenu) GetMenuTree(authorityId string) (err error, menus []SysMenu) {
// @title getChildrenList
// @description 获取子菜单
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @param menu *SysMenu
// @param SQLstatement string
// @return err error
func getChildrenList(menu *SysMenu) (err error) {
err = global.GVA_DB.Where("authority_id = ? AND parent_id = ?", menu.AuthorityId, menu.MenuId).Order("sort", true).Find(&menu.Children).Error
func getChildrenList(menu *SysMenu, SQLstatement string) (err error) {
err = global.GVA_DB.Raw(SQLstatement, menu.AuthorityId, menu.MenuId).Scan(&menu.Children).Error
for i := 0; i < len(menu.Children); i++ {
err = getChildrenList(&menu.Children[i])
err = getChildrenList(&menu.Children[i], SQLstatement)
}
return err
}