/**
 * 封装getFetch
 */
import { request } from '@/utils/request.js';

export default function getFetch(api, prefix) {
  api = api || {};
  let keys = Object.keys(api);
  keys.forEach(key => {
    let opt = api[key];
    if (typeof opt === 'string') opt = { url: opt };
    opt.url = `${prefix}${opt.url}`;

    // restObj: 重置url 支持restful api
    api[key] = (params, restObj) => {
      return request(opt, params, restObj);
    };
  });
  return api;
}
