extract-url.js 1.43 KB
/**
 * 提取URL中的参数
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/19
 */

var opt = {};

var paramStr = window.location.search.split('?')[1];

var keyVal = paramStr.split('&');

var i, key, val;

for (i = keyVal.length; i > 0; i--) {
    key = keyVal[i - 1].split('=');

    val = key[1];
    key = key[0];

    //初始化默认参数
    switch (key) {
        case 'gender':
            opt.gender = val;
            break;
        case 'brand':
            opt.brand = val;
            break;
        case 'sort':
            opt.sort = val;
            break;
        case 'msort':
            opt.msort = val;
            break;
        case 'misort':
            opt.misort = val;
            break;
        case 'color':
            opt.color = val;
            break;
        case 'size':
            opt.size = val;
            break;
        case 'price':
            opt.price = val;
            break;
        case 'discount':
            opt.discount = val;
            break;
        case 'query':
            opt.query = val;
            break;
        case 'style':
            opt.style = val;
            break;
        case 'limit':
            opt.limit = val;
            break;
        case 'channel':
            opt.channel = val;
            break;
        case 'p_d':
            opt.p_d = val;
            break;
        case 'dayLimit':
            opt.dayLimit = val;
            break;
    }
}

module.exports = opt;