
let utils = {
  /**
   * 生成UUID字符串
   * @returns {string}
   * @constructor
   */
  UUID() {
    let d = new Date().getTime();
    let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      let r = (d + Math.random()*16)%16 | 0;
      d = Math.floor(d/16);
      return (c=='x' ? r : (r&0x7|0x8)).toString(16);
    });
    return uuid;
  },

  getCurrDate() {
    let date = new Date()
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes()
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
  },
  getCurrDateWithHMS() {
    let date = new Date()
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes()
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return h + ':' + minute + ':' + second;
  },

  /**
   * 获取用户信息
   * @returns {any}
   */
  userInfo() {
    return JSON.parse(localStorage.getItem('userInfo'))
  },

  /**
   * 判断value是否为Number类型
   * @param {*} value
   */
  isNumber(value) {
    return Object.prototype.toString.call(value) === '[object Number]'
  },

  /**
   * 判断value是否为String类型
   * @param {*} value
   */
  isString(value) {
    return Object.prototype.toString.call(value) === '[object String]'
  },

  /**
   * 判断value是否为Array类型
   * @param {*} value
   */
  isArray(value) {
    return Object.prototype.toString.call(value) === '[object Array]'
  },

  /**
   * 判断value是否为Date类型
   * @param {*} value
   */
  isDate(value) {
    return Object.prototype.toString.call(value) === '[object Date]'
  },

  /**
   * 判断value是否Undefined
   * @param {*} value
   */
  isUndefined(value) {
    return Object.prototype.toString.call(value) === '[object Undefined]'
  },

  /**
   * 判断value是否为布尔类型
   * @param {*} value
   */
  isBoolean(value) {
    return Object.prototype.toString.call(value) === '[object Boolean]'
  },

  /**
   * 判断value是否为null
   * @param {*} value
   */
  isNull(value) {
    return Object.prototype.toString.call(value) === '[object Null]'
  },

  /**
   * 判断value是否为Object类型
   * @param {*} value
   */
  isObject(value) {
    return Object.prototype.toString.call(value) === '[object Object]'
  },

  /**
   * 判断value是否为函数
   * @param {*} value
   */
  ifFunction(value) {
    return Object.prototype.toString.call(value) === '[object Function]'
  },

  initData(params) {
    let URLSearchParams = require('url-search-params');
    //360浏览器不支持URLSearchParams
    if (typeof URLSearchParams === "function") {
      let formMap = new URLSearchParams();
      for (let key in params) {
        formMap.append(key, params[key]);
      }
      return formMap;
    }
    else {
      return params;
    }
  },
}

export default utils
