Explorar o código

feat: (i18n) 测试

gemercheung %!s(int64=2) %!d(string=hai) anos
pai
achega
fed2cfb387
Modificáronse 3 ficheiros con 104 adicións e 105 borrados
  1. 69 69
      src/locales/useLocale.ts
  2. 29 29
      src/settings/localeSetting.ts
  3. 6 7
      src/views/dashboard/analysis/index.vue

+ 69 - 69
src/locales/useLocale.ts

@@ -1,69 +1,69 @@
-/**
- * Multi-language related operations
- */
-import type { LocaleType } from '/#/config';
-
-import { i18n } from './setupI18n';
-import { useLocaleStoreWithOut } from '/@/store/modules/locale';
-import { unref, computed } from 'vue';
-import { loadLocalePool, setHtmlPageLang } from './helper';
-
-interface LangModule {
-  message: Recordable;
-  dateLocale: Recordable;
-  dateLocaleName: string;
-}
-
-function setI18nLanguage(locale: LocaleType) {
-  const localeStore = useLocaleStoreWithOut();
-
-  if (i18n.mode === 'legacy') {
-    i18n.global.locale = locale;
-  } else {
-    (i18n.global.locale as any).value = locale;
-  }
-  localeStore.setLocaleInfo({ locale });
-  setHtmlPageLang(locale);
-}
-
-export function useLocale() {
-  const localeStore = useLocaleStoreWithOut();
-  const getLocale = computed(() => localeStore.getLocale);
-  const getShowLocalePicker = computed(() => localeStore.getShowPicker);
-
-  const getAntdLocale = computed((): any => {
-    return i18n.global.getLocaleMessage(unref(getLocale))?.antdLocale ?? {};
-  });
-
-  // Switching the language will change the locale of useI18n
-  // And submit to configuration modification
-  async function changeLocale(locale: LocaleType) {
-    const globalI18n = i18n.global;
-    const currentLocale = unref(globalI18n.locale);
-    if (currentLocale === locale) {
-      return locale;
-    }
-
-    if (loadLocalePool.includes(locale)) {
-      setI18nLanguage(locale);
-      return locale;
-    }
-    const langModule = ((await import(`./lang/${locale}.ts`)) as any).default as LangModule;
-    if (!langModule) return;
-
-    const { message } = langModule;
-
-    globalI18n.setLocaleMessage(locale, message);
-    loadLocalePool.push(locale);
-
-    setI18nLanguage(locale);
-    return locale;
-  }
-
-  return {
-    getLocale,
-    getShowLocalePicker,
-    changeLocale,
-    getAntdLocale,
-  };
-}
+/**
+ * Multi-language related operations
+ */
+import type { LocaleType } from '/#/config';
+
+import { i18n } from './setupI18n';
+import { useLocaleStoreWithOut } from '/@/store/modules/locale';
+import { unref, computed } from 'vue';
+import { loadLocalePool, setHtmlPageLang } from './helper';
+
+interface LangModule {
+  message: Recordable;
+  dateLocale: Recordable;
+  dateLocaleName: string;
+}
+
+function setI18nLanguage(locale: LocaleType) {
+  const localeStore = useLocaleStoreWithOut();
+
+  if (i18n.mode === 'legacy') {
+    i18n.global.locale = locale;
+  } else {
+    (i18n.global.locale as any).value = locale;
+  }
+  localeStore.setLocaleInfo({ locale });
+  setHtmlPageLang(locale);
+}
+
+export function useLocale() {
+  const localeStore = useLocaleStoreWithOut();
+  const getLocale = computed(() => localeStore.getLocale);
+  const getShowLocalePicker = computed(() => localeStore.getShowPicker);
+
+  const getAntdLocale = computed((): any => {
+    return i18n.global.getLocaleMessage(unref(getLocale))?.antdLocale ?? {};
+  });
+
+  // Switching the language will change the locale of useI18n
+  // And submit to configuration modification
+  async function changeLocale(locale: LocaleType) {
+    const globalI18n = i18n.global;
+    const currentLocale = unref(globalI18n.locale);
+    if (currentLocale === locale) {
+      return locale;
+    }
+
+    if (loadLocalePool.includes(locale)) {
+      setI18nLanguage(locale);
+      return locale;
+    }
+    const langModule = ((await import(`./lang/${locale}.ts`)) as any).default as LangModule;
+    if (!langModule) return;
+
+    const { message } = langModule;
+
+    globalI18n.setLocaleMessage(locale, message);
+    loadLocalePool.push(locale);
+
+    setI18nLanguage(locale);
+    return locale;
+  }
+
+  return {
+    getLocale,
+    getShowLocalePicker,
+    changeLocale,
+    getAntdLocale,
+  };
+}

+ 29 - 29
src/settings/localeSetting.ts

@@ -1,29 +1,29 @@
-import type { DropMenu } from '../components/Dropdown';
-import type { LocaleSetting, LocaleType } from '/#/config';
-
-export const LOCALE: { [key: string]: LocaleType } = {
-  ZH_CN: 'zh_CN',
-  EN_US: 'en',
-};
-
-export const localeSetting: LocaleSetting = {
-  showPicker: false,
-  // Locale
-  locale: LOCALE.ZH_CN,
-  // Default locale
-  fallback: LOCALE.ZH_CN,
-  // available Locales
-  availableLocales: [LOCALE.ZH_CN, LOCALE.EN_US],
-};
-
-// locale list
-export const localeList: DropMenu[] = [
-  {
-    text: '简体中文',
-    event: LOCALE.ZH_CN,
-  },
-  {
-    text: 'English',
-    event: LOCALE.EN_US,
-  },
-];
+import type { DropMenu } from '../components/Dropdown';
+import type { LocaleSetting, LocaleType } from '/#/config';
+
+export const LOCALE: { [key: string]: LocaleType } = {
+  ZH_CN: 'zh_CN',
+  EN_US: 'en',
+};
+
+export const localeSetting: LocaleSetting = {
+  showPicker: true,
+  // Locale
+  locale: LOCALE.ZH_CN,
+  // Default locale
+  fallback: LOCALE.ZH_CN,
+  // available Locales
+  availableLocales: [LOCALE.ZH_CN, LOCALE.EN_US],
+};
+
+// locale list
+export const localeList: DropMenu[] = [
+  {
+    text: '简体中文',
+    event: LOCALE.ZH_CN,
+  },
+  {
+    text: 'English',
+    event: LOCALE.EN_US,
+  },
+];

+ 6 - 7
src/views/dashboard/analysis/index.vue

@@ -52,13 +52,10 @@
     bulletChatExportApi,
   } from '/@/api/dashboard/analysis';
   import { listRoomsApi } from '/@/api/scene/list';
-  import { formatToDate } from '/@/utils/dateUtil';
-  import dayjs from 'dayjs';
-  import 'dayjs/locale/zh-cn';
-  dayjs.locale('zh-cn');
+  import { dateUtil, formatToDate } from '/@/utils/dateUtil';
 
-  const today = formatToDate(dayjs(new Date()));
-  const priorDate = formatToDate(dayjs(new Date().setDate(new Date().getDate() - 30)));
+  const today = formatToDate(dateUtil(new Date()));
+  const priorDate = formatToDate(dateUtil(new Date().setDate(new Date().getDate() - 30)));
 
   const loading = ref(true);
   // const { t } = useI18n();
@@ -112,6 +109,8 @@
           resultField: 'list',
           valueField: 'id',
           immediate: false,
+          showSearch: true,
+          optionFilterProp: 'label',
           params: {
             page: 1,
             limit: 1000,
@@ -131,7 +130,7 @@
           // mode: 'date',
           disabledDate(current) {
             // console.log('current', current, date);
-            return current && current > dayjs().endOf('day');
+            return current && current > dateUtil().endOf('day');
           },
           onChange: (value) => {
             console.log('onchange', value);