Files
urldb/web/composables/useImageUrl.ts
2025-08-18 09:41:19 +08:00

25 lines
750 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.
export const useImageUrl = () => {
const getImageUrl = (url: string) => {
if (!url) return ''
// 如果已经是完整URL直接返回
if (url.startsWith('http://') || url.startsWith('https://')) {
return url
}
// 如果是相对路径,在开发环境中添加后端地址
if (process.env.NODE_ENV === 'development') {
const fullUrl = `http://localhost:8080${url}`
// console.log('useImageUrl - 开发环境:', { original: url, processed: fullUrl })
return fullUrl
}
// 生产环境中直接返回相对路径通过Nginx代理
// console.log('useImageUrl - 生产环境:', { original: url, processed: url })
return url
}
return {
getImageUrl
}
}