Commit d677729acbe2c024ab13cf490b205528507c4823

Authored by Vben
1 parent d81481c5

perf(i18n): improve circular dependencies

src/components/Application/src/AppDarkModeToggle.vue
... ... @@ -29,17 +29,12 @@
29 29 export default defineComponent({
30 30 name: 'DarkModeToggle',
31 31 components: { SvgIcon },
32   - // props: {
33   - // size: {
34   - // type: String,
35   - // default: 'default',
36   - // validate: (val) => ['default', 'large'].includes(val),
37   - // },
38   - // },
39 32 setup() {
40 33 const { prefixCls } = useDesign('dark-mode-toggle');
41 34 const { getDarkMode, setDarkMode, getShowDarkModeToggle } = useRootSetting();
  35 +
42 36 const isDark = computed(() => getDarkMode.value === ThemeEnum.DARK);
  37 +
43 38 function toggleDarkMode() {
44 39 const darkMode = getDarkMode.value === ThemeEnum.DARK ? ThemeEnum.LIGHT : ThemeEnum.DARK;
45 40 setDarkMode(darkMode);
... ... @@ -95,16 +90,5 @@
95 90 transform: translateX(calc(100% + 2px));
96 91 }
97 92 }
98   -
99   - // &--large {
100   - // width: 70px;
101   - // height: 34px;
102   - // padding: 0 10px;
103   -
104   - // .@{prefix-cls}-inner {
105   - // width: 26px;
106   - // height: 26px;
107   - // }
108   - // }
109 93 }
110 94 </style>
... ...
src/components/Application/src/search/AppSearch.vue
1 1 <script lang="tsx">
2 2 import { defineComponent, ref, unref } from 'vue';
3   -
4 3 import { Tooltip } from 'ant-design-vue';
5 4 import { SearchOutlined } from '@ant-design/icons-vue';
6 5 import AppSearchModal from './AppSearchModal.vue';
7   -
8   - import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
9 6 import { useI18n } from '/@/hooks/web/useI18n';
10   -
11 7 export default defineComponent({
12 8 name: 'AppSearch',
13   - components: { AppSearchModal, Tooltip },
14 9 setup() {
15 10 const showModal = ref(false);
16 11  
17   - const { getShowSearch } = useHeaderSetting();
18 12 const { t } = useI18n();
19 13  
20 14 function changeModal(show: boolean) {
... ... @@ -22,9 +16,6 @@
22 16 }
23 17  
24 18 return () => {
25   - if (!unref(getShowSearch)) {
26   - return null;
27   - }
28 19 return (
29 20 <div class="p-1" onClick={changeModal.bind(null, true)}>
30 21 <Tooltip>
... ...
src/components/Application/src/search/AppSearchFooter.vue
... ... @@ -2,21 +2,17 @@
2 2 <div :class="`${prefixCls}`">
3 3 <AppSearchKeyItem :class="`${prefixCls}__item`" icon="ant-design:enter-outlined" />
4 4 <span>{{ t('component.app.toSearch') }}</span>
5   -
6 5 <AppSearchKeyItem :class="`${prefixCls}__item`" icon="ion:arrow-up-outline" />
7 6 <AppSearchKeyItem :class="`${prefixCls}__item`" icon="ion:arrow-down-outline" />
8 7 <span>{{ t('component.app.toNavigate') }}</span>
9 8 <AppSearchKeyItem :class="`${prefixCls}__item`" icon="mdi:keyboard-esc" />
10   -
11 9 <span>{{ t('common.closeText') }}</span>
12 10 </div>
13 11 </template>
14 12  
15 13 <script lang="ts">
16 14 import { defineComponent } from 'vue';
17   -
18 15 import AppSearchKeyItem from './AppSearchKeyItem.vue';
19   -
20 16 import { useDesign } from '/@/hooks/web/useDesign';
21 17 import { useI18n } from '/@/hooks/web/useI18n';
22 18 export default defineComponent({
... ...
src/components/Application/src/search/AppSearchModal.vue
... ... @@ -85,7 +85,7 @@
85 85 visible: propTypes.bool,
86 86 },
87 87 emits: ['close'],
88   - setup(_, { emit }) {
  88 + setup(props, { emit }) {
89 89 const scrollWrap = ref<ElRef>(null);
90 90 const { prefixCls } = useDesign('app-search-modal');
91 91 const { t } = useI18n();
... ... @@ -96,9 +96,7 @@
96 96 const { handleSearch, searchResult, keyword, activeIndex, handleEnter, handleMouseenter } =
97 97 useMenuSearch(refs, scrollWrap, emit);
98 98  
99   - const getIsNotData = computed(() => {
100   - return !keyword || unref(searchResult).length === 0;
101   - });
  99 + const getIsNotData = computed(() => !keyword || unref(searchResult).length === 0);
102 100  
103 101 const getClass = computed(() => {
104 102 return [
... ... @@ -109,13 +107,8 @@
109 107 ];
110 108 });
111 109  
112   - function handleClose() {
113   - searchResult.value = [];
114   - emit('close');
115   - }
116   -
117 110 watch(
118   - () => _.visible,
  111 + () => props.visible,
119 112 (v: boolean) => {
120 113 v &&
121 114 nextTick(() => {
... ... @@ -124,6 +117,11 @@
124 117 }
125 118 );
126 119  
  120 + function handleClose() {
  121 + searchResult.value = [];
  122 + emit('close');
  123 + }
  124 +
127 125 return {
128 126 t,
129 127 prefixCls,
... ...
src/layouts/default/header/index.vue
... ... @@ -33,7 +33,7 @@
33 33  
34 34 <!-- action -->
35 35 <div :class="`${prefixCls}-action`">
36   - <AppSearch :class="`${prefixCls}-action__item `" />
  36 + <AppSearch :class="`${prefixCls}-action__item `" v-if="getShowSearch" />
37 37  
38 38 <ErrorAction v-if="getUseErrorHandle" :class="`${prefixCls}-action__item error-action`" />
39 39  
... ... @@ -123,6 +123,7 @@
123 123 getShowBread,
124 124 getShowHeaderLogo,
125 125 getShowHeader,
  126 + getShowSearch,
126 127 } = useHeaderSetting();
127 128  
128 129 const { getShowLocalePicker } = useLocale();
... ... @@ -190,6 +191,7 @@
190 191 getIsMixSidebar,
191 192 getShowSettingButton,
192 193 getShowSetting,
  194 + getShowSearch,
193 195 };
194 196 },
195 197 });
... ...
src/locales/helper.ts
  1 +import type { LocaleType } from '/#/config';
  2 +
1 3 import { set } from 'lodash-es';
2 4  
  5 +export const loadLocalePool: LocaleType[] = [];
  6 +
  7 +export function setHtmlPageLang(locale: LocaleType) {
  8 + document.querySelector('html')?.setAttribute('lang', locale);
  9 +}
  10 +
  11 +export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) {
  12 + cb(loadLocalePool);
  13 +}
  14 +
3 15 export function genMessage(langs: Record<string, Record<string, any>>, prefix = 'lang') {
4 16 const obj: Recordable = {};
5 17  
... ...
src/locales/setupI18n.ts
... ... @@ -2,8 +2,7 @@ import type { App } from &#39;vue&#39;;
2 2 import type { I18n, I18nOptions } from 'vue-i18n';
3 3  
4 4 import { createI18n } from 'vue-i18n';
5   -
6   -import { setLoadLocalePool, setHtmlPageLang } from './useLocale';
  5 +import { setHtmlPageLang, setLoadLocalePool } from './helper';
7 6 import { localeSetting } from '/@/settings/localeSetting';
8 7 import { useLocaleStoreWithOut } from '/@/store/modules/locale';
9 8  
... ... @@ -16,8 +15,8 @@ async function createI18nOptions(): Promise&lt;I18nOptions&gt; {
16 15 const locale = localeStore.getLocale;
17 16 const defaultLocal = await import(`./lang/${locale}.ts`);
18 17 const message = defaultLocal.default?.message ?? {};
19   -
20   - setHtmlPageLang(locale)
  18 +
  19 + setHtmlPageLang(locale);
21 20 setLoadLocalePool((loadLocalePool) => {
22 21 loadLocalePool.push(locale);
23 22 });
... ...
src/locales/useLocale.ts
... ... @@ -8,6 +8,7 @@ import moment from &#39;moment&#39;;
8 8 import { i18n } from './setupI18n';
9 9 import { useLocaleStoreWithOut } from '/@/store/modules/locale';
10 10 import { unref, computed } from 'vue';
  11 +import { loadLocalePool, setHtmlPageLang } from './helper';
11 12  
12 13 interface LangModule {
13 14 message: Recordable;
... ... @@ -15,16 +16,6 @@ interface LangModule {
15 16 momentLocaleName: string;
16 17 }
17 18  
18   -const loadLocalePool: LocaleType[] = [];
19   -
20   -export function setHtmlPageLang(locale: LocaleType) {
21   - document.querySelector('html')?.setAttribute('lang', locale);
22   -}
23   -
24   -export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) {
25   - cb(loadLocalePool);
26   -}
27   -
28 19 function setI18nLanguage(locale: LocaleType) {
29 20 const localeStore = useLocaleStoreWithOut();
30 21  
... ... @@ -34,7 +25,7 @@ function setI18nLanguage(locale: LocaleType) {
34 25 (i18n.global.locale as any).value = locale;
35 26 }
36 27 localeStore.setLocaleInfo({ locale });
37   - setHtmlPageLang(locale)
  28 + setHtmlPageLang(locale);
38 29 }
39 30  
40 31 export function useLocale() {
... ...