export function resolveFileString(str) {
  return str ? str.split(';').map((s) => resolveSingleFileString(s)) : []
}

export function resolveSingleFileString(str, sign = '|') {
  const [url, name] = str.split(sign)
  return {
    name,
    url: url.startsWith('http') ? url : window.GLOBAL_CONFIG.oss + '/' + url,
    origin: url
  }
}

// 获取完整文件地址
export function getFullUrl(url) {
  if (!url) return '';
  return url.startsWith('http') ? url : window.GLOBAL_CONFIG.oss + '/' + url
}

// 获取不完整文件地址
export function getPartUrl(url) {
  if (!url) return '';
  return url.startsWith('http') ? url.startsWith(window.GLOBAL_CONFIG.oss) ? url.substring(window.GLOBAL_CONFIG.oss.length) : Error('oss 地址错误') : url
}

export function getAvatarUrl(id) {
  return window.GLOBAL_CONFIG.oss + '/user/main/user_avatar?user_id=' + id
}
