fix:图片
This commit is contained in:
+13
-7
@@ -29,20 +29,26 @@ function toRelativeUrl(url) {
|
||||
return url;
|
||||
}
|
||||
|
||||
// 将相对路径转换为完整URL(用于返回给前端)
|
||||
// 将相对路径转换为完整URL(用于返回给前端,图片URL不带端口)
|
||||
function toFullUrl(url) {
|
||||
if (!url) return '';
|
||||
// 如果已经是完整URL,直接返回
|
||||
// 如果已经是完整URL,替换路径并移除端口
|
||||
if (url.startsWith('http://') || url.startsWith('https://')) {
|
||||
return url;
|
||||
// 将 /uploads/goods/ 替换为 /img/,并移除端口
|
||||
return url.replace('/uploads/goods/', '/img/').replace(/:\d+/, '');
|
||||
}
|
||||
// 如果是相对路径,拼接当前域名
|
||||
const baseUrl = DOMAIN_CONFIG.BASE_URL;
|
||||
// 如果是相对路径,拼接图片域名(不带端口)并替换路径
|
||||
const imgDomain = DOMAIN_CONFIG.IMG_DOMAIN || DOMAIN_CONFIG.BASE_URL.replace(/:\d+/, '');
|
||||
if (url.startsWith('/')) {
|
||||
return baseUrl + url;
|
||||
// 将 /uploads/goods/ 替换为 /img/
|
||||
return imgDomain + url.replace('/uploads/goods/', '/img/');
|
||||
}
|
||||
if (url.startsWith('img/')) {
|
||||
return baseUrl + '/' + url;
|
||||
return imgDomain + '/' + url;
|
||||
}
|
||||
// 处理可能的 uploads/goods/ 开头的路径
|
||||
if (url.startsWith('uploads/goods/')) {
|
||||
return imgDomain + '/img/' + url.replace('uploads/goods/', '');
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user