Files
nl-im-uniapp/src/utils/image.ts
2026-07-08 08:18:02 +08:00

27 lines
564 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 图片 URL 处理工具函数
*/
import { API_ORIGIN } from '@/config/app'
/**
* 解析图片 URL为相对路径添加域名前缀
*/
export function resolveImageUrl(url?: string): string {
if (!url) return ''
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('data:')) {
return url
}
const normalized = url.startsWith('/') ? url : `/${url}`
if (normalized.startsWith('/uploads/')) {
return API_ORIGIN + normalized
}
return url
}
export function getImageBaseUrl(): string {
return API_ORIGIN
}