import { request } from '@/utils/request.js';

export default function getFetch(api, baseUrl) {
  api = api || {};
  let keys = Object.keys(api);
  keys.forEach(key => {
    let opt = api[key];
    if (typeof opt === 'string') opt = { url: opt };
    opt.url = `${baseUrl}${opt.url}`;
    // requestConfig提供请求发起之前动态设置axios配置的能力
    // requestConfig的所有属性同request.js的opt参数
    api[key] = (params, requestConfig) => request(opt, params, requestConfig);
  });
  return api;
}
