import axios from 'axios';
import { getQueryString } from './utils';
//禁用F12功能
function disableF12() {
  document.onkeydown = function() {
    var e = window.event || arguments[0];
    if (e.keyCode == 123) {
      return false;
    } else if (e.ctrlKey && e.shiftKey && e.keyCode == 73) {
      return false;
    }
  };
  //禁用鼠标右键
  document.oncontextmenu = function() {
    return false;
  };
}
// disableF12();

// console.log('window.location.href', window.location);
// console.log('window-----', localStorage.getItem('token'));
// console.log('getQueryString', getQueryString('token'));
// console.log('localStorage', localStorage.getItem('token'));
const baseURL = 'http://69.235.144.91:8048/';
// const baseURL = 'http://61.177.38.58:8048/';
// const baseURL = 'http://172.16.20.9:8048/';
const token = getQueryString('token') || localStorage.getItem('token');
const request = axios.create({
  baseURL,
  timeout: 15000,
  headers: {
    // 'Content-Type': 'application/json',
    accessToken: token,
    token,
  },
});

//拦截器
request.interceptors.request.use((config) => {
  if (localStorage.getItem('token')) {
    config.headers['accessToken'] = localStorage.getItem('token');
    config.headers['token'] = localStorage.getItem('token');
  }
  return config;
});
// request.interceptors.response.use(
//   (res) => {
//     return res;
//   },
//   (err) => {
//     console.log('err', err);
//     return err;
//   }
// );

export default request;
