Showing
5 changed files
with
14 additions
and
45 deletions
@@ -23,6 +23,7 @@ const memcached = require('connect-memcached'); | @@ -23,6 +23,7 @@ const memcached = require('connect-memcached'); | ||
23 | const pkg = require('./package.json'); | 23 | const pkg = require('./package.json'); |
24 | const devtools = require('./doraemon/middleware/devtools'); | 24 | const devtools = require('./doraemon/middleware/devtools'); |
25 | 25 | ||
26 | +const uuid = require('uuid'); | ||
26 | const app = express(); | 27 | const app = express(); |
27 | const MemcachedStore = memcached(session); | 28 | const MemcachedStore = memcached(session); |
28 | 29 | ||
@@ -82,6 +83,9 @@ app.use((req, res, next) => { | @@ -82,6 +83,9 @@ app.use((req, res, next) => { | ||
82 | req.user = {}; // 全局的用户数据 | 83 | req.user = {}; // 全局的用户数据 |
83 | req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等 | 84 | req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等 |
84 | 85 | ||
86 | + if (!req.sessionID) { | ||
87 | + req.sessionID = uuid.v4(); | ||
88 | + } | ||
85 | next(); | 89 | next(); |
86 | }); | 90 | }); |
87 | 91 |
@@ -7,25 +7,6 @@ | @@ -7,25 +7,6 @@ | ||
7 | const homeModel = require('../models/index'); | 7 | const homeModel = require('../models/index'); |
8 | const helpers = global.yoho.helpers; | 8 | const helpers = global.yoho.helpers; |
9 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
10 | -const md5 = require('md5'); | ||
11 | -const requestIp = require('request-ip'); | ||
12 | - | ||
13 | -/** | ||
14 | - * 获取客户端唯一标识 | ||
15 | - * @return string | ||
16 | - */ | ||
17 | -const getUdid = (req, res) => { | ||
18 | - let udid = req.cookies.udid; | ||
19 | - | ||
20 | - if (!udid) { | ||
21 | - udid = md5(req.ip || requestIp.getClientIp(req)); | ||
22 | - | ||
23 | - if (res && res.cookie) { | ||
24 | - res.cookie('udid', udid); | ||
25 | - } | ||
26 | - } | ||
27 | - return udid; | ||
28 | -}; | ||
29 | 10 | ||
30 | /** | 11 | /** |
31 | * 个人中心主页 | 12 | * 个人中心主页 |
@@ -235,7 +216,7 @@ const component = { | @@ -235,7 +216,7 @@ const component = { | ||
235 | message: 'not login' | 216 | message: 'not login' |
236 | }); | 217 | }); |
237 | } else { | 218 | } else { |
238 | - homeModel.recordNum(req.user.uid, getUdid(req, res)).then(result => { | 219 | + homeModel.recordNum(req.user.uid, req.sessionID).then(result => { |
239 | res.json(result); | 220 | res.json(result); |
240 | }).catch(next); | 221 | }).catch(next); |
241 | } | 222 | } |
@@ -250,7 +231,7 @@ const component = { | @@ -250,7 +231,7 @@ const component = { | ||
250 | message: 'not login' | 231 | message: 'not login' |
251 | }); | 232 | }); |
252 | } else { | 233 | } else { |
253 | - homeModel.addRecords(req.user.uid, getUdid(req, res), browserSkn).then(result => { | 234 | + homeModel.addRecords(req.user.uid, req.sessionID, browserSkn).then(result => { |
254 | res.cookie('_browseskn', '', { | 235 | res.cookie('_browseskn', '', { |
255 | maxAge: 0, | 236 | maxAge: 0, |
256 | domain: '.yohoblk.com' | 237 | domain: '.yohoblk.com' |
@@ -4,9 +4,7 @@ | @@ -4,9 +4,7 @@ | ||
4 | * @date: 2016/12/6 | 4 | * @date: 2016/12/6 |
5 | */ | 5 | */ |
6 | 'use strict'; | 6 | 'use strict'; |
7 | -const requestIp = require('request-ip'); | ||
8 | const preferModel = require('../models/prefer'); | 7 | const preferModel = require('../models/prefer'); |
9 | -const md5 = require('md5'); | ||
10 | 8 | ||
11 | const _channel = (channel) => { | 9 | const _channel = (channel) => { |
12 | let yhChannel = 1; | 10 | let yhChannel = 1; |
@@ -29,23 +27,6 @@ const _channel = (channel) => { | @@ -29,23 +27,6 @@ const _channel = (channel) => { | ||
29 | }; | 27 | }; |
30 | 28 | ||
31 | /** | 29 | /** |
32 | - * 获取客户端唯一标识 | ||
33 | - * @return string | ||
34 | - */ | ||
35 | -const getUdid = (req, res) => { | ||
36 | - let udid = req.cookies.udid; | ||
37 | - | ||
38 | - if (!udid) { | ||
39 | - udid = md5(req.ip || requestIp.getClientIp(req)); | ||
40 | - | ||
41 | - if (res && res.cookie) { | ||
42 | - res.cookie('udid', udid); | ||
43 | - } | ||
44 | - } | ||
45 | - return udid; | ||
46 | -}; | ||
47 | - | ||
48 | -/** | ||
49 | * 个人中心主页 | 30 | * 个人中心主页 |
50 | */ | 31 | */ |
51 | const component = { | 32 | const component = { |
@@ -58,7 +39,7 @@ const component = { | @@ -58,7 +39,7 @@ const component = { | ||
58 | list(req, res, next) { | 39 | list(req, res, next) { |
59 | let params = { | 40 | let params = { |
60 | yh_channel: _channel(req.query.channel || req.cookies._Channel || 'men'), | 41 | yh_channel: _channel(req.query.channel || req.cookies._Channel || 'men'), |
61 | - udid: getUdid(req, res) | 42 | + udid: req.sessionID |
62 | }; | 43 | }; |
63 | 44 | ||
64 | preferModel.getlist(params).then((result) => { | 45 | preferModel.getlist(params).then((result) => { |
@@ -92,7 +92,6 @@ | @@ -92,7 +92,6 @@ | ||
92 | "webpack-stream": "^3.1.0", | 92 | "webpack-stream": "^3.1.0", |
93 | "yoho-cookie": "1.2.0", | 93 | "yoho-cookie": "1.2.0", |
94 | "yoho-qs": "1.0.1", | 94 | "yoho-qs": "1.0.1", |
95 | - "yoho-store": "^1.3.20", | ||
96 | - "request-ip": "^1.2.3" | 95 | + "yoho-store": "^1.3.20" |
97 | } | 96 | } |
98 | } | 97 | } |
@@ -48,13 +48,17 @@ | @@ -48,13 +48,17 @@ | ||
48 | } | 48 | } |
49 | }, | 49 | }, |
50 | created() { | 50 | created() { |
51 | + const skns = {}; | ||
51 | const limit = 50; | 52 | const limit = 50; |
52 | let page = 0; | 53 | let page = 0; |
53 | 54 | ||
54 | this.floor.forEach(item => { | 55 | this.floor.forEach(item => { |
55 | - this.productSkn.push(item.id); | 56 | + // 去除重复 skn |
57 | + if (!skns[item.id]) { | ||
58 | + skns[item.id] = 1; | ||
59 | + } | ||
56 | }); | 60 | }); |
57 | - | 61 | + this.productSkn = Object.keys(skns); |
58 | this.getProducts(this.productSkn.slice(page, limit)); | 62 | this.getProducts(this.productSkn.slice(page, limit)); |
59 | 63 | ||
60 | bus.$on('list.paging', () => { | 64 | bus.$on('list.paging', () => { |
-
Please register or login to post a comment