|
@@ -4,10 +4,12 @@ import (
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"iot_manager_service/app/middleware"
|
|
|
"iot_manager_service/app/system/dao"
|
|
|
+ "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)
|
|
@@ -89,8 +91,47 @@ 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
|
|
|
+ var i int64
|
|
|
+ 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) {
|