"use strict";
const common_vendor = require("../common/vendor.js");
const config_app = require("../config/app.js");
const hooks_useToast = require("../hooks/useToast.js");
function baseRequest(url, method, data, { noAuth = false, noVerify = false }, params) {
  const { Toast } = hooks_useToast.useToast();
  let Url = config_app.HTTP_REQUEST_URL, header = config_app.HEADER;
  if (params != void 0) {
    header = config_app.HEADERPARAMS;
  }
  return new Promise((reslove, reject) => {
    Url = config_app.HTTP_REQUEST_URL;
    common_vendor.index.request({
      url: Url + "/api/front/" + url,
      method: method || "GET",
      header,
      timeout: 3e4,
      data: data || {},
      success: (res) => {
        if (noVerify)
          reslove(res.data, res);
        else if (res.data.code == 200)
          reslove(res.data, res);
        else if ([41e4, 410001, 410002, 401].indexOf(res.data.code) !== -1) {
          reject(res.data);
        } else
          Toast({ title: res.data.message || "系统错误" });
        reject(res.data.message || "系统错误");
      },
      fail: (msg) => {
        Toast({ title: "请求失败" });
        reject("请求失败");
      }
    });
  });
}
const request = {};
["options", "get", "post", "put", "head", "delete", "trace", "connect"].forEach(
  (method) => {
    request[method] = (api, data, opt, params) => baseRequest(api, method, data, opt || {}, params);
  }
);
exports.request = request;
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/request.js.map
