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

export function resolveSingleFileString(str: string, 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: string) {
  if (!url)
    return ''
  return url.startsWith('http') ? url : `${window.GLOBAL_CONFIG.oss}/${url}`
}

// 获取不完整文件地址
export function getPartUrl(url: string) {
  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: string) {
  return `${window.GLOBAL_CONFIG.oss}/user/main/user_avatar?user_id=${id}`
}

import { user } from '~/store/index'

export function getThirdFrameLink(url: string, params?: Record<string, string>) {
  console.log('getThirdFrameLink', `${url}?token=${user.value?.token}&t=myx&js_code=myx&frame=1${params ? '&' + new URLSearchParams(params) : ''}`)
  return `${url}?token=${user.value?.token}&t=myx&js_code=myx&frame=1${params ? '&' + new URLSearchParams(params) : ''}`
}

export function getThirdLink(url: string, params?: Record<string, string>) {
  console.log('getThirdFrameLink', `${url}?token=${user.value?.token}&t=myx&js_code=myx${params ? '&' + new URLSearchParams(params) : ''}`)
  return `${url}?token=${user.value?.token}&t=myx&js_code=myx${params ? '&' + new URLSearchParams(params) : ''}`
}
