menu-crumb-handler.js
2.2 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
/**
* 个人中心布局(顶部面包屑和左侧导航)
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/7/5
*/
'use strict';
const _ = require('lodash');
const blk = global.yoho;
const url = blk.helpers.urlFormat;
const meCode = require('../../../config/channel-type').meCode;
const api = global.yoho.ServiceAPI;
// 获取个人中心资源位
const getMeThumb = () => {
const data = {
client_type: 'web',
content_code: meCode
};
return api.get('operations/api/v5/resource/home', data, {
cache: true,
code: 200
}).then(result => {
const obj = _.get(result, 'data.list[0].data[0]', {});
if (result.data) {
return {
banner: result.data.list[0].data[0].src,
url: result.data.list[0].data[0].url
};
}
return {
banner: obj.src || '',
url: obj.url || ''
};
});
};
// 左侧菜单
const navigation = [
{
link: url('/me/order'),
name: '我的订单'
},
{
link: url('/me/return'),
name: '我的退/换货'
},
{
link: url('/me/collection'),
name: '我的收藏'
},
{
link: url('/me/currency'),
name: '我的YOHO币'
},
{
link: url('/me/setting'),
name: '个人设置'
},
{
link: url('/me/address'),
name: '收货地址'
}
];
// 头部导航面包屑
const getMeCrumb = name => {
return [
{
link: blk.config.siteUrl,
name: 'YOHO!BLK首页'
},
{
link: url('/me'),
name: '个人中心'
},
{
name: name ? name : '我的订单'
}
];
};
// 侧栏菜单
const getSideMenu = focus => {
let copiedNav = _.cloneDeep(navigation);
if (focus && _.some(copiedNav, {name: focus})) {
Object.assign(_.find(copiedNav, {name: focus}), {
focus: true
});
} else {
// 若没有传focus || focus不在navigation中,则默认focus第1个菜单
copiedNav[0].focus = true;
}
return copiedNav;
};
module.exports = {
getMeCrumb,
getMeThumb,
getSideMenu
};