import axios from "axios";
const token =
  "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzA1MDUxMDAsInVzZXJuYW1lIjoiYWRtaW4ifQ.0SkpWAfwuHTJvNBXSBJ-xn4HVTRKW3mf_tz2HJwtFXs";
const tenantid = 0;
// 创建实例默认设置
const service = axios.create({
  baseURL: "",
  timeout: 1000,
});

service.interceptors.request.use(
  (config) => {
    if (token) {
      config.headers["X-Access-Token"] = token; // 让每个请求携带自定义 token 请根据实际情况自行修改
    }

    config.headers["tenant-id"] = tenantid;
    // (config.headers["tenantName"] = "master");
    if (config.method == "get") {
      if (config.url.indexOf("sys/dict/getDictItems") < 0) {
        config.params = {
          _t: Date.parse(new Date()) / 1000,
          ...config.params,
        };
      }
    }

    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
// response interceptor
service.interceptors.response.use(
  (res) => {
    return res.data;
  },
  (error) => {
    return Promise.reject({
      code: error.response.status,
      msg: error.response.statusText,
    });
  }
);
export default service;
