From 879e80459267155e875258c69bf21b8272e710b5 Mon Sep 17 00:00:00 2001 From: yxh Date: Thu, 24 Mar 2022 18:31:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/common/captcha.go | 4 +- api/v1/demo/demo.go | 2 +- api/v1/system/sys_auth_rule.go | 32 +++++++--- api/v1/system/sys_dict_data.go | 9 +-- api/v1/system/sys_user.go | 8 +-- go.mod | 2 +- go.sum | 4 +- .../app/system/controller/sys_auth_rule.go | 12 ++++ .../app/system/model/entity/sys_auth_rule.go | 7 ++- internal/app/system/model/sys_auth_rule.go | 35 ++++++----- .../internal/dao/internal/sys_auth_rule.go | 14 +++-- .../service/internal/do/sys_auth_rule.go | 7 ++- internal/app/system/service/middleware.go | 2 +- internal/app/system/service/sys_auth_rule.go | 62 ++++++++++++++++--- internal/app/system/service/sys_role.go | 15 +++++ internal/app/system/service/sys_user.go | 20 +++--- manifest/config/config.yaml | 4 +- 17 files changed, 164 insertions(+), 75 deletions(-) diff --git a/api/v1/common/captcha.go b/api/v1/common/captcha.go index 6f49648..aca0c14 100644 --- a/api/v1/common/captcha.go +++ b/api/v1/common/captcha.go @@ -10,10 +10,10 @@ package common import "github.com/gogf/gf/v2/frame/g" type CaptchaReq struct { - g.Meta `path:"/get" tags:"get captcha" method:"get" summary:"获取验证码"` + g.Meta `path:"/get" tags:"验证码" method:"get" summary:"获取验证码"` } type CaptchaRes struct { - g.Meta `mime:"application/json" example:""` + g.Meta `mime:"application/json"` Key string `json:"key"` Img string `json:"img"` } diff --git a/api/v1/demo/demo.go b/api/v1/demo/demo.go index c39bedf..c5cf9ec 100644 --- a/api/v1/demo/demo.go +++ b/api/v1/demo/demo.go @@ -13,6 +13,6 @@ type DmReq struct { g.Meta `path:"/demo" tags:"Demo" method:"get" summary:"demo api"` } type DmRes struct { - g.Meta `mime:"text/html" example:"string"` + g.Meta `mime:"text/html"` Name string `json:"name"` } diff --git a/api/v1/system/sys_auth_rule.go b/api/v1/system/sys_auth_rule.go index 25f3b10..de1e6b5 100644 --- a/api/v1/system/sys_auth_rule.go +++ b/api/v1/system/sys_auth_rule.go @@ -7,29 +7,45 @@ package system -import "github.com/gogf/gf/v2/frame/g" +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/tiger1103/gfast/v3/internal/app/system/model" + "github.com/tiger1103/gfast/v3/internal/app/system/model/entity" +) type RuleAddReq struct { - g.Meta `path:"/menu/add" tags:"menu add" method:"post" summary:"添加菜单"` + g.Meta `path:"/menu/add" tags:"菜单管理" method:"post" summary:"添加菜单"` Authorization string `p:"Authorization" in:"header" dc:"Bearer {{token}}"` MenuType uint `p:"menuType" v:"min:0|max:2#菜单类型最小值为:min|菜单类型最大值为:max"` Pid uint `p:"parentId" v:"min:0"` Name string `p:"name" v:"required#请填写规则名称"` Title string `p:"menuName" v:"required|length:1,100#请填写标题|标题长度在:min到:max位"` Icon string `p:"icon"` - Weigh int `p:"orderNum" ` + Weigh int `p:"menuSort" ` Condition string `p:"condition" ` Remark string `p:"remark" ` - Status uint `p:"status" ` - AlwaysShow uint `p:"visible"` + IsHide uint `p:"isHide"` Path string `p:"path"` + Redirect string `p:"redirect"` // 路由重定向 + Roles []uint `p:"roles"` // 角色ids Component string `p:"component" v:"required-if:menuType,1#组件路径不能为空"` IsLink uint `p:"isLink"` IsIframe uint `p:"isIframe"` - IsCached uint `p:"isCached"` - ModuleType string `p:"moduleType"` - ModelId uint `p:"modelId"` + IsCached uint `p:"isKeepAlive"` + IsAffix uint `p:"isAffix"` + LinkUrl string `p:"linkUrl"` } type RuleAddRes struct { } + +type RuleGetParamsReq struct { + g.Meta `path:"/menu/getParams" tags:"菜单管理" method:"get" summary:"获取添加、编辑菜单相关参数"` + Authorization string `p:"Authorization" in:"header" dc:"Bearer {{token}}"` +} + +type RuleGetParamsRes struct { + g.Meta `mime:"application/json"` + Roles []*entity.SysRole `json:"roles"` + Menus []*model.SysAuthRuleInfoRes `json:"menus"` +} diff --git a/api/v1/system/sys_dict_data.go b/api/v1/system/sys_dict_data.go index c15faae..d9a4b74 100644 --- a/api/v1/system/sys_dict_data.go +++ b/api/v1/system/sys_dict_data.go @@ -14,14 +14,15 @@ import ( // GetDictReq 获取字典信息请求参数 type GetDictReq struct { - g.Meta `path:"/dict/data/getDictData" tags:"get dict data" method:"get" summary:"获取字典数据公共方法"` - DictType string `p:"dictType" v:"required#字典类型不能为空"` - DefaultValue string `p:"defaultValue"` + g.Meta `path:"/dict/data/getDictData" tags:"字典管理" method:"get" summary:"获取字典数据公共方法"` + Authorization string `p:"Authorization" in:"header" dc:"Bearer {{token}}"` + DictType string `p:"dictType" v:"required#字典类型不能为空"` + DefaultValue string `p:"defaultValue"` } // GetDictRes 完整的一个字典信息 type GetDictRes struct { - g.Meta `mime:"application/json" example:""` + g.Meta `mime:"application/json"` Info *commonModel.DictTypeRes `json:"info"` Values []*commonModel.DictDataRes `json:"values"` } diff --git a/api/v1/system/sys_user.go b/api/v1/system/sys_user.go index a545e73..3c02261 100644 --- a/api/v1/system/sys_user.go +++ b/api/v1/system/sys_user.go @@ -6,7 +6,7 @@ import ( ) type UserLoginReq struct { - g.Meta `path:"/login" tags:"login" method:"post" summary:"用户登录"` + g.Meta `path:"/login" tags:"登录" method:"post" summary:"用户登录"` Username string `p:"username" v:"required#用户名不能为空"` Password string `p:"password" v:"required#密码不能为空"` VerifyCode string `p:"verifyCode" v:"required#验证码不能为空"` @@ -14,7 +14,7 @@ type UserLoginReq struct { } type UserLoginRes struct { - g.Meta `mime:"application/json" example:""` + g.Meta `mime:"application/json"` UserInfo *model.LoginUserRes `json:"userInfo"` Token string `json:"token"` MenuList []*model.UserMenus `json:"menuList"` @@ -22,12 +22,12 @@ type UserLoginRes struct { } type UserMenusReq struct { - g.Meta `path:"/getUserMenus" tags:"getUserMenus" method:"get" summary:"获取用户菜单"` + g.Meta `path:"/user/getUserMenus" tags:"登录" method:"get" summary:"获取用户菜单"` Authorization string `p:"Authorization" in:"header" dc:"Bearer {{token}}"` } type UserMenusRes struct { - g.Meta `mime:"application/json" example:""` + g.Meta `mime:"application/json"` MenuList []*model.UserMenus `json:"menuList"` Permissions []string `json:"permissions"` } diff --git a/go.mod b/go.mod index 6f084b8..9324263 100644 --- a/go.mod +++ b/go.mod @@ -8,5 +8,5 @@ require ( github.com/mojocn/base64Captcha v1.3.5 github.com/mssola/user_agent v0.5.3 github.com/tiger1103/gfast-cache v0.0.6 - github.com/tiger1103/gfast-token v0.0.8 + github.com/tiger1103/gfast-token v0.0.9 ) diff --git a/go.sum b/go.sum index a266b5b..5469896 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tiger1103/gfast-cache v0.0.6 h1:H40Txv6co5bjaRlFQ/ixcMfpgsihhPpNftvCHm7hLpI= github.com/tiger1103/gfast-cache v0.0.6/go.mod h1:s6cRWyr87wz6IJNGKRV6Ahq9hcuVz8h2PAtGrO66JO8= -github.com/tiger1103/gfast-token v0.0.8 h1:1iEwwL3zOri0ETR8Ee4ubW/Sq29Cln/ydxHwVhUGfRk= -github.com/tiger1103/gfast-token v0.0.8/go.mod h1:RnVRqmWD3h4qfTU1vJNXNhQjh2L5ht1vxLnjwShwGuY= +github.com/tiger1103/gfast-token v0.0.9 h1:+cKNu4zAMZpqaeILy3QIjuEO0HQMXtMSqVGPmhKAP90= +github.com/tiger1103/gfast-token v0.0.9/go.mod h1:RnVRqmWD3h4qfTU1vJNXNhQjh2L5ht1vxLnjwShwGuY= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= diff --git a/internal/app/system/controller/sys_auth_rule.go b/internal/app/system/controller/sys_auth_rule.go index e36eb4e..c70c3f5 100644 --- a/internal/app/system/controller/sys_auth_rule.go +++ b/internal/app/system/controller/sys_auth_rule.go @@ -22,3 +22,15 @@ func (c *menuController) Add(ctx context.Context, req *system.RuleAddReq) (res * err = service.Rule().Add(ctx, req) return } + +// GetAddParams 获取菜单添加及编辑相关参数 +func (c *menuController) GetAddParams(ctx context.Context, req *system.RuleGetParamsReq) (res *system.RuleGetParamsRes, err error) { + // 获取角色列表 + res = new(system.RuleGetParamsRes) + res.Roles, err = service.Role().GetRoleList(ctx) + if err != nil { + return + } + res.Menus, err = service.Rule().GetIsMenuList(ctx) + return +} diff --git a/internal/app/system/model/entity/sys_auth_rule.go b/internal/app/system/model/entity/sys_auth_rule.go index e9a0e56..b4d8197 100644 --- a/internal/app/system/model/entity/sys_auth_rule.go +++ b/internal/app/system/model/entity/sys_auth_rule.go @@ -19,16 +19,17 @@ type SysAuthRule struct { Remark string `json:"remark" description:"备注"` MenuType uint `json:"menuType" description:"类型 0目录 1菜单 2按钮"` Weigh int `json:"weigh" description:"权重"` - Status uint `json:"status" description:"状态"` - AlwaysShow uint `json:"alwaysShow" description:"显示状态"` + IsHide uint `json:"isHide" description:"显示状态"` Path string `json:"path" description:"路由地址"` - JumpPath string `json:"jumpPath" description:"跳转路由"` Component string `json:"component" description:"组件路径"` IsLink uint `json:"isLink" description:"是否外链 1是 0否"` ModuleType string `json:"moduleType" description:"所属模块"` ModelId uint `json:"modelId" description:"模型ID"` IsIframe uint `json:"isIframe" description:"是否内嵌iframe"` IsCached uint `json:"isCached" description:"是否缓存"` + Redirect string `json:"redirect" description:"路由重定向地址"` + IsAffix uint `json:"isAffix" description:"是否固定"` + LinkUrl string `json:"linkUrl" description:"链接地址"` CreatedAt *gtime.Time `json:"createdAt" description:"创建日期"` UpdatedAt *gtime.Time `json:"updatedAt" description:"修改日期"` } diff --git a/internal/app/system/model/sys_auth_rule.go b/internal/app/system/model/sys_auth_rule.go index 0f52754..ebfda65 100644 --- a/internal/app/system/model/sys_auth_rule.go +++ b/internal/app/system/model/sys_auth_rule.go @@ -8,23 +8,24 @@ package model type SysAuthRuleInfoRes struct { - Id uint `orm:"id,primary" json:"id"` // - Pid uint `orm:"pid" json:"pid"` // 父ID - Name string `orm:"name,unique" json:"name"` // 规则名称 - Title string `orm:"title" json:"title"` // 规则名称 - Icon string `orm:"icon" json:"icon"` // 图标 - Condition string `orm:"condition" json:"condition"` // 条件 - Remark string `orm:"remark" json:"remark"` // 备注 - MenuType uint `orm:"menu_type" json:"menuType"` // 类型 0目录 1菜单 2按钮 - Weigh int `orm:"weigh" json:"weigh"` // 权重 - Status uint `orm:"status" json:"status"` // 状态 - AlwaysShow uint `orm:"always_show" json:"alwaysShow"` // 显示状态 - Path string `orm:"path" json:"path"` // 路由地址 - JumpPath string `orm:"jump_path" json:"jumpPath"` // 跳转路由 - Component string `orm:"component" json:"component"` // 组件路径 - IsFrame uint `orm:"is_frame" json:"isFrame"` // 是否外链 1是 0否 - ModuleType string `orm:"module_type" json:"moduleType"` // 所属模块 - ModelId uint `orm:"model_id" json:"modelId"` // 模型ID + Id uint `orm:"id,primary" json:"id"` // + Pid uint `orm:"pid" json:"pid"` // 父ID + Name string `orm:"name,unique" json:"name"` // 规则名称 + Title string `orm:"title" json:"title"` // 规则名称 + Icon string `orm:"icon" json:"icon"` // 图标 + Condition string `orm:"condition" json:"condition"` // 条件 + Remark string `orm:"remark" json:"remark"` // 备注 + MenuType uint `orm:"menu_type" json:"menuType"` // 类型 0目录 1菜单 2按钮 + Weigh int `orm:"weigh" json:"weigh"` // 权重 + IsHide uint `orm:"is_hide" json:"isHide"` // 显示状态 + IsCached uint `orm:"is_hide" json:"isCached"` // 是否缓存 + IsAffix uint `orm:"is_affix" json:"isAffix"` //是否固定 + Path string `orm:"path" json:"path"` // 路由地址 + Redirect string `orm:"redirect" json:"redirect"` // 跳转路由 + Component string `orm:"component" json:"component"` // 组件路径 + IsIframe uint `orm:"is_iframe" json:"isIframe"` // 是否iframe + IsLink uint `orm:"is_link" json:"isLink"` // 是否外链 1是 0否 + LinkUrl string `orm:"link_url" json:"linkUrl"` //链接地址 } type UserMenu struct { diff --git a/internal/app/system/service/internal/dao/internal/sys_auth_rule.go b/internal/app/system/service/internal/dao/internal/sys_auth_rule.go index 4923c6b..1d85b46 100644 --- a/internal/app/system/service/internal/dao/internal/sys_auth_rule.go +++ b/internal/app/system/service/internal/dao/internal/sys_auth_rule.go @@ -28,16 +28,17 @@ type SysAuthRuleColumns struct { Remark string // 备注 MenuType string // 类型 0目录 1菜单 2按钮 Weigh string // 权重 - Status string // 状态 - AlwaysShow string // 显示状态 + IsHide string // 显示状态 Path string // 路由地址 - JumpPath string // 跳转路由 Component string // 组件路径 IsLink string // 是否外链 1是 0否 ModuleType string // 所属模块 ModelId string // 模型ID IsIframe string // 是否内嵌iframe IsCached string // 是否缓存 + Redirect string // 路由重定向地址 + IsAffix string // 是否固定 + LinkUrl string // 链接地址 CreatedAt string // 创建日期 UpdatedAt string // 修改日期 } @@ -53,16 +54,17 @@ var sysAuthRuleColumns = SysAuthRuleColumns{ Remark: "remark", MenuType: "menu_type", Weigh: "weigh", - Status: "status", - AlwaysShow: "always_show", + IsHide: "is_hide", Path: "path", - JumpPath: "jump_path", Component: "component", IsLink: "is_link", ModuleType: "module_type", ModelId: "model_id", IsIframe: "is_iframe", IsCached: "is_cached", + Redirect: "redirect", + IsAffix: "is_affix", + LinkUrl: "link_url", CreatedAt: "created_at", UpdatedAt: "updated_at", } diff --git a/internal/app/system/service/internal/do/sys_auth_rule.go b/internal/app/system/service/internal/do/sys_auth_rule.go index b509bfd..3efd7af 100644 --- a/internal/app/system/service/internal/do/sys_auth_rule.go +++ b/internal/app/system/service/internal/do/sys_auth_rule.go @@ -21,16 +21,17 @@ type SysAuthRule struct { Remark interface{} // 备注 MenuType interface{} // 类型 0目录 1菜单 2按钮 Weigh interface{} // 权重 - Status interface{} // 状态 - AlwaysShow interface{} // 显示状态 + IsHide interface{} // 显示状态 Path interface{} // 路由地址 - JumpPath interface{} // 跳转路由 Component interface{} // 组件路径 IsLink interface{} // 是否外链 1是 0否 ModuleType interface{} // 所属模块 ModelId interface{} // 模型ID IsIframe interface{} // 是否内嵌iframe IsCached interface{} // 是否缓存 + Redirect interface{} // 路由重定向地址 + IsAffix interface{} // 是否固定 + LinkUrl interface{} // 链接地址 CreatedAt *gtime.Time // 创建日期 UpdatedAt *gtime.Time // 修改日期 } diff --git a/internal/app/system/service/middleware.go b/internal/app/system/service/middleware.go index f87cf50..9d7016c 100644 --- a/internal/app/system/service/middleware.go +++ b/internal/app/system/service/middleware.go @@ -82,7 +82,7 @@ func (s *middlewareImpl) Auth(r *ghttp.Request) { } url := gstr.TrimLeft(r.Request.URL.Path, "/") + accessParamsStr //获取地址对应的菜单id - menuList, err := Rule().GetIsMenuStatusList(ctx) + menuList, err := Rule().GetIsMenuList(ctx) if err != nil { g.Log().Error(ctx, err) libResponse.FailJson(true, r, "请求数据失败") diff --git a/internal/app/system/service/sys_auth_rule.go b/internal/app/system/service/sys_auth_rule.go index ebe6772..c5790ea 100644 --- a/internal/app/system/service/sys_auth_rule.go +++ b/internal/app/system/service/sys_auth_rule.go @@ -9,20 +9,24 @@ package service import ( "context" + "fmt" + "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/util/gconv" "github.com/tiger1103/gfast/v3/api/v1/system" "github.com/tiger1103/gfast/v3/internal/app/common/service" + commonService "github.com/tiger1103/gfast/v3/internal/app/common/service" "github.com/tiger1103/gfast/v3/internal/app/system/consts" "github.com/tiger1103/gfast/v3/internal/app/system/model" "github.com/tiger1103/gfast/v3/internal/app/system/service/internal/dao" + "github.com/tiger1103/gfast/v3/internal/app/system/service/internal/do" "github.com/tiger1103/gfast/v3/library/liberr" ) type IRule interface { - GetIsMenuStatusList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) + GetIsMenuList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) GetMenuList(ctx context.Context) (list []*model.SysAuthRuleInfoRes, err error) - GetIsButtonStatusList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) + GetIsButtonList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) Add(ctx context.Context, req *system.RuleAddReq) (err error) } @@ -35,15 +39,15 @@ func Rule() IRule { return IRule(&rule) } -// GetIsMenuStatusList 获取isMenu=0|1且status=1的菜单列表 -func (s *ruleImpl) GetIsMenuStatusList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) { +// GetIsMenuList 获取isMenu=0|1 +func (s *ruleImpl) GetIsMenuList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) { list, err := s.GetMenuList(ctx) if err != nil { return nil, err } var gList = make([]*model.SysAuthRuleInfoRes, 0, len(list)) for _, v := range list { - if (v.MenuType == 0 || v.MenuType == 1) && v.Status == 1 { + if v.MenuType == 0 || v.MenuType == 1 { gList = append(gList, v) } } @@ -74,15 +78,15 @@ func (s *ruleImpl) getMenuListFromDb(ctx context.Context) (value interface{}, er return } -// GetIsButtonStatusList 获取所有按钮isMenu=2 且status=1的菜单列表 -func (s *ruleImpl) GetIsButtonStatusList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) { +// GetIsButtonList 获取所有按钮isMenu=2 菜单列表 +func (s *ruleImpl) GetIsButtonList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) { list, err := s.GetMenuList(ctx) if err != nil { return nil, err } var gList = make([]*model.SysAuthRuleInfoRes, 0, len(list)) for _, v := range list { - if v.MenuType == 2 && v.Status == 1 { + if v.MenuType == 2 { gList = append(gList, v) } } @@ -91,9 +95,47 @@ func (s *ruleImpl) GetIsButtonStatusList(ctx context.Context) ([]*model.SysAuthR // Add 添加菜单 func (s *ruleImpl) Add(ctx context.Context, req *system.RuleAddReq) (err error) { + err = g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { + err = g.Try(func() { + //菜单数据 + data := do.SysAuthRule{ + Pid: req.Pid, + Name: req.Name, + Title: req.Title, + Icon: req.Icon, + Condition: req.Condition, + Remark: req.Remark, + MenuType: req.MenuType, + Weigh: req.Weigh, + IsHide: req.IsHide, + Path: req.Path, + Component: req.Component, + IsLink: req.IsLink, + IsIframe: req.IsIframe, + IsCached: req.IsCached, + Redirect: req.Redirect, + IsAffix: req.IsAffix, + LinkUrl: req.LinkUrl, + } + ruleId, e := dao.SysAuthRule.Ctx(ctx).TX(tx).InsertAndGetId(data) + liberr.ErrIsNil(ctx, e, "添加菜单失败") + e = s.BindRoleRule(ctx, ruleId, req.Roles) + liberr.ErrIsNil(ctx, e, "添加菜单失败") + }) + return err + }) + return +} + +// BindRoleRule 绑定角色权限 +func (s *ruleImpl) BindRoleRule(ctx context.Context, ruleId interface{}, roleIds []uint) (err error) { err = g.Try(func() { - _, err = dao.SysAuthRule.Ctx(ctx).Insert(req) - liberr.ErrIsNil(ctx, err, "添加菜单失败") + enforcer, e := commonService.CasbinEnforcer(ctx) + liberr.ErrIsNil(ctx, e) + for _, roleId := range roleIds { + _, err = enforcer.AddPolicy(fmt.Sprintf("%d", roleId), fmt.Sprintf("%d", ruleId), "All") + liberr.ErrIsNil(ctx, err) + } }) return } diff --git a/internal/app/system/service/sys_role.go b/internal/app/system/service/sys_role.go index f003c3d..e13d75f 100644 --- a/internal/app/system/service/sys_role.go +++ b/internal/app/system/service/sys_role.go @@ -9,6 +9,7 @@ package service import ( "context" + "fmt" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/util/gconv" commonService "github.com/tiger1103/gfast/v3/internal/app/common/service" @@ -55,3 +56,17 @@ func (s *roleImpl) getRoleListFromDb(ctx context.Context) (value interface{}, er }) return } + +// AddRoleRule 添加角色权限 +func (s *roleImpl) AddRoleRule(ctx context.Context, iRule interface{}, roleId int64) (err error) { + err = g.Try(func() { + enforcer, e := commonService.CasbinEnforcer(ctx) + liberr.ErrIsNil(ctx, e) + rule := gconv.Strings(iRule) + for _, v := range rule { + _, err = enforcer.AddPolicy(fmt.Sprintf("%d", roleId), fmt.Sprintf("%s", v), "All") + liberr.ErrIsNil(ctx, err) + } + }) + return +} diff --git a/internal/app/system/service/sys_user.go b/internal/app/system/service/sys_user.go index f3a3b0b..990225a 100644 --- a/internal/app/system/service/sys_user.go +++ b/internal/app/system/service/sys_user.go @@ -196,7 +196,7 @@ func (s *userImpl) GetAdminRoleIds(ctx context.Context, userId uint64) (roleIds func (s *userImpl) GetAllMenus(ctx context.Context) (menus []*model.UserMenus, err error) { //获取所有开启的菜单 var allMenus []*model.SysAuthRuleInfoRes - allMenus, err = Rule().GetIsMenuStatusList(ctx) + allMenus, err = Rule().GetIsMenuList(ctx) if err != nil { return } @@ -225,7 +225,7 @@ func (s *userImpl) GetAdminMenusByRoleIds(ctx context.Context, roleIds []uint) ( } } //获取所有开启的菜单 - allMenus, err := Rule().GetIsMenuStatusList(ctx) + allMenus, err := Rule().GetIsMenuList(ctx) liberr.ErrIsNil(ctx, err) menus = make([]*model.UserMenus, 0, len(allMenus)) for _, v := range allMenus { @@ -260,10 +260,10 @@ func (s *userImpl) setMenuData(menu *model.UserMenu, entity *model.SysAuthRuleIn Icon: entity.Icon, Title: entity.Title, IsLink: "", - IsHide: false, - IsKeepAlive: false, - IsAffix: false, - IsIframe: false, + IsHide: entity.IsHide == 1, + IsKeepAlive: entity.IsCached == 1, + IsAffix: entity.IsAffix == 1, + IsIframe: entity.IsIframe == 1, }, } if entity.MenuType != 0 { @@ -273,10 +273,8 @@ func (s *userImpl) setMenuData(menu *model.UserMenu, entity *model.SysAuthRuleIn menu.Component = "layout/routerView/parent" menu.Path = "/" + entity.Path } - if entity.AlwaysShow == 1 { - menu.MenuMeta.IsHide = false - } else { - menu.MenuMeta.IsHide = true + if menu.MenuMeta.IsIframe || entity.IsLink == 1 { + menu.MenuMeta.IsLink = entity.LinkUrl } return menu } @@ -296,7 +294,7 @@ func (s *userImpl) GetPermissions(ctx context.Context, roleIds []uint) (userButt } } //获取所有开启的按钮 - allButtons, err := Rule().GetIsButtonStatusList(ctx) + allButtons, err := Rule().GetIsButtonList(ctx) liberr.ErrIsNil(ctx, err) userButtons = make([]string, 0, len(allButtons)) for _, button := range allButtons { diff --git a/manifest/config/config.yaml b/manifest/config/config.yaml index c56ff64..4519b11 100644 --- a/manifest/config/config.yaml +++ b/manifest/config/config.yaml @@ -76,10 +76,10 @@ gfcli: gen: dao: - link: "mysql:root:123456@tcp(127.0.0.1:3306)/gfast-v3" - tables: "sys_dict_type,sys_dict_data,sys_config" + tables: "sys_auth_rule" removePrefix: "gf_" descriptionTag: true noModelComment: true - path: "./internal/app/common" + path: "./internal/app/system"