fix: withBase 兼容后端返回的 OSS 绝对地址,避免拼接出现错误前缀
This commit is contained in:
@@ -118,9 +118,15 @@ const AppPackageAPI = {
|
|||||||
|
|
||||||
export default AppPackageAPI;
|
export default AppPackageAPI;
|
||||||
|
|
||||||
/** 拼接静态资源完整访问地址(img / el-image 的 src 不经过 axios,需手动补 baseURL) */
|
/**
|
||||||
|
* 拼接静态资源完整访问地址(img / el-image 的 src 不经过 axios,需手动补 baseURL)
|
||||||
|
* 说明:后端现在直接返回 OSS 绝对地址(https://xxx.aliyuncs.com/...),不再需要拼前缀,
|
||||||
|
* 这里同时兼容历史相对路径(/20261019/xxx.png)。
|
||||||
|
*/
|
||||||
export function withBase(url?: string): string {
|
export function withBase(url?: string): string {
|
||||||
if (!url) return "";
|
if (!url) return "";
|
||||||
|
// 已是绝对地址(http(s)://、协议相对 //、base64)时原样返回,避免拼出 /dev-apihttps://... 这类错误地址
|
||||||
|
if (/^(https?:)?\/\//i.test(url) || url.startsWith("data:")) return url;
|
||||||
const baseApi = import.meta.env.VITE_APP_BASE_API ?? "";
|
const baseApi = import.meta.env.VITE_APP_BASE_API ?? "";
|
||||||
return `${baseApi}${url}`;
|
return `${baseApi.replace(/\/$/, "")}${url.startsWith("/") ? "" : "/"}${url}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,7 @@
|
|||||||
v-for="(s, i) in current.screenshots || []"
|
v-for="(s, i) in current.screenshots || []"
|
||||||
:key="i"
|
:key="i"
|
||||||
:src="withBase(s)"
|
:src="withBase(s)"
|
||||||
:preview-src-list="(current.screenshots || []).map(withBase)"
|
:preview-src-list="(current.screenshots || []).map((s) => withBase(s))"
|
||||||
:initial-index="i"
|
:initial-index="i"
|
||||||
fit="cover"
|
fit="cover"
|
||||||
class="shot-gallery__item"
|
class="shot-gallery__item"
|
||||||
|
|||||||
Reference in New Issue
Block a user