Authored by 沈志敏

代码整理

... ... @@ -5,7 +5,6 @@
*/
'use strict';
const homeModel = require('../models/index');
const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
... ... @@ -29,12 +28,10 @@ const component = {
page: 'index',
noLocalCSS: true,
head_ico: proData && proData.head_ico ? helpers.image(proData.head_ico, 200, 200) : '',
nickname: proData ? proData.nickname : '登录/注册',
userinfourl: proData ? '/home/mydetails' : '',
serviceUrl: '/home/service'
nickname: proData ? proData.nickname : '登录/注册'
};
res.render('index', _.merge(result, data[1]));
res.render('index', Object.assign(result, data[1]));
}).catch(next);
},
mydetails: (req, res, next) => {
... ... @@ -121,22 +118,12 @@ const component = {
},
saveFeedback: (req, res, next) => {
let saveFeedbackPara = {
uid: req.user.uid,
udid: req.user.udid, // todo
content: req.body.content,
suggest_type: 2
};
if (req.user && req.user.uid) {
_.merge(saveFeedbackPara, {
uid: req.user.uid
});
}
if (req.user && req.user.udid && !req.user.uid) {
_.merge(saveFeedbackPara, {
udid: req.user.udid
});
}
homeModel.saveFeedback(saveFeedbackPara).then(result => {
if (result.code === 200) {
return res.json({
... ...
... ... @@ -16,6 +16,8 @@ exports.getFavProductData = (uid, page, limit) => {
uid: uid,
page: page,
limit: limit
}, {
code: 200
}).then(result => {
var isend = true,
list = [],
... ... @@ -77,6 +79,8 @@ exports.getFavBrandData = (uid, gender, page, limit) => {
gender: gender,
page: page,
limit: limit
}, {
code: 200
}).then(result => {
var isend = true,
list = [],
... ...
... ... @@ -2,7 +2,6 @@
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const Promise = require('bluebird');
const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
... ... @@ -15,6 +14,8 @@ const _getUserProfileData = exports.getUserProfileData = (uid) => {
return api.get('', {
uid: uid,
method: 'app.passport.profile'
}, {
code: 200
}).then(result => {
return result.data;
});
... ... @@ -30,9 +31,13 @@ const _getInfoNumData = (uid) => {
return api.all([api.get('', {
uid: uid,
method: 'app.home.getInfoNum' // 收藏及订单数目数据
}, {
code: 200
}), api.get('', {
uid: uid,
method: 'app.address.gethidden' // 用户地址的数据
}, {
code: 200
})]).then(data => {
let res = {
wait_pay_num: '',
... ... @@ -44,7 +49,6 @@ const _getInfoNumData = (uid) => {
yoho_coin_num: ''
};
if (data[0].data) {
for (let k in data[0].data) {
if (res[k] !== null) {
res[k] = data[0].data[k] ? data[0].data[k] : '';
... ... @@ -53,13 +57,10 @@ const _getInfoNumData = (uid) => {
}
}
}
}
if (data[1].data) {
res = _.merge(res, {
return Object.assign(res, {
address_num: data[1].data.length ? data[1].data.length : ''
});
}
return res;
});
};
... ... @@ -86,12 +87,14 @@ exports.getHelpInfo = (data) => {
},
infoData = Object.assign(defaultParam, data);
return api.get('', infoData).then(result => {
return api.get('', infoData, {
code: 200
}).then(result => {
var helpData = result.data;
var formatData = [];
helpData = helpData || [];
_.forEach(helpData, (item) => {
helpData.forEach(function(item) {
formatData.push({
name: item.caption,
code: item.code,
... ... @@ -117,9 +120,9 @@ exports.getHelpDetail = (data) => {
},
detailData = Object.assign(defaultParam, data);
return api.get('', detailData).then(result => {
return result;
});
return api.get('', detailData, {
code: 200
}).then(result => result);
};
/**
... ... @@ -149,7 +152,5 @@ exports.saveMydetails = (params) => {
},
data = Object.assign(defaultParam, params);
return api.get('', data).then(result => {
return result;
});
return api.get('', data).then(result => result);
};
... ...
... ... @@ -28,6 +28,8 @@ const refund = {
getExpressCompany() {
return api.get('', {
method: 'app.express.getExpressCompany'
}, {
code: 200
});
},
... ... @@ -42,7 +44,9 @@ const refund = {
* @returns {Promise.<T>|*}
*/
getRefundOrders(param) {
param = Object.assign({method: 'app.refund.getList'}, param);
param = Object.assign({
method: 'app.refund.getList'
}, param);
return api.get('', param, {
cache: true,
... ...
<div class="my-page">
<div class="my-header">
<span class="setting icon icon-setting" id="setting"></span>
<a class="user-info" id="user-info" {{#if userinfourl}} href='{{userinfourl}}' {{/if}}>
<a class="user-info no-intercept" id="user-info" href='/home/mydetails'>
<span class="user-avatar" {{#if head_ico}} style="background-image: url('{{head_ico}}');" {{/if}}></span>
<br><span class="username">{{nickname}}</span>
</a>
</div>
<div class="my-order">
<a class="order-title" href="/home/orders?type=1">
<a class="order-title no-intercept" href="/home/orders?type=1">
我的订单
<span class="read-order">
查看全部订单 <span class="icon icon-right"></span>
</span>
</a>
<div class="order-type clearfix">
<a class="type-item" href="/home/orders?type=2">
<a class="type-item no-intercept" href="/home/orders?type=2">
<span class="icon icon-wait-pay"></span>
<br>待付款
{{#if wait_pay_num}}
<span class="num">{{wait_pay_num}}</span>
{{/if}}
</a>
<a class="type-item" href="/home/orders?type=3">
<a class="type-item no-intercept" href="/home/orders?type=3">
<span class="icon icon-wait-cargo"></span>
<br>待发货
{{#if wait_cargo_num}}
<span class="num">{{wait_cargo_num}}</span>
{{/if}}
</a>
<a class="type-item" href="/home/orders?type=4">
<a class="type-item no-intercept" href="/home/orders?type=4">
<span class="icon icon-send-cargo"></span>
<br>待收货
{{#if send_cargo_num}}
<span class="num">{{send_cargo_num}}</span>
{{/if}}
</a>
<a class="type-item" href="/home/refund/orders">
<a class="type-item no-intercept" href="/home/refund/orders">
<span class="icon icon-refund-exchange"></span>
<br>退换货
{{#if refund_exchange_num}}
... ... @@ -45,33 +45,33 @@
</div>
</div>
<div class="group-list">
<a class="list-item" id="address">
<a class="list-item no-intercept" id="address">
地址管理
<span class="num">{{address_num}} <span class="icon icon-right"></span></span>
</a>
</div>
<div class="group-list">
<a class="list-item" href="/home/favorite">
<a class="list-item no-intercept" href="/home/favorite">
收藏的商品
<span class="num">{{product_favorite_total}} <span class="icon icon-right"></span></span>
</a>
<a class="list-item" href="/home/favorite?tab=brand">
<a class="list-item no-intercept" href="/home/favorite?tab=brand">
收藏的品牌
<span class="num">{{brand_favorite_total}} <span class="icon icon-right"></span></span>
</a>
</div>
<div class="group-list">
<a class="list-item" href="/home/mycurrency">
<a class="list-item no-intercept" href="/home/mycurrency">
YOHO 币
<span class="num">{{yoho_coin_num}} <span class="icon icon-right"></span></span>
</a>
</div>
<div class="group-list">
<a class="list-item" href="/home/help">
<a class="list-item no-intercept" href="/home/help">
帮助中心
<span class="num"><span class="icon icon-right"></span></span>
</a>
<a class="list-item" href="{{serviceUrl}}">
<a class="list-item no-intercept" href="/home/service">
在线客服
<span class="num"><span class="icon icon-right"></span></span>
</a>
... ...
... ... @@ -2,31 +2,31 @@ var yoho = require('yoho');
var $ = require('yoho-jquery');
var interceptClick = require('common/intercept-click');
$('.my-page').on('click', 'a', function() {
// 拦截跳转
var href = $(this).attr('href');
if (href) {
interceptClick(href);
return false;
}
});
// 跳转登录页
$('#user-info').on('click', function() {
var href = $(this).attr('href');
if (!href) {
yoho.goLogin();
}
});
// 地址管理
$('#address').on('click', function() {
yoho.goAddress({
'type': '2'
});
return false;
});
// 系统设置
$('#setting').on('click', function() {
yoho.goSetting();
return false;
});
$('.my-page').on('click', 'a', function() {
// 未登录时跳转至登录页
if (!yoho.isLogin) {
yoho.goLogin();
return false;
}
// 拦截跳转
var href = $(this).attr('href');
if (href) {
interceptClick(href);
return false;
}
});
... ...
... ... @@ -8,7 +8,7 @@
*
* 希望能与 微信 JS-SDK 一样方便
*/
const cookie = require('yoho-cookie');
const tip = require('common/tip');
/* 空方法 */
... ... @@ -24,6 +24,11 @@ const yoho = {
isApp: /yh_blk/i.test(navigator.userAgent || ''),
/**
* 判断是否是 登录
*/
isLogin: cookie.get('_YOHOUID'),
/**
* JS 与 APP 共享的对象
*/
data: window.yohoInterfaceData,
... ...
... ... @@ -12,7 +12,7 @@
.setting {
float: left;
margin-top: 30px;
margin-top: 40px;
margin-left: 15px;
font-size: 46px;
}
... ...