store2
This commit is contained in:
+29
-8
@@ -1,6 +1,5 @@
|
||||
|
||||
export function getConfigApp(key: string) {
|
||||
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user:{}
|
||||
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user : {}
|
||||
|
||||
if (config) {
|
||||
return config[key]
|
||||
@@ -8,11 +7,33 @@ export function getConfigApp(key: string) {
|
||||
return null
|
||||
}
|
||||
|
||||
let storeModeFromSettings: boolean | null = null
|
||||
|
||||
function isSwitchOn(value: string | undefined | null): boolean {
|
||||
const v = (value ?? '').trim().toLowerCase()
|
||||
return v === 'true' || v === '1' || v === 'yes'
|
||||
}
|
||||
|
||||
export function setStoreModeFromSettings(value: boolean): void {
|
||||
storeModeFromSettings = value
|
||||
}
|
||||
|
||||
/** is_store فقط از API تنظیمات (get_settings) خوانده میشود — نه از get_user */
|
||||
export async function initStoreModeFromSettings(): Promise<boolean> {
|
||||
if (storeModeFromSettings !== null) return storeModeFromSettings
|
||||
|
||||
try {
|
||||
const { getConfiguration } = await import('@/api/configuration')
|
||||
const rows = await getConfiguration()
|
||||
const row = Array.isArray(rows) ? rows.find((item) => item.key === 'is_store') : null
|
||||
storeModeFromSettings = row ? isSwitchOn(row.value) : false
|
||||
} catch {
|
||||
storeModeFromSettings = false
|
||||
}
|
||||
|
||||
return storeModeFromSettings
|
||||
}
|
||||
|
||||
export function isStoreApp(): boolean {
|
||||
const value = getConfigApp('is_store')
|
||||
if (value === true || value === 1) return true
|
||||
if (typeof value === 'string') {
|
||||
return ['true', '1', 'yes'].includes(value.trim().toLowerCase())
|
||||
}
|
||||
return false
|
||||
return storeModeFromSettings === true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user