refactor: pc导航重构
Some checks failed
Gitea Actions Official-website / deploy-dev (push) Failing after 3s

This commit is contained in:
2026-03-30 18:03:03 +08:00
parent 8a9d66f5d3
commit e8a3a88c07
4 changed files with 1669 additions and 4 deletions

View File

@@ -38,10 +38,10 @@ abstract class Common extends BaseController
}
// 获取产品分类
$categorys = $this->getProductCategory($this->lang_id);
$categorys = $this->getProductCategory($this->lang_id, true);
// 输出产品分类
View::assign('header_categorys', $categorys);
// dump($categorys);exit;
// 获取热销产品
$hot_products = $this->getHotProducts($this->lang_id);
// 输出热销产品
@@ -63,6 +63,15 @@ abstract class Common extends BaseController
// 输出底部导航
View::assign('footer_navigation', $footer_navigation);
}
private function handlerCategory($categorys)
{
foreach ($categorys as &$item) {
if ($item['children']) {
$item['children'] = $this->handlerCategory($item['children']);
}
}
return $categorys;
}
// 获取当前语言
protected function getCurrentLanguage($languages)
@@ -78,7 +87,7 @@ abstract class Common extends BaseController
}
// 获取产品分类
protected function getProductCategory($language = 1)
protected function getProductCategory($language = 1, $with_recommends = false)
{
$categorys = ProductCategoryModel::field([
'id',
@@ -87,10 +96,17 @@ abstract class Common extends BaseController
'icon',
'level'
])
->when($with_recommends, function($query) {
$query->with(['recommends' => function($query) {
$query->field(['id', 'category_id', 'title', 'image', 'desc', 'link'])
->order(['sort' => 'asc', 'id' => 'desc']);
}]);
})
->language($language)
->displayed()
->order(['sort' => 'asc', 'id' => 'desc'])
->select();
->select()
->hidden(["recommends.category_id"]);
if ($categorys->isEmpty()) {
return [];
}