Authored by Rock Zhang

修复侧边栏数据的数据格式,方便从后来获取配置

Code Review By Rock Zhang
... ... @@ -18,7 +18,7 @@ class SideData
{
const URI_LEFTNAV_ENTRANCE = 'operations/api/v5/entrance/getEntrance';
const URI_LEFTNAV_CATEGORY = 'operations/api/v5/category/getCategory';
const URI_LEFTNAV_CATEGORY = 'operations/api/v6/category/getCategory';
/**
* 左侧边栏的分类和图标数据
... ...
<div class="side-nav">
{{# sideNav}}
<ul>
{{# sideNav}}
{{# this}}
<li class="{{styleClass}}">
{{# url}}
<a href="{{.}}">
... ... @@ -43,6 +44,7 @@
</ul>
{{/ subNav}}
</li>
{{/ sideNav}}
{{/ this}}
</ul>
{{/sideNav}}
</div>
\ No newline at end of file
... ...
... ... @@ -39,16 +39,38 @@ class SideModel
// 调用接口获取后台配置的侧边栏数据
$side = SideData::leftNav();
if (!empty($side['data'])) {
$group = array();
$num = 0;
$groupKey = 0;
$count = count(($side['data']));
foreach ($side['data'] as $key => $value) {
if ($value['separative_sign'] === 'Y') {
$result[$num] = $group;
$num++;
$groupKey = 0;
$group = array();
}
// 逛的按照原来的做法,使用配置
if ($value['sort_name_en'] === 'TRENDFINDER') {
continue;
}
$result[$key]['textCn'] = $value['sort_name'];
$result[$key]['textEn'] = $value['sort_name_en'];
$result[$key]['styleClass'] = strtolower($value['sort_name_en']);
$result[$key]['url'] = Helpers::getFilterUrl($value['sort_url']);
$result[$key]['img'] = Helpers::getImageUrl($value['sort_ico'], 60, 60, 1);
$group[$groupKey] = self::formatSideItem($value);
// 如果存在子菜单,就输出子菜单
if (isset($value['sub']) && !empty($value['sub'])) {
$subs = array();
foreach ($value['sub'] as $oneSub) {
$subs[] = self::formatSideItem($oneSub);
}
$group[$groupKey]['subNav'] = $subs;
}
$groupKey++;
if ($count === $key + 1) {
$result[$num] = $group;
}
}
}
... ... @@ -126,4 +148,24 @@ class SideModel
);
}
/**
* 格式化侧边栏数据
*
* @param array $data 要格式化的侧边栏数据
* @return array
*/
private static function formatSideItem($data)
{
$result = array();
$result['textCn'] = $data['sort_name'];
$result['textEn'] = $data['sort_name_en'];
$result['styleClass'] = strtolower($data['sort_name_en']);
$result['url'] = Helpers::getFilterUrl($data['sort_url']);
$result['img'] = Helpers::getImageUrl($data['sort_ico'], 60, 60, 1);
return $result;
}
}
... ...