63 lines
2.4 KiB
JavaScript
63 lines
2.4 KiB
JavaScript
import {
|
|
STATIC_ASSETS_BASE_URL_DEFAULT,
|
|
STATIC_ASSETS_BASE_URL_PRODUCTION,
|
|
STATIC_ASSETS_BASE_URL_TEST
|
|
} from '@/config/static-assets-defaults'
|
|
import { getStaticAssetsVersion, withOssVersion } from '@/utils/ossCache'
|
|
|
|
function normalizeBase(u) {
|
|
const s = (u || '').trim() || STATIC_ASSETS_BASE_URL_DEFAULT
|
|
return s.endsWith('/') ? s : `${s}/`
|
|
}
|
|
|
|
function isPlaceholderBaseUrl(value) {
|
|
const text = String(value || '').trim().toLowerCase()
|
|
if (!text) return true
|
|
return text.includes('replace_') || text.includes('replace_prod_static_host')
|
|
}
|
|
|
|
function resolveBase() {
|
|
// 优先当前 APP_ENV;占位则回退空串走本地 /static/
|
|
const remote = STATIC_ASSETS_BASE_URL_DEFAULT || STATIC_ASSETS_BASE_URL_PRODUCTION || STATIC_ASSETS_BASE_URL_TEST
|
|
if (isPlaceholderBaseUrl(remote)) return ''
|
|
return normalizeBase(remote)
|
|
}
|
|
|
|
function localStaticUrl(relativePath) {
|
|
const p = String(relativePath || '').replace(/^\/+/, '')
|
|
return `/static/${p}`
|
|
}
|
|
|
|
export function getStaticAssetsBaseUrl() {
|
|
return resolveBase()
|
|
}
|
|
|
|
/**
|
|
* 拼接静态资源完整 URL。
|
|
* 未配置远程 CDN 时,回退到项目内 `/static/` 目录(本地开发/框架阶段默认行为)。
|
|
*/
|
|
export function staticAssetUrl(relativePath) {
|
|
const p = String(relativePath || '').replace(/^\/+/, '')
|
|
const base = getStaticAssetsBaseUrl()
|
|
if (!base) {
|
|
return localStaticUrl(p)
|
|
}
|
|
const seg = p.split('/').filter(Boolean).map((s) => encodeURIComponent(s)).join('/')
|
|
const url = `${base}${seg}`
|
|
return withOssVersion(url, getStaticAssetsVersion())
|
|
}
|
|
|
|
export const DEFAULT_PLACEHOLDER_IMAGE_URL = staticAssetUrl('images/logo.gif')
|
|
export const IMG_DEFAULT_PRODUCT = staticAssetUrl('images/default-product.png')
|
|
/** 全端统一:空列表 / 暂无 等占位图 */
|
|
export const IMG_NOTHING = staticAssetUrl('images/nothing.svg')
|
|
export const IMG_EMPTY = IMG_NOTHING
|
|
export const IMG_LOGO_WATERMARK = staticAssetUrl('images/logo.gif')
|
|
export const IMG_CLIPBOARD = staticAssetUrl('images/logo.gif')
|
|
export const IMG_PASSWORD_CARD = staticAssetUrl('images/logo.gif')
|
|
export const IMG_LINK = staticAssetUrl('images/logo.gif')
|
|
export const IMG_SETTINGS_AVATAR = staticAssetUrl('images/logo.gif')
|
|
export const IMG_SETTINGS_PASSWORD = staticAssetUrl('images/logo.gif')
|
|
export const IMG_CUSTOMER_SERVICE = staticAssetUrl('images/logo.gif')
|
|
export const ICON_ARROW_BOTTOM = staticAssetUrl('images/logo.gif')
|