22 lines
785 B
TypeScript
22 lines
785 B
TypeScript
import { useFetchJson } from '@/composable/useFetchJson'
|
|
import type { Resp } from '@/types'
|
|
import type { Settings } from '@/types/settings'
|
|
import { defineStore } from 'pinia'
|
|
import { computed, ref } from 'vue'
|
|
|
|
export const useSettingsStore = defineStore('settings', () => {
|
|
const settings = ref<Settings | null>(null)
|
|
const loaded = ref(false)
|
|
const shopDefaultLanguage = computed(() => settings.value?.app?.shop_default_language ?? 1)
|
|
|
|
async function getSettings(): Promise<Settings | null> {
|
|
if (loaded.value && settings.value) return settings.value
|
|
const resp = await useFetchJson<Settings>('/api/v1/settings')
|
|
settings.value = resp.items
|
|
loaded.value = true
|
|
return resp.items
|
|
}
|
|
|
|
return { settings, loaded, shopDefaultLanguage, getSettings }
|
|
})
|