import axios from "axios";
//拦截器

const service = axios.create({
  baseURL: "/api",
  timeout: 150000,
});
axios.defaults.headers["Content-Type"] = "application/json;charset=utf-8";

service.interceptors.request.use(
  (config) => {
    // debugger

        config.headers['Authorization'] = 'Bearer '  + JSON.parse(window.localStorage.getItem('adminInfo')).access_token; // 请求头带上token token要在登录的时候保存在localStorage中
    // config.headers["Authorization"] =
    //   "bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5kZXgiOiIyMTg3MTY2YjU1MDU0YjNjOGQyOTBkYTMzNGMxMGJmYiIsInVzZXJfbmFtZSI6ImdoYWluYW4iLCJzY29wZSI6WyJhbGwiXSwibmlja25hbWUiOiLnrqHkv4oiLCJ1c2VyVHlwZSI6MSwiZGVwdEluZGV4IjoiMDJkMWI0ZTE2ODA0MTNlYjcyZjNmYTYzZDQ2YzQ5NmMiLCJleHAiOjE3OTkwMjAwNjksImF1dGhvcml0aWVzIjpbImhuYWRtaW4iXSwianRpIjoiNjcwNTEyMmMtMDUyOS00MzUyLThhZWUtZDM1ODFiZmUyMTRiIiwiY2xpZW50X2lkIjoibmpjbnRlc3QiLCJoZWFkU2N1bHB0dXJlIjpudWxsfQ.Gce6c0_73yyGrK9sIDDuNfw-ZXv3pQ8WwsGg8J_EtaPgS3cp8Lbvr1SWt_e8NsVjG24DG6cCPzZC9zPq7sQFWSsAOaf_K2cCZZ9FaZVOGq2ZPjtyOW2jKsFdNrpO0KXi2xVVnUkz7aFB_14lP6okb5nqJSQVtz3bWHKsLtsdczdGeEdhOJh6I2TeTLxn7KSELBu0U-U1qpKc-2LcBK6l-QSMUt7ZGB1Kfms_I9fd6iYrTQyPIGfdHHgvnqqRnplFNAjJlv5CDjWyPFazbJM_wXfAcdoD_qFgzIm3i02vhhpXee9MOUWcVL7pGeXiDDXg4qwhOJe2NsoXWiQOax3ltQ";
    // NProgress.done()
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
service.interceptors.response.use(({ config, data }) => {
  const { code, message } = data;
  return data;
});
export default service;
