mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-28 05:39:34 +08:00
wip: multi-language support
This commit is contained in:
3
src/components/Application/index.ts
Normal file
3
src/components/Application/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import AppLocalPicker from './src/AppLocalPicker.vue';
|
||||
|
||||
export { AppLocalPicker };
|
53
src/components/Application/src/AppLocalPicker.vue
Normal file
53
src/components/Application/src/AppLocalPicker.vue
Normal file
@@ -0,0 +1,53 @@
|
||||
<template>
|
||||
<Dropdown
|
||||
:trigger="['click']"
|
||||
:dropMenuList="localeList"
|
||||
:selectedKeys="selectedKeys"
|
||||
@menuEvent="handleMenuEvent"
|
||||
>
|
||||
<GlobalOutlined class="app-locale" />
|
||||
</Dropdown>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent, ref, watchEffect, unref } from 'vue';
|
||||
|
||||
import { Dropdown, DropMenu } from '/@/components/Dropdown';
|
||||
import { GlobalOutlined } from '@ant-design/icons-vue';
|
||||
|
||||
import { useLocale } from '/@/hooks/web/useLocale';
|
||||
import { useLocaleSetting } from '/@/settings/use/useLocaleSetting';
|
||||
|
||||
import { LocaleType } from '/@/locales/types';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'AppLocalPicker',
|
||||
components: { GlobalOutlined, Dropdown },
|
||||
setup() {
|
||||
const { localeList } = useLocaleSetting();
|
||||
const selectedKeys = ref<string[]>([]);
|
||||
|
||||
const { changeLocale, getLang } = useLocale();
|
||||
|
||||
watchEffect(() => {
|
||||
selectedKeys.value = [unref(getLang)];
|
||||
});
|
||||
|
||||
function toggleLocale(lang: LocaleType | string) {
|
||||
changeLocale(lang as LocaleType);
|
||||
selectedKeys.value = [lang as string];
|
||||
}
|
||||
|
||||
function handleMenuEvent(menu: DropMenu) {
|
||||
toggleLocale(menu.event as string);
|
||||
}
|
||||
|
||||
return { localeList, handleMenuEvent, selectedKeys };
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.app-locale {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user