Browse Source

feat(i18n): 维护中英文导航id,移除代码写死的id

master
peijunlei 2 weeks ago
parent
commit
39ae813db8
  1. 18
      app/common.php
  2. 25
      config/ui_ids.php
  3. 8
      public/themes/website/1/en/demo/components/footer.html
  4. 42
      public/themes/website/1/en/demo/components/header.html
  5. 3
      public/themes/website/1/en/demo/single_search.html
  6. 8
      public/themes/website/1/zh/demo/components/footer.html
  7. 41
      public/themes/website/1/zh/demo/components/header.html
  8. 3
      public/themes/website/1/zh/demo/single_search.html

18
app/common.php

@ -318,6 +318,24 @@ function getLang()
return $firstPath;
}
/**
* 按当前语言取前台语义 ID(config/ui_ids.php)
* @param string $key nav_header / product
* @param string|null $lang 默认 getLang();zh-cn 会归一为 zh
*/
function uiId(string $key, ?string $lang = null): int
{
$lang = $lang ?: getLang();
if ($lang === 'zh-cn' || $lang === config('lang.simplified_chinese')) {
$lang = 'zh';
}
$row = config('ui_ids.' . $key);
if (!is_array($row)) {
return (int)$row;
}
return (int)($row[$lang] ?? $row['zh'] ?? 0);
}
function optEventLog($id, $title, $operation)
{

25
config/ui_ids.php

@ -0,0 +1,25 @@
<?php
/**
* 前台模板语义 ID 映射(方案 A)
* 键名供 uiId('xxx') 使用;按语言取对应数字 ID。
* 英文站栏目建好后,只改本文件 en 值即可,不必改模板。
*
* 说明:nav_header / nav_footer 为导航分类 ID,库内 zh/en 条目共用同一 nav_cate_id。
*/
return [
// 导航分类
'nav_header' => ['zh' => 47, 'en' => 49], // 顶部导航_新
'nav_footer' => ['zh' => 48, 'en' => 50], // 睿能科技底部导航
// 栏目(header / footer 业务判断与标签查询)
'home' => ['zh' => 36, 'en' => 706], // 首页
'product' => ['zh' => 333, 'en' => 704], // 产品
'solution' => ['zh' => 345, 'en' => 716], // 解决方案
'support' => ['zh' => 355, 'en' => 724], // 服务支持
'news' => ['zh' => 361, 'en' => 730], // 新闻动态
'exhibition' => ['zh' => 364, 'en' => 733], // 展会与活动
'invest' => ['zh' => 365, 'en' => 734], // 投资者关系
'about' => ['zh' => 371, 'en' => 740], // 关于睿能
'search_hot' => ['zh' => 679, 'en' => 748], // 搜索-热门搜索词
'social_channel' => ['zh' => 707, 'en' => 749], // 社交频道
];

8
public/themes/website/1/en/demo/components/footer.html

@ -25,9 +25,13 @@
</div>
</div>
<nav class="site-footer__cols" aria-label="Footer navigation">
{hcTaglib:nav cid="48" max-level="2" item="vo" name="hc_nav" sort="sort asc"}
{php}
$ft_is_product = ((int)($vo['category_id'] ?? 0) === 333);
$ui_nav_footer = uiId('nav_footer');
$ui_product = uiId('product');
{/php}
{hcTaglib:nav cid="$ui_nav_footer" max-level="2" item="vo" name="hc_nav" sort="sort asc"}
{php}
$ft_is_product = ((int)($vo['category_id'] ?? 0) === $ui_product);
{/php}
<div class="site-footer__col">
<div class="site-footer__colTitle">{$vo.title}</div>

42
public/themes/website/1/en/demo/components/header.html

@ -63,7 +63,7 @@
</span>
</span>
{php}
$content_arr = getDescriptionSeparate(707);
$content_arr = getDescriptionSeparate(uiId('social_channel'));
$douyin_url = $content_arr['0'] ?? '';
$sina_url = $content_arr['1'] ?? '';
$zhihu_url = $content_arr['2'] ?? '';
@ -183,30 +183,40 @@
</a>
<nav class="site-header__nav" aria-label="Main navigation">
<ul>
{hcTaglib:nav cid="47" max-level="2" item="vo" name="hc_header_nav" sort="sort asc"}
{php}
$ui_nav_header = uiId('nav_header');
$ui_home = uiId('home');
$ui_product = uiId('product');
$ui_solution = uiId('solution');
$ui_support = uiId('support');
$ui_news = uiId('news');
$ui_invest = uiId('invest');
$ui_about = uiId('about');
$ui_exhibition = uiId('exhibition');
{/php}
{hcTaglib:nav cid="$ui_nav_header" max-level="2" item="vo" name="hc_header_nav" sort="sort asc"}
{php}
$nav_title = $vo['title'] ?? '';
$nav_href = $vo['href'] ?? '';
$nav_id = (int)($vo['id'] ?? 0);
$nav_cid = (int)($vo['category_id'] ?? 0);
$nav_children = $vo['children'] ?? [];
// 产品 333 / 解决方案 345 走特殊下拉
$nav_is_product = ($nav_cid === 333);
$nav_is_solution = ($nav_cid === 345);
$nav_is_home = ($nav_cid === 36);
// 普通下拉面板样式 class
// Product / Solutions mega menus (IDs from config/ui_ids.php)
$nav_is_product = ($nav_cid === $ui_product);
$nav_is_solution = ($nav_cid === $ui_solution);
$nav_is_home = ($nav_cid === $ui_home);
$nav_mega_map = [
355 => 'support', // 服务支持
361 => 'news', // 新闻动态
365 => 'invest', // 投资者关系
371 => 'about', // 关于睿能
$ui_support => 'support',
$ui_news => 'news',
$ui_invest => 'invest',
$ui_about => 'about',
];
$nav_mega_class = $nav_mega_map[$nav_cid] ?? 'support';
{/php}
{if $nav_is_product}
<!-- 产品导航(特殊处理) -->
<li class="site-header__nav-item site-header__nav-item--mega">
{hcTaglib:category id="333" item="vo" field="*"}
{hcTaglib:category id="$ui_product" item="vo" field="*"}
<a
href="{$vo.alias}"
class="site-header__nav-link"
@ -238,7 +248,7 @@
<div class="nav-mega__inner">
<div class="nav-mega__dropdown-content product">
<aside class="nav-mega__cats" aria-label="Product categories">
{hcTaglib:subcategory pid="333" item="vo" sort=""}
{hcTaglib:subcategory pid="$ui_product" item="vo" sort=""}
<button type="button" class="nav-mega__cat {if $key==1}is-active{/if}" data-mega-cat="product_{$key}">
<span>{$vo.title}</span>
@ -264,7 +274,7 @@
</aside>
<div class="nav-mega__main">
<div class="nav-mega__panels">
{hcTaglib:subcategory pid="333" item="vo" sort=""}
{hcTaglib:subcategory pid="$ui_product" item="vo" sort=""}
<div class="nav-mega__panel {if $key==1}is-active{/if}" data-mega-panel="product_{$key}" {if $key!=1}hidden{/if}>
{php}
$sub_cate_id = $vo['id']; // 获取子分类的ID
@ -360,7 +370,7 @@
</div>
<div class="nav-mega__promo-side">
{hcTaglib:category id="364" item="vo" field="*"}
{hcTaglib:category id="$ui_exhibition" item="vo" field="*"}
{php}
$zhanhui_and_activity = $vo;
$thumbnail_url_header = $vo['thumbnail']['url'] ?? '';
@ -437,7 +447,7 @@
<div class="nav-mega__inner">
<div class="nav-mega__dropdown-content solution">
<div class="nav-mega__cols nav-mega__cols--solution">
{hcTaglib:allSubCategory pid="345" item="vo" sort=""}
{hcTaglib:allSubCategory pid="$ui_solution" item="vo" sort=""}
<div class="nav-mega__col">
<div class="nav-mega__group">
<span class="nav-mega__group-title">{$vo.title}</span>

3
public/themes/website/1/en/demo/single_search.html

@ -70,7 +70,8 @@
<div class="sr-hot">
<span class="sr-hot__label">Popular searches:</span>
<div class="sr-hot__list">
{hcTaglib:category id="679" item="vo" field="id,title,description"}
{php}$ui_search_hot = uiId('search_hot');{/php}
{hcTaglib:category id="$ui_search_hot" item="vo" field="id,title,description"}
{php}
$description = $vo['description'] ?? '';
$descriptionArr = [];

8
public/themes/website/1/zh/demo/components/footer.html

@ -25,9 +25,13 @@
</div>
</div>
<nav class="site-footer__cols" aria-label="底部导航">
{hcTaglib:nav cid="48" max-level="2" item="vo" name="hc_nav" sort="sort asc"}
{php}
$ft_is_product = ((int)($vo['category_id'] ?? 0) === 333);
$ui_nav_footer = uiId('nav_footer');
$ui_product = uiId('product');
{/php}
{hcTaglib:nav cid="$ui_nav_footer" max-level="2" item="vo" name="hc_nav" sort="sort asc"}
{php}
$ft_is_product = ((int)($vo['category_id'] ?? 0) === $ui_product);
{/php}
<div class="site-footer__col">
<div class="site-footer__colTitle">{$vo.title}</div>

41
public/themes/website/1/zh/demo/components/header.html

@ -63,7 +63,7 @@
</span>
</span>
{php}
$content_arr = getDescriptionSeparate(707);
$content_arr = getDescriptionSeparate(uiId('social_channel'));
$douyin_url = $content_arr['0'] ?? '';
$sina_url = $content_arr['1'] ?? '';
$zhihu_url = $content_arr['2'] ?? '';
@ -183,30 +183,41 @@
</a>
<nav class="site-header__nav" aria-label="主导航">
<ul>
{hcTaglib:nav cid="47" max-level="2" item="vo" name="hc_header_nav" sort="sort asc"}
{php}
$ui_nav_header = uiId('nav_header');
$ui_home = uiId('home');
$ui_product = uiId('product');
$ui_solution = uiId('solution');
$ui_support = uiId('support');
$ui_news = uiId('news');
$ui_invest = uiId('invest');
$ui_about = uiId('about');
$ui_exhibition = uiId('exhibition');
{/php}
{hcTaglib:nav cid="$ui_nav_header" max-level="2" item="vo" name="hc_header_nav" sort="sort asc"}
{php}
$nav_title = $vo['title'] ?? '';
$nav_href = $vo['href'] ?? '';
$nav_id = (int)($vo['id'] ?? 0);
$nav_cid = (int)($vo['category_id'] ?? 0);
$nav_children = $vo['children'] ?? [];
// 产品 333 / 解决方案 345 走特殊下拉
$nav_is_product = ($nav_cid === 333);
$nav_is_solution = ($nav_cid === 345);
$nav_is_home = ($nav_cid === 36);
// 产品 / 解决方案 走特殊下拉(ID 见 config/ui_ids.php)
$nav_is_product = ($nav_cid === $ui_product);
$nav_is_solution = ($nav_cid === $ui_solution);
$nav_is_home = ($nav_cid === $ui_home);
// 普通下拉面板样式 class
$nav_mega_map = [
355 => 'support', // 服务支持
361 => 'news', // 新闻动态
365 => 'invest', // 投资者关系
371 => 'about', // 关于睿能
$ui_support => 'support', // 服务支持
$ui_news => 'news', // 新闻动态
$ui_invest => 'invest', // 投资者关系
$ui_about => 'about', // 关于睿能
];
$nav_mega_class = $nav_mega_map[$nav_cid] ?? 'support';
{/php}
{if $nav_is_product}
<!-- 产品导航(特殊处理) -->
<li class="site-header__nav-item site-header__nav-item--mega">
{hcTaglib:category id="333" item="vo" field="*"}
{hcTaglib:category id="$ui_product" item="vo" field="*"}
<a
href="{$vo.alias}"
class="site-header__nav-link"
@ -238,7 +249,7 @@
<div class="nav-mega__inner">
<div class="nav-mega__dropdown-content product">
<aside class="nav-mega__cats" aria-label="产品分类">
{hcTaglib:subcategory pid="333" item="vo" sort=""}
{hcTaglib:subcategory pid="$ui_product" item="vo" sort=""}
<button type="button" class="nav-mega__cat {if $key==1}is-active{/if}" data-mega-cat="product_{$key}">
<span>{$vo.title}</span>
@ -264,7 +275,7 @@
</aside>
<div class="nav-mega__main">
<div class="nav-mega__panels">
{hcTaglib:subcategory pid="333" item="vo" sort=""}
{hcTaglib:subcategory pid="$ui_product" item="vo" sort=""}
<div class="nav-mega__panel {if $key==1}is-active{/if}" data-mega-panel="product_{$key}" {if $key!=1}hidden{/if}>
{php}
$sub_cate_id = $vo['id']; // 获取子分类的ID
@ -360,7 +371,7 @@
</div>
<div class="nav-mega__promo-side">
{hcTaglib:category id="364" item="vo" field="*"}
{hcTaglib:category id="$ui_exhibition" item="vo" field="*"}
{php}
$zhanhui_and_activity = $vo;
$thumbnail_url_header = $vo['thumbnail']['url'] ?? '';
@ -437,7 +448,7 @@
<div class="nav-mega__inner">
<div class="nav-mega__dropdown-content solution">
<div class="nav-mega__cols nav-mega__cols--solution">
{hcTaglib:allSubCategory pid="345" item="vo" sort=""}
{hcTaglib:allSubCategory pid="$ui_solution" item="vo" sort=""}
<div class="nav-mega__col">
<div class="nav-mega__group">
<span class="nav-mega__group-title">{$vo.title}</span>

3
public/themes/website/1/zh/demo/single_search.html

@ -70,7 +70,8 @@
<div class="sr-hot">
<span class="sr-hot__label">热门搜索:</span>
<div class="sr-hot__list">
{hcTaglib:category id="679" item="vo" field="id,title,description"}
{php}$ui_search_hot = uiId('search_hot');{/php}
{hcTaglib:category id="$ui_search_hot" item="vo" field="id,title,description"}
{php}
$description = $vo['description'] ?? '';
$descriptionArr = [];

Loading…
Cancel
Save