Authored by Rock Zhang

逛频道优化-banner切换会根据章雷彪不同而不同

Code Review By Rock Zhang
1 {{> layout/header}} 1 {{> layout/header}}
2 <div class="guang-list-page guang-page yoho-page"> 2 <div class="guang-list-page guang-page yoho-page">
3 {{# guang}} 3 {{# guang}}
  4 +
  5 + <ul id="guang-nav" class="guang-nav clearfix">
  6 + {{# navs}}
  7 + <li class="guang-nav-item {{#focus}}focus{{/focus}}" data-type={{typeId}}>
  8 + {{type}}
  9 + </li>
  10 + {{/ navs}}
  11 + </ul>
  12 +
4 {{#if swiper}} 13 {{#if swiper}}
5 <div class="swiper-container"> 14 <div class="swiper-container">
6 <div class="swiper-wrapper"> 15 <div class="swiper-wrapper">
@@ -17,14 +26,6 @@ @@ -17,14 +26,6 @@
17 </div> 26 </div>
18 {{/if}} 27 {{/if}}
19 28
20 - <ul id="guang-nav" class="guang-nav clearfix">  
21 - {{# navs}}  
22 - <li class="guang-nav-item {{#focus}}focus{{/focus}}" data-type={{typeId}}>  
23 - {{type}}  
24 - </li>  
25 - {{/ navs}}  
26 - </ul>  
27 -  
28 <div id="info-list" class="info-list-container"> 29 <div id="info-list" class="info-list-container">
29 {{# infos}} 30 {{# infos}}
30 <div class="info-list{{^show}} hide{{/show}}"> 31 <div class="info-list{{^show}} hide{{/show}}">
@@ -315,6 +315,50 @@ class IndexModel @@ -315,6 +315,50 @@ class IndexModel
315 } 315 }
316 316
317 /** 317 /**
  318 + * @param string $gender "1,3"表示男, "2,3"表示女
  319 + * @param int $sortId 分类ID
  320 + * @param int $uid 用户ID
  321 + * @param string $udid 客户端唯一标识
  322 + * @param int $page 分页第几页, 默认第1页
  323 + * @param string $tag 标签
  324 + * @param string $authorId 作者ID
  325 + * @param boolean $isApp 是否是APP
  326 + * @param boolean $showAuthor 是否显示作者
  327 + * @param boolean $isTab 是否为tab切换操作
  328 + * @return array
  329 + */
  330 + public static function getPageData($gender, $sortId, $uid, $udid, $page, $tag, $authorId, $isApp, $showAuthor, $isTab)
  331 + {
  332 + $result = array();
  333 +
  334 + do {
  335 + $article = ListData::article($gender, $sortId, $uid, $udid, $page, $tag, $authorId);
  336 + if (empty($article['data']['list']['artList'])) {
  337 + break;
  338 + }
  339 +
  340 + // 广告列表
  341 + if ($isTab && !empty($article['data']['list']['adlist'])) {
  342 + foreach ($article['data']['list']['adlist'] as $value) {
  343 + $build = array();
  344 + $build['url'] = Helpers::getFilterUrl($value['url']);
  345 + $build['img'] = Helpers::getImageUrl($value['src'], 830, 327);
  346 + $data['guang']['swiper'][] = $build;
  347 + }
  348 + }
  349 +
  350 + /* 构建资讯文章内容 */
  351 + $build = array();
  352 + foreach ($article['data']['list']['artList'] as $article) {
  353 + $build[] = Helpers::formatArticle($article, true, $isApp, $showAuthor, $uid);
  354 + }
  355 + $result['infos'] = $build;
  356 + } while (false);
  357 +
  358 + return $result;
  359 + }
  360 +
  361 + /**
318 * 构建信息内容 362 * 构建信息内容
319 * 363 *
320 * @param array $data 364 * @param array $data
1 <?php 1 <?php
2 2
3 use Action\AbstractAction; 3 use Action\AbstractAction;
  4 +use Guang\IndexModel;
4 use LibModels\Wap\Guang\ListData; 5 use LibModels\Wap\Guang\ListData;
5 use Plugin\Helpers; 6 use Plugin\Helpers;
6 use Plugin\Cache; 7 use Plugin\Cache;
@@ -42,7 +43,7 @@ class IndexController extends AbstractAction @@ -42,7 +43,7 @@ class IndexController extends AbstractAction
42 // $this->setNavSide(); 43 // $this->setNavSide();
43 // } 44 // }
44 45
45 - $this->_view->display('index', Guang\IndexModel::getArticle($gender, $type, $uid, $udid)); 46 + $this->_view->display('index', IndexModel::getArticle($gender, $type, $uid, $udid));
46 } 47 }
47 48
48 /** 49 /**
@@ -91,7 +92,7 @@ class IndexController extends AbstractAction @@ -91,7 +92,7 @@ class IndexController extends AbstractAction
91 92
92 // 标签聚合内容列表 93 // 标签聚合内容列表
93 //$article = ListData::article($gender, 0, $uid, $udid, 1, $tag); 94 //$article = ListData::article($gender, 0, $uid, $udid, 1, $tag);
94 - $article = Guang\IndexModel::getArticleByTagOrEditor($gender, 0, $uid, $udid, 1, $tag); 95 + $article = IndexModel::getArticleByTagOrEditor($gender, 0, $uid, $udid, 1, $tag);
95 // 标签聚合内容不存在, 跳到错误页面 96 // 标签聚合内容不存在, 跳到错误页面
96 if (empty($article['data']['list']['artList'])) { 97 if (empty($article['data']['list']['artList'])) {
97 $this->error(); 98 $this->error();
@@ -184,7 +185,7 @@ class IndexController extends AbstractAction @@ -184,7 +185,7 @@ class IndexController extends AbstractAction
184 185
185 // 标签聚合内容列表 186 // 标签聚合内容列表
186 //$article = ListData::article($gender, 0, $uid, $udid, 1, null, $id); 187 //$article = ListData::article($gender, 0, $uid, $udid, 1, null, $id);
187 - $article = Guang\IndexModel::getArticleByTagOrEditor($gender, 0, $uid, $udid, 1, null, $id); 188 + $article = IndexModel::getArticleByTagOrEditor($gender, 0, $uid, $udid, 1, null, $id);
188 // 构建资讯文章内容 189 // 构建资讯文章内容
189 if (!empty($article['data']['list']['artList'])) { 190 if (!empty($article['data']['list']['artList'])) {
190 $build = array(); 191 $build = array();
@@ -227,6 +228,7 @@ class IndexController extends AbstractAction @@ -227,6 +228,7 @@ class IndexController extends AbstractAction
227 $gender = $this->get('gender'); 228 $gender = $this->get('gender');
228 $authorId = $this->get('authorId'); 229 $authorId = $this->get('authorId');
229 $isApp = $this->get('isApp', false); 230 $isApp = $this->get('isApp', false);
  231 + $isTab = $this->get('isTab', false); // 是否为tab切换操作
230 $showAuthor = true; 232 $showAuthor = true;
231 if (!empty($sortId) && !is_numeric($sortId)) { 233 if (!empty($sortId) && !is_numeric($sortId)) {
232 break; 234 break;
@@ -247,18 +249,7 @@ class IndexController extends AbstractAction @@ -247,18 +249,7 @@ class IndexController extends AbstractAction
247 $udid = $this->getUdid(); 249 $udid = $this->getUdid();
248 } 250 }
249 //$page = intval($page) + 1; 251 //$page = intval($page) + 1;
250 - $article = ListData::article($gender, $sortId, $uid, $udid, $page, $tag, $authorId);  
251 - if (empty($article['data']['list']['artList'])) {  
252 - break;  
253 - }  
254 -  
255 - /* 构建资讯文章内容 */  
256 - $data = array();  
257 - $build = array();  
258 - foreach ($article['data']['list']['artList'] as $article) {  
259 - $build[] = Helpers::formatArticle($article, true, $isApp, $showAuthor, $uid);  
260 - }  
261 - $data['infos'] = $build; 252 + $data = IndexModel::getPageData($gender, $sortId, $uid, $udid, $page, $tag, $authorId, $isApp, $showAuthor, $isTab);
262 } while (false); 253 } while (false);
263 254
264 if (isset($data)) { 255 if (isset($data)) {