123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "iot_manager_service/app/middleware"
- "iot_manager_service/app/system/model"
- "iot_manager_service/app/system/service"
- "iot_manager_service/util/common"
- "net/http"
- "strconv"
- "strings"
- )
- var Menu = new(menu)
- type menu struct{}
- func (c *menu) GetDetail(ctx *gin.Context) {
- id := ctx.Query("id")
- iId, err := strconv.Atoi(id)
- if err != nil {
- ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- detail, err := service.MenuService.Get(iId)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, detail))
- }
- func (c *menu) List(ctx *gin.Context) {
- }
- func (c *menu) LazyList(ctx *gin.Context) {
- id := ctx.Query("parentId")
- name := ctx.Query("name")
- code := ctx.Query("code")
- alias := ctx.Query("alias")
- parentId := -1
- if id != "" {
- parentId, _ = strconv.Atoi(id)
- }
- menus, err := service.MenuService.LazyList(parentId, name, code, alias)
- if err != nil {
- ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, menus))
- }
- func (c *menu) MenuList(ctx *gin.Context) {
- }
- func (c *menu) LazyMenuList(ctx *gin.Context) {
- }
- func (c *menu) Submit(ctx *gin.Context) {
- var req model.MenuSubmit
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.MenuService.Submit(req)
- ctx.JSON(http.StatusOK, err)
- }
- func (c *menu) Remove(ctx *gin.Context) {
- }
- func (c *menu) Routes(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- menus, err := service.MenuService.Routes(claims.RoleId)
- if err != nil {
- ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, menus))
- }
- func (c *menu) RoutesExt(cxt *gin.Context) {
- }
- // 由于子菜单 没有分的很详细,这里直接先让他们全部有这个权限 2022-12-07 dsx
- func (c *menu) Buttons(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- menus, err := service.MenuService.Routes(claims.RoleId)
- if err != nil {
- ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
- return
- }
- var menus2 []model.MenuRouteDetail
- subMenus := make(map[string]string)
- subMenus["add"] = "新增"
- subMenus["edit"] = "修改"
- subMenus["view"] = "查看"
- subMenus["delete"] = "删除"
- for _, menu := range menus {
- if menu.Children != nil {
- for _, child := range menu.Children {
- var menus3 []model.MenuRouteDetail
- i := 1
- for k, v := range subMenus {
- var menu4 model.MenuRouteDetail
- menu4.ID = child.ID + i
- menu4.ParentId = child.ID
- child.Path = strings.ReplaceAll(child.Path, "-", "")
- subPaths := strings.Split(child.Path, "/")
- subPath := subPaths[len(subPaths)-1]
- menu4.Code = subPath + "_" + k
- menu4.Name = v
- menu4.Path = child.Path + "/" + k
- menu4.Source = k
- menus3 = append(menus3, menu4)
- i++
- }
- child.Children = menus3
- menus2 = append(menus2, child)
- }
- }
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, menus2))
- }
- func (c *menu) Tree(ctx *gin.Context) {
- menus, err := service.MenuService.Tree()
- if err != nil {
- ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, menus))
- }
- func (c *menu) GrantTree(ctx *gin.Context) {
- //菜单权限
- tree, err := service.MenuService.GetTree()
- if err != nil {
- ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
- return
- }
- rsp := model.ResGrantTree{
- Menu: tree,
- DataScope: nil,
- ApiScope: nil,
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
- //数据权限
- //接口权限
- }
- func (c *menu) RoleTreeKeys(ctx *gin.Context) {
- roleIds, _ := strconv.Atoi(ctx.Query("roleIds"))
- menuIds := service.RoleMenuService.GetMenuIdByRoleId(roleIds)
- rsp := model.ResMenuIds{
- Menu: menuIds,
- DataScope: nil,
- ApiScope: nil,
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
- }
- func (c *menu) GrantTopTree(ctx *gin.Context) {
- }
- func (c *menu) TopTreeKeys(ctx *gin.Context) {
- }
- func (c *menu) TopMenu(ctx *gin.Context) {
- }
- func (c *menu) authRoutes(ctx *gin.Context) {
- }
|