站点 Logo 展示:优先显示图片,无 URL 或加载失败时回退为站点名称首字母。

This commit is contained in:
tzy 2026-06-06 14:50:42 +08:00
parent c556af99eb
commit 1a08bc47f4

View File

@ -0,0 +1,30 @@
import { computed, ref, watch } from 'vue'
import { useSiteStore } from '@/stores/site'
/**
* Logo退
*/
export function useSiteLogo(src?: () => string | undefined) {
const siteStore = useSiteStore()
const siteName = computed(() => siteStore.siteName || 'MES系统')
const siteLogo = computed(() => src?.() ?? siteStore.siteLogo)
const logoLoadFailed = ref(false)
const showSiteLogoImg = computed(() => !!siteLogo.value && !logoLoadFailed.value)
const fallbackLetter = computed(() => siteName.value.charAt(0) || 'M')
watch(siteLogo, () => {
logoLoadFailed.value = false
})
function handleLogoError() {
logoLoadFailed.value = true
}
return {
siteName,
siteLogo,
showSiteLogoImg,
fallbackLetter,
handleLogoError,
}
}