"use strict";
const common_vendor = require("./common/vendor.js");
const url_all = new UTSJSONObject({
  "DEV": "https://gpt.aiym.run"
  // 开发
  // 'PRO': 'http://111.111.111.111:8080', // 生产
});
let BASEURL = url_all["DEV"];
const request = (path = null, method = null, data = new UTSJSONObject({}), loading = null) => {
  let token = common_vendor.index.getStorageSync("token");
  if (loading) {
    common_vendor.index.showLoading({
      title: "加载中",
      mask: true
    });
  }
  if (token != "") {
    return tokenRequest(path, method, data, loading, token);
  } else {
    return noTokenRequest(path, method, data, loading);
  }
};
function noTokenRequest(path = null, method = null, data = null, loading = null) {
  return new Promise((resolve, reject) => {
    common_vendor.index.request({
      url: BASEURL + path,
      method,
      data,
      header: new UTSJSONObject({
        "X-Access-Token": "111"
      }),
      success(response) {
        resolve(response.data);
      },
      fail(err) {
        common_vendor.index.showToast({
          icon: "none",
          title: "服务响应失败"
        });
        common_vendor.index.__f__("error", "at request.uts:76", err);
        reject(err);
      },
      complete() {
        common_vendor.index.hideLoading();
      }
    });
  });
}
function tokenRequest(path = null, method = null, data = null, loading = null, token = null) {
  return new Promise((resolve, reject) => {
    common_vendor.index.request({
      url: BASEURL + path,
      method,
      data,
      header: new UTSJSONObject({
        "X-Access-Token": token
      }),
      success(response) {
        if (response.data.code === 40101)
          ;
        resolve(response.data);
      },
      fail(err) {
        common_vendor.index.showToast({
          icon: "none",
          title: "服务响应失败"
        });
        common_vendor.index.__f__("error", "at request.uts:109", err);
        reject(err);
      },
      complete() {
        common_vendor.index.hideLoading();
      }
    });
  });
}
exports.request = request;
//# sourceMappingURL=../.sourcemap/mp-weixin/request.js.map
