/**
 * @desc 函数防抖
 * @param func 函数
 * @param wait 延迟执行毫秒数
 * @param immediate true 表立即执行，false 表非立即执行
 */
export function debounce(func, wait, immediate = true) {
  let timeout
  return function () {
    if (timeout) clearTimeout(timeout)
    if (immediate) {
      var callNow = !timeout
      timeout = setTimeout(() => {
        timeout = null
      }, wait)
      if (callNow) func.apply(this, arguments)
    } else {
      timeout = setTimeout(function () {
        func.apply(context, args)
      }, wait)
    }
  }
}

// 获取完整的url，根据环境进行配置
export function getTotalUrl(url) {
  if (url) {
    let fullUrl = ''
    let urlArr = url.split('files')
    // if (process.env.NODE_ENV == 'development') {
    //   fullUrl = url
    // } else {
    //   fullUrl = '/files' + urlArr[1]
    // }
    fullUrl = '/files' + urlArr[1]
    return fullUrl
  } else {
    return ''
  }

}
