Authored by ccbikai

函数修改

@@ -9,7 +9,7 @@ const _ = require('lodash'); @@ -9,7 +9,7 @@ const _ = require('lodash');
9 const channelModel = require('../models/channel'); 9 const channelModel = require('../models/channel');
10 const helpers = require(`${library}/helpers`); 10 const helpers = require(`${library}/helpers`);
11 11
12 -const renderData = { 12 +let _renderData = {
13 module: 'channel', 13 module: 'channel',
14 page: 'home', 14 page: 'home',
15 homeHeader: { 15 homeHeader: {
@@ -33,19 +33,19 @@ const renderData = { @@ -33,19 +33,19 @@ const renderData = {
33 * @param {[object]} data 自定义数据 33 * @param {[object]} data 自定义数据
34 * @return {[type]} 34 * @return {[type]}
35 */ 35 */
36 -const channelPage = (req, res, data) => { 36 +let _channelPage = (req, res, data) => {
37 return channelModel.getChannelData({ // TODO 内部的Promise方法必须 return 出来 37 return channelModel.getChannelData({ // TODO 内部的Promise方法必须 return 出来
38 gender: data.gender, 38 gender: data.gender,
39 uid: _.toString(req.user.uid) 39 uid: _.toString(req.user.uid)
40 }).then(result => { 40 }).then(result => {
41 - res.render('channel', Object.assign({}, renderData, data, result)); 41 + res.render('channel', Object.assign({}, _renderData, data, result));
42 }); 42 });
43 }; 43 };
44 44
45 /** 45 /**
46 * 频道选择页 46 * 频道选择页
47 */ 47 */
48 -exports.index = (req, res, next) => { 48 +let index = (req, res, next) => {
49 channelModel.getChannelSwitchData().then((result) => { 49 channelModel.getChannelSwitchData().then((result) => {
50 res.render('index', { 50 res.render('index', {
51 module: 'channel', 51 module: 'channel',
@@ -67,7 +67,7 @@ exports.index = (req, res, next) => { @@ -67,7 +67,7 @@ exports.index = (req, res, next) => {
67 * @param {Function} next 67 * @param {Function} next
68 * @return {Function} 68 * @return {Function}
69 */ 69 */
70 -exports.switchChannel = (req, res, next) => { 70 +let switchChannel = (req, res, next) => {
71 let channel = req.cookies._Channel; 71 let channel = req.cookies._Channel;
72 72
73 // 如果查询字符串设置了 go 参数,跳转到 cookie 中设置的频道页 73 // 如果查询字符串设置了 go 参数,跳转到 cookie 中设置的频道页
@@ -83,8 +83,8 @@ exports.switchChannel = (req, res, next) => { @@ -83,8 +83,8 @@ exports.switchChannel = (req, res, next) => {
83 /** 83 /**
84 * 男生首页 84 * 男生首页
85 */ 85 */
86 -exports.boys = (req, res, next) => {  
87 - channelPage(req, res, { 86 +let boys = (req, res, next) => {
  87 + _channelPage(req, res, {
88 gender: 'boys', 88 gender: 'boys',
89 title: '男生首页', 89 title: '男生首页',
90 boysHomePage: true 90 boysHomePage: true
@@ -94,8 +94,8 @@ exports.boys = (req, res, next) => { @@ -94,8 +94,8 @@ exports.boys = (req, res, next) => {
94 /** 94 /**
95 * 女生首页 95 * 女生首页
96 */ 96 */
97 -exports.girls = (req, res, next) => {  
98 - channelPage(req, res, { 97 +let girls = (req, res, next) => {
  98 + _channelPage(req, res, {
99 gender: 'girls', 99 gender: 'girls',
100 title: '女生首页', 100 title: '女生首页',
101 girlsHomePage: true 101 girlsHomePage: true
@@ -106,8 +106,8 @@ exports.girls = (req, res, next) => { @@ -106,8 +106,8 @@ exports.girls = (req, res, next) => {
106 * 潮童首页 106 * 潮童首页
107 */ 107 */
108 108
109 -exports.kids = (req, res, next) => {  
110 - channelPage(req, res, { 109 +let kids = (req, res, next) => {
  110 + _channelPage(req, res, {
111 gender: 'kids', 111 gender: 'kids',
112 title: '潮童首页', 112 title: '潮童首页',
113 kidsHomePage: true 113 kidsHomePage: true
@@ -117,8 +117,8 @@ exports.kids = (req, res, next) => { @@ -117,8 +117,8 @@ exports.kids = (req, res, next) => {
117 /** 117 /**
118 * 创意生活首页 118 * 创意生活首页
119 */ 119 */
120 -exports.lifestyle = (req, res, next) => {  
121 - channelPage(req, res, { 120 +let lifestyle = (req, res, next) => {
  121 + _channelPage(req, res, {
122 gender: 'lifestyle', 122 gender: 'lifestyle',
123 title: '创意生活首页', 123 title: '创意生活首页',
124 lifestyleHomePage: true 124 lifestyleHomePage: true
@@ -131,10 +131,20 @@ exports.lifestyle = (req, res, next) => { @@ -131,10 +131,20 @@ exports.lifestyle = (req, res, next) => {
131 * @param {[object]} res 131 * @param {[object]} res
132 * @return {[type]} 132 * @return {[type]}
133 */ 133 */
134 -exports.bottomBanner = (req, res, next) => { 134 +let bottomBanner = (req, res, next) => {
135 let gender = req.query.gender || 'boys'; 135 let gender = req.query.gender || 'boys';
136 136
137 channelModel.getBottomBannerData(gender).then(result => { 137 channelModel.getBottomBannerData(gender).then(result => {
138 res.send(result); 138 res.send(result);
139 }).catch(next); 139 }).catch(next);
140 }; 140 };
  141 +
  142 +module.exports = {
  143 + switchChannel,
  144 + index,
  145 + boys,
  146 + girls,
  147 + kids,
  148 + lifestyle,
  149 + bottomBanner
  150 +};
@@ -9,7 +9,6 @@ const utils = '../../../utils'; @@ -9,7 +9,6 @@ const utils = '../../../utils';
9 const contentCodeConfig = require('../../../config/content-code'); 9 const contentCodeConfig = require('../../../config/content-code');
10 const _ = require('lodash'); 10 const _ = require('lodash');
11 const ServiceAPI = require(`${library}/api`).ServiceAPI; 11 const ServiceAPI = require(`${library}/api`).ServiceAPI;
12 -const sign = require(`${library}/sign`);  
13 const camelCase = require(`${library}/camel-case`); 12 const camelCase = require(`${library}/camel-case`);
14 const logger = require(`${library}/logger`); 13 const logger = require(`${library}/logger`);
15 const resourcesProcess = require(`${utils}/resources-process`); 14 const resourcesProcess = require(`${utils}/resources-process`);
@@ -67,7 +66,7 @@ const channelList = [ @@ -67,7 +66,7 @@ const channelList = [
67 * @param {[string]} choosed 66 * @param {[string]} choosed
68 * @return {[string]} 67 * @return {[string]}
69 */ 68 */
70 -const getSidebarColor = (choosed) => { 69 +const _getSidebarColor = (choosed) => {
71 let color = false; 70 let color = false;
72 71
73 if (choosed === 'girls') { 72 if (choosed === 'girls') {
@@ -86,7 +85,7 @@ const getSidebarColor = (choosed) => { @@ -86,7 +85,7 @@ const getSidebarColor = (choosed) => {
86 * @param {[array]} list 85 * @param {[array]} list
87 * @return {[array]} 86 * @return {[array]}
88 */ 87 */
89 -const processSideBar = (list, choosed) => { 88 +const _processSideBar = (list, choosed) => {
90 const formatData = []; 89 const formatData = [];
91 let offset = 0; // 分割数组用到的游标 90 let offset = 0; // 分割数组用到的游标
92 91
@@ -100,7 +99,7 @@ const processSideBar = (list, choosed) => { @@ -100,7 +99,7 @@ const processSideBar = (list, choosed) => {
100 sortNameEn: item.sortNameEn, 99 sortNameEn: item.sortNameEn,
101 back: true, 100 back: true,
102 isSelect: false, 101 isSelect: false,
103 - bgColor: getSidebarColor(choosed) 102 + bgColor: _getSidebarColor(choosed)
104 }); 103 });
105 } 104 }
106 105
@@ -121,7 +120,7 @@ const processSideBar = (list, choosed) => { @@ -121,7 +120,7 @@ const processSideBar = (list, choosed) => {
121 * @param {[object]} gender 120 * @param {[object]} gender
122 * @return {[type]} 121 * @return {[type]}
123 */ 122 */
124 -const getChannelResource = (params) => { 123 +const _getChannelResource = (params) => {
125 params.gender = params.gender || 'boys'; 124 params.gender = params.gender || 'boys';
126 125
127 params = Object.assign({ 126 params = Object.assign({
@@ -134,7 +133,7 @@ const getChannelResource = (params) => { @@ -134,7 +133,7 @@ const getChannelResource = (params) => {
134 params.new_device = true; // eslint-disable-line 133 params.new_device = true; // eslint-disable-line
135 } 134 }
136 135
137 - return api.get('operations/api/v5/resource/home', sign.apiSign(params), true).then(result => { 136 + return api.get('operations/api/v5/resource/home', params, true).then(result => {
138 if (result && result.code === 200) { 137 if (result && result.code === 200) {
139 return resourcesProcess(result.data.list); 138 return resourcesProcess(result.data.list);
140 } else { 139 } else {
@@ -149,12 +148,12 @@ const getChannelResource = (params) => { @@ -149,12 +148,12 @@ const getChannelResource = (params) => {
149 * @param {[string]} choosed 148 * @param {[string]} choosed
150 * @return {[object]} 149 * @return {[object]}
151 */ 150 */
152 -const getLeftNav = (choosed) => { 151 +const _getLeftNav = (choosed) => {
153 choosed = choosed || 'all'; 152 choosed = choosed || 'all';
154 153
155 - return api.get('operations/api/v6/category/getCategory', sign.apiSign({}), true).then(result => { 154 + return api.get('operations/api/v6/category/getCategory', {}, true).then(result => {
156 if (result && result.code === 200) { 155 if (result && result.code === 200) {
157 - return processSideBar(result.data, choosed); 156 + return _processSideBar(result.data, choosed);
158 } else { 157 } else {
159 logger.error('侧边栏数据接口返回状态码 不是 200'); 158 logger.error('侧边栏数据接口返回状态码 不是 200');
160 return result; 159 return result;
@@ -166,8 +165,8 @@ const getLeftNav = (choosed) => { @@ -166,8 +165,8 @@ const getLeftNav = (choosed) => {
166 * 获取频道选择页数据 165 * 获取频道选择页数据
167 * @return {[type]} 166 * @return {[type]}
168 */ 167 */
169 -const getChannelList = () => {  
170 - return api.get('operations/api/v5/entrance/getEntrance', sign.apiSign({}), true).then((result) => { 168 +const _getChannelList = () => {
  169 + return api.get('operations/api/v5/entrance/getEntrance', {}, true).then((result) => {
171 if (result && result.code === 200) { 170 if (result && result.code === 200) {
172 const list = {}; 171 const list = {};
173 172
@@ -199,10 +198,10 @@ const getChannelList = () => { @@ -199,10 +198,10 @@ const getChannelList = () => {
199 * 获取频道选择页 背景 198 * 获取频道选择页 背景
200 * @return {[type]} 199 * @return {[type]}
201 */ 200 */
202 -const getChannelBg = () => {  
203 - return api.get('operations/api/v5/resource/get', sign.apiSign({ 201 +const _getChannelBg = () => {
  202 + return api.get('operations/api/v5/resource/get', {
204 content_code: contentCode.index 203 content_code: contentCode.index
205 - }), true).then(result => { 204 + }, true).then(result => {
206 if (result && result.code === 200) { 205 if (result && result.code === 200) {
207 return result.data.length && result.data[0] && result.data[0].data && result.data[0].data.list[0]; 206 return result.data.length && result.data[0] && result.data[0].data && result.data[0].data.list[0];
208 } else { 207 } else {
@@ -219,8 +218,8 @@ const getChannelBg = () => { @@ -219,8 +218,8 @@ const getChannelBg = () => {
219 * @param {[string]} gender 218 * @param {[string]} gender
220 * @return {[type]} 219 * @return {[type]}
221 */ 220 */
222 -exports.getChannelSwitchData = () => {  
223 - return Promise.all([getChannelList(), getChannelBg()]); 221 +let getChannelSwitchData = () => {
  222 + return Promise.all([_getChannelList(), _getChannelBg()]);
224 }; 223 };
225 224
226 /** 225 /**
@@ -228,10 +227,10 @@ exports.getChannelSwitchData = () => { @@ -228,10 +227,10 @@ exports.getChannelSwitchData = () => {
228 * @param {[object]} params 227 * @param {[object]} params
229 * @return {[object]} 228 * @return {[object]}
230 */ 229 */
231 -exports.getChannelData = (params) => { 230 +let getChannelData = (params) => {
232 var channelData = {}; 231 var channelData = {};
233 232
234 - return Promise.all([getChannelResource(params), getLeftNav(params.gender)]).then((data) => { 233 + return Promise.all([_getChannelResource(params), _getLeftNav(params.gender)]).then((data) => {
235 channelData.content = data[0]; // 资源位数据 234 channelData.content = data[0]; // 资源位数据
236 channelData.sideNav = data[1]; // 侧边栏数据 235 channelData.sideNav = data[1]; // 侧边栏数据
237 236
@@ -244,13 +243,13 @@ exports.getChannelData = (params) => { @@ -244,13 +243,13 @@ exports.getChannelData = (params) => {
244 * @param {[string]} gender 243 * @param {[string]} gender
245 * @return {[type]} 244 * @return {[type]}
246 */ 245 */
247 -exports.getBottomBannerData = (gender) => { 246 +let getBottomBannerData = (gender) => {
248 gender = gender || 'boys'; 247 gender = gender || 'boys';
249 248
250 if (gender === 'boys' || gender === 'girls') { 249 if (gender === 'boys' || gender === 'girls') {
251 - return api.get('operations/api/v5/resource/get', sign.apiSign({ 250 + return api.get('operations/api/v5/resource/get', {
252 content_code: bottomBannerCode[gender] // eslint-disable-line 251 content_code: bottomBannerCode[gender] // eslint-disable-line
253 - }), true); 252 + }, true);
254 } 253 }
255 return Promise.resolve({ 254 return Promise.resolve({
256 code: 400, 255 code: 400,
@@ -258,3 +257,9 @@ exports.getBottomBannerData = (gender) => { @@ -258,3 +257,9 @@ exports.getBottomBannerData = (gender) => {
258 message: '参数错误' 257 message: '参数错误'
259 }); 258 });
260 }; 259 };
  260 +
  261 +module.exports = {
  262 + getChannelData,
  263 + getChannelSwitchData,
  264 + getBottomBannerData
  265 +};