Authored by 郝肖肖

'store-search'

... ... @@ -130,6 +130,7 @@
"yoho-lint": "^1.0.1",
"yoho-mlellipsis": "0.0.3",
"yoho-qs": "^1.0.1",
"store": "^2.0.12",
"yoho-swiper": "^3.3.1",
"yoho-swiper2": "0.0.5"
}
... ...
const store = require('store');
const expirePlugin = require('store/plugins/expire');
store.addPlugin(expirePlugin);
module.exports = {
get: (...params) => {
return store.get(...params);
},
set: (...params) => {
return store.set(...params, new Date().getTime() + 180000);
}
};
... ...
... ... @@ -11,6 +11,7 @@
const filter = require('plugin/filter');
const noResultHbs = require('product/search/no-result-new.hbs');
const lazyLoad = require('yoho-jquery-lazyload');
const cacheStore = require('./cache-store');
class ProductListWithFilter {
constructor(filterParams, searchUrl, extra) {
... ... @@ -101,6 +102,42 @@ class ProductListWithFilter {
});
}
dataRender(result) {
// 去掉正在加载
$('.search-divide').remove();
let noResult = !result || result.length < 1 || (result.list && result.list.length < 1);
// 没有结果输出没有结果页面
if (noResult) {
if (this.isScrollLoad) {
this.view.container.after(() => {
return '<div class="search-divide">没有更多内容了...</div>';
});
} else {
this.view.container.html(noResultHbs());
}
if (this.nav) {
this.nav.end = true;
}
this.onSearching = false;
return false;
}
if (this.isScrollLoad) {
this.view.container.append(result);
} else {
this.view.container.html(result);
}
lazyLoad(this.view.container.find('img[class=lazy]').not('img[src]'));
this.onSearching = false;
}
/**
* 获取商品列表
*/
... ... @@ -128,6 +165,8 @@ class ProductListWithFilter {
}
if (!this.onSearching) {
let catchKey = this.searchUrl + '?' + $.param(this.defaultOpt);
this.onSearching = true;
$.ajax({
... ... @@ -138,46 +177,24 @@ class ProductListWithFilter {
withCredentials: true
},
beforeSend: () => {
let cacheData = cacheStore.get(catchKey);
if (cacheData) {
this.dataRender(cacheData);
return false;
}
if ($('.no-result-new').length > 0) {
$('.no-result-new').remove();
}
this.view.container.after(() => {
return '<div class="search-divide">正在加载...</div>';
});
},
success: (result) => {
// 去掉正在加载
$('.search-divide').remove();
let noResult = !result || result.length < 1 || (result.list && result.list.length < 1);
// 没有结果输出没有结果页面
if (noResult) {
if (this.isScrollLoad) {
this.view.container.after(() => {
return '<div class="search-divide">没有更多内容了...</div>';
});
} else {
this.view.container.html(noResultHbs());
}
if (this.nav) {
this.nav.end = true;
}
this.onSearching = false;
return false;
}
if (this.isScrollLoad) {
this.view.container.append(result);
} else {
this.view.container.html(result);
}
lazyLoad(this.view.container.find('img[class=lazy]').not('img[src]'));
this.onSearching = false;
cacheStore.set(catchKey, result);
this.dataRender(result);
},
error: () => {
let $divide = $('.search-divide');
... ...