动态路由删除修改等操作
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"main/model/modelInterface"
|
||||
)
|
||||
|
||||
// @Tags Menu
|
||||
// @Tags authorityAndMenu
|
||||
// @Summary 获取用户动态路由
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
@@ -27,7 +27,7 @@ func GetMenu(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Tags menu
|
||||
// @Summary 分页获取基础menu列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
@@ -51,7 +51,7 @@ func GetMenuList(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Tags menu
|
||||
// @Summary 分页获取基础menu列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
@@ -70,7 +70,7 @@ func AddBaseMenu(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags Menu
|
||||
// @Tags authorityAndMenu
|
||||
// @Summary 获取用户动态路由
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
@@ -91,7 +91,7 @@ type AddMenuAuthorityInfo struct {
|
||||
AuthorityId string
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Tags authorityAndMenu
|
||||
// @Summary 增加menu和角色关联关系
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
@@ -114,7 +114,7 @@ type AuthorityIdInfo struct {
|
||||
AuthorityId string
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Tags authorityAndMenu
|
||||
// @Summary 获取指定角色menu
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
@@ -132,3 +132,26 @@ func GetMenuAuthority(c *gin.Context) {
|
||||
servers.ReportFormat(c, true, "获取成功", gin.H{"menus": menus})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type IdInfo struct {
|
||||
Id float64
|
||||
}
|
||||
// @Tags menu
|
||||
// @Summary 获取指定角色menu
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body modelInterface.IdInfo true "删除菜单"
|
||||
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /menu/deleteBaseMenu [post]
|
||||
func DeleteBaseMenu(c *gin.Context) {
|
||||
var idInfo IdInfo
|
||||
_ = c.BindJSON(&idInfo)
|
||||
err :=new(dbModel.BaseMenu).DeleteBaseMenu(idInfo.Id)
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "删除成功", gin.H{})
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,14 @@ func (b *BaseMenu) AddBaseMenu() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *BaseMenu) DeleteBaseMenu(name string) (err error) {
|
||||
err = qmsql.DEFAULTDB.Where("name = ?", name).Delete(&b).Delete(&Menu{}).Error
|
||||
func (b *BaseMenu) DeleteBaseMenu(id float64) (err error) {
|
||||
err = qmsql.DEFAULTDB.Where("parent_id = ?",id).First(&BaseMenu{}).Error
|
||||
if(err!=nil){
|
||||
err = qmsql.DEFAULTDB.Where("id = ?", id).Delete(&b).Error
|
||||
err = qmsql.DEFAULTDB.Where("menu_id = ?", id).Delete(&Menu{}).Error
|
||||
}else{
|
||||
return errors.New("此菜单存在子菜单不可删除")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -15,5 +15,6 @@ func InitMenuRouter(Router *gin.Engine) {
|
||||
MenuRouter.POST("getBaseMenuTree", api.GetBaseMenuTree)
|
||||
MenuRouter.POST("addMenuAuthority", api.AddMenuAuthority)
|
||||
MenuRouter.POST("getMenuAuthority", api.GetMenuAuthority)
|
||||
MenuRouter.POST("deleteBaseMenu",api.DeleteBaseMenu)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user