Newer
Older
XiaoGanWXMini / unpackage / dist / dev / mp-weixin / utils / request.js
@zhangdeliang zhangdeliang on 29 Jul 1 KB 迁移
"use strict";
const common_vendor = require("../common/vendor.js");
let baseUrl = "";
baseUrl = "https://server1.wh-nf.cn:8131/prod-api";
function requestBody(path, method, data = {}, contType) {
  common_vendor.index.showLoading({
    title: "加载中",
    mask: true
  });
  return new Promise((resolve, reject) => {
    common_vendor.index.request({
      url: baseUrl + path,
      method,
      header: {
        "Content-Type": contType ? contType : "application/json;charset=utf-8"
      },
      data,
      timeout: 6e3 * 10,
      //超时时间
      success(response) {
        common_vendor.index.hideLoading();
        if (response.data.code !== 200) {
          common_vendor.index.showToast({
            icon: "none",
            duration: 2e3,
            title: response.data.msg || "请求失败,请检查网络"
          });
          return false;
        } else {
          resolve(response.data);
        }
      },
      fail(err) {
        common_vendor.index.hideLoading();
        common_vendor.index.showToast({
          icon: "none",
          title: "服务响应失败"
        });
        console.error(
          err
        );
        reject(err);
      },
      complete() {
      }
    });
  });
}
exports.requestBody = requestBody;