new UI and handle cashing
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import type { AppConfig } from './types'
|
||||
|
||||
type RawAppConfig = AppConfig & {
|
||||
user?: Record<string, any>
|
||||
}
|
||||
|
||||
let appConfig: RawAppConfig | null = null
|
||||
|
||||
export function setAppConfig(config: RawAppConfig) {
|
||||
appConfig = config || {}
|
||||
window.__APP_CONFIG__ = appConfig
|
||||
}
|
||||
|
||||
export function getRawAppConfig() {
|
||||
return appConfig ?? window.__APP_CONFIG__ ?? null
|
||||
}
|
||||
|
||||
export function getTenantConfig() {
|
||||
const rawConfig = getRawAppConfig()
|
||||
|
||||
if (rawConfig?.user && typeof rawConfig.user === 'object') {
|
||||
return rawConfig.user
|
||||
}
|
||||
|
||||
if (rawConfig && Object.keys(rawConfig).length > 0) {
|
||||
return rawConfig
|
||||
}
|
||||
|
||||
return {}
|
||||
}
|
||||
|
||||
export function getConfig<T = any>(key: string, fallback?: T): T {
|
||||
const config = getTenantConfig()
|
||||
const value = config?.[key]
|
||||
|
||||
return (value ?? fallback ?? null) as T
|
||||
}
|
||||
Reference in New Issue
Block a user