router.js
4.89 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
149
150
151
152
153
154
155
156
157
/**
* router of sub app product
* @author: weiqingting<qingting.wei@yoho.cn>
* @date: 2016/05/06
*/
'use strict';
const express = require('express');
const router = express.Router(); // eslint-disable-line
const cRoot = './controllers';
const headerModel = require('../../doraemon/models/header');
const _ = require('lodash');
const helpers = global.yoho.helpers;
// const config = global.yoho.config;
const commentController = require(`${cRoot}/comment`);
const consultController = require(`${cRoot}/consult`);
const returnsController = require(`${cRoot}/returns`);
const IndexController = require(`${cRoot}/Index`);
const CurrencyController = require(`${cRoot}/Currency`);
const personalController = require(`${cRoot}/qrcode`);
const RedenvelopesController = require(`${cRoot}/Redenvelopes`);
const VipController = require(`${cRoot}/vip`);
const FavoriteController = require(`${cRoot}/Favorite`);
const CouponsController = require(`${cRoot}/coupons`);
const UserController = require(`${cRoot}/user`);
const homeNav = [
{
title: '交易管理',
subNav: [
{name: '我的订单', href: '/home/orders', catchs: ['/home/orders', '/home/index']},
{name: '我的收藏', href: '/home/favorite'},
{name: '我的YOHO币', href: '/home/currency'},
{name: '我的红包', href: '/home/redenvelopes'},
{name: '我的优惠券', href: '/home/coupons'},
{name: '我的VIP', href: '/home/vip'}
]
},
{
title: '服务中心',
subNav: [
{name: '我的退/换货', href: '/home/returns'},
{name: '我的咨询', href: '/home/consult'},
{name: '我的评论', href: '/home/comment'},
{name: '我的投诉', href: '/home/complaints'},
{name: '我的信息', href: '/home/message', count: 0},
{name: '在线客服', href: 'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409&info=', isBlank: true}
]
},
{
title: '个人信息管理',
subNav: [
{name: '编辑个人资料', href: '/home/user'},
{name: '账号安全', href: '/home/account'},
{name: '地址管理', href: '/home/address'},
{name: '兑换礼品卡', href: '/home/gift'}
]
}
];
const getActiveNav = (req)=>{
return homeNav.map((item)=>{
item.subNav = item.subNav.map((nav)=>{
if (nav.catchs) {
console.log(nav.catchs);
if (nav.catchs.indexOf(req.originalUrl) > -1) {
nav.active = true;
}
} else {
if (req.originalUrl === nav.href) {
nav.active = true;
}
}
nav.href = nav.href.indexOf('http://') > -1 ? nav.href : helpers.urlFormat(nav.href);
return nav;
});
return item;
});
};
const getHomeNav = (req, res, next) => {
res.locals.path = [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}, {name: '个人中心'}];
res.locals.homeNav = getActiveNav(req);
res.locals.userThumb = `//img10.static.yhbimg.com/headimg/
2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100`;
next();
};
const getCommonHeader = (req, res, next) => {
let channel = req.query.channel ? req.query.channel : 'boys';
headerModel.requestHeaderData(channel).then((result)=>{
_.merge(res.locals, result);
next();
});
};
/* const sessionEffective = (req, res, next) => {
let refer = req.cookies.refer;
if (req.user.uid) {
next();
return;
}
if (refer) {
refer = decodeURI(req.cookies.refer);
} else {
refer = config.siteUrl;
}
res.redirect(helpers.urlFormat('/signin.html', {
refer: refer
}));
// next();
};*/
// 查看二维码
router.get('/QRcode', [getCommonHeader, getHomeNav], personalController.QRcode);
// 我的评论
router.get('/comment', commentController.index);
router.post('/comment/saveComment', commentController.saveComment);
// 我的咨询
router.get('/consult', consultController.index);
// 我的退/换货
router.get('/returns', returnsController.index);
// // 地址管理
// router.get('address', addressController.index);
// router.get('address/area', addressController.area);
router.get('/index', [getCommonHeader, getHomeNav], IndexController.index);
router.get('/currency', CurrencyController.index);
/* 我的红包*/
router.get('/redenvelopes', RedenvelopesController.index);
/* 我的VIP*/
router.get('/vip', VipController.index);
router.get('/user', UserController.index);
router.get('/favorite', FavoriteController.index);
router.get('/coupons', CouponsController.index);
module.exports = router;