ps.js
4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* plus/star页控制器文件
* @author: xuqi(qi.xu@yoho.cn)
* @date: 2015/4/15
*/
var data = require('../../public/js/data'),
ps = data('ps'),
list = data('ps-list'),
path = require('path'),
fs = require('fs'),
tabpage = require('../../public/js/data_tabpage')('temp'),
original = require('../../public/js/data_tabpage')('original'),
newtagpage = require('../../public/js/data_newtabpage')(),
tplPath = path.normalize(path.join(__dirname, '../partials/ps/info-item.html'));
function clone(myObj) {
if (typeof(myObj) != 'object') return myObj;
if (myObj == null) return myObj;
var myNewObj = new Object();
for (var i in myObj)
myNewObj[i] = clone(myObj[i]);
return myNewObj;
}
exports.show = function(req, res) {
res.render('pages/ps', {
data: ps,
layout: '../layouts/layout',
isPs: true,
isLogin: 'Y'
});
};
exports.readTpl = function(req, res) {
fs.readFile(tplPath, 'utf8', function(err, data) {
if (err) {
res.send({
success: false
});
}
fs.readFile(
path.normalize(path.join(__dirname, '../partials/common/time-view-like-share.html')),
'utf8',
function(err, subData) {
if (err) {
res.send({
success: false
});
}
data = data.replace('{{> common/time_view_like_share}}', subData); //Note: 后端需将partials目录替换为内容
res.send(data);
});
});
};
exports.tabPageNew = function(req, res) {
var obj = {};
obj.global_fetchdataurl = 'getBrand';
obj.global_brandcat = '1';
obj.global_showpannel = 'showpannel1';
obj.global_totalcount = 20;
res.render('pages/ps-newtabpage', {
data: newtagpage,
globalConfig: obj,
layout: '../layouts/layout',
isNewTabPage: true
});
}
/**
* 首次跳转
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.tabPage = function(req, res) {
var obj = {};
obj.global_fetchdataurl = 'getBrand';
obj.global_brandcat = '1';
obj.global_showpannel = 'showpannel1';
var data = tabpage[2].starinner;
var renddata = data[0].brandList;
obj.global_totalcount = original[2].starinner[0].brandList.length;
var responsedata = renddata.slice(0, 10);
tabpage[2].starinner[0].brandList = responsedata;
tabpage[2].starinner[1].brandList = [];
res.render('pages/ps-tabpage', {
data: tabpage,
globalConfig: obj,
layout: '../layouts/layout',
isTabPage: true
});
}
/**
* 异步获取数据
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.getBrand = function(req, res) {
var obj = {};
var data = original[2].starinner;
var start = parseInt(req.body.start);
var count = parseInt(req.body.count);
var catid = parseInt(req.body.brandcat);
var renddata = data[catid - 1].brandList;
var totalcount = data[catid - 1].brandList.length;
var end = start + count;
if (end > totalcount) {
end = totalcount;
}
var responsedata = renddata.slice(start, end);
obj.code = 200,
obj.message = 'ok',
obj.data = {
brandList: responsedata,
total: totalcount
};
res.send(obj);
}
/**
* 渲染模板
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.psTmplage = function(req, res) {
var temp = '{{#brandList}}' +
'<div class="swiper-container swiper-container{{subId}}" id="{{subId}}">' +
'<div class="swiper-wrapper">' +
'{{# imgList}}' +
'<div class="swiper-slide branddetail">' +
'<a href="{{url}}">' +
'<img data-src="{{src}}" class="img" src="{{src}}"/>' +
'</a>' +
'</div>' +
'{{/imgList}}' +
'</div>' +
'<div class="swiper-pagination swiper-pagination{{subId}}"></div>' +
'</div>' +
'{{/brandList}}';
res.send(temp);
}
exports.list = function(req, res) {
res.render('pages/ps-list', {
data: list,
layout: '../layouts/layout',
isPsList: true
});
};