| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import type { LocaleSetting, LocaleType } from '/#/config';
- import { defineStore } from 'pinia';
- import { store } from '/@/store';
- import { LOCALE_KEY } from '/@/enums/cacheEnum';
- import { createLocalStorage } from '/@/utils/cache';
- import { localeSetting } from '/@/settings/localeSetting';
- const ls = createLocalStorage();
- const lsLocaleSetting = (ls.get(LOCALE_KEY) || localeSetting) as LocaleSetting;
- interface LocaleState {
- localInfo: LocaleSetting;
- }
- interface appList {
- name: string;
- url: string;
- }
- interface appItem {
- name: string;
- icon: string;
- appList: appList[];
- }
- export const useLocaleStore = defineStore({
- id: 'app-locale',
- state: (): LocaleState => ({
- localInfo: lsLocaleSetting,
- }),
- getters: {
- getShowPicker(): boolean {
- return !!this.localInfo?.showPicker;
- },
- getLocale(): LocaleType {
- return this.localInfo?.locale ?? 'zh_CN';
- },
- getAppList(): appItem[] {
- return [
- {
- name: 'iOS',
- icon: 'uil:apple',
- appList: [
- {
- name: 'Pro',
- url: 'https://apps.apple.com/cn/app/id6451010749',
- },
- {
- name: 'Minion/Mega',
- url: 'https://apps.apple.com/cn/app/id6451013242',
- },
- ],
- },
- {
- name: 'Android',
- icon: 'uil:android',
- appList: [
- {
- name: 'Pro',
- url: 'https://play.google.com/store/apps/details?id=com.fdage.eight.jp',
- },
- {
- name: 'Minion/Mega',
- url: 'https://play.google.com/store/apps/details?id=com.fdage.turn.dual.jp',
- },
- ],
- },
- ];
- },
- },
- actions: {
- /**
- * Set up multilingual information and cache
- * @param info multilingual info
- */
- setLocaleInfo(info: Partial<LocaleSetting>) {
- this.localInfo = { ...this.localInfo, ...info };
- ls.set(LOCALE_KEY, this.localInfo);
- },
- /**
- * Initialize multilingual information and load the existing configuration from the local cache
- */
- initLocale() {
- this.setLocaleInfo({
- ...localeSetting,
- ...this.localInfo,
- });
- },
- },
- });
- // Need to be used outside the setup
- export function useLocaleStoreWithOut() {
- return useLocaleStore(store);
- }
|