forked from vbenjs/vue-vben-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
512 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
## Wip | ||
|
||
### 🎫 Chores | ||
|
||
- 移除 messageSetting 配置 | ||
|
||
## 2.0.0-rc.11 (2020-11-18) | ||
|
||
### ✨ Features | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import AppLocalPicker from './src/AppLocalPicker.vue'; | ||
|
||
export { AppLocalPicker }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { default as Dropdown } from './Dropdown'; | ||
export * from './types'; | ||
export { default as Dropdown } from './src/Dropdown'; | ||
export * from './src/types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,74 @@ | ||
/** | ||
* Multi-language related operations | ||
*/ | ||
import type { LocaleType } from '/@/locales/types'; | ||
import { appStore } from '/@/store/modules/app'; | ||
|
||
import { unref, ref } from 'vue'; | ||
|
||
import { getI18n } from '/@/setup/i18n'; | ||
|
||
import { useLocaleSetting } from '/@/settings/use/useLocaleSetting'; | ||
|
||
import moment from 'moment'; | ||
|
||
import 'moment/dist/locale/zh-cn'; | ||
|
||
moment.locale('zh-cn'); | ||
|
||
const antConfigLocaleRef = ref<any>(null); | ||
|
||
export function useLocale() { | ||
/** | ||
* | ||
*/ | ||
function getLocale(): string { | ||
return appStore.getProjectConfig.locale; | ||
const { getLang, getLocale, setLocale: setLocalSetting } = useLocaleSetting(); | ||
|
||
// Switching the language will change the locale of useI18n | ||
// And submit to configuration modification | ||
function changeLocale(lang: LocaleType): void { | ||
(getI18n().global.locale as any).value = lang; | ||
setLocalSetting({ lang }); | ||
// i18n.global.setLocaleMessage(locale, messages); | ||
|
||
antConfigLocaleRef.value = { a: 1 }; | ||
switch (lang) { | ||
// Simplified Chinese | ||
case 'zh_CN': | ||
import('ant-design-vue/es/locale/zh_CN').then((locale) => { | ||
antConfigLocaleRef.value = locale.default; | ||
}); | ||
|
||
moment.locale('cn'); | ||
break; | ||
// English | ||
case 'en': | ||
import('ant-design-vue/es/locale/en_US').then((locale) => { | ||
antConfigLocaleRef.value = locale.default; | ||
}); | ||
moment.locale('en-us'); | ||
break; | ||
|
||
// other | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param locale | ||
*/ | ||
async function changeLocale(locale: LocaleType): Promise<void> { | ||
appStore.commitProjectConfigState({ locale: locale }); | ||
// initialization | ||
function setupLocale() { | ||
const lang = unref(getLang); | ||
lang && changeLocale(lang); | ||
} | ||
|
||
return { getLocale, changeLocale }; | ||
return { | ||
setupLocale, | ||
getLocale, | ||
getLang, | ||
changeLocale, | ||
antConfigLocale: antConfigLocaleRef, | ||
}; | ||
} | ||
|
||
/** | ||
* For non-setup use | ||
*/ | ||
export function useExternalI18n() { | ||
return getI18n().global; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.