cmsTheme 当前设置的模板主题路径

<link src="${.cmsTheme}/css/style.css">

cmsConfig 站点配置信息

类型为map[string]string

${.cmsConfig.home_url}
// 输入后台配置的主页路径

urlInfo 当前访问的url信息

类型:map[string]interface{}

字段 说明
scheme 协议类型:http , https
host 主机域名
port 端口
user
pass
path 路径, /cms/list
query 参数
fragment

Date 日期时间对象

类型 *gtime.Time 对象
可使用gtime.Time的所有方法,详情见官方文档
https://godoc.org/github.com/gogf/gf/os/gtime

request 当前请求对象

类型: *http.Request
官方介绍:https://goframe.org/pages/viewpage.action?pageId=1114483
注意和官方的模板内置对象 Reqeust 作区分,前者为大写开头且只是获取请求参数

数据结构:

type Request struct {
    Method           string
    URL              *url.URL
    Proto            string
    ProtoMajor       int
    ProtoMinor       int
    Header           Header
    Body             io.ReadCloser
    GetBody          func() (io.ReadCloser, error)
    ContentLength    int64
    TransferEncoding []string
    Close            bool
    Host             string
    Form             url.Values
    PostForm         url.Values
    MultipartForm    *multipart.Form
    Trailer          Header
    RemoteAddr       string
    RequestURI       string
    TLS              *tls.ConnectionState
    Cancel           <-chan struct{}
    Response         *Response
    ctx              context.Context
}

使用方式:

// 输出当前请求的URL地址
${.request.URL}

Session.memberInfo 用户信息

用户属性在前端模板中都使用 json 字段值
结构

{
    Id          uint64      `p:"id" json:"id"`
    Nickname    string      `p:"nickname" json:"nickname"`       //昵称
    Sex         string      `p:"sex" json:"sex"`                 //性别
    Email       string      `p:"email" json:"email"`             //邮箱
    Mobile      string      `p:"mobile" json:"mobile"`           //手机号
    Username    string      `p:"username" json:"username"`       //用户名
    Uuid        string      `p:"uuid" json:"uuid"`               //UUID
    RegType     string      `p:"regType" json:"regType"`         //注册类型
    Avatar      string      `p:"avatar" json:"avatar"`           //头像
    CreatedAt   *gtime.Time `p:"createdAt" json:"createdAt"`     //创建时间
    IsSecret    int         `p:"isSecret" json:"isSecret"`       // 是否保密
    CustomBg    string      `p:"customBg" json:"customBg"`       // 自定义背景
    Description string      `p:"description" json:"description"` // 个人描述
    IsOpen      string      `p:"isOpen" json:"isOpen"`           //是否激活
    Status      string      `p:"status" json:"status"`           //状态
    Qq          string      `p:"qq" json:"qq"`                   // QQ
    Score       int         `p:"score" json:"score"`             // 用户积分
    Level       uint        `p:"level" json:"level"`             // 用户等级
}

示例:

${.Session.memberInfo.nickname}

Session.memberId 用户ID

${.Session.memberId}

Session.memberUuid 用户Uuid

${.Session.memberUuid}

Session.token 会员登录后的令牌

可用于获取gftoken里的数据

import "gfast/app/ucenter/api"

api.GfToken.GetTokenData(r)

UcenterContext 用户中心上下文

结构

type UcenterContext struct {
    Session *ghttp.Session  // 当前Session管理对象
    Data    g.Map           // 自定KV变量
    Member  *UcenterMembers // 用户信息
}

获取上下文对象
需要路由使用 ucenterMiddleware.Ctx

ucenterContent := ucenterService.UcenterContext.Get(r.GetCtx())
作者:袁学飞  创建时间:2023-03-08 11:33
最后编辑:袁学飞  更新时间:2024-04-29 14:44