intercept-click.js 2.01 KB
/**
 * 拦截跳转, 在这里给将要打开的页面设置一下 header 样式
 * @return {[type]}
 */
const yoho = require('yoho');

/**
 * 跳转 App 头部参数
 * 文档 http://git.yoho.cn/mobile/AppJSBridge/blob/master/HeaderType.md
 * @type {Object}
 */
const titleMap = {
    1: {
        headerid: '1',
        left: {
            action: ''
        },
        title: {
            des: '标题1',
            action: ''
        }
    },
    2: {
        headerid: '2',
        left: {
            action: ''
        },
        title: {
            des: '标题2',
            action: ''
        },
        right: {
            action: ''
        }
    },
    3: {
        headerid: '3',
        left: {
            action: ''
        },
        title: {
            des: '标题3',
            action: ''
        },
        right: {
            des: '提交',
            action: ''
        }
    },
    4: {
        headerid: '4',
        ltitle: {
            des: '品牌4',
            action: ''
        },
        rtitle: {
            des: '品类4',
            action: ''
        }
    },
    5: {
        headerid: '5',
        left: {
            action: ''
        },
        ltitle: {
            des: '商品5',
            action: ''
        },
        rtitle: {
            des: '品牌5',
            action: ''
        },
        right: {
            des: '编辑5',
            action: ''
        }
    },
    6: {
        headerid: '6',
        title: {
            des: '资讯6',
            action: ''
        }
    }
};

const matchHeader = (url) => {
    let header = '';

    if (/product\/new/.test(url)) {
        header = titleMap[1];

        // header.xxx = '111';// 匹配到头类型以后,可修改里边的内容
        return header;
    }

    return '';
};

module.exports = (url) => {
    console.log(url);
    if (yoho.isApp) {
        let data = {
            header: matchHeader(url),
            url: url
        };

        yoho.goNewPage(data);
    } else {
        location.href = url;
    }
};