Authored by 陈峰

品牌搜索页pagecache

... ... @@ -70,7 +70,6 @@ let search = (req, res, next) => {
channel: req.query.channel || '1'
};
indexModel.branchSearch(param).then(result => {
res.render('brand/search', Object.assign(responseData, result));
}).catch(next);
... ... @@ -114,10 +113,26 @@ let delBrandHistory = (req, res, next) => {
res.json(result);
}).catch(next);
};
/**
* [品牌搜索异步数据]
*/
let searchAsync = (req, res, next) => {
if (!req.xhr) {
return next();
}
let uid = req.user.uid;
if (!uid) {
return res.json({code: 200, data: {}})
}
return indexModel.branchSearchHistoryAsync(uid).then((result) => {
return res.json({code: 200, data: { history: result }})
})
}
module.exports = {
index,
search,
delBrandHistory,
addBrandSearch
addBrandSearch,
searchAsync
};
... ...
... ... @@ -323,8 +323,111 @@ const branchSearchHot = () => {
});
};
// /**
// * 获取搜索的品牌列表
// *
// * @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
// * @return array
// */
// const branchSearch = (params) => {
// return api.all([
// getBrandForSearch(params.channel),
// branchSearchHistory(params),
// branchSearchHot(),
// ]).then(result => {
// let resu = {
// brandPage: true,
// showDownloadApp: true,
// pageFooter: true,
// hot: [],
// history: [],
// brandList: []
// };
// if (result && result[0] && result[0].data) {
// let brandList = result[0].data.brands;
// let obj = {};
// for (let key in brandList) {
// let build = [];
// brandList[key].forEach(row => {
// build.push({
// name: row.brand_name,
// isHot: row.is_hot === 'Y' ? true : false,
// isNew: row.is_show_new === 'Y' ? true : false,
// url: helpers.urlFormat('', null, row.brand_domain),
// brandId: row.id,
// brandDomain: row.brand_domain,
// searchName: row.brand_name_en + row.brand_name_cn
// });
// obj[key] = build;
// });
// }
// resu.brandList = JSON.stringify(obj);
// }
// if (result && result[2] && result[2].data) {
// let hotList = result[2].data;
// for (let key in hotList) {
// let obj = {};
// obj = Object.assign(obj, {name: hotList[key].brandName});
// resu.hot.push(obj);
// }
// }
// if (result && result[1] && result[1].data) {
// let hisList = result[1].data;
// let obj = [];
// let build = {
// list: []
// };
// for (let key in hisList) {
// obj.push({
// name: hisList[key].searchTerms,
// searchTime: hisList[key].searchTime
// });
// }
// build.list = obj;
// resu.history = build;
// }
// return resu;
// });
// };
/**
* 获取搜索的品牌列表
* 获取搜索的品牌列表 pagecache重构
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
... ... @@ -333,7 +436,7 @@ const branchSearch = (params) => {
return api.all([
getBrandForSearch(params.channel),
branchSearchHistory(params),
// branchSearchHistory(params),
branchSearchHot(),
]).then(result => {
... ... @@ -379,9 +482,9 @@ const branchSearch = (params) => {
}
if (result && result[2] && result[2].data) {
if (result && result[1] && result[1].data) {
let hotList = result[2].data;
let hotList = result[1].data;
for (let key in hotList) {
... ... @@ -395,32 +498,32 @@ const branchSearch = (params) => {
}
if (result && result[1] && result[1].data) {
// if (result && result[1] && result[1].data) {
let hisList = result[1].data;
// let hisList = result[1].data;
let obj = [];
// let obj = [];
let build = {
// let build = {
list: []
// list: []
};
// };
for (let key in hisList) {
// for (let key in hisList) {
obj.push({
name: hisList[key].searchTerms,
searchTime: hisList[key].searchTime
});
// obj.push({
// name: hisList[key].searchTerms,
// searchTime: hisList[key].searchTime
// });
}
// }
build.list = obj;
// build.list = obj;
resu.history = build;
// resu.history = build;
}
// }
return resu;
... ... @@ -439,10 +542,40 @@ const delBrandSearchHistory = (param) => {
});
};
/**
* [异步获取用户最近搜索词]
*/
const branchSearchHistoryAsync = (uid) => {
return branchSearchHistory({uid}).then((result) => {
let hisList = result.data;
let obj = [];
let build = {
list: []
};
for (let key in hisList) {
obj.push({
name: hisList[key].searchTerms,
searchTime: hisList[key].searchTime
});
}
build.list = obj;
return build;
});
}
module.exports = {
getBrandByChannel,
branchSearch,
delBrandSearchHistory,
addSearchHistory
addSearchHistory,
branchSearchHistoryAsync
};
... ...
... ... @@ -23,6 +23,7 @@ router.get('/channel/bottomBanner', channel.bottomBanner);
router.get('/brands', brandController.index); // 品牌首页
router.get('/brands/search', brandController.search); // 品牌搜索页
router.post('/brands/searchAsync', brandController.searchAsync); // 品牌搜索异步数据
router.post('/brands/addBrandSearch', brandController.addBrandSearch); // 添加品牌搜索记录
router.get('/brands/delBrandHistory', brandController.delBrandHistory); // 删除品牌搜索记录
... ...
... ... @@ -15,21 +15,15 @@
<div class="search-brand-page">
<div class="search-items">
{{#if history}}
<div class="net-history hide">
<div class="history-search net-search hide">
<ul class="history clearfix net">
{{# history}}
{{# list}}
<li>
<a href="{{url}}" brandName="{{name}}" collectTime="{{searchTime}}">{{name}}</a>
</li>
{{/ list}}
{{/ history}}
</ul>
</div>
</div>
{{/if}}
<div class="history-search local-search">
<h3><span class="iconfont left-icon">&#xe64a;</span>最近搜索
<button id="clear-history" class="clear-icon iconfont">&#xe64c;</button>
... ...
... ... @@ -16,9 +16,9 @@ module.exports = {
siteUrl: '//m.yohobuy.com',
assetUrl: '//localhost:5001',
domains: {
api: 'http://api.yoho.yohoops.org/',
service: 'http://service.yoho.yohoops.org/',
liveApi: 'http://api.live.yoho.cn/'
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
liveApi: 'http://testapi.live.yohops.com:9999/'
},
subDomains: {
host: '.m.yohobuy.com',
... ...
... ... @@ -187,7 +187,7 @@ gulp.task('webpack-dev-server', () => {
new WebpackDevServer(webpack(devConfig), {
contentBase: '.',
publicPath: '//localhost:5001/',
publicPath: 'http://localhost:5001/',
hot: true,
stats: {
colors: true
... ...
var $ = require('yoho-jquery'),
dbClass = 'data-bind';
module.exports = function(callback) {
$.ajax({
type: 'POST',
url: '/brands/searchAsync',
success: function(data) {
render(data.data);
callback && callback(data);
}
});
};
function render(data) {
console.log(data)
if (data.history && data.history.list && data.history.list.length) {
var hisEl = $('.history>li').remove();
$.each(data.history.list, function(i, his) {
var itemEl = hisEl.clone();
itemEl.find('a')
.attr('href', his.url)
.attr('brandName', his.name)
.attr('collectTime', his.searchTime)
.text(his.name);
$('.history').append(itemEl);
})
$('.net-history').removeClass(dbClass);
} else {
$('.net-history').remove();
}
}
\ No newline at end of file
... ...
... ... @@ -430,9 +430,9 @@ function removeHistory() {
}
// 初始化历史搜索的内容
if ($('.brand-search-page').length > 0) {
require('./brand-render')(function() {
$netHistory = $('.net-history')
if ($('.brand-search-page').length > 0) {
chHammer = new Hammer($clearHistory[0]);
chHammer.on('tap', function() {
if (isLocalStorageSupported()) {
... ... @@ -571,4 +571,6 @@ if ($('.brand-search-page').length > 0) {
}());
}
}
})
... ...
.data-bind {
display: none;
}
\ No newline at end of file
... ...