/**
 * 根据上传地址获取文件名称
*/
export function getFileTitle(url) {
  if (!url) {
    return
  }
  const lastSplitIndex = url.lastIndexOf('/')
  if (lastSplitIndex < 0) {
    return
  }
  return window.decodeURIComponent(url.substr(lastSplitIndex + 1))
}

/**
 * 格式化文件尺寸
*/
export function formatBytes(bytes) {
  var b = 2
  if (bytes === 0) {
    return '0 B'
  }
  var c = 1024
  var d = b || 2
  var e = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  var f = Math.floor(Math.log(bytes) / Math.log(c))
  return parseFloat((bytes / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
}
