utils.js 424 B

123456789101112
  1. /**
  2. * 获取完整的图片URL
  3. * @param {string|object} image 图片文件ID、文件展示对象或完整地址
  4. * @returns {string} 完整的图片URL
  5. */
  6. export function getImageUrl(image) {
  7. if (!image) return ''
  8. if (typeof image === 'object') return image.thumbnail_url || image.url || ''
  9. if (/^(https?:)?\/\//i.test(image) || image.startsWith('/')) return image
  10. return `/file/${encodeURIComponent(image)}`
  11. }