fix
This commit is contained in:
33
src/composables/systemBranding.ts
Normal file
33
src/composables/systemBranding.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { computed, readonly, ref } from 'vue'
|
||||
import { fetchPublicSystemBranding, type SystemBranding } from '@/api/ops/systemSettings'
|
||||
|
||||
const branding = ref<SystemBranding | null>(null)
|
||||
let pending: Promise<SystemBranding> | null = null
|
||||
|
||||
export async function loadSystemBranding(force = false): Promise<SystemBranding> {
|
||||
if (!force && branding.value) return branding.value
|
||||
if (!force && pending) return pending
|
||||
pending = fetchPublicSystemBranding()
|
||||
.then((response: any) => {
|
||||
if (response.code !== 0 || !response.details?.system_name) {
|
||||
throw new Error(response.message || '系统品牌配置无效')
|
||||
}
|
||||
branding.value = response.details as SystemBranding
|
||||
document.title = branding.value.system_name
|
||||
return branding.value
|
||||
})
|
||||
.finally(() => {
|
||||
pending = null
|
||||
})
|
||||
return pending
|
||||
}
|
||||
|
||||
export function useSystemBranding() {
|
||||
return {
|
||||
branding: readonly(branding),
|
||||
systemName: computed(() => branding.value?.system_name || ''),
|
||||
logoURL: computed(() => branding.value?.logo?.url || ''),
|
||||
loginBackgroundURLs: computed(() => (branding.value?.login_backgrounds || []).map((item) => item.url)),
|
||||
loadSystemBranding,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user