Authored by ccbikai

cate

  1 +/**
  2 + * 分类页面
  3 + */
  4 +'use strict';
  5 +const cateModel = require('../models/cate');
  6 +const helpers = global.yoho.helpers;
  7 +
  8 +let index = (req, res, next) => {
  9 + let channel = req.yoho.channel;
  10 +
  11 + // 根据频道设置默认的焦点
  12 + // if (!empty($classes)) {
  13 + // $classes[$channel - 1]['focus'] = true;
  14 + // }
  15 + cateModel.getCateData().then((result) => {
  16 + console.log(result);
  17 + res.render('cate', {
  18 + module: 'channel',
  19 + page: 'cate',
  20 + title: '商品分类',
  21 + category: {
  22 + cate: {},
  23 + searchUrl: helpers.urlFormat('/search', null, 'search')
  24 + }
  25 + });
  26 + }).catch(next);
  27 +};
  28 +
  29 +module.exports = {
  30 + index
  31 +};
  1 +/**
  2 + * 分类页面 model
  3 + * @author: Bi Kai<kai.bi@yoho.cn>
  4 + * @date: 2016/07/06
  5 + */
  6 +'use strict';
  7 +
  8 +const api = global.yoho.API;
  9 +
  10 +let getCateData = () => {
  11 + return api.get('', {
  12 + method: 'app.sort.get'
  13 + }, {
  14 + cache: true
  15 + });
  16 +};
  17 +
  18 +module.exports = {
  19 + getCateData
  20 +};
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 const express = require('express'); 9 const express = require('express');
10 const cRoot = './controllers'; 10 const cRoot = './controllers';
11 const channel = require(cRoot); 11 const channel = require(cRoot);
  12 +const cate = require(cRoot + '/cate');
12 13
13 const router = express.Router(); // eslint-disable-line 14 const router = express.Router(); // eslint-disable-line
14 15
@@ -20,4 +21,6 @@ router.get('/lifestyle', channel.switchChannel, channel.lifestyle); @@ -20,4 +21,6 @@ router.get('/lifestyle', channel.switchChannel, channel.lifestyle);
20 21
21 router.get('/channel/bottomBanner', channel.bottomBanner); 22 router.get('/channel/bottomBanner', channel.bottomBanner);
22 23
  24 +router.get('/cate', cate.index);
  25 +
23 module.exports = router; 26 module.exports = router;
@@ -47,6 +47,8 @@ @@ -47,6 +47,8 @@
47 <script src="//cdn.yoho.cn/m-yohobuy-node/{{version}}/libs.js"></script> 47 <script src="//cdn.yoho.cn/m-yohobuy-node/{{version}}/libs.js"></script>
48 <script src="//cdn.yoho.cn/m-yohobuy-node/{{version}}/{{module}}.{{page}}.js"></script> 48 <script src="//cdn.yoho.cn/m-yohobuy-node/{{version}}/{{module}}.{{page}}.js"></script>
49 {{/if}} 49 {{/if}}
  50 + {{#unless devEnv}}
50 {{> analysis}} 51 {{> analysis}}
  52 + {{/unless}}
51 </body> 53 </body>
52 </html> 54 </html>
  1 +/**
  2 + * 分类
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/14
  5 + */
  6 +
  7 +var $ = require('yoho-jquery');
  8 +
  9 +var $nav = $('.category-nav'),
  10 + $categoryContainer = $('.category-container'),
  11 + $contents = $categoryContainer.children('.content'),
  12 + $subLevelItem = $categoryContainer.find('.sub-level li'),
  13 + $primaryItem = $categoryContainer.find('.primary-level li');
  14 +
  15 +var $curContent = $contents.not('.hide');
  16 +
  17 +(function() {
  18 + var $header = $('.yoho-header'),
  19 + $search = $('#search-input');
  20 +
  21 + var h = $(window).height() - $header.outerHeight() - $search.outerHeight() - $nav.outerHeight();
  22 +
  23 + $categoryContainer.css('min-height', h);
  24 +
  25 + $contents.height(h);
  26 +}());
  27 +
  28 +$('#search-input').focus(function() {
  29 + $(this).blur();
  30 +});
  31 +$nav.bind('contextmenu', function() {
  32 + return false;
  33 +});
  34 +$('.category-container').bind('contextmenu', function() {
  35 + return false;
  36 +});
  37 +
  38 +$nav.on('touchend touchcancel', function(e) {
  39 + var $this = $(e.target).closest('li'),
  40 + index = $this.index();
  41 +
  42 + if ($this.hasClass('focus')) {
  43 + return;
  44 + }
  45 +
  46 + $nav.find('li.focus').removeClass('focus');
  47 + $this.addClass('focus');
  48 +
  49 + $curContent.addClass('hide');
  50 + $curContent = $contents.eq(index).removeClass('hide');
  51 +});
  52 +
  53 +$categoryContainer.on('touchend', function(e) {
  54 + var $this = $(e.target),
  55 + $subLevel,
  56 + $cur, index;
  57 +
  58 + $cur = $this.closest('.p-level-item');
  59 + if ($cur.length > 0) {
  60 + index = $cur.index();
  61 + $subLevel = $this.closest('.content').find('.sub-level');
  62 +
  63 + if ($this.hasClass('focus')) {
  64 + return;
  65 + }
  66 +
  67 + $this.closest('.primary-level').children('.focus').removeClass('focus');
  68 + $this.addClass('focus');
  69 +
  70 + $subLevel.not('.hide').addClass('hide');
  71 + $subLevel.eq(index).removeClass('hide');
  72 + }
  73 +});
  74 +
  75 +$categoryContainer.find('.primary-level').on('touchstart touchend touchcancel', 'li', function() {
  76 + $primaryItem.removeClass('highlight');
  77 + $(this).addClass('highlight');
  78 +}).on('touchend touchcancel', 'li', function() {
  79 + $(this).removeClass('highlight');
  80 +});
  81 +
  82 +$categoryContainer.find('.sub-level').on('touchstart', 'li', function() {
  83 + $subLevelItem.removeClass('highlight');
  84 + $(this).addClass('highlight');
  85 +}).on('touchend touchcancel', 'li', function() {
  86 + $(this).removeClass('highlight');
  87 +});
  88 +
  89 +$nav.on('touchstart', 'li', function() {
  90 + $nav.find('li').removeClass('bytouch');
  91 + $(this).addClass('bytouch');
  92 +}).on('touchend touchcancel', 'li', function() {
  93 + $nav.find('li').removeClass('bytouch');
  94 +});
  1 +.category-page {
  2 + font-size: 30px;
  3 +
  4 + .search-input {
  5 + position: relative;
  6 + background-color: #f8f8f8;
  7 + padding: 13px 20px;
  8 +
  9 + p {
  10 + box-sizing: border-box;
  11 + width: 100%;
  12 + height: 60px;
  13 + line-height: 60px;
  14 + border: none;
  15 + padding-left: 66px;
  16 + border-radius: 60px;
  17 + font-size: 26px;
  18 + background: #fff;
  19 + color: #999;
  20 + }
  21 + }
  22 +
  23 + .search-icon {
  24 + position: absolute;
  25 + top: 0;
  26 + bottom: 0;
  27 + left: 43px;
  28 + line-height: 86px;
  29 + color: #999;
  30 + }
  31 +
  32 + .category-nav {
  33 + height: 70px;
  34 + border-bottom: 1px solid #e6e6e6;
  35 +
  36 + li {
  37 + display: block;
  38 + box-sizing: border-box;
  39 + float: left;
  40 + height: 100%;
  41 + padding: 20px 0;
  42 + width: 25%;
  43 + text-align: center;
  44 + color: #999;
  45 +
  46 + &:last-child {
  47 + border-right: none;
  48 + }
  49 +
  50 + &.focus {
  51 + color: #000;
  52 + }
  53 +
  54 + &.bytouch{
  55 + background:#eee;
  56 + }
  57 + }
  58 +
  59 +
  60 +
  61 + span {
  62 + display: block;
  63 + width: 100%;
  64 + height: 30px;
  65 + line-height: 30px;
  66 + font-size: 30px;
  67 + border-right: 1px solid #e6e6e6;
  68 + }
  69 +
  70 + li:last-child span {
  71 + border-right: 0;
  72 + }
  73 + }
  74 +
  75 + .content {
  76 + background: #f8f8f8;
  77 +
  78 + &.hide {
  79 + display: none;
  80 + }
  81 + }
  82 +
  83 + .primary-level {
  84 + float: left;
  85 + box-sizing: border-box;
  86 + width: 45%;
  87 +
  88 + > li {
  89 + height: 89px;
  90 + line-height: 89px;
  91 + padding: 0 32px;
  92 + white-space: nowrap;
  93 + overflow: hidden;
  94 + text-overflow: ellipsis;
  95 +
  96 + &.focus {
  97 + background-color: #fff;
  98 + }
  99 +
  100 + &.highlight {
  101 + background-color: #eee;
  102 + }
  103 + }
  104 + }
  105 +
  106 + .sub-level-container {
  107 + float: left;
  108 + box-sizing: border-box;
  109 + background: #fff;
  110 + width: 55%;
  111 + height: 100%;
  112 + }
  113 +
  114 + .sub-level {
  115 + width: 100%;
  116 +
  117 + &.hide {
  118 + display: none;
  119 + }
  120 +
  121 + > li {
  122 + box-sizing: border-box;
  123 + height: 89px;
  124 + line-height: 89px;
  125 + border-bottom: 1px solid #e6e6e6;
  126 + padding-left: 20px;
  127 +
  128 + &.highlight {
  129 + background: #eee;
  130 + }
  131 +
  132 + &:last-child {
  133 + border-bottom: none;
  134 + }
  135 + }
  136 +
  137 + a {
  138 + display: block;
  139 + height: 100%;
  140 + width: 100%;
  141 + color: #000;
  142 + }
  143 + }
  144 +}
@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
21 @import "notice"; 21 @import "notice";
22 @import "fresh-only"; 22 @import "fresh-only";
23 @import "coupon"; 23 @import "coupon";
  24 +@import "cate";
24 25
25 .mobile-container { 26 .mobile-container {
26 margin-left: auto; 27 margin-left: auto;