index.js 1.28 KB
import { Message } from 'element-ui'
export function debounce(func, wait = 200) {
  let timeout
  return function(event) {
    clearTimeout(timeout)
    timeout = setTimeout(() => {
      func.call(this, event)
    }, wait)
  }
}

export function dateFormat(dateTime, format = 'YYYY-MM-DD HH:mm:ss') {
  const date = new Date(dateTime)
  const config = {
    YYYY: date.getFullYear(),
    MM: date.getMonth() + 1, //getMonth() 方法根据本地时间返回指定日期的月份(从 0 到 11)
    DD: date.getDate(),
    HH: date.getHours(),
    mm: date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
    ss: date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  }
  for (const key in config) {
    format = format.replace(key, config[key])
  }
  return format
}

export function cloneText(message) {
  let input = document.createElement('input')
  input.value = message
  document.body.appendChild(input)
  input.select()
  input.setSelectionRange(0, input.value.length), document.execCommand('Copy')
  document.body.removeChild(input)
  Message.success({ message: '复制成功', customClass: 'msgTips' })
}

export function openTab(url) {
  const link = document.createElement('a')
  link.href = url
  link.target = '_blank'
  link.rel = 'opener'
  link.click()
}