list-params-process.js 1.19 KB
const _ = require('lodash');

/**
 * 参数列表
 */
const PARAMMAP = {
    ag: 'age_level',
    gd: 'gender',
    sn: 'sort_name',
    pa: 'phrase',
    ci: 'category_id',
    so: 'sort',
    ms: 'msort',
    mi: 'misort',
    tp: 'type',
    sz: 'size',
    cl: 'color',
    pc: 'price',
    bd: 'brand',
    qr: 'query',
    lt: 'limit',
    ld: 'limited',
    od: 'order',
    nw: 'new',
    pg: 'page',
    st: 'style',
    sd: 'standard',
    si: 'specialsale_id',
    sf: 'specialoffer'
};

/**
 * 获取标准参数
 */
const getParams = (url) => {
    let params = [];
    let paramStringRaw = _.split(url, '/list/')[1];

    if (paramStringRaw) {
        let paramsRaw = _.split(paramStringRaw, '-');

        _.forEach(paramsRaw, paramRaw => {
            let keyRaw = paramRaw.substr(0, 2);
            let valueRaw = _.chain(paramRaw)
                .replace(keyRaw, '')
                .replace('__', '-')
                .value();

            if (PARAMMAP[keyRaw]) {
                params[PARAMMAP[keyRaw]] = valueRaw;
            }
        });
    }

    return params;
};

/**
 * 生成链接
 */
const generateUrl = () => {
    return '';
};

module.exports = {
    getParams,
    generateUrl
};