Files
gfast/app/controller/admin/index.go
T
2020-02-21 17:37:08 +08:00

50 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package admin
import (
"gfast/app/service/admin/user_service"
"gfast/library/response"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/util/gconv"
"strings"
)
type Index struct{}
//后台首页接口数据
func (c *Index) Index(r *ghttp.Request) {
//获取用户信息
userInfo := user_service.GetCacheAdminInfo(r)
//菜单列表
var menuList g.List
if userInfo != nil {
userId := gconv.Int(userInfo["id"])
delete(userInfo, "user_password")
//获取用户角色信息
roles, err := user_service.GetAdminRole(userId)
if err == nil {
name := make([]string, len(roles))
roleIds := make([]int, len(roles))
for k, v := range roles {
name[k] = v.Name
roleIds[k] = v.Id
}
userInfo["roles"] = strings.Join(name, "")
//获取菜单信息
menuList, err = user_service.GetAdminMenusByRoleIds(roleIds)
if err != nil {
g.Log().Error(err)
}
} else {
g.Log().Error(err)
userInfo["roles"] = ""
}
}
result := g.Map{
"userInfo": userInfo,
"menuList": menuList,
}
response.SusJson(true, r, "ok", result)
}