import { extend } from "umi-request";
import { Toast } from "vant";

const request = extend({
  timeout: 20000,
  timeoutMessage: "请求超时",
});
let timer: ReturnType<typeof setTimeout>;
request.interceptors.request.use(
  (url, options: any) => {
    clearTimeout(timer);
    Toast({
      type: "loading",
      message: "加载中",
      duration: 0,
    });
    // console.log(options);
    return {
      url,
      options,
    };
  },
  { global: false }
);
request.interceptors.response.use(
  (response) => {
    timer = setTimeout(() => {
      Toast.clear();
    }, 300);
    return response;
  },
  { global: false }
);

export default request;
