This commit is contained in:
李志强 2026-06-02 21:15:42 +08:00
parent 1f5f4d16e6
commit a0cdd2b851
2 changed files with 28 additions and 5 deletions

View File

@ -18,7 +18,7 @@
>
<img
v-if="logo"
:src="API_BASE_URL + logo.replace(/^\//, '/')"
:src="getPreviewUrl(logo)"
class="logo-image"
/>
<el-icon v-else class="logo-uploader-icon"><Plus /></el-icon>
@ -33,7 +33,7 @@
>
<img
v-if="logow"
:src="API_BASE_URL + logow.replace(/^\//, '/')"
:src="getPreviewUrl(logow)"
class="logo-image darkbg"
/>
<el-icon v-else class="logo-uploader-icon"><Plus /></el-icon>
@ -48,7 +48,7 @@
>
<img
v-if="ico"
:src="API_BASE_URL + ico.replace(/^\//, '/')"
:src="getPreviewUrl(ico)"
class="logo-image"
/>
<el-icon v-else class="logo-uploader-icon"><Plus /></el-icon>
@ -119,6 +119,18 @@ const normalRules: FormRules = {
sitename: [{ required: true, message: "请输入站点名称", trigger: "blur" }],
};
const getPreviewUrl = (url: string) => {
const value = String(url || "").trim().replace(/\\/g, "/");
if (!value) return "";
if (/^(https?:\/\/|\/\/|data:|blob:)/i.test(value)) {
return value;
}
const base = String(API_BASE_URL || "").replace(/\/+$/, "");
const path = value.startsWith("/") ? value : `/${value}`;
return `${base}${path}`;
};
//
const initNormalInfos = async () => {
const res = await getNormalInfos(authStore.user.tid);

View File

@ -589,9 +589,20 @@ const getUserCateData = async () => {
}
};
//
//
// http/https 使
const getFileUrl = (url: string) => {
return `${import.meta.env.VITE_API_BASE_URL}${url}`;
if (!url) return "";
const normalizedUrl = String(url).trim().replace(/\\/g, "/");
if (/^(https?:\/\/|data:|blob:)/i.test(normalizedUrl)) {
return normalizedUrl;
}
const baseUrl = String(import.meta.env.VITE_API_BASE_URL || "").replace(/\/$/, "");
const path = normalizedUrl.startsWith("/") ? normalizedUrl : `/${normalizedUrl}`;
return `${baseUrl}${path}`;
};
//