"use strict";
const common_vendor = require("../common/vendor.js");
const config_url = require("./url.js");
const request = (option) => {
  return new Promise((resolve, reject) => {
    if (!option.hideLoading) {
      common_vendor.index.showLoading({
        title: option.loadingText || "加载中...",
        mask: true
      });
    }
    common_vendor.index.request({
      url: config_url.URL + option.url,
      method: option.method,
      data: option.data,
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        ...option.headers,
        "appid": config_url.appid,
        "Authorization": "Bearer " + common_vendor.index.getStorageSync("token"),
        "Clientid": common_vendor.index.getStorageSync("client_id")
      },
      success(res) {
        if (res.statusCode !== 200) {
          common_vendor.index.__f__("error", "at config/http.js:33", `HTTP状态码错误: ${res.statusCode}`, res.data);
          if (res.data) {
            resolve(res.data);
            return;
          }
          reject({ msg: `请求失败，状态码：${res.statusCode}` });
          return;
        }
        if (res.data && res.data.code !== 200) {
          common_vendor.index.__f__("warn", "at config/http.js:47", `业务状态码错误: ${res.data.code}`, res.data);
          if (option.ignoreEmptyError && (res.data.code === 500 && res.data.msg && (res.data.msg.includes("未找到") || res.data.msg.includes("不存在")))) {
            resolve({
              code: 200,
              msg: "操作成功",
              data: []
            });
            return;
          }
          resolve(res.data);
          return;
        }
        resolve(res.data);
      },
      fail(err) {
        common_vendor.index.__f__("error", "at config/http.js:71", `请求失败: ${option.url}`, err);
        reject(err);
      },
      complete() {
        if (!option.hideLoading) {
          common_vendor.index.hideLoading();
        }
      }
    });
  });
};
exports.request = request;
//# sourceMappingURL=../../.sourcemap/mp-weixin/config/http.js.map
