Files
nl-im-uniapp/src/utils/image.ts

27 lines
564 B
TypeScript
Raw Normal View History

2025-12-09 12:49:28 +08:00
/**
* 图片 URL 处理工具函数
*/
2026-07-08 08:18:02 +08:00
import { API_ORIGIN } from '@/config/app'
2025-12-09 12:49:28 +08:00
/**
* 解析图片 URL,为相对路径添加域名前缀
*/
export function resolveImageUrl(url?: string): string {
if (!url) return ''
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('data:')) {
return url
}
2026-07-08 08:18:02 +08:00
const normalized = url.startsWith('/') ? url : `/${url}`
if (normalized.startsWith('/uploads/')) {
return API_ORIGIN + normalized
2025-12-09 12:49:28 +08:00
}
return url
}
export function getImageBaseUrl(): string {
2026-07-08 08:18:02 +08:00
return API_ORIGIN
2025-12-09 12:49:28 +08:00
}