yxh 379abd65e0 fix 1、修复虚拟树形结构ID错误问题
2、修复组件name首字母大写造成的页面缓存失败问题
    3、修复excel导出文件未关闭资源的问题
    4、更新数据权限同时支持按创建人划分(created_by)或按部门(dept_id划分)
    5、更新token自动刷新功能
2024-06-08 23:17:33 +08:00

76 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @desc:context-service
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/23 14:51
*/
package context
import (
"context"
"github.com/gogf/gf/v2/net/ghttp"
"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"
)
func init() {
service.RegisterContext(New())
}
type sContext struct{}
func New() service.IContext {
return &sContext{}
}
// Init 初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。
func (s *sContext) Init(r *ghttp.Request, customCtx *model.Context) {
r.SetCtxVar(consts.CtxKey, customCtx)
}
// Get 获得上下文变量如果没有设置那么返回nil
func (s *sContext) Get(ctx context.Context) *model.Context {
value := ctx.Value(consts.CtxKey)
if value == nil {
return nil
}
if localCtx, ok := value.(*model.Context); ok {
return localCtx
}
return nil
}
// SetUser 将上下文信息设置到上下文请求中,注意是完整覆盖
func (s *sContext) SetUser(ctx context.Context, ctxUser *model.ContextUser) {
s.Get(ctx).User = ctxUser
}
// GetLoginUser 获取当前登陆用户信息
func (s *sContext) GetLoginUser(ctx context.Context) *model.ContextUser {
context := s.Get(ctx)
if context == nil {
return nil
}
return context.User
}
// GetUserId 获取当前登录用户id
func (s *sContext) GetUserId(ctx context.Context) uint64 {
user := s.GetLoginUser(ctx)
if user != nil {
return user.Id
}
return 0
}
// GetDeptId 获取当前登录用户部门id
func (s *sContext) GetDeptId(ctx context.Context) uint64 {
user := s.GetLoginUser(ctx)
if user != nil {
return user.DeptId
}
return 0
}