Authored by 沈志敏

代码整理

@@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 const homeModel = require('../models/index'); 7 const homeModel = require('../models/index');
8 -const _ = require('lodash');  
9 const helpers = global.yoho.helpers; 8 const helpers = global.yoho.helpers;
10 9
11 /** 10 /**
@@ -29,12 +28,10 @@ const component = { @@ -29,12 +28,10 @@ const component = {
29 page: 'index', 28 page: 'index',
30 noLocalCSS: true, 29 noLocalCSS: true,
31 head_ico: proData && proData.head_ico ? helpers.image(proData.head_ico, 200, 200) : '', 30 head_ico: proData && proData.head_ico ? helpers.image(proData.head_ico, 200, 200) : '',
32 - nickname: proData ? proData.nickname : '登录/注册',  
33 - userinfourl: proData ? '/home/mydetails' : '',  
34 - serviceUrl: '/home/service' 31 + nickname: proData ? proData.nickname : '登录/注册'
35 }; 32 };
36 33
37 - res.render('index', _.merge(result, data[1])); 34 + res.render('index', Object.assign(result, data[1]));
38 }).catch(next); 35 }).catch(next);
39 }, 36 },
40 mydetails: (req, res, next) => { 37 mydetails: (req, res, next) => {
@@ -121,22 +118,12 @@ const component = { @@ -121,22 +118,12 @@ const component = {
121 }, 118 },
122 saveFeedback: (req, res, next) => { 119 saveFeedback: (req, res, next) => {
123 let saveFeedbackPara = { 120 let saveFeedbackPara = {
  121 + uid: req.user.uid,
  122 + udid: req.user.udid, // todo
124 content: req.body.content, 123 content: req.body.content,
125 suggest_type: 2 124 suggest_type: 2
126 }; 125 };
127 126
128 - if (req.user && req.user.uid) {  
129 - _.merge(saveFeedbackPara, {  
130 - uid: req.user.uid  
131 - });  
132 - }  
133 -  
134 - if (req.user && req.user.udid && !req.user.uid) {  
135 - _.merge(saveFeedbackPara, {  
136 - udid: req.user.udid  
137 - });  
138 - }  
139 -  
140 homeModel.saveFeedback(saveFeedbackPara).then(result => { 127 homeModel.saveFeedback(saveFeedbackPara).then(result => {
141 if (result.code === 200) { 128 if (result.code === 200) {
142 return res.json({ 129 return res.json({
@@ -16,6 +16,8 @@ exports.getFavProductData = (uid, page, limit) => { @@ -16,6 +16,8 @@ exports.getFavProductData = (uid, page, limit) => {
16 uid: uid, 16 uid: uid,
17 page: page, 17 page: page,
18 limit: limit 18 limit: limit
  19 + }, {
  20 + code: 200
19 }).then(result => { 21 }).then(result => {
20 var isend = true, 22 var isend = true,
21 list = [], 23 list = [],
@@ -77,6 +79,8 @@ exports.getFavBrandData = (uid, gender, page, limit) => { @@ -77,6 +79,8 @@ exports.getFavBrandData = (uid, gender, page, limit) => {
77 gender: gender, 79 gender: gender,
78 page: page, 80 page: page,
79 limit: limit 81 limit: limit
  82 + }, {
  83 + code: 200
80 }).then(result => { 84 }).then(result => {
81 var isend = true, 85 var isend = true,
82 list = [], 86 list = [],
@@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
2 const api = global.yoho.API; 2 const api = global.yoho.API;
3 const serviceAPI = global.yoho.ServiceAPI; 3 const serviceAPI = global.yoho.ServiceAPI;
4 const Promise = require('bluebird'); 4 const Promise = require('bluebird');
5 -const _ = require('lodash');  
6 const helpers = global.yoho.helpers; 5 const helpers = global.yoho.helpers;
7 6
8 /** 7 /**
@@ -15,6 +14,8 @@ const _getUserProfileData = exports.getUserProfileData = (uid) => { @@ -15,6 +14,8 @@ const _getUserProfileData = exports.getUserProfileData = (uid) => {
15 return api.get('', { 14 return api.get('', {
16 uid: uid, 15 uid: uid,
17 method: 'app.passport.profile' 16 method: 'app.passport.profile'
  17 + }, {
  18 + code: 200
18 }).then(result => { 19 }).then(result => {
19 return result.data; 20 return result.data;
20 }); 21 });
@@ -30,9 +31,13 @@ const _getInfoNumData = (uid) => { @@ -30,9 +31,13 @@ const _getInfoNumData = (uid) => {
30 return api.all([api.get('', { 31 return api.all([api.get('', {
31 uid: uid, 32 uid: uid,
32 method: 'app.home.getInfoNum' // 收藏及订单数目数据 33 method: 'app.home.getInfoNum' // 收藏及订单数目数据
  34 + }, {
  35 + code: 200
33 }), api.get('', { 36 }), api.get('', {
34 uid: uid, 37 uid: uid,
35 method: 'app.address.gethidden' // 用户地址的数据 38 method: 'app.address.gethidden' // 用户地址的数据
  39 + }, {
  40 + code: 200
36 })]).then(data => { 41 })]).then(data => {
37 let res = { 42 let res = {
38 wait_pay_num: '', 43 wait_pay_num: '',
@@ -44,22 +49,18 @@ const _getInfoNumData = (uid) => { @@ -44,22 +49,18 @@ const _getInfoNumData = (uid) => {
44 yoho_coin_num: '' 49 yoho_coin_num: ''
45 }; 50 };
46 51
47 - if (data[0].data) {  
48 - for (let k in data[0].data) {  
49 - if (res[k] !== null) {  
50 - res[k] = data[0].data[k] ? data[0].data[k] : '';  
51 - if (k !== 'yoho_coin_num' && res[k] > 99) {  
52 - res[k] = '99+';  
53 - } 52 + for (let k in data[0].data) {
  53 + if (res[k] !== null) {
  54 + res[k] = data[0].data[k] ? data[0].data[k] : '';
  55 + if (k !== 'yoho_coin_num' && res[k] > 99) {
  56 + res[k] = '99+';
54 } 57 }
55 } 58 }
56 } 59 }
57 - if (data[1].data) {  
58 - res = _.merge(res, {  
59 - address_num: data[1].data.length ? data[1].data.length : ''  
60 - });  
61 - }  
62 - return res; 60 +
  61 + return Object.assign(res, {
  62 + address_num: data[1].data.length ? data[1].data.length : ''
  63 + });
63 }); 64 });
64 }; 65 };
65 66
@@ -86,12 +87,14 @@ exports.getHelpInfo = (data) => { @@ -86,12 +87,14 @@ exports.getHelpInfo = (data) => {
86 }, 87 },
87 infoData = Object.assign(defaultParam, data); 88 infoData = Object.assign(defaultParam, data);
88 89
89 - return api.get('', infoData).then(result => { 90 + return api.get('', infoData, {
  91 + code: 200
  92 + }).then(result => {
90 var helpData = result.data; 93 var helpData = result.data;
91 var formatData = []; 94 var formatData = [];
92 95
93 helpData = helpData || []; 96 helpData = helpData || [];
94 - _.forEach(helpData, (item) => { 97 + helpData.forEach(function(item) {
95 formatData.push({ 98 formatData.push({
96 name: item.caption, 99 name: item.caption,
97 code: item.code, 100 code: item.code,
@@ -117,9 +120,9 @@ exports.getHelpDetail = (data) => { @@ -117,9 +120,9 @@ exports.getHelpDetail = (data) => {
117 }, 120 },
118 detailData = Object.assign(defaultParam, data); 121 detailData = Object.assign(defaultParam, data);
119 122
120 - return api.get('', detailData).then(result => {  
121 - return result;  
122 - }); 123 + return api.get('', detailData, {
  124 + code: 200
  125 + }).then(result => result);
123 }; 126 };
124 127
125 /** 128 /**
@@ -149,7 +152,5 @@ exports.saveMydetails = (params) => { @@ -149,7 +152,5 @@ exports.saveMydetails = (params) => {
149 }, 152 },
150 data = Object.assign(defaultParam, params); 153 data = Object.assign(defaultParam, params);
151 154
152 - return api.get('', data).then(result => {  
153 - return result;  
154 - }); 155 + return api.get('', data).then(result => result);
155 }; 156 };
@@ -28,6 +28,8 @@ const refund = { @@ -28,6 +28,8 @@ const refund = {
28 getExpressCompany() { 28 getExpressCompany() {
29 return api.get('', { 29 return api.get('', {
30 method: 'app.express.getExpressCompany' 30 method: 'app.express.getExpressCompany'
  31 + }, {
  32 + code: 200
31 }); 33 });
32 }, 34 },
33 35
@@ -42,7 +44,9 @@ const refund = { @@ -42,7 +44,9 @@ const refund = {
42 * @returns {Promise.<T>|*} 44 * @returns {Promise.<T>|*}
43 */ 45 */
44 getRefundOrders(param) { 46 getRefundOrders(param) {
45 - param = Object.assign({method: 'app.refund.getList'}, param); 47 + param = Object.assign({
  48 + method: 'app.refund.getList'
  49 + }, param);
46 50
47 return api.get('', param, { 51 return api.get('', param, {
48 cache: true, 52 cache: true,
1 <div class="my-page"> 1 <div class="my-page">
2 <div class="my-header"> 2 <div class="my-header">
3 <span class="setting icon icon-setting" id="setting"></span> 3 <span class="setting icon icon-setting" id="setting"></span>
4 - <a class="user-info" id="user-info" {{#if userinfourl}} href='{{userinfourl}}' {{/if}}> 4 + <a class="user-info no-intercept" id="user-info" href='/home/mydetails'>
5 <span class="user-avatar" {{#if head_ico}} style="background-image: url('{{head_ico}}');" {{/if}}></span> 5 <span class="user-avatar" {{#if head_ico}} style="background-image: url('{{head_ico}}');" {{/if}}></span>
6 <br><span class="username">{{nickname}}</span> 6 <br><span class="username">{{nickname}}</span>
7 </a> 7 </a>
8 </div> 8 </div>
9 <div class="my-order"> 9 <div class="my-order">
10 - <a class="order-title" href="/home/orders?type=1"> 10 + <a class="order-title no-intercept" href="/home/orders?type=1">
11 我的订单 11 我的订单
12 <span class="read-order"> 12 <span class="read-order">
13 查看全部订单 <span class="icon icon-right"></span> 13 查看全部订单 <span class="icon icon-right"></span>
14 </span> 14 </span>
15 </a> 15 </a>
16 <div class="order-type clearfix"> 16 <div class="order-type clearfix">
17 - <a class="type-item" href="/home/orders?type=2"> 17 + <a class="type-item no-intercept" href="/home/orders?type=2">
18 <span class="icon icon-wait-pay"></span> 18 <span class="icon icon-wait-pay"></span>
19 <br>待付款 19 <br>待付款
20 {{#if wait_pay_num}} 20 {{#if wait_pay_num}}
21 <span class="num">{{wait_pay_num}}</span> 21 <span class="num">{{wait_pay_num}}</span>
22 {{/if}} 22 {{/if}}
23 </a> 23 </a>
24 - <a class="type-item" href="/home/orders?type=3"> 24 + <a class="type-item no-intercept" href="/home/orders?type=3">
25 <span class="icon icon-wait-cargo"></span> 25 <span class="icon icon-wait-cargo"></span>
26 <br>待发货 26 <br>待发货
27 {{#if wait_cargo_num}} 27 {{#if wait_cargo_num}}
28 <span class="num">{{wait_cargo_num}}</span> 28 <span class="num">{{wait_cargo_num}}</span>
29 {{/if}} 29 {{/if}}
30 </a> 30 </a>
31 - <a class="type-item" href="/home/orders?type=4"> 31 + <a class="type-item no-intercept" href="/home/orders?type=4">
32 <span class="icon icon-send-cargo"></span> 32 <span class="icon icon-send-cargo"></span>
33 <br>待收货 33 <br>待收货
34 {{#if send_cargo_num}} 34 {{#if send_cargo_num}}
35 <span class="num">{{send_cargo_num}}</span> 35 <span class="num">{{send_cargo_num}}</span>
36 {{/if}} 36 {{/if}}
37 </a> 37 </a>
38 - <a class="type-item" href="/home/refund/orders"> 38 + <a class="type-item no-intercept" href="/home/refund/orders">
39 <span class="icon icon-refund-exchange"></span> 39 <span class="icon icon-refund-exchange"></span>
40 <br>退换货 40 <br>退换货
41 {{#if refund_exchange_num}} 41 {{#if refund_exchange_num}}
@@ -45,33 +45,33 @@ @@ -45,33 +45,33 @@
45 </div> 45 </div>
46 </div> 46 </div>
47 <div class="group-list"> 47 <div class="group-list">
48 - <a class="list-item" id="address"> 48 + <a class="list-item no-intercept" id="address">
49 地址管理 49 地址管理
50 <span class="num">{{address_num}} <span class="icon icon-right"></span></span> 50 <span class="num">{{address_num}} <span class="icon icon-right"></span></span>
51 </a> 51 </a>
52 </div> 52 </div>
53 <div class="group-list"> 53 <div class="group-list">
54 - <a class="list-item" href="/home/favorite"> 54 + <a class="list-item no-intercept" href="/home/favorite">
55 收藏的商品 55 收藏的商品
56 <span class="num">{{product_favorite_total}} <span class="icon icon-right"></span></span> 56 <span class="num">{{product_favorite_total}} <span class="icon icon-right"></span></span>
57 </a> 57 </a>
58 - <a class="list-item" href="/home/favorite?tab=brand"> 58 + <a class="list-item no-intercept" href="/home/favorite?tab=brand">
59 收藏的品牌 59 收藏的品牌
60 <span class="num">{{brand_favorite_total}} <span class="icon icon-right"></span></span> 60 <span class="num">{{brand_favorite_total}} <span class="icon icon-right"></span></span>
61 </a> 61 </a>
62 </div> 62 </div>
63 <div class="group-list"> 63 <div class="group-list">
64 - <a class="list-item" href="/home/mycurrency"> 64 + <a class="list-item no-intercept" href="/home/mycurrency">
65 YOHO 币 65 YOHO 币
66 <span class="num">{{yoho_coin_num}} <span class="icon icon-right"></span></span> 66 <span class="num">{{yoho_coin_num}} <span class="icon icon-right"></span></span>
67 </a> 67 </a>
68 </div> 68 </div>
69 <div class="group-list"> 69 <div class="group-list">
70 - <a class="list-item" href="/home/help"> 70 + <a class="list-item no-intercept" href="/home/help">
71 帮助中心 71 帮助中心
72 <span class="num"><span class="icon icon-right"></span></span> 72 <span class="num"><span class="icon icon-right"></span></span>
73 </a> 73 </a>
74 - <a class="list-item" href="{{serviceUrl}}"> 74 + <a class="list-item no-intercept" href="/home/service">
75 在线客服 75 在线客服
76 <span class="num"><span class="icon icon-right"></span></span> 76 <span class="num"><span class="icon icon-right"></span></span>
77 </a> 77 </a>
@@ -2,31 +2,31 @@ var yoho = require('yoho'); @@ -2,31 +2,31 @@ var yoho = require('yoho');
2 var $ = require('yoho-jquery'); 2 var $ = require('yoho-jquery');
3 var interceptClick = require('common/intercept-click'); 3 var interceptClick = require('common/intercept-click');
4 4
5 -$('.my-page').on('click', 'a', function() {  
6 - // 拦截跳转  
7 - var href = $(this).attr('href');  
8 - if (href) {  
9 - interceptClick(href);  
10 - return false;  
11 - }  
12 -});  
13 -  
14 -// 跳转登录页  
15 -$('#user-info').on('click', function() {  
16 - var href = $(this).attr('href');  
17 - if (!href) {  
18 - yoho.goLogin();  
19 - }  
20 -});  
21 -  
22 // 地址管理 5 // 地址管理
23 $('#address').on('click', function() { 6 $('#address').on('click', function() {
24 yoho.goAddress({ 7 yoho.goAddress({
25 'type': '2' 8 'type': '2'
26 }); 9 });
  10 + return false;
27 }); 11 });
28 12
29 // 系统设置 13 // 系统设置
30 $('#setting').on('click', function() { 14 $('#setting').on('click', function() {
31 yoho.goSetting(); 15 yoho.goSetting();
  16 + return false;
  17 +});
  18 +
  19 +$('.my-page').on('click', 'a', function() {
  20 + // 未登录时跳转至登录页
  21 + if (!yoho.isLogin) {
  22 + yoho.goLogin();
  23 + return false;
  24 + }
  25 +
  26 + // 拦截跳转
  27 + var href = $(this).attr('href');
  28 + if (href) {
  29 + interceptClick(href);
  30 + return false;
  31 + }
32 }); 32 });
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 * 8 *
9 * 希望能与 微信 JS-SDK 一样方便 9 * 希望能与 微信 JS-SDK 一样方便
10 */ 10 */
11 - 11 +const cookie = require('yoho-cookie');
12 const tip = require('common/tip'); 12 const tip = require('common/tip');
13 13
14 /* 空方法 */ 14 /* 空方法 */
@@ -24,6 +24,11 @@ const yoho = { @@ -24,6 +24,11 @@ const yoho = {
24 isApp: /yh_blk/i.test(navigator.userAgent || ''), 24 isApp: /yh_blk/i.test(navigator.userAgent || ''),
25 25
26 /** 26 /**
  27 + * 判断是否是 登录
  28 + */
  29 + isLogin: cookie.get('_YOHOUID'),
  30 +
  31 + /**
27 * JS 与 APP 共享的对象 32 * JS 与 APP 共享的对象
28 */ 33 */
29 data: window.yohoInterfaceData, 34 data: window.yohoInterfaceData,
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 12
13 .setting { 13 .setting {
14 float: left; 14 float: left;
15 - margin-top: 30px; 15 + margin-top: 40px;
16 margin-left: 15px; 16 margin-left: 15px;
17 font-size: 46px; 17 font-size: 46px;
18 } 18 }