"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const crypto = require("./crypto.js");
require("../../../node_modules/element-plus/es/index.js");
;/* empty css                                                       */
;/* empty css                                                             */
const v4 = require("../../../node_modules/uuid/dist/esm-browser/v4.js");
const index = require("../../../node_modules/element-plus/es/components/loading/index.js");
const LoadingInstance = {
  target: null,
  // 保存Loading实例
  count: 0
};
function successRollback(resolve, res) {
  closeLoading();
  resolve(res);
}
function errRollback(reject, err) {
  closeLoading();
  reject(err.data || err);
}
function paramHandler(params, showLoading, isUpload = false) {
  params = params || {};
  if (!isUpload && $data_crypto) {
    let paramsObj;
    if (Array.isArray(params)) {
      paramsObj = {
        oriArrayParams: JSON.stringify(params)
      };
    } else {
      paramsObj = Object.assign({}, params);
    }
    let file = paramsObj.file;
    paramsObj.nonce = v4.default();
    paramsObj.timestamp = Date.now();
    if ($data_verify_sign && JSON.stringify(paramsObj) != "{}") {
      var keysArr = Object.keys(paramsObj).sort();
      params = {};
      let paramStr = "";
      for (var i in keysArr) {
        let key = keysArr[i];
        if (key == "file") {
          continue;
        }
        let value = paramsObj[key];
        if (!value && value !== false && value != 0) {
          value = "";
        }
        params[key] = value;
        if (typeof value == "object") {
          value = JSON.stringify(
            value,
            (key2, value2) => value2 === null ? void 0 : value2
          );
        }
        paramStr += key + "=" + value + "&";
      }
      let signMsg = crypto.sha256(paramStr);
      params.sig = signMsg;
    } else {
      params = paramsObj;
    }
    let userInfo = window.$store.getters.user;
    params.uid = userInfo.userId;
    if ($data_crypto) {
      if ("{}" != JSON.stringify(params)) {
        let paramStr = encodeURIComponent(JSON.stringify(params));
        params = { request: crypto.aes.en(paramStr) };
      }
    } else {
      if (params["oriArrayParams"]) {
        params = JSON.parse(params["oriArrayParams"]);
      }
    }
    if (file) {
      params.file = file;
    }
  }
  if (showLoading === true) {
    LoadingInstance.count++;
    if (LoadingInstance.count === 1) {
      LoadingInstance.target = index.ElLoading.service({
        fullscreen: true,
        lock: true,
        text: "拼命加载中",
        // spinner: loadingSvg,
        background: "rgba(0, 0, 0, 0)",
        customClass: "h-loading"
      });
    }
  }
  return params || {};
}
function closeLoading() {
  if (LoadingInstance.count > 0) {
    LoadingInstance.count--;
  }
  if (LoadingInstance.count === 0 && LoadingInstance.target) {
    LoadingInstance.target.close();
    LoadingInstance.target = null;
  }
}
exports.errRollback = errRollback;
exports.paramHandler = paramHandler;
exports.successRollback = successRollback;
