From af4566b6ea716b2833b90fb8839507024be375d6 Mon Sep 17 00:00:00 2001 From: Terry <2358269014@qq.com> Date: Mon, 11 Nov 2019 14:37:30 +0800 Subject: [PATCH] category block --- .../modules/Catalog/block/category/Index.php | 25 +++++++++++-------- .../modules/Catalog/block/category/Index.php | 8 +++++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/appfront/modules/Catalog/block/category/Index.php b/app/appfront/modules/Catalog/block/category/Index.php index fa82359b..bc140916 100644 --- a/app/appfront/modules/Catalog/block/category/Index.php +++ b/app/appfront/modules/Catalog/block/category/Index.php @@ -199,13 +199,14 @@ class Index extends \yii\base\BaseObject } } $frontSort = []; + $hasSelect = false; if (is_array($sort) && !empty($sort)) { $attrUrlStr = $this->_sort; - $dirUrlStr = $this->_direction; + $dirUrlStr = $this->_direction; foreach ($sort as $np=>$info) { - $label = $info['label']; - $direction = $info['direction']; - $arr['sort'] = [ + $label = $info['label']; + $direction = $info['direction']; + $arr['sort']= [ 'key' => $attrUrlStr, 'val' => $np, ]; @@ -214,19 +215,23 @@ class Index extends \yii\base\BaseObject 'val' => $direction, ]; $urlInfo = Yii::$service->url->category->getFilterSortAttrUrl($arr, $this->_page); - //var_dump($urlInfo); - //exit; + if ($urlInfo['selected']) { + $hasSelect = true; + } $frontSort[] = [ 'label' => $label, - 'value' => $np, - 'url' => $urlInfo['url'], - 'selected' => $urlInfo['selected'], + 'value' => $np, + 'url' => $urlInfo['url'], + 'selected' => $urlInfo['selected'], ]; } } + if (!$hasSelect ){ // 默认第一个为选中的排序方式 + $frontSort[0]['selected'] = true; + } $data = [ 'frontNumPerPage' => $frontNumPerPage, - 'frontSort' => $frontSort, + 'frontSort' => $frontSort, ]; return $data; diff --git a/app/apphtml5/modules/Catalog/block/category/Index.php b/app/apphtml5/modules/Catalog/block/category/Index.php index 1fadddc6..c5ac0a77 100644 --- a/app/apphtml5/modules/Catalog/block/category/Index.php +++ b/app/apphtml5/modules/Catalog/block/category/Index.php @@ -213,6 +213,7 @@ class Index extends \yii\base\BaseObject } } $frontSort = []; + $hasSelect = false; if (is_array($sort) && !empty($sort)) { $attrUrlStr = $this->_sort; $dirUrlStr = $this->_direction; @@ -228,7 +229,9 @@ class Index extends \yii\base\BaseObject 'val' => $direction, ]; $urlInfo = Yii::$service->url->category->getFilterSortAttrUrl($arr, $this->_page); - + if ($urlInfo['selected']) { + $hasSelect = true; + } $frontSort[] = [ 'label' => $label, 'value' => $np, @@ -237,6 +240,9 @@ class Index extends \yii\base\BaseObject ]; } } + if (!$hasSelect ){ // 默认第一个为选中的排序方式 + $frontSort[0]['selected'] = true; + } $data = [ 'frontNumPerPage' => $frontNumPerPage, 'frontSort' => $frontSort, -- GitLab