Authored by 姜枫

fix list ssr

... ... @@ -46,6 +46,7 @@ if (app.locals.devEnv) {
app.use(devtools());
}
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
... ...
... ... @@ -5,18 +5,33 @@
'use strict';
const searchModel = require('../models/search');
const _ = require('lodash');
/* 搜索 页面 */
exports.index = (req, res, next) => {
const params = req.query;
params.page = 1;
params.limit = 4;
searchModel.products(params).then(result => {
let list = result && result.data ? result.data.product_list : [];
_.forEach(list, d => {
d.goodsList = d.goods_list;
d.productId = d.product_id;
d.goodsId = d.goods_id;
d.cnAlphabet = d.cn_alphabet;
_.forEach(d.goodsList, g => {
g.goodsId = g.goods_id;
});
});
res.render('product-list', {
navTitle: params.title || params.sort_name,
module: 'product',
page: 'list',
list: result && result.data ? result.data.productList : []
list: list
});
}).catch(next);
};
... ...
<div id="ssr" style="position: absolute; top: 0;">
<div id="ssr" style="position: absolute; top: 0; width: 100%;">
<div class="blk-header-wrap" class="is-fixed">
<div class="blk-header">
<div class="blk-header-left">
... ... @@ -43,19 +43,19 @@
<li class="card">
<div class="card-pic">
<a href="{{goodsUrl this}}">
<img src="{{resizeImage defaultImages 372 499}}" alt="{{productName}}">
<img src="{{resizeImage default_images 372 499}}" alt="{{product_name}}">
</a>
</div>
<div class="card-bd">
<h2 class="card-label">
<a href="{{goodsUrl this}}" class="line-clamp-2">{{productName}}</a>
<a href="{{goodsUrl this}}" class="line-clamp-2">{{product_name}}</a>
</h2>
{{#if marketPrice}}
<span class="good-price" class="old-price">
¥ {{toFixed marketPrice}}
¥ {{toFixed market_price}}
</span>
{{/if}}
<span class="good-price {{#if marketPrice}}sale-price{{/if}}">¥ {{toFixed salesPrice}}</span>
<span class="good-price {{#if market_price}}sale-price{{/if}}">¥ {{toFixed sales_price}}</span>
</div>
</li>
{{/list}}
... ...
... ... @@ -93,10 +93,10 @@
if (result.length) {
dataCache[param] = result;
}
setTimeout(()=> {
$('#ssr').remove();
}, 2000);
}, 1000);
}).fail(() => {
tip('网络错误');
});
... ...
... ... @@ -116,12 +116,11 @@
})
.always(() => {
self.inSearching = false;
// 完成后删除服务端渲染的元素
setTimeout(()=> {
$('#ssr').remove();
});
}, 500);
});
},
... ...