/* eslint-disable */
const toolClass = {
  dateFormat: (timestamp, fmt) => { // 时间格式转换
    if (timestamp) {
      if (!fmt) {
        fmt = 'yyyy-MM-dd hh:mm'
      }
      let date = new Date(timestamp)
      var o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds(),
        'q+': Math.floor((date.getMonth() + 3) / 3),
        'S': date.getMilliseconds()
      }
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
      }
      for (var k in o) {
        if (new RegExp('(' + k + ')').test(fmt)) {
          fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
        }
      }
      return fmt
    } else {
      return ''
    }
  },
  getCode: (appid) => {
    const refer = window.encodeURIComponent(window.location.href.replace(/code=[^?&#/=]+/, '').replace(/state=[^?&=#/]+/, '').replace(/\?\&+/, '?'))
    let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${refer}&response_type=code&scope=snsapi_userinfo&state=12313#wechat_redirect`
    window.location.href = url
  },
  UrlSearch: (urls) => {
    let url = urls // 获取url中"?"符后的字串
    let theRequest = {}
    if (url.indexOf('?') !== -1) {
      let str = url.substr(1)
      let strs = str.split('&')
      for (var i = 0; i < strs.length; i++) {
        theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])
      }
    }
    return theRequest
  }
}

export default toolClass
