"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _message = _interopRequireDefault(require("@alifd/next/lib/message"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _axios = _interopRequireDefault(require("axios"));
var _storage = require("../storage");
/**
 * 网络请求配置
 */

// const baseURL = 'https://gzmpc-paas-test.gzmpc.com'
var baseURL = process.env.API_URL || 'https://gzmpc-paas-test.gzmpc.com';
var TextToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJ1c2VyX25hbWUiOiJhZG1pbiIsInJlYWxfbmFtZSI6IueUqOaIt-Wnk-WQjSIsImF2YXRhciI6Imh0dHBzOi8vZ3cuYWxpcGF5b2JqZWN0cy5jb20vem9zL3Jtc3BvcnRhbC9CaWF6ZmFueG1hbU5Sb3h4VnhrYS5wbmciLCJhdXRob3JpdGllcyI6WyJhZG1pbmlzdHJhdG9yIl0sImNsaWVudF9pZCI6InNhYmVyIiwicm9sZV9uYW1lIjoiYWRtaW5pc3RyYXRvciIsImxpY2Vuc2UiOiJwb3dlcmVkIGJ5IGJsYWRleCIsInBvc3RfaWQiOiIxMTIzNTk4ODE3NzM4Njc1MjAxIiwidXNlcl9pZCI6IjExMjM1OTg4MjE3Mzg2NzUyMDEiLCJyb2xlX2lkIjoiMTEyMzU5ODgxNjczODY3NTIwMSIsInNjb3BlIjpbImFsbCJdLCJuaWNrX25hbWUiOiLnrqHnkIblkZjnlKjmiLfmmLXnp7AiLCJvYXV0aF9pZCI6IiIsImRldGFpbCI6eyJ0eXBlIjoid2ViIn0sImV4cCI6MTY5MDI4ODg2MiwiZGVwdF9pZCI6IjExMjM1OTg4MTM3Mzg2NzUyMDEiLCJqdGkiOiJhYTZlNDcxMy1hNWE2LTQwNzgtYmZkOC0wMzI2MDBkMWZiNGQiLCJhY2NvdW50IjoiYWRtaW4ifQ.dQCI8x6WT6aWi3XmgWfs-wGofrAwOtpWFywe2Ge_3io';
var BaseHeaders = {
  'Content-Type': 'application/json;charset=UTF-8',
  'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
};

// 使用create方法创建axios实例
var request = _axios["default"].create({
  baseURL: baseURL,
  //1. 设置默认地址
  timeout: 7000,
  // 2. 请求超时时间
  headers: BaseHeaders
});

//3. 给POST请求添加请求头设置（不同项目，值不一样）
//   Service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';

//4.1 添加请求拦截器
request.interceptors.request.use(function (config) {
  config.headers['Blade-Auth'] = _storage.session.getItem('Token') || TextToken;
  config.headers['Tenant-Id'] = _storage.session.getItem('TenantId') || '000000';
  return config;
}, function (err) {
  return Promise.reject(err);
});

//4.2 添加响应拦截器
request.interceptors.response.use(function (response) {
  // console.log(response)
  var data = response.data;
  if (data.success != null && !data.success) {
    return Promise.reject(data);
  }
  return response.data;
}, /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(error) {
    var data;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          // console.log(error)
          data = error.response.data;
          _message["default"].error(data.msg);
          return _context.abrupt("return", Promise.reject(data));
        case 3:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
  return function (_x) {
    return _ref.apply(this, arguments);
  };
}());
var _default = request;
exports["default"] = _default;