Helper.js 1.11 KB

'use strict';


function excludeParams(groupParams, needGender=true){
    let newParams = {};
    try{
        let params = groupParams.toJS();

        for(let key in params){
            if(params[key]){
                newParams[key] = params[key]
            }
        }

        //gender 需要进行空处理,防止原生会添加默认值
        if(needGender && !newParams["gender"]){
            newParams["gender"] = "";
        }

        //size因为字段是关键字,使用了g_size替换
        if(newParams["g_size"]){
            newParams["size"] = newParams["g_size"];
            delete newParams["g_size"]
        }
    }catch(e){

    }

    return newParams;
}

function joinWxProgramPath(wxPath, groupParams){
    let params = excludeParams(groupParams, false);

    let paramStr = "";
    for(let key in params){
        paramStr = paramStr + "&" + key + "=" + params[key];
    }

    if(wxPath.indexOf("?") != -1){
        wxPath = wxPath + paramStr;
    }else{
        wxPath = wxPath + "?" + paramStr.substring(1);
    }
    return wxPath;
}

module.exports = {
	excludeParams,
	joinWxProgramPath
};