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