站点 Logo 展示:优先显示图片,无 URL 或加载失败时回退为站点名称首字母。
This commit is contained in:
parent
c556af99eb
commit
1a08bc47f4
30
src/composables/useSiteLogo.ts
Normal file
30
src/composables/useSiteLogo.ts
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user