fix: store
This commit is contained in:
21
bo/src/stores/admin/settings.ts
Normal file
21
bo/src/stores/admin/settings.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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 }
|
||||
})
|
||||
Reference in New Issue
Block a user