import { getStore, setStore } from 'common/utils/web-store' import { defineStore } from 'pinia' import { ref, watch } from 'vue-demi' import { useI18n } from 'vue-i18n' import { LOCALE_STORE } from '../utils/consts' export const useSettingsStore = defineStore('protal-settings', () => { const { locale: i18nLocale } = useI18n() // 国际化设置 const locale = ref<'zh-CN'|'zh-TW'>(getStore(LOCALE_STORE) ?? (i18nLocale.value as 'zh-CN'|'zh-TW') ?? 'zh-CN') function triggerLocale (type?: 'zh-CN'|'zh-TW') { locale.value = type ?? (i18nLocale.value === 'zh-CN' ? 'zh-TW' : 'zh-CN') } watch(locale, (value) => { if (i18nLocale.value !== value) { i18nLocale.value = value setStore(LOCALE_STORE, value) } }, { immediate: true }) return { locale, triggerLocale } })