Authored by 毕凯

修改楼层数据结构

... ... @@ -57,5 +57,5 @@ exports.boys = (req, res) => {
showFooterTab: footerTab,
pageFooter: true
}, result));
}).catch(console.error);
}).catch(console.trace);
};
... ...
... ... @@ -21,31 +21,19 @@ const contentCode = {
girl: '8512bf0755cc549ac323f852c9fd945d'
};
const processFloor = (list) => {
const formatData = {};
list = list || [];
_.forEach(list, (floor) => {
// FIXME 楼层数据处理有问题
formatData[_.camelCase(floor.template_name)] = floor.data; // 接口数据格式化,键使用驼峰写法
});
return formatData;
};
/**
* 获取二级菜单顶部颜色
* @param {[string]} guangChoosed
* @param {[string]} choosed
* @return {[string]}
*/
const getSidebarColor = (guangChoosed) => {
const getSidebarColor = (choosed) => {
let color = false;
if (guangChoosed === 'girls') {
if (choosed === 'girls') {
color = '#FF88AE';
} else if (guangChoosed === 'kids') {
} else if (choosed === 'kids') {
color = '#7ad9f9';
} else if (guangChoosed === 'lifestyle') {
} else if (choosed === 'lifestyle') {
color = '#4f4138';
}
... ... @@ -61,23 +49,18 @@ const processSideBar = (list, choosed) => {
const formatData = [];
let offset = 0; // 分割数组用到的游标
_.forEach(list, (item, i) => {
item = camelCase.listCamelCase(item);
list = list || [];
list = camelCase(list);
_.forEach(list, (item, i) => {
if (item.sub) {
let sub = [{
item.sub.unshift({
sortName: item.sortName,
sortNameEn: item.sortNameEn,
back: true,
isSelect: false,
bgColor: getSidebarColor(choosed)
}];
_.forEach(item.sub, (s) => {
s = camelCase.listCamelCase(s); // 子菜单键名驼峰化
sub.push(s);
});
item.sub = sub;
}
// 如果有分隔符,分割数组
... ... @@ -93,8 +76,29 @@ const processSideBar = (list, choosed) => {
};
/**
* 获取频道页面资源位
*/
* 处理楼层数据
* @param {[array]} list
* @return {[array]}
*/
const processFloor = (list) => {
const formatData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, (floor) => {
floor[_.camelCase(floor.templateName)] = true;
formatData.push(floor);
});
return formatData;
};
/**
* 获取频道页面资源位
* @param {[object]} gender
* @return {[type]}
*/
const getChannelResource = (gender) => {
gender = gender || 'boy';
... ... @@ -115,6 +119,11 @@ const getChannelResource = (gender) => {
});
};
/**
* 获取左侧边栏数据
* @param {[string]} choosed
* @return {[object]}
*/
const getLeftNav = (choosed) => {
choosed = choosed || 'all';
... ...
... ... @@ -3,34 +3,38 @@
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
const _ = require('lodash');
/**
* 对象键值驼峰化(未测试)
* @param {[object]} obj
* @return {[object]}
*/
const camelCase = (obj) => {
_.forEach(obj, (k) => {
obj[_.camelCase(k)] = obj[k]; // 下划线变量名转换为驼峰
});
let camelCase,
camelCaseObject,
camelCaseArray;
camelCaseObject = (obj) => {
_.forEach(Object.keys(obj), (k) => {
obj[k] = camelCase(obj[k]);
obj[_.camelCase(k)] = obj[k];
});
return obj;
};
/**
* 对象数组,对象键值驼峰化
* @param {[type]} list
* @return {[type]}
*/
const listCamelCase = (list) => {
_.forEach(Object.keys(list), (k) => {
list[_.camelCase(k)] = list[k]; // 下划线变量名转换为驼峰
camelCaseArray = (list) => {
_.forEach(list, (k) => {
k = camelCase(k);
});
return list;
};
exports.camelCase = camelCase;
exports.listCamelCase = listCamelCase;
camelCase = (data) => {
if (_.isObject(data)) {
data = camelCaseObject(data);
}
if (_.isArray(data)) {
data = camelCaseArray(data);
}
return data;
};
module.exports = camelCase;
... ...
... ... @@ -18,6 +18,7 @@ const config = require('../config/common');
*/
exports.image = (url, width, height, mode) => {
mode = _.isNumber(mode) ? mode : 2;
url = url || '';
return url.replace(/{width}/g, width).replace(/{height}/g, height).replace(/{mode}/g, mode);
};
... ...