const apiList = [
'system/v2/markes',
]
let urlStr, apiName, API = {}
apiList.forEach(path => {
urlStr = path.indexOf("?") != -1;
apiName = urlStr ? /(?<=\/)[^/]+$/.exec(path)[0].split('?')[0] : /(?<=\/)[^/]+$/.exec(path)[0];
API[apiName] = (data = '', method = 'get', url = baseURL) => {
if (method == 'post') {
return axios.post(url + path, data)
} else {
if (urlStr) {
return axios.get(url + path + utils.param(data))
} else {
return axios.get(url + path + '?' + utils.param(data))
}
}
}
})
export { API }
function filter(str) {
str += '';
str = str.replace(/%/g, '%25');
str = str.replace(/\+/g, '%2B');
str = str.replace(/ /g, '%20');
str = str.replace(/\//g, '%2F');
str = str.replace(/\?/g, '%3F');
str = str.replace(/&/g, '%26');
str = str.replace(/\=/g, '%3D');
str = str.replace(/#/g, '%23');
return str;
}
export const param = (paramObj) => {
const sdata = [];
for (let attr in paramObj) {
sdata.push(`${attr}=${filter(paramObj[attr])}`);
}
return sdata.join('&');
};