Merge branch 'feature/web' of http://git.dev.yoho.cn/web/yohobuy into feature/web
Showing
7 changed files
with
219 additions
and
29 deletions
@@ -2,17 +2,7 @@ | @@ -2,17 +2,7 @@ | ||
2 | <div class="commodity"> | 2 | <div class="commodity"> |
3 | 3 | ||
4 | <ul class="clearfix"> | 4 | <ul class="clearfix"> |
5 | - {{#each commodity}} | ||
6 | - <li> | ||
7 | - {{# state}} | ||
8 | - <i class="commodity-tag{{.}}"></i> | ||
9 | - {{/ state}} | ||
10 | - <a href="{{url}}"><div class="commodity-img"><img class="lazy" data-original="{{img}}"/></div> | ||
11 | - <p class="commodity-name">{{name}}</p> | ||
12 | - <p class="commodity-price"><span>¥{{price}}</span></p> | ||
13 | - </a> | ||
14 | - </li> | ||
15 | - {{/each}} | 5 | + |
16 | </ul> | 6 | </ul> |
17 | <div class="loading"> | 7 | <div class="loading"> |
18 | <p>Loading...</p> | 8 | <p>Loading...</p> |
web-static/js/common/infiniteLoad.js
0 → 100644
1 | + | ||
2 | +var $ = require('jquery'); | ||
3 | + | ||
4 | + | ||
5 | +function infiniteLoad(options) { | ||
6 | + var defaults = { | ||
7 | + index: 0, | ||
8 | + isload: true,//是否正在加载 | ||
9 | + isrun: true,//判断是否执行 | ||
10 | + offset: { | ||
11 | + height: null, | ||
12 | + width: null | ||
13 | + } | ||
14 | + }; | ||
15 | + | ||
16 | + this.registerEvent = { | ||
17 | + before: [], | ||
18 | + change: [], | ||
19 | + after: [] | ||
20 | + }; | ||
21 | + | ||
22 | + this.options = $.extend(true, {}, defaults, options); | ||
23 | + | ||
24 | + return this; | ||
25 | +} | ||
26 | + | ||
27 | +infiniteLoad.prototype.on = function(name, callback) { | ||
28 | + var g = this; | ||
29 | + var _e = g.registerEvent[name]; | ||
30 | + | ||
31 | + if (_e) { | ||
32 | + _e.push(callback); | ||
33 | + } | ||
34 | + return _e; | ||
35 | +}; | ||
36 | + | ||
37 | +infiniteLoad.prototype.off = function(name, callback) { | ||
38 | + var g = this; | ||
39 | + var _e = g.registerEvent[name]; | ||
40 | + var e = []; | ||
41 | + | ||
42 | + $.each(_e, function(name, _callback) { | ||
43 | + if (_callback === callback) { | ||
44 | + e.push(name); | ||
45 | + } | ||
46 | + }); | ||
47 | + | ||
48 | + $.each(e.reverse(), function(name, _callback) { | ||
49 | + _e.splice(_callback, 1); | ||
50 | + }); | ||
51 | +}; | ||
52 | + | ||
53 | +infiniteLoad.prototype.exect = function(key, params) { | ||
54 | + var g = this; | ||
55 | + var e; | ||
56 | + | ||
57 | + if (g.registerEvent[key] && g.registerEvent[key].length > 0) { | ||
58 | + for (e in g.registerEvent[key]) { | ||
59 | + if (g.registerEvent[key].hasOwnProperty(e)) { | ||
60 | + g.registerEvent[key][e](params); | ||
61 | + } | ||
62 | + } | ||
63 | + } | ||
64 | +}; | ||
65 | + | ||
66 | +infiniteLoad.prototype.init = function() { | ||
67 | + var g = this; | ||
68 | + var p = this.options; | ||
69 | + | ||
70 | + function __loadMore() { | ||
71 | + | ||
72 | + if (p.isload && g.__directionCalculation()) { | ||
73 | + p.isload = false; | ||
74 | + p.index++; | ||
75 | + g.exect('after', p); | ||
76 | + } | ||
77 | + | ||
78 | + g.exect('change', p); | ||
79 | + } | ||
80 | + | ||
81 | + g.exect('before', p); | ||
82 | + | ||
83 | + $(window).scroll(__loadMore); | ||
84 | +}; | ||
85 | + | ||
86 | +infiniteLoad.prototype.emit = function() { | ||
87 | + var p = this.options; | ||
88 | + | ||
89 | + p.isload = true; | ||
90 | +}; | ||
91 | + | ||
92 | +infiniteLoad.prototype.__directionCalculation = function() { | ||
93 | + var p = this.options; | ||
94 | + | ||
95 | + if (p.offset.height() > 0 && $(window).scrollTop() + $(window).height() >= p.offset.height()) { | ||
96 | + return true; | ||
97 | + } | ||
98 | + | ||
99 | + if (p.offset.width() > 0 && $(window).scrollLeft() + $(window).width() >= p.offset.width()) { | ||
100 | + return true; | ||
101 | + } | ||
102 | + return false; | ||
103 | +}; | ||
104 | + | ||
105 | +module.exports = infiniteLoad; |
web-static/js/common/newArrivls.js
0 → 100644
1 | +var $ = require('jquery'); | ||
2 | + | ||
3 | +//var Lazyload = require('yoho.lazyload'); | ||
4 | +var Handlebars = require('yoho.handlebars'); | ||
5 | +var InfiniteLoad = require('../common/infiniteLoad'); | ||
6 | + | ||
7 | +(function($) { | ||
8 | + var $container = $('div.commodity ul'); | ||
9 | + var $load = $('.loading'); | ||
10 | + var load = new InfiniteLoad({ | ||
11 | + offset: { | ||
12 | + height: function() { | ||
13 | + return parseFloat($container.offset().top) + parseFloat($container.height()); | ||
14 | + } | ||
15 | + } | ||
16 | + }); | ||
17 | + | ||
18 | + load.on('after', function(p) { | ||
19 | + var options = { | ||
20 | + type: 'POST', | ||
21 | + url: '/boys/commodity', | ||
22 | + data: { | ||
23 | + pageIndex: p.index, | ||
24 | + pageCount: 10, | ||
25 | + flag: 'boy' | ||
26 | + }, | ||
27 | + success: function(data) { | ||
28 | + var code = data.code; | ||
29 | + var myTemplate; | ||
30 | + | ||
31 | + if (code === 200) { | ||
32 | + | ||
33 | + myTemplate = Handlebars.compile(load.tpl); | ||
34 | + | ||
35 | + $container.append(myTemplate(data.commodity)); | ||
36 | + | ||
37 | + //懒加载插件貌似有点问题,图片先直接展示 | ||
38 | + //Lazyload($container.find('img.lazy')); | ||
39 | + | ||
40 | + load.emit(); | ||
41 | + } else { | ||
42 | + | ||
43 | + $load.html('END'); | ||
44 | + } | ||
45 | + }, | ||
46 | + error: function() { | ||
47 | + | ||
48 | + $load.html('网络断开连接了~'); | ||
49 | + } | ||
50 | + }; | ||
51 | + | ||
52 | + $.ajax(options); | ||
53 | + }); | ||
54 | + | ||
55 | + load.on('before', function() { | ||
56 | + | ||
57 | + //请求模板 | ||
58 | + load.tpl = '{{#each this}}'; | ||
59 | + load.tpl += '<li>'; | ||
60 | + load.tpl += ' {{# state}}'; | ||
61 | + load.tpl += ' <i class="commodity-tag{{.}}"></i>'; | ||
62 | + load.tpl += ' {{/ state}}'; | ||
63 | + load.tpl += ' <a href="{{url}}"><div class="commodity-img">'; | ||
64 | + load.tpl += ' <img class="lazy" data-original="{{img}}" src="{{img}}"/></div>'; | ||
65 | + load.tpl += ' <p class="commodity-name">{{name}}</p>'; | ||
66 | + load.tpl += ' <p class="commodity-price"><span>¥{{price}}</span></p>'; | ||
67 | + load.tpl += ' </a>'; | ||
68 | + load.tpl += '</li>'; | ||
69 | + load.tpl += '{{/each}}'; | ||
70 | + | ||
71 | + load.emit(); | ||
72 | + }); | ||
73 | + | ||
74 | + load.init(); | ||
75 | +}($)); | ||
76 | + | ||
77 | + |
@@ -9,10 +9,13 @@ var $ = require('jquery'), | @@ -9,10 +9,13 @@ var $ = require('jquery'), | ||
9 | 9 | ||
10 | require('../common/linkage-slider'); | 10 | require('../common/linkage-slider'); |
11 | require('../common/slider2'); | 11 | require('../common/slider2'); |
12 | +require('../common/newArrivls'); | ||
13 | + | ||
12 | 14 | ||
13 | $('.slide-container').linkageSlider(); | 15 | $('.slide-container').linkageSlider(); |
14 | $('.img-brand').slider2(); | 16 | $('.img-brand').slider2(); |
15 | 17 | ||
18 | + | ||
16 | $.ajax({ | 19 | $.ajax({ |
17 | type: 'GET', | 20 | type: 'GET', |
18 | url: '/boys/getBrand', | 21 | url: '/boys/getBrand', |
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | "main": "index.js", | 14 | "main": "index.js", |
15 | "dependencies": { | 15 | "dependencies": { |
16 | "jquery": "1.8.3", | 16 | "jquery": "1.8.3", |
17 | + "yoho.lazyload": "1.0.0", | ||
17 | "yoho.handlebars": "3.0.3" | 18 | "yoho.handlebars": "3.0.3" |
18 | }, | 19 | }, |
19 | "devDependencies": { | 20 | "devDependencies": { |
@@ -277,8 +277,10 @@ | @@ -277,8 +277,10 @@ | ||
277 | } | 277 | } |
278 | } | 278 | } |
279 | .tpl-category{ | 279 | .tpl-category{ |
280 | + height: 228px; | ||
280 | padding: 10px 0; | 281 | padding: 10px 0; |
281 | background-color: #f8f8f8; | 282 | background-color: #f8f8f8; |
283 | + overflow: hidden; | ||
282 | a{ | 284 | a{ |
283 | float: left; | 285 | float: left; |
284 | width: 50%; | 286 | width: 50%; |
@@ -373,7 +373,32 @@ class BoysController extends AbstractAction | @@ -373,7 +373,32 @@ class BoysController extends AbstractAction | ||
373 | 'href' => '', | 373 | 'href' => '', |
374 | 'name' => 'MORE' | 374 | 'name' => 'MORE' |
375 | ) | 375 | ) |
376 | - ), | 376 | + ) |
377 | + ) | ||
378 | + ) | ||
379 | + ); | ||
380 | + $this->_view->display('index', $data); | ||
381 | + } | ||
382 | + /** | ||
383 | + * 男装首页 新品上架 接口数据 | ||
384 | + * | ||
385 | + * @param int $pageIndex 当前页数 | ||
386 | + * @param int $pageCount 一页显示个数 | ||
387 | + * @param string flag 类型(男装/女装等,用于区分) | ||
388 | + * @return json | ||
389 | + */ | ||
390 | + public function commodityAction() | ||
391 | + { | ||
392 | + $result = array(); | ||
393 | + | ||
394 | + do { | ||
395 | + /* 判断是不是AJAX请求 */ | ||
396 | + if (!$this->isAjax()) { | ||
397 | + break; | ||
398 | + } | ||
399 | + | ||
400 | + $result=array( | ||
401 | + 'code'=>200, | ||
377 | 'commodity'=>array( | 402 | 'commodity'=>array( |
378 | array( | 403 | array( |
379 | 'url' =>'http://www.muji.com.cn/cn/store/goods/4547315967308' , | 404 | 'url' =>'http://www.muji.com.cn/cn/store/goods/4547315967308' , |
@@ -409,26 +434,12 @@ class BoysController extends AbstractAction | @@ -409,26 +434,12 @@ class BoysController extends AbstractAction | ||
409 | 'name'=> '优显led触控台灯', | 434 | 'name'=> '优显led触控台灯', |
410 | 'price'=> 168, | 435 | 'price'=> 168, |
411 | 'state'=> 1 //状态 | 436 | 'state'=> 1 //状态 |
412 | - ), | ||
413 | - array( | ||
414 | - 'url' =>'http://www.muji.com.cn/cn/store/goods/4547315967308' , | ||
415 | - 'img'=> 'http://img11.static.yhbimg.com/yhb-img01/2015/12/01/02/01c21e6610eefdc5ebd7ad890e49b09c2d.jpg', | ||
416 | - 'name'=> '优显led触控台灯', | ||
417 | - 'price'=> 168, | ||
418 | - 'state'=> 1 //状态 | ||
419 | - ), | ||
420 | - array( | ||
421 | - 'url' =>'http://www.muji.com.cn/cn/store/goods/4547315967308' , | ||
422 | - 'img'=> 'http://img11.static.yhbimg.com/yhb-img01/2015/12/01/02/01c21e6610eefdc5ebd7ad890e49b09c2d.jpg', | ||
423 | - 'name'=> '优显led触控台灯', | ||
424 | - 'price'=> 168, | ||
425 | - 'state'=> 1 //状态 | ||
426 | - ) | ||
427 | - ) | ||
428 | ) | 437 | ) |
429 | ) | 438 | ) |
430 | ); | 439 | ); |
431 | - $this->_view->display('index', $data); | 440 | + } while (false); |
441 | + | ||
442 | + $this->echoJson($result); | ||
432 | } | 443 | } |
433 | 444 | ||
434 | public function getBrandAction() | 445 | public function getBrandAction() |
@@ -693,6 +704,7 @@ class BoysController extends AbstractAction | @@ -693,6 +704,7 @@ class BoysController extends AbstractAction | ||
693 | ) | 704 | ) |
694 | ) | 705 | ) |
695 | ); | 706 | ); |
707 | + | ||
696 | $this->echoJson($data); | 708 | $this->echoJson($data); |
697 | } | 709 | } |
698 | } | 710 | } |
-
Please register or login to post a comment