13 changed files with 522 additions and 7 deletions
@ -1,9 +1,13 @@ |
|||||
package version1 |
package version1 |
||||
|
|
||||
import "appPlatform/api/version1/user" |
import ( |
||||
|
"appPlatform/api/version1/menus" |
||||
|
"appPlatform/api/version1/user" |
||||
|
) |
||||
|
|
||||
type ApiEntry struct { |
type ApiEntry struct { |
||||
UserApi user.ApiMethod //人员信息
|
UserApi user.ApiMethod //人员信息
|
||||
|
MenusApi menus.ApiMethod //菜单路由
|
||||
} |
} |
||||
|
|
||||
var AppApiEntry = new(ApiEntry) |
var AppApiEntry = new(ApiEntry) |
||||
|
|||||
@ -0,0 +1,99 @@ |
|||||
|
package menus |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/models/modelAppPlatform" |
||||
|
"appPlatform/overall" |
||||
|
"appPlatform/overall/publicmethod" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-05-22 13:26:16 |
||||
|
@ 功能: 获取路由树 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) GetMenusThree(c *gin.Context) { |
||||
|
var menusList []modelAppPlatform.Menus |
||||
|
err := overall.CONSTANT_DB_AppPlatform.Where("visible IN ?", []int{1, 2}).Find(&menusList).Error |
||||
|
if err != nil && len(menusList) < 1 { |
||||
|
publicmethod.Result(1, err, c, "没有路由!") |
||||
|
return |
||||
|
} |
||||
|
routerThree := publicmethod.GetMenuRouterThree(0, menusList) |
||||
|
publicmethod.Result(0, routerThree, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-05-22 15:36:33 |
||||
|
@ 功能: 获取菜单列表树 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) GetMenusListTree(c *gin.Context) { |
||||
|
var requestData ShearMenu |
||||
|
c.ShouldBindJSON(&requestData) |
||||
|
var menusList []modelAppPlatform.Menus |
||||
|
gormDb := overall.CONSTANT_DB_AppPlatform.Where("visible IN ?", []int{1, 2}) |
||||
|
if requestData.Title != "" { |
||||
|
gormDb = gormDb.Where("`name` LIKE ?", "%"+requestData.Title+"%") |
||||
|
} |
||||
|
err := gormDb.Find(&menusList).Error |
||||
|
if err != nil && len(menusList) < 1 { |
||||
|
publicmethod.Result(1, err, c, "没有路由!") |
||||
|
return |
||||
|
} |
||||
|
routerThree := publicmethod.GetAppMenuThree(0, menusList) |
||||
|
publicmethod.Result(0, routerThree, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-05-22 16:21:11 |
||||
|
@ 功能: 菜单下拉列表 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) MenuOptions(c *gin.Context) { |
||||
|
var menusList []modelAppPlatform.Menus |
||||
|
err := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Menus{}).Select("`id`,`name`,`parentId`").Where("visible IN ?", []int{1, 2}).Find(&menusList).Error |
||||
|
if err != nil && len(menusList) < 1 { |
||||
|
publicmethod.Result(1, err, c, "没有路由!") |
||||
|
return |
||||
|
} |
||||
|
routerThree := publicmethod.GetMenuOptionsThree(0, menusList) |
||||
|
publicmethod.Result(0, routerThree, c) |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
package menus |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/overall/publicmethod" |
||||
|
"sync" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
type ApiMethod struct{} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-05-22 13:17:38 |
||||
|
@ 功能: 菜单路由入口 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) Index(c *gin.Context) { |
||||
|
outputCont := publicmethod.MapOut[string]() |
||||
|
outputCont["index"] = "菜单路由入口" |
||||
|
publicmethod.Result(0, outputCont, c) |
||||
|
} |
||||
|
|
||||
|
// 协程设置
|
||||
|
var syncSeting = sync.WaitGroup{} |
||||
|
|
||||
|
// 菜单搜索关键字
|
||||
|
type ShearMenu struct { |
||||
|
Title string `json:"title"` |
||||
|
} |
||||
@ -0,0 +1,131 @@ |
|||||
|
package user |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/models/modelshr" |
||||
|
"appPlatform/models/modelssystempermission" |
||||
|
"appPlatform/overall" |
||||
|
"appPlatform/overall/publicmethod" |
||||
|
"encoding/json" |
||||
|
"fmt" |
||||
|
"strconv" |
||||
|
"strings" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-05-22 10:54:15 |
||||
|
@ 功能: 获取当前登录用户信息 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) GetUserCont(c *gin.Context) { |
||||
|
context, _ := c.Get(overall.MyContJwt) |
||||
|
var myContInfo modelshr.ManCont |
||||
|
jsonCont, _ := json.Marshal(context) |
||||
|
jsonUnErr := json.Unmarshal(jsonCont, &myContInfo) |
||||
|
outMap := publicmethod.MapOut[string]() |
||||
|
outMap["context"] = context |
||||
|
outMap["exi"] = jsonUnErr |
||||
|
outMap["myContInfo"] = myContInfo |
||||
|
var sendData SendUserCont |
||||
|
sendData.UserId = strconv.FormatInt(myContInfo.Key, 10) |
||||
|
sendData.Number = myContInfo.Number |
||||
|
sendData.NickName = myContInfo.Name |
||||
|
sendData.Company = strconv.FormatInt(myContInfo.Company, 10) //公司
|
||||
|
var companyCont modelshr.AdministrativeOrganization |
||||
|
companyCont.GetCont(map[string]interface{}{"`id`": myContInfo.Company}, "`name`") |
||||
|
sendData.CompanyName = companyCont.Name //公司名称
|
||||
|
sendData.Department = strconv.FormatInt(myContInfo.MainDeparment, 10) //主部门
|
||||
|
var departCont modelshr.AdministrativeOrganization |
||||
|
departCont.GetCont(map[string]interface{}{"`id`": myContInfo.MainDeparment}, "`name`") |
||||
|
sendData.DepartmentName = departCont.Name //主部门名称
|
||||
|
sendData.Organization = strconv.FormatInt(myContInfo.AdminOrg, 10) //行政组织
|
||||
|
var orgCont modelshr.AdministrativeOrganization |
||||
|
orgCont.GetCont(map[string]interface{}{"`id`": myContInfo.MainDeparment}, "`name`") |
||||
|
sendData.OrganizationName = orgCont.Name //行政组织名称
|
||||
|
sendData.Avatar = myContInfo.Icon |
||||
|
roleList := strings.Split(myContInfo.Role, ",") |
||||
|
roleList = append(roleList, "ROOT") |
||||
|
sendData.Roles = roleList |
||||
|
//获取权限
|
||||
|
menuPoint, opeart, orgList := GetUserPower("app", myContInfo.Position, roleList) |
||||
|
fmt.Printf("menuPoint======>%v\nopeart======>%v\norgList======>%v\n", menuPoint, opeart, orgList) |
||||
|
sendData.Perms = menuPoint |
||||
|
publicmethod.Result(0, sendData, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-05-22 11:30:44 |
||||
|
@ 功能: 获取用户权限 |
||||
|
@ 参数 |
||||
|
|
||||
|
#appType 系统标识 |
||||
|
#postId 职务 |
||||
|
#roleList 角色列表 |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
#menuPoint 菜单操作列表 |
||||
|
#opeart 点位 |
||||
|
#orgList 行政组织 |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
#func GetUserPower(appType string, postId int64, roleList []string) (menuPoint []string, opeart []string, orgList []string) |
||||
|
*/ |
||||
|
func GetUserPower(appType string, postId int64, roleList []string) (menuPoint, opeart, orgList []string) { |
||||
|
//获取职务权限
|
||||
|
var emPower modelssystempermission.Empower |
||||
|
err := emPower.GetCont(map[string]interface{}{"`post_id`": postId, "`system`": appType}) |
||||
|
if err == nil { |
||||
|
if emPower.PointId != "" { |
||||
|
pointIdList := strings.Split(emPower.PointId, ",") |
||||
|
menuPoint = publicmethod.MergeStruct[string](pointIdList, menuPoint) |
||||
|
} |
||||
|
if emPower.Operation != "" { |
||||
|
operationIdList := strings.Split(emPower.Operation, ",") |
||||
|
opeart = publicmethod.MergeStruct[string](operationIdList, opeart) |
||||
|
} |
||||
|
if emPower.Organization != "" { |
||||
|
orgIdList := strings.Split(emPower.Organization, ",") |
||||
|
orgList = publicmethod.MergeStruct[string](orgIdList, orgList) |
||||
|
} |
||||
|
} |
||||
|
//获取角色权限
|
||||
|
if len(roleList) > 0 { |
||||
|
for _, v := range roleList { |
||||
|
var roleEmpower modelssystempermission.RoleEmpower |
||||
|
err = roleEmpower.GetCont(map[string]interface{}{"`role_id`": v, "`system`": appType}) |
||||
|
if err == nil { |
||||
|
if roleEmpower.PointId != "" { |
||||
|
pointIdList := strings.Split(roleEmpower.PointId, ",") |
||||
|
menuPoint = publicmethod.MergeStruct[string](pointIdList, menuPoint) |
||||
|
} |
||||
|
if roleEmpower.Operation != "" { |
||||
|
operationIdList := strings.Split(roleEmpower.Operation, ",") |
||||
|
opeart = publicmethod.MergeStruct[string](operationIdList, opeart) |
||||
|
} |
||||
|
if roleEmpower.Organization != "" { |
||||
|
orgIdList := strings.Split(roleEmpower.Organization, ",") |
||||
|
orgList = publicmethod.MergeStruct[string](orgIdList, orgList) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
package menusrouters |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/api/version1" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
// 权限管理PC端
|
||||
|
func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { |
||||
|
apiRouter := router.Group("menus") |
||||
|
|
||||
|
var methodBinding = version1.AppApiEntry.MenusApi |
||||
|
{ |
||||
|
apiRouter.GET("", methodBinding.Index) //入口
|
||||
|
apiRouter.POST("", methodBinding.Index) //入口
|
||||
|
apiRouter.GET("get_routers_three", methodBinding.GetMenusThree) //获取路由树
|
||||
|
apiRouter.GET("get_menus_three", methodBinding.GetMenusListTree) //获取菜单树
|
||||
|
apiRouter.GET("menu_options", methodBinding.MenuOptions) //菜单下拉列表
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,4 @@ |
|||||
|
package menusrouters |
||||
|
|
||||
|
//菜单路由
|
||||
|
type ApiRouter struct{} |
||||
@ -0,0 +1,67 @@ |
|||||
|
package modelAppPlatform |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
// 行政组织类型
|
||||
|
type Menus struct { |
||||
|
Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` |
||||
|
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:菜单名称"` |
||||
|
Types int `json:"type" gorm:"column:type;type:int(1) unsigned;default:1;not null;comment:菜单类型(1-菜单;2-目录;3-外链;4-按钮权限"` |
||||
|
Path string `json:"path" gorm:"column:path;type:varchar(255) ;default:'';comment:路由路径"` |
||||
|
Component string `json:"component" gorm:"column:component;type:varchar(255) ;default:'';comment:组件路径(vue页面完整路径,省略.vue后缀)"` |
||||
|
Perm int64 `json:"perm" gorm:"column:perm;type:bigint(20) unsigned;default:0;not null;comment:权限标识"` |
||||
|
Visible int `json:"visible" gorm:"column:visible;type:int(1) unsigned;default:1;not null;comment:显示状态(1:显示;2:隐藏,3:删除)"` |
||||
|
Sort int `json:"sort" gorm:"column:sort;type:int(1) unsigned;default:50;not null;comment:排序(数字越小排名越靠前))"` |
||||
|
Icon string `json:"icon" gorm:"column:icon;type:varchar(255) ;default:'';comment:菜单图标"` |
||||
|
Redirect string `json:"redirect" gorm:"column:redirect;type:varchar(255) ;default:'';comment:跳转路径"` |
||||
|
ParentId int `json:"parentId" gorm:"column:parentId;type:int(5) unsigned;default:0;not null;comment:父菜单ID"` |
||||
|
Time int `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
||||
|
} |
||||
|
|
||||
|
func (menus *Menus) TableName() string { |
||||
|
return "menus" |
||||
|
} |
||||
|
|
||||
|
// 编辑内容
|
||||
|
func (cont *Menus) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 获取内容
|
||||
|
func (cont *Menus) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
gormDb = gormDb.Where(whereMap) |
||||
|
err = gormDb.First(&cont).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 根据条件获取总数
|
||||
|
func (cont *Menus) CountCont(whereMap interface{}) (countId int64) { |
||||
|
overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 读取全部信息
|
||||
|
func (cont *Menus) ContMap(whereMap interface{}, field ...string) (countAry []Menus, err error) { |
||||
|
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
err = gormDb.Where(whereMap).Find(&countAry).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 删除内容
|
||||
|
func (cont *Menus) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
Loading…
Reference in new issue