增加模板
This commit is contained in:
@@ -18,12 +18,30 @@ func TagDocs() []TagMeta {
|
||||
{
|
||||
Name: "全局站点信息",
|
||||
Category: "global",
|
||||
Syntax: "{yz:sitename} {yz:logo} {yz:logow} {yz:ico} {yz:icp} {yz:copyright} {yz:companyname} {yz:description}",
|
||||
Desc: "取自当前租户的站点设置(backend 端 - 站点设置),直接替换为对应文本/地址,无需闭合。",
|
||||
Syntax: "{yz:sitename} {yz:logo} {yz:logow} {yz:ico} {yz:icp} {yz:copyright} {yz:companyname} {yz:description} {yz:companyintroduction}",
|
||||
Desc: "取自当前租户的站点设置(backend 端 - 站点设置 - 基本信息),直接替换为对应文本/地址,无需闭合。logo 彩色Logo / logow 白色Logo / ico 站点图标 / companyintroduction 企业介绍(富文本)。",
|
||||
Params: nil,
|
||||
Fields: nil,
|
||||
Example: "<title>{yz:sitename}</title>\n<img src=\"{yz:logo}\" alt=\"{yz:sitename}\" />\n<p>{yz:icp} {yz:copyright}</p>",
|
||||
},
|
||||
{
|
||||
Name: "全局联系方式",
|
||||
Category: "global",
|
||||
Syntax: "{yz:phone} {yz:email} {yz:address} {yz:worktime}",
|
||||
Desc: "取自租户的公司信息(backend 端 - 站点设置 - 公司信息),直接替换为文本,无需闭合。phone 联系电话(别名 {yz:tel} / {yz:mobile}) / email 电子邮箱 / address 公司地址 / worktime 工作时间。",
|
||||
Params: nil,
|
||||
Fields: nil,
|
||||
Example: "<a href=\"tel:{yz:phone}\">{yz:phone}</a>\n<a href=\"mailto:{yz:email}\">{yz:email}</a>\n<p>{yz:address}</p>\n<p>工作时间:{yz:worktime}</p>",
|
||||
},
|
||||
{
|
||||
Name: "全局 SEO 信息",
|
||||
Category: "global",
|
||||
Syntax: "{yz:seo_title} {yz:keywords} {yz:seo_description}",
|
||||
Desc: "取自租户的 SEO 设置(backend 端 - 站点设置 - SEO 设置),用于 head 区域的 meta 标签。seo_title 未填时建议回退用 {yz:sitename}。",
|
||||
Params: nil,
|
||||
Fields: nil,
|
||||
Example: "<title>{yz:seo_title}</title>\n<meta name=\"keywords\" content=\"{yz:keywords}\">\n<meta name=\"description\" content=\"{yz:seo_description}\">",
|
||||
},
|
||||
{
|
||||
Name: "nav 导航菜单",
|
||||
Category: "loop",
|
||||
|
||||
@@ -54,28 +54,85 @@ func publishedCond(qs orm.QuerySeter) orm.QuerySeter {
|
||||
return qs.Filter("status__in", []int8{1, 2})
|
||||
}
|
||||
|
||||
// globalSiteInfo 全局标签:站点设置各字段
|
||||
// globalSiteInfo 全局标签:站点设置各字段 + 租户表联系信息(电话/邮箱/地址等)
|
||||
func globalSiteInfo(tid uint64, ctx *RenderCtx) (map[string]string, error) {
|
||||
out := map[string]string{
|
||||
"sitename": "", "logo": "", "logow": "", "ico": "", "icp": "",
|
||||
"copyright": "", "companyname": "", "description": "",
|
||||
"companyintroduction": "",
|
||||
"phone": "", "tel": "", "mobile": "", "email": "", "address": "", "worktime": "",
|
||||
"keywords": "", "seo_title": "", "seo_description": "",
|
||||
}
|
||||
var row models.TenantSiteSetting
|
||||
err := models.Orm.QueryTable(new(models.TenantSiteSetting)).
|
||||
Filter("tid", tid).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&row)
|
||||
if err != nil {
|
||||
return out, nil
|
||||
if err == nil {
|
||||
out["sitename"] = row.Sitename
|
||||
out["logo"] = row.Logo
|
||||
out["logow"] = row.Logow
|
||||
out["ico"] = row.Ico
|
||||
out["icp"] = row.Icp
|
||||
out["copyright"] = row.Copyright
|
||||
out["companyname"] = row.Companyname
|
||||
out["description"] = row.Description
|
||||
out["companyintroduction"] = row.Companyintroduction
|
||||
}
|
||||
|
||||
// 联系方式取自租户表(backend 端 - 站点设置 - 公司信息)
|
||||
var tenant models.SystemTenant
|
||||
if err := models.Orm.QueryTable(new(models.SystemTenant)).
|
||||
Filter("id", tid).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&tenant); err == nil {
|
||||
if tenant.ContactPhone != nil {
|
||||
out["phone"] = *tenant.ContactPhone
|
||||
out["tel"] = *tenant.ContactPhone
|
||||
out["mobile"] = *tenant.ContactPhone
|
||||
}
|
||||
if tenant.ContactEmail != nil {
|
||||
out["email"] = *tenant.ContactEmail
|
||||
}
|
||||
if tenant.Address != nil {
|
||||
out["address"] = *tenant.Address
|
||||
}
|
||||
if tenant.Worktime != nil {
|
||||
out["worktime"] = *tenant.Worktime
|
||||
}
|
||||
}
|
||||
|
||||
// SEO 三项取自租户扩展设置表(backend 端 - 站点设置 - SEO 设置)
|
||||
if vals, err := queryTenantSettingItems(tid, "seoKeywords", "seoTitle", "seoDescription"); err == nil {
|
||||
out["keywords"] = vals["seoKeywords"]
|
||||
out["seo_title"] = vals["seoTitle"]
|
||||
out["seo_description"] = vals["seoDescription"]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// queryTenantSettingItems 查询租户扩展设置表 yz_system_tenant_setting_items;
|
||||
// 表不存在等异常不阻断渲染,返回错误由调用方忽略
|
||||
func queryTenantSettingItems(tid uint64, keys ...string) (map[string]string, error) {
|
||||
out := make(map[string]string, len(keys))
|
||||
for _, k := range keys {
|
||||
out[k] = ""
|
||||
}
|
||||
type kv struct {
|
||||
SettingKey string
|
||||
SettingValue string
|
||||
}
|
||||
var rows []kv
|
||||
_, err := models.Orm.Raw(
|
||||
"SELECT setting_key, IFNULL(setting_value, '') AS setting_value FROM yz_system_tenant_setting_items WHERE tid = ? AND setting_key IN ('"+strings.Join(keys, "','")+"') AND delete_time IS NULL",
|
||||
tid,
|
||||
).QueryRows(&rows)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
for _, r := range rows {
|
||||
out[r.SettingKey] = r.SettingValue
|
||||
}
|
||||
out["sitename"] = row.Sitename
|
||||
out["logo"] = row.Logo
|
||||
out["logow"] = row.Logow
|
||||
out["ico"] = row.Ico
|
||||
out["icp"] = row.Icp
|
||||
out["copyright"] = row.Copyright
|
||||
out["companyname"] = row.Companyname
|
||||
out["description"] = row.Description
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user