list-params-process.js 900 Bytes
const _ = require('lodash');

/**
 * 参数列表
 */
const PARAMMAP = {
    gd: 'gender',
    sn: 'sort_name',
    so: 'sort',
    ms: 'msort',
    mi: 'misort',
    tp: 'type',
    sz: 'size',
    cl: 'color',
    pc: 'price',
    bd: 'brand',
    qr: 'type'
};

/**
 * 获取标准参数
 */
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 = _.replace(paramRaw, keyRaw, '');

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

    return params;
};

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

module.exports = {
    getParams,
    generateUrl
};