menu-crumb-handler.js 1.55 KB
/**
 * 个人中心布局(顶部面包屑和左侧导航)
 * @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 navigation = [
    {
        link: url('/me/order'),
        name: '我的订单'
    },
    {
        link: url('/me/return'),
        name: '我的退/换货'
    },
    {
        link: url('/me/collection'),
        name: '我的收藏'
    },
    {
        link: url('/me/message'),
        name: '我的消息'
    },
    {
        link: url('/me/currency'),
        name: '我的YOHO币'
    },
    {
        link: url('/me/setting'),
        name: '个人设置'
    },
    {
        link: url('/me/address'),
        name: '收货地址'
    }
];

// 头部导航面包屑
const getMeCrumb = name => {
    return [
        {
            link: blk.config.sitUrl,
            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,
    getSideMenu
};