mirror of
https://github.com/tiger1103/gfast.git
synced 2026-09-21 18:20:47 +00:00
菜单增删改查
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"gfast/app/model/auth_rule"
|
||||
"gfast/app/service/auth_service"
|
||||
"gfast/library/response"
|
||||
"gfast/library/utils"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
"github.com/gogf/gf/util/gvalid"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//用户管理
|
||||
@@ -15,16 +19,89 @@ func (c *Auth) AddGroup(r *ghttp.Request) {
|
||||
r.Response.Write("添加用户组")
|
||||
}
|
||||
|
||||
//菜单列表
|
||||
func (c *Auth) MenuList(r *ghttp.Request) {
|
||||
//获取菜单信息
|
||||
err, list := auth_service.GetMenuList("")
|
||||
if err != nil {
|
||||
g.Log().Error(err)
|
||||
response.FailJson(true, r, "获取数据失败")
|
||||
}
|
||||
list = utils.PushSonToParent(list)
|
||||
response.SusJson(true, r, "成功", g.Map{
|
||||
"list": list,
|
||||
})
|
||||
}
|
||||
|
||||
//添加菜单
|
||||
func (c *Auth) AddMenu(r *ghttp.Request) {
|
||||
if r.Method == "POST" {
|
||||
postData := r.GetFormMap()
|
||||
response.SusJson(true, r, "成功", postData)
|
||||
menu := new(auth_service.MenuReq)
|
||||
if err := r.Parse(menu); err != nil {
|
||||
response.FailJson(true, r, err.(*gvalid.Error).FirstString())
|
||||
}
|
||||
//保存到数据库
|
||||
err, _ := auth_service.AddMenu(menu)
|
||||
if err != nil {
|
||||
g.Log().Error(err)
|
||||
response.FailJson(true, r, "添加菜单失败")
|
||||
}
|
||||
response.SusJson(true, r, "添加菜单成功")
|
||||
}
|
||||
//获取父级菜单信息
|
||||
err, list := auth_service.GetMenuList()
|
||||
err, list := auth_service.GetMenuList("ismenu=?", 1)
|
||||
if err != nil {
|
||||
response.FailJson(true, r, "获取数据失败")
|
||||
}
|
||||
returnData := g.Map{"parentList": list}
|
||||
response.SusJson(true, r, "成功", returnData)
|
||||
list = utils.ParentSonSort(list)
|
||||
response.SusJson(true, r, "成功", g.Map{"parentList": list})
|
||||
}
|
||||
|
||||
//修改菜单
|
||||
func (c *Auth) EditMenu(r *ghttp.Request) {
|
||||
id := r.GetRequestInt("id")
|
||||
if r.Method == "POST" {
|
||||
menu := new(auth_service.MenuReq)
|
||||
if err := r.Parse(menu); err != nil {
|
||||
response.FailJson(true, r, err.(*gvalid.Error).FirstString())
|
||||
}
|
||||
//保存到数据库
|
||||
err, _ := auth_service.EditMenu(menu, id)
|
||||
if err != nil {
|
||||
g.Log().Error(err)
|
||||
response.FailJson(true, r, "修改菜单失败")
|
||||
}
|
||||
response.SusJson(true, r, "修改菜单成功")
|
||||
}
|
||||
menuEntity, err := auth_rule.Model.Where("id=?", id).One()
|
||||
if err != nil {
|
||||
g.Log().Error(err)
|
||||
response.FailJson(true, r, "获取数据失败")
|
||||
}
|
||||
//获取父级菜单信息
|
||||
err, list := auth_service.GetMenuList("ismenu=?", 1)
|
||||
if err != nil {
|
||||
response.FailJson(true, r, "获取数据失败")
|
||||
}
|
||||
list = utils.ParentSonSort(list)
|
||||
response.SusJson(true, r, "成功", g.Map{
|
||||
"parentList": list,
|
||||
"menu": menuEntity,
|
||||
})
|
||||
}
|
||||
|
||||
//删除菜单
|
||||
func (c *Auth) DeleteMenu(r *ghttp.Request) {
|
||||
ids := r.GetRequestArray("ids")
|
||||
where := "id in(" + strings.TrimRight(strings.Repeat("?,", len(ids)), ",") + ")"
|
||||
idsInterface := make([]interface{}, len(ids))
|
||||
for k, v := range ids {
|
||||
idsInterface[k] = v
|
||||
}
|
||||
_, err := auth_rule.Model.Where(where, idsInterface...).Delete()
|
||||
if err != nil {
|
||||
g.Log().Error(err)
|
||||
response.FailJson(true, r, "删除失败")
|
||||
}
|
||||
response.SusJson(true, r, "删除成功")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user