"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _MapTool = _interopRequireDefault(require("./MapTool"));
var _lodash = _interopRequireDefault(require("lodash"));
var _getVtxToken = _interopRequireDefault(require("@vtx/utils/lib/getVtxToken"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var timer = null;
var PublicService = exports["default"] = /*#__PURE__*/function () {
  function PublicService() {
    _classCallCheck(this, PublicService);
  }
  _createClass(PublicService, null, [{
    key: "transformPiePercent",
    value:
    // 获取饼图数据占比
    function transformPiePercent(data, total) {
      var selected = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
      var all = 0;
      data.map(function (item, index) {
        if (_lodash["default"].isEmpty(selected) || selected["".concat(item.name)]) {
          item.percent = (item.value / total * 100).toFixed(2);
          all += Number(item.percent);
          if (index === data.length - 1 && all < 100) {
            var count = 100 - all;
            data[0].percent = Number(item.percent) + count;
          }
        }
      });
      return data;
    }

    // 转换参数
  }, {
    key: "transformParams",
    value: function transformParams(params, type) {
      var areaId = PublicService.getLocalStorage('userInfo', 'areaId');
      if (areaId) {
        var name = type ? 'areaId=' : 'areaId%3d';
        var where = name + areaId;
        params.cql_filter = params.cql_filter ? "".concat(params.cql_filter, " and ").concat(where) : where;
      }
      return params;
    }
  }, {
    key: "getQueryString",
    value: function getQueryString(name) {
      var reg = new RegExp("(^|&?)".concat(name, "=([^&]*)(&|$)"));
      var r = window.location.href.substr(1).match(reg);
      if (r !== null) {
        return unescape(r[2]);
      }
      return null;
    }

    // @name 对象深克隆
  }, {
    key: "deepClone",
    value: function deepClone(obj) {
      if (_typeof(obj) !== 'object') {
        return obj;
      }
      if (!obj) {
        return;
      }
      var newObj = obj.constructor === Array ? [] : {}; //开辟一块新的内存空间
      for (var i in obj) {
        newObj[i] = this.deepClone(obj[i]); //通过递归实现深层的复制
      }
      return newObj;
    }

    /**
     * @name cookie存值
     * @param c_name 要保存字段的名称
     * @param value 要保存字段的值
     * @param expireDays 过期时间
     */
  }, {
    key: "setCookie",
    value: function setCookie(c_name, value) {
      var expireDays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 30;
      document.cookie = "".concat(c_name, "=").concat(escape(value));
      // cookie过期时间
      // let expireTimeCode = timeCode + (60 * 60 * 24 * expireDays);
      // if (expireDays)
      //   document.cookie = 'expireTimeCode=' + expireTimeCode
    }

    /**
     * @name 拼接参数
     * @param params 导出文件所需参数
     * @returns {*}   返回导出拼接字符串
     */
  }, {
    key: "paramSerializer",
    value: function paramSerializer(params) {
      if (!params) return '';
      var urlPart = [];
      for (var k in params) {
        var value = params[k];
        if (value === null || typeof value === 'undefined') continue;
        if (Array.isArray(value)) {
          for (var i = 0, l = value.length; i < l; i++) {
            urlPart.push("".concat(k, "=").concat(value[i]));
          }
        } else {
          urlPart.push("".concat(k, "=").concat(value));
        }
      }
      return urlPart.join('&');
    }

    /**
     * @name cookie取值
     * @param c_name 要取得的字段名
     * @returns {string} 返回字段对应的值, 若字段不存在则返回空
     */
  }, {
    key: "getCookie",
    value: function getCookie(c_name) {
      if (document.cookie.length > 0) {
        var c_start = document.cookie.indexOf("".concat(c_name, "="));
        if (c_start !== -1) {
          c_start = c_start + c_name.length + 1;
          var c_end = document.cookie.indexOf(';', c_start);
          if (c_end == -1) c_end = document.cookie.length;
          return unescape(document.cookie.substring(c_start, c_end));
        }
      }
      return '';
    }

    /**
     * @name cookie删值
     * @param name 要清空的字段名
     */
  }, {
    key: "clearCookie",
    value: function clearCookie(name) {
      this.setCookie(name, '', -1);
    }

    /**
     * @name localStorage取值
     * @param field 要获取的对象信息
     * @param fieldName 要获取的对象中的信息
     */
  }, {
    key: "getLocalStorage",
    value: function getLocalStorage(field, fieldName) {
      var content = '';
      if (localStorage.getItem(field)) {
        if (fieldName) {
          var session = JSON.parse(localStorage.getItem(field));
          if (session) {
            content = session[fieldName];
          }
        } else {
          content = localStorage.getItem(field);
        }
      }
      return content;
    }

    /**
     *  @name 数组中取出指定的字段
     *  @param data[]: 数据
     *  @param key: 指定键名
     *  @returns list 返回一维数组
     *
     */
  }, {
    key: "getDataByKey",
    value: function getDataByKey(data, key) {
      var list = [];
      if (data && data.length) {
        data.map(function (item) {
          list.push(item[key]);
        });
      }
      return list;
    }

    /**
     * @name 转换下拉选数据
     * @param data 数据源
     * @param valueIndex option的value
     * @param labelIndex option的label
     * @param addAll 添加option {value: '', text: '全部'}
     * @param paramsAll 添加全部元素
     * @returns {Array} 根据需要生成的select option配置
     */
  }, {
    key: "transformOptions",
    value: function transformOptions(_ref) {
      var data = _ref.data,
        _ref$valueIndex = _ref.valueIndex,
        valueIndex = _ref$valueIndex === void 0 ? 'id' : _ref$valueIndex,
        _ref$labelIndex = _ref.labelIndex,
        labelIndex = _ref$labelIndex === void 0 ? 'name' : _ref$labelIndex,
        addAll = _ref.addAll,
        paramsAll = _ref.paramsAll,
        valueType = _ref.valueType;
      var options = [];
      if (addAll) {
        options.push({
          value: '',
          label: '全部'
        });
      }
      if (data && data.length) {
        var _loop = function _loop() {
          var option = {
            value: data[i][valueIndex],
            label: data[i][labelIndex],
            text: data[i][labelIndex]
          };
          if (valueType && valueType === 'string') {
            option.value = String(option.value);
          }
          if (valueType && valueType === 'number') {
            option.value = Number(option.value);
          }
          if (data[i].children || data[i].childList) {
            var _data = data[i].children || data[i].childList;
            option.children = [];
            _data.forEach(function (item, index) {
              var _option = {
                value: item[valueIndex],
                label: item[labelIndex],
                text: item[labelIndex]
              };
              if (valueType && valueType === 'string') {
                _option.value = String(_option.value);
              }
              option.children.push(_option);
            });
          }
          if (paramsAll) {
            option = _objectSpread(_objectSpread({}, data[i]), option);
          }
          options.push(option);
        };
        for (var i = 0; i < data.length; i++) {
          _loop();
        }
      }
      return options;
    }

    /**
     * @name 转换树状表格数据
     * @param data 需要转换结构的源数据
     * @param needKey 需要增加唯一标识key
     * @param parentKey 父级key
     * @returns {*} 转换后的数据
     */
  }, {
    key: "transformTreeData",
    value: function transformTreeData(_ref2) {
      var _this = this;
      var data = _ref2.data,
        needKey = _ref2.needKey,
        justKey = _ref2.justKey,
        disabledKey = _ref2.disabledKey,
        disabledValue = _ref2.disabledValue;
      if (needKey) {
        data.map(function (item, index) {
          if (!item.key) {
            item.key = item.id || item.value;
          }
          if (!justKey) {
            item.label = item.name;
            item.value = item.id || item.value;
            item.title = item.name;
          }
          if (item.disabled) {
            item.selectable = !item.disabled;
          }
          if (item.disableCheckbox) {
            item.chkDisabled = item.disableCheckbox;
          }
          if (disabledKey && disabledValue) {
            item.disabled = String(item[disabledKey]) === String(disabledValue);
          }
          if (item.children && item.children.length) {
            _this.transformTreeData({
              data: item.children,
              needKey: needKey,
              justKey: justKey,
              disabledKey: disabledKey,
              disabledValue: disabledValue
            });
          } else if (item.child && item.child.length) {
            _this.transformTreeData({
              data: item.child,
              needKey: needKey,
              justKey: justKey,
              disabledKey: disabledKey,
              disabledValue: disabledValue
            });
          }
          if (item.children && !item.children.length) {
            delete item.children;
          } else if (item.child && !item.child.length) {
            delete item.child;
          }
        });
        return data;
      }
    }

    /**
     * @name 转换表格数据
     * @param data 需要转换结构的源数据
     * @param needColNum 需要增加table序号列数据
     * @param needKey 需要增加唯一标识key
     * @param currentPage 当前页
     * @param pageSize 每页数据数目
     * @returns {*} 转换后的数据
     */
  }, {
    key: "transformArrayData",
    value: function transformArrayData(_ref3) {
      var data = _ref3.data,
        needColNum = _ref3.needColNum,
        needKey = _ref3.needKey,
        currentPage = _ref3.currentPage,
        pageSize = _ref3.pageSize;
      // 需要添加table序号
      if (needColNum) {
        for (var i = 0; i < data.length; i++) {
          // 有分页
          if (currentPage && pageSize) {
            data[i]['num'] = pageSize * (currentPage - 1) + i + 1;
            // 无分页
          } else {
            data[i]['num'] = i + 1;
          }
        }
        // 需要添加唯一标识key
      }
      // 添加Key
      if (needKey) {
        for (var _i = 0; _i < data.length; _i++) {
          // 若数据不存在key字段,则增加唯一标识key
          if (!data[_i]['key']) data[_i]['key'] = _i;
        }
      }
      if (!needColNum) {
        console.info('检查transformArrayData方法参数(needColNum,needKey),返回数据结构未改变');
      }
      return data;
    }

    /**
     * @name 权限验证
     * @param code 按钮类型
     */
  }, {
    key: "checkAuth",
    value: function checkAuth(code) {
      var access = false,
        name = '',
        pageName = '';
      var accessBtn = localStorage.getItem('accessBtn');
      if (accessBtn) {
        var _accessBtn;
        accessBtn = JSON.parse(accessBtn);
        if ((_accessBtn = accessBtn) !== null && _accessBtn !== void 0 && _accessBtn.length) {
          var hash = window.location.hash;
          var path = hash.split('#')[1].split('?')[0];
          if (path.indexOf('/') !== -1) {
            var pathList = path.split('/');
            if (pathList.length > 2) {
              pathList = pathList.splice(pathList.length - 2, pathList.length);
            }
            name = pathList[0];
            pageName = pathList[1];
          }
          var val = "".concat(name, "_").concat(pageName, "_").concat(code);
          access = accessBtn.some(function (item) {
            return item.code === val;
          });
        }
      }
      return access;
    }
    /**
     * @name 乘法精度
     * @param num1 数字1
     * @param num2 数字2
     */
  }, {
    key: "accMul",
    value: function accMul(num1, num2) {
      var m = 0;
      var s1 = num1.toString();
      var s2 = num2.toString();
      try {
        m += s1.split('.')[1].length;
      } catch (e) {
        // console.log('e:', e);
      }
      try {
        m += s2.split('.')[1].length;
      } catch (e) {
        // console.log('e:', e);
      }
      return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m);
    }

    /**
     * 获取token
     */
  }, {
    key: "getToken",
    value: function getToken() {
      return (0, _getVtxToken["default"])('token');
    }

    /**
     * 设置标签名称
     * @param data - 数据
     * @param value - 值
     * @returns {string}
     */
  }, {
    key: "selectLabel",
    value: function selectLabel(data, value) {
      var actions = [];
      Object.keys(data).some(function (key) {
        if (String(data[key].value) === String(value)) {
          actions.push(data[key].label || data[key].text);
          return true;
        }
      });
      return actions.join('');
    }

    /**
     * 设置标签名称
     * @param data - 数据
     * @param value - 值
     * @param key - 键
     * @returns {string}
     */
  }, {
    key: "treeSelectLabel",
    value: function treeSelectLabel(treeData, value, key) {
      var result = value;
      var renderTree = function renderTree(data) {
        data.map(function (item) {
          // 行政村支持点击跳转
          if (value === item["".concat(key)]) {
            result = item.name;
          }
          if (item.children && item.children.length) {
            renderTree(item.children);
          }
        });
      };
      renderTree(treeData);
      return result;
    }
  }, {
    key: "getSystemInfo",
    value: function getSystemInfo(key) {
      var systemInfo = localStorage.getItem('systemInfo');
      var system = {};
      if (systemInfo && systemInfo !== '[object Object]') {
        system = JSON.parse(decodeURIComponent(decodeURIComponent(systemInfo)));
        system = _objectSpread(_objectSpread({}, system), {}, {
          access_token: system.token
        });
      }
      if (key) {
        return system[key];
      }
    }
  }, {
    key: "cacheMessage",
    value: function cacheMessage(cacheKey, mess) {
      // 缓存上次登录 账号和租户等登陆信息
      var m = _objectSpread({}, mess);
      localStorage.setItem(cacheKey, this.enCode(JSON.stringify(m)));
      sessionStorage.setItem(cacheKey, this.enCode(JSON.stringify(m)));
      return this;
    }
  }, {
    key: "enCode",
    value: function enCode(data) {
      return encodeURIComponent(encodeURIComponent(data));
    }

    // @name 高德坐标转天地图坐标
  }, {
    key: "onConvertFrom",
    value: function onConvertFrom(lng, lat) {
      //定义一些常量
      var PI = 3.1415926535897932384626;
      var a = 6378245.0;
      var ee = 0.00669342162296594323;
      function gcj02towgs84(lng, lat) {
        if (out_of_china(lng, lat)) {
          return [lng, lat];
        } else {
          var dlat = transformlat(lng - 105.0, lat - 35.0);
          var dlng = transformlng(lng - 105.0, lat - 35.0);
          var radlat = lat / 180.0 * PI;
          var magic = Math.sin(radlat);
          magic = 1 - ee * magic * magic;
          var sqrtmagic = Math.sqrt(magic);
          dlat = dlat * 180.0 / (a * (1 - ee) / (magic * sqrtmagic) * PI);
          dlng = dlng * 180.0 / (a / sqrtmagic * Math.cos(radlat) * PI);
          var mglat = lat + dlat;
          var mglng = lng + dlng;
          return [lng * 2 - mglng, lat * 2 - mglat];
        }
      }
      function transformlat(lng, lat) {
        var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
        ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
        return ret;
      }
      function transformlng(lng, lat) {
        var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
        ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
        return ret;
      }
      function out_of_china(lng, lat) {
        return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271 || false;
      }
      return gcj02towgs84(lng, lat);
    }

    // @name 天地图坐标转高德坐标
  }, {
    key: "onConvertFrom2",
    value: function onConvertFrom2(LNG, LAT) {
      //转换常数
      var pi = 3.14159265358979324;
      var a = 6378245.0;
      var ee = 0.00669342162296594323;
      function transformLon(x, y) {
        var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
        return ret;
      }
      function transformLat(x, y) {
        var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
        return ret;
      }
      function outOfChina(lng, lat) {
        return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271 || false;
      }
      function transform(wgLat, wgLon) {
        var point = {};
        if (outOfChina(wgLat, wgLon)) {
          point.lat = wgLat;
          point.lon = wgLon;
          return point;
        }
        var dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
        var dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
        var radLat = wgLat / 180.0 * pi;
        var magic = Math.sin(radLat);
        magic = 1 - ee * magic * magic;
        var sqrtMagic = Math.sqrt(magic);
        dLat = dLat * 180.0 / (a * (1 - ee) / (magic * sqrtMagic) * pi);
        dLon = dLon * 180.0 / (a / sqrtMagic * Math.cos(radLat) * pi);
        point.lat = wgLat + dLat - 0.00345;
        point.lon = wgLon + dLon - 0.00145;
        return point;
      }
      return transform(LNG, LAT);
    }

    /**
     * 定时器刷新
     * @param {*} fun  定时刷新的函数
     * @param {*} delay  延时时长
     */
  }, {
    key: "setIntervalData",
    value: function setIntervalData(fun) {
      var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10000;
      timer = setInterval(function () {
        fun();
      }, delay);
    }

    /**
     * 清除定时器
     */
  }, {
    key: "clearIntervalData",
    value: function clearIntervalData() {
      if (timer) {
        clearInterval(timer);
      }
    }
  }, {
    key: "getFlatternDistance",
    value: function getFlatternDistance(_ref4) {
      var lon1 = _ref4.lon1,
        lat1 = _ref4.lat1,
        lon2 = _ref4.lon2,
        lat2 = _ref4.lat2;
      var DEF_PI = 3.14159265359; // PI
      var DEF_2PI = 6.28318530712; // 2*PI
      var DEF_PI180 = 0.01745329252; // PI/180.0
      var DEF_R = 6370693.5; // radius of earth
      var ew1, ns1, ew2, ns2;
      var dx, dy, dew;
      var distance; // 角度转换为弧度
      ew1 = lon1 * DEF_PI180;
      ns1 = lat1 * DEF_PI180;
      ew2 = lon2 * DEF_PI180;
      ns2 = lat2 * DEF_PI180;
      // 经度差
      dew = ew1 - ew2; // 若跨东经和西经180 度，进行调整
      if (dew > DEF_PI) dew = DEF_2PI - dew;else if (dew < -DEF_PI) dew = DEF_2PI + dew;
      dx = DEF_R * Math.cos(ns1) * dew; // 东西方向长度(在纬度圈上的投影长度)
      dy = DEF_R * (ns1 - ns2); // 南北方向长度(在经度圈上的投影长度)
      // 勾股定理求斜边长
      distance = Math.sqrt(dx * dx + dy * dy).toFixed(0);
      return distance;
    }
  }, {
    key: "getTenantById",
    value: function getTenantById() {
      var tenantId = PublicService.getQueryString('tenantId') || PublicService.getSystemInfo('tenantId') || '';
      window.$sdk.ums.getTenantById({
        tenantId: tenantId
      }).then(function (data) {
        window.sessionStorage.setItem('systemInfo', JSON.stringify(data.data));
      });
    }
  }, {
    key: "getDefaultMapInfo",
    value: function getDefaultMapInfo() {
      var systemInfo = this.getSystemInfoValue() || {};
      var val = {
        longitude: systemInfo.longitude,
        latitude: systemInfo.latitude,
        mapType: 'wgs84'
      };
      if (systemInfo !== null && systemInfo !== void 0 && systemInfo.mapDefJson) {
        var mapDefJson = JSON.parse(systemInfo.mapDefJson);
        var defaultMap = mapDefJson.find(function (v) {
          return v.defaultMap;
        }) || {};
        val = _objectSpread(_objectSpread(_objectSpread({}, val), defaultMap), {}, {
          mapType: defaultMap.coordinate || 'wgs84'
        });
      }
      return val;
    }
  }, {
    key: "getSystemInfoValue",
    value: function getSystemInfoValue(key) {
      var _systemInfo;
      var systemInfo = window.sessionStorage.getItem('systemInfo');
      systemInfo = systemInfo && JSON.parse(systemInfo) || {};
      var info = key ? (_systemInfo = systemInfo) === null || _systemInfo === void 0 ? void 0 : _systemInfo[key] : systemInfo;
      return info;
    }
  }, {
    key: "transformLonLatBySystemMapInfo",
    value: function transformLonLatBySystemMapInfo(x, y) {
      var _x = x,
        _y = y;
      var _this$getDefaultMapIn = this.getDefaultMapInfo(),
        mapType = _this$getDefaultMapIn.mapType;
      if (mapType === 'bmap') {
        var gcj = _MapTool["default"].wgs84togcj02(x, y);
        var bd = _MapTool["default"].gcj02tobd09(gcj[0], gcj[1]);
        _x = bd[0];
        _y = bd[1];
      } else if (mapType === 'amap') {
        var _gcj = _MapTool["default"].wgs84togcj02(x, y);
        _x = _gcj[0];
        _y = _gcj[1];
      }
      return [_x, _y];
    }
  }, {
    key: "transformGeometryInfoBySystemMapInfo",
    value: function transformGeometryInfoBySystemMapInfo(geometryData, type) {
      var _this2 = this;
      var val = {
        coordType: 'wgs84',
        lngLats: '',
        type: type
      };
      var _this$getDefaultMapIn2 = this.getDefaultMapInfo(),
        mapType = _this$getDefaultMapIn2.mapType;
      val.coordType = mapType;
      if (geometryData !== null && geometryData !== void 0 && geometryData.length) {
        if (type === 'point') {
          val.lngLats = this.transformLonLatByType(geometryData, val.coordType).join(',');
        } else if (type === 'polygon') {
          var _geometryData;
          var lngLats = '';
          var arr = ((_geometryData = geometryData[geometryData.length - 1]) === null || _geometryData === void 0 ? void 0 : _geometryData[0]) || [];
          arr.map(function (v, i) {
            var str = '';
            if (i === arr.length - 1) {
              lngLats += "".concat(_this2.transformLonLatByType(geometryData, val.coordType).join(','));
            } else {
              lngLats += "".concat(_this2.transformLonLatByType(geometryData, val.coordType).join(','), ";");
            }
            lngLats += str;
          });
          val.lngLats = lngLats;
        } else {
          var _lngLats = '';
          geometryData.map(function (v, i) {
            var str = '';
            if (i === geometryData.length - 1) {
              _lngLats += "".concat(_this2.transformLonLatByType(v, val.coordType).join(','));
            } else {
              _lngLats += "".concat(_this2.transformLonLatByType(v, val.coordType).join(','), ";");
            }
            _lngLats += str;
          });
          val.lngLats = _lngLats;
        }
      }
      return val;
    }
  }, {
    key: "transformGeometryInfoToWGS84",
    value: function transformGeometryInfoToWGS84(lngLats, type) {
      var _this3 = this;
      var _this$getDefaultMapIn3 = this.getDefaultMapInfo(),
        mapType = _this$getDefaultMapIn3.mapType;
      var lngLatArr = [];
      if (lngLats) {
        if (type === 'point') {
          var _l = typeof lngLats === 'string' ? lngLats.split(',') : lngLats;
          lngLatArr = this.transformLonLatToWGS84(_l, mapType);
        } else if (type === 'polygon') {
          lngLats.split(';').map(function (res) {
            lngLatArr.push(_this3.transformLonLatToWGS84(res.split(','), mapType));
          });
        } else {
          lngLats.split(';').map(function (res) {
            lngLatArr.push(_this3.transformLonLatToWGS84(res.split(','), mapType));
          });
        }
      }
      return lngLatArr;
    }
  }, {
    key: "transformLonLatByType",
    value: function transformLonLatByType(lonLat, type) {
      var _lonLat = _toConsumableArray(lonLat);
      if (type === 'bmap') {
        var gcj = _MapTool["default"].wgs84togcj02(lonLat[0], lonLat[1]);
        _lonLat = _MapTool["default"].gcj02tobd09(gcj[0], gcj[1]);
      } else if (type === 'amap') {
        _lonLat = _MapTool["default"].wgs84togcj02(lonLat[0], lonLat[1]);
      }
      return _lonLat;
    }
  }, {
    key: "transformLonLatToWGS84",
    value: function transformLonLatToWGS84(lonLat, type) {
      var _lonLat = _toConsumableArray(lonLat);
      if (type === 'bmap') {
        var gcj = _MapTool["default"].bd09togcj02(lonLat[0], lonLat[1]);
        _lonLat = _MapTool["default"].gcj02towgs84(gcj[0], gcj[1]);
      } else if (type === 'amap') {
        _lonLat = _MapTool["default"].gcj02towgs84(lonLat[0], lonLat[1]);
      }
      return _lonLat;
    }

    /**
     * @description:cq_filter传参转换
     * @param {array} data 数据
     * @param {string} field 字段
     * @return {string}
     */
  }, {
    key: "setCenterAndZoom",
    value:
    // 设置地图中心点位及层级
    function setCenterAndZoom(map) {
      var center = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [119.954392, 30.05157];
      var zoom = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 12;
      map.getView().animate({
        center: center,
        zoom: zoom,
        duration: 500
      });
    }

    // 根据因子增加日期其他参数
  }, {
    key: "getCollectFrequencyByDate",
    value: function getCollectFrequencyByDate(type) {
      var list = {
        DAY: 'hour',
        MONTH: 'day',
        YEAR: 'day',
        HISTORY: 'day',
        // 历史
        AUTO: 'day',
        // 自定义
        day: 'hour',
        week: 'day',
        month: 'day',
        year: 'day'
      };
      return (list === null || list === void 0 ? void 0 : list[type]) || 'day';
    }

    /**
     * 通过类型更改filtrate查询框提示信息
     */
  }, {
    key: "filtrateToPlaceholder",
    value: function filtrateToPlaceholder(v) {
      var placeholder = '';
      if (['number', 'textArea', 'input'].includes(v === null || v === void 0 ? void 0 : v.type)) {
        placeholder = "\u8BF7\u8F93\u5165".concat(v === null || v === void 0 ? void 0 : v.label);
      } else {
        placeholder = "\u8BF7\u9009\u62E9".concat(v === null || v === void 0 ? void 0 : v.label);
      }
      return placeholder;
    }
  }]);
  return PublicService;
}();
_defineProperty(PublicService, "getFilterParams", function (data) {
  var field = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'code';
  var join = arguments.length > 2 ? arguments[2] : undefined;
  var codes = [];
  if (join) {
    codes = data;
  } else {
    (data || []).map(function (v) {
      if (v[field]) {
        codes.push(v[field]);
      }
    });
  }
  var str = '';
  codes.map(function (v, i) {
    if (i === codes.length - 1) {
      str += "'".concat(v, "'");
    } else {
      str += "'".concat(v, "',");
    }
  });
  return str;
});
/**
 * @description: 获取数组的交集
 * @param {array} arrs 所有数组集合[aeeay1, array2, array3]
 * @return {array}
 */
_defineProperty(PublicService, "getArrayIntersection", function (arrs) {
  var res = arrs[0].slice();
  var intersection = function intersection(arr1, arr2) {
    var res = [];
    for (var i = 0; i < arr1.length; i++) {
      if (!arr2.includes(arr1[i])) {
        continue;
      }
      res.push(arr1[i]);
    }
    return res;
  };
  for (var i = 1; i < arrs.length; i++) {
    res = intersection(res, arrs[i]);
  }
  return res || [];
});
//# sourceMappingURL=PublicService.js.map
