Initial commit: 商品售卖网站
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080/api'
|
||||
const BASE_URL = API_BASE_URL.replace('/api', '')
|
||||
|
||||
export function getImageUrl(path: string): string {
|
||||
if (!path) return ''
|
||||
if (path.startsWith('http://') || path.startsWith('https://')) {
|
||||
return path
|
||||
}
|
||||
if (path.startsWith('/')) {
|
||||
return BASE_URL + path
|
||||
}
|
||||
return BASE_URL + '/' + path
|
||||
}
|
||||
|
||||
export function getFirstImage(images: string): string {
|
||||
if (!images) return ''
|
||||
const arr = images.split(',').map((s: string) => s.trim()).filter(Boolean)
|
||||
const first = arr[0] || ''
|
||||
return getImageUrl(first)
|
||||
}
|
||||
Reference in New Issue
Block a user