diff --git a/README.md b/README.md index 65f26e4..d19ab1e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ## 🏭在线体验 -演示地址:http://103.145.39.46:8080/ 帐号:admin 密码:123456 +演示地址:http://47.104.252.2:8080/ 帐号:admin 密码:123456 --- 系统在线文档 diff --git a/apps/system/api/menu.go b/apps/system/api/menu.go index 090b135..46af28e 100644 --- a/apps/system/api/menu.go +++ b/apps/system/api/menu.go @@ -36,7 +36,9 @@ func (m *MenuApi) GetMenuTreeSelect(rc *ctx.ReqCtx) { // @Router /system/menu/menuRole [get] // @Security X-TOKEN func (m *MenuApi) GetMenuRole(rc *ctx.ReqCtx) { - rc.ResData = Build(*m.MenuApp.SelectMenuRole(rc.LoginAccount.RoleKey)) + roleKey := rc.GinCtx.Query("roleKey") + biz.IsTrue(roleKey != "", "请传入角色Key") + rc.ResData = Build(*m.MenuApp.SelectMenuRole(roleKey)) } // @Summary 获取角色的菜单树 diff --git a/apps/system/api/user.go b/apps/system/api/user.go index 8ef013b..7b21a77 100644 --- a/apps/system/api/user.go +++ b/apps/system/api/user.go @@ -88,16 +88,10 @@ func (u *UserApi) Login(rc *ctx.ReqCtx) { }) biz.ErrIsNil(err, "生成Token失败") - //前端权限 - permis := u.RoleMenuApp.GetPermis(role.RoleId) - menus := u.MenuApp.SelectMenuRole(role.RoleKey) rc.ResData = map[string]interface{}{ - "user": login, - "permissions": permis, - "menus": Build(*menus), - "token": token, - "expire": time.Now().Unix() + config.Conf.Jwt.ExpireTime, + "token": token, + "expire": time.Now().Unix() + config.Conf.Jwt.ExpireTime, } var loginLog logEntity.LogLogin @@ -117,6 +111,31 @@ func (u *UserApi) Login(rc *ctx.ReqCtx) { u.LogLogin.Insert(loginLog) } +// @Tags Base +// @Summary 用户权限信息 +// @Param userName query string false "userName" +// @Produce application/json +// @Success 200 {string} string "{"success":true,"data":{},"msg":"成功"}" +// @Router /system/user/auth [get] +func (u *UserApi) Auth(rc *ctx.ReqCtx) { + userName := rc.GinCtx.Query("username") + biz.NotEmpty(userName, "用户名必传") + var user entity.SysUser + user.Username = userName + userData := u.UserApp.FindOne(user) + role := u.RoleApp.FindOne(userData.RoleId) + //前端权限 + permis := u.RoleMenuApp.GetPermis(role.RoleId) + menus := u.MenuApp.SelectMenuRole(role.RoleKey) + + rc.ResData = map[string]interface{}{ + "user": userData, + "role": role, + "permissions": permis, + "menus": Build(*menus), + } +} + // @Tags Base // @Summary 退出登录 // @Produce application/json diff --git a/apps/system/router/user.go b/apps/system/router/user.go index 9f69a3f..0eced61 100644 --- a/apps/system/router/user.go +++ b/apps/system/router/user.go @@ -27,7 +27,10 @@ func InitUserRouter(router *gin.RouterGroup) { user.POST("login", func(c *gin.Context) { ctx.NewReqCtxWithGin(c).WithLog(loginLog).WithNeedToken(false).WithNeedCasbin(false).Handle(s.Login) }) - + authLog := ctx.NewLogInfo("认证信息") + user.GET("auth", func(c *gin.Context) { + ctx.NewReqCtxWithGin(c).WithLog(authLog).WithNeedCasbin(false).Handle(s.Auth) + }) logoutLog := ctx.NewLogInfo("退出登录") user.POST("logout", func(c *gin.Context) { ctx.NewReqCtxWithGin(c).WithLog(logoutLog).WithNeedToken(false).WithNeedCasbin(false).Handle(s.LogOut) diff --git a/base/model/model.go b/base/model/model.go index 9cd17d9..4212705 100644 --- a/base/model/model.go +++ b/base/model/model.go @@ -94,7 +94,7 @@ func UpdateById(model interface{}) error { return global.Db.Model(model).Updates(model).Error } func UpdateByWhere(model interface{}, where interface{}) error { - return global.Db.Model(model).Updates(model).Error + return global.Db.Model(model).Where(where).Updates(model).Error } // 根据id删除model diff --git a/initialize/router.go b/initialize/router.go index 386027a..ecdf07a 100644 --- a/initialize/router.go +++ b/initialize/router.go @@ -2,7 +2,9 @@ package initialize import ( "fmt" + ginSwagger "github.com/swaggo/gin-swagger" + "github.com/swaggo/gin-swagger/swaggerFiles" devRouter "pandax/apps/develop/router"