2026-06-25 00:13:03 +03:30
|
|
|
import { ref } from 'vue'
|
2026-06-23 22:31:07 +03:30
|
|
|
import { setCachedMainMetal } from '@/utils/metalLabels'
|
|
|
|
|
|
2026-01-24 17:45:54 +03:30
|
|
|
export function getConfigApp(key: string) {
|
2026-06-12 20:30:00 +03:30
|
|
|
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user : {}
|
2026-01-24 17:45:54 +03:30
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
|
return config[key]
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-06-11 22:29:28 +03:30
|
|
|
|
2026-06-12 20:30:00 +03:30
|
|
|
let storeModeFromSettings: boolean | null = null
|
2026-06-15 15:48:10 +03:30
|
|
|
let settingsBootstrapped = false
|
2026-06-12 20:30:00 +03:30
|
|
|
|
2026-06-25 00:13:03 +03:30
|
|
|
/** reactive — برای فیلتر منوی «بنرها» در پیکربندی */
|
|
|
|
|
export const bannerEnabledSetting = ref(false)
|
|
|
|
|
|
2026-06-12 20:30:00 +03:30
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-25 00:13:03 +03:30
|
|
|
export function setBannerEnabledFromSettings(value: boolean): void {
|
|
|
|
|
bannerEnabledSetting.value = value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function applyBannerEnabledFromRows(rows: Array<{ key?: string; value?: string | null }>) {
|
|
|
|
|
const row = rows.find((item) => item.key === 'banner_enabled')
|
|
|
|
|
setBannerEnabledFromSettings(row ? isSwitchOn(row.value) : false)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-15 15:48:10 +03:30
|
|
|
async function bootstrapSettingsFromApi(): Promise<void> {
|
|
|
|
|
if (settingsBootstrapped) return
|
2026-06-12 20:30:00 +03:30
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const { getConfiguration } = await import('@/api/configuration')
|
2026-06-15 15:48:10 +03:30
|
|
|
const { parseMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
|
2026-06-12 20:30:00 +03:30
|
|
|
const rows = await getConfiguration()
|
2026-06-15 15:48:10 +03:30
|
|
|
const list = Array.isArray(rows) ? rows : []
|
|
|
|
|
const isStoreRow = list.find((item) => item.key === 'is_store')
|
|
|
|
|
const mainWalletRow = list.find((item) => item.key === 'main_wallet_products')
|
2026-06-23 22:31:07 +03:30
|
|
|
const mainMetalRow = list.find((item) => item.key === 'main_metal')
|
2026-06-15 15:48:10 +03:30
|
|
|
storeModeFromSettings = isStoreRow ? isSwitchOn(isStoreRow.value) : false
|
2026-06-25 00:13:03 +03:30
|
|
|
applyBannerEnabledFromRows(list)
|
2026-06-23 22:31:07 +03:30
|
|
|
setCachedMainMetal(mainMetalRow?.value)
|
2026-06-15 15:48:10 +03:30
|
|
|
const { setCachedMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
|
|
|
|
|
setCachedMainWalletProductIds(parseMainWalletProductIds(mainWalletRow?.value))
|
2026-06-12 20:30:00 +03:30
|
|
|
} catch {
|
|
|
|
|
storeModeFromSettings = false
|
2026-06-25 00:13:03 +03:30
|
|
|
setBannerEnabledFromSettings(false)
|
2026-06-23 22:31:07 +03:30
|
|
|
setCachedMainMetal(null)
|
2026-06-15 15:48:10 +03:30
|
|
|
const { setCachedMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
|
|
|
|
|
setCachedMainWalletProductIds([])
|
|
|
|
|
} finally {
|
|
|
|
|
settingsBootstrapped = true
|
2026-06-12 20:30:00 +03:30
|
|
|
}
|
2026-06-15 15:48:10 +03:30
|
|
|
}
|
2026-06-12 20:30:00 +03:30
|
|
|
|
2026-06-15 15:48:10 +03:30
|
|
|
/** is_store و main_wallet_products از API تنظیمات — نه از get_user */
|
|
|
|
|
export async function initStoreModeFromSettings(): Promise<boolean> {
|
|
|
|
|
if (storeModeFromSettings !== null) return storeModeFromSettings
|
|
|
|
|
|
|
|
|
|
await bootstrapSettingsFromApi()
|
|
|
|
|
|
|
|
|
|
return storeModeFromSettings === true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function initWalletSettingsFromApi(): Promise<void> {
|
|
|
|
|
await bootstrapSettingsFromApi()
|
2026-06-12 20:30:00 +03:30
|
|
|
}
|
|
|
|
|
|
2026-06-11 22:29:28 +03:30
|
|
|
export function isStoreApp(): boolean {
|
2026-06-12 20:30:00 +03:30
|
|
|
return storeModeFromSettings === true
|
2026-06-11 22:29:28 +03:30
|
|
|
}
|