From c10e38cdf23e0792f987b24a044d1554e40cf7b6 Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Wed, 5 May 2021 18:01:21 +0800 Subject: [PATCH] perf: dict perfect --- src/layout/components/Navbar.vue | 17 +- src/plugins/element-plus/index.ts | 4 + src/plugins/i18n/config.ts | 8 + src/plugins/i18n/index.ts | 2 +- src/plugins/vxe-table/index.ts | 6 + src/router/index.ts | 4 +- src/views/system/dict/config.vue | 177 ++++++++++++++++++ src/views/system/{dict.vue => dict/index.vue} | 63 ++++--- 8 files changed, 254 insertions(+), 27 deletions(-) create mode 100644 src/views/system/dict/config.vue rename src/views/system/{dict.vue => dict/index.vue} (87%) diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index b9be8f5f5..652ebe0f4 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -49,12 +49,15 @@ import { useMapGetters } from "../store"; import { useRouter, useRoute } from "vue-router"; import { useStore } from "vuex"; import { storageSession } from "/@/utils/storage"; -import { useI18n } from "vue-i18n"; import ch from "/@/assets/ch.png"; import en from "/@/assets/en.png"; import favicon from "/favicon.ico"; import { emitter } from "/@/utils/mitt"; import { deviceDetection } from "/@/utils/deviceDetection"; +import { useI18n } from "vue-i18n"; +import { locale as eleplusLocale } from "element-plus"; +import enLocale from "element-plus/lib/locale/lang/en"; +import zhLocale from "element-plus/lib/locale/lang/zh-cn"; export default defineComponent({ name: "Navbar", @@ -77,7 +80,13 @@ export default defineComponent({ // 国际化语言切换 const toggleLang = (): void => { langs.value = !langs.value; - langs.value ? (locale.value = "zh") : (locale.value = "en"); + if (langs.value) { + locale.value = "zh"; + eleplusLocale(zhLocale); + } else { + locale.value = "en"; + eleplusLocale(enLocale); + } }; watch( @@ -121,7 +130,9 @@ export default defineComponent({ en, favicon, onPanel, - deviceDetection + deviceDetection, + locale, + t }; } }); diff --git a/src/plugins/element-plus/index.ts b/src/plugins/element-plus/index.ts index 45d63ef5b..68e2caf7f 100644 --- a/src/plugins/element-plus/index.ts +++ b/src/plugins/element-plus/index.ts @@ -26,6 +26,8 @@ import { ElPopover, ElPopper, ElTooltip, + ElDrawer, + ElPagination, } from "element-plus"; const components = [ @@ -54,6 +56,8 @@ const components = [ ElPopover, ElPopper, ElTooltip, + ElDrawer, + ElPagination, ]; const plugins = [ElLoading]; diff --git a/src/plugins/i18n/config.ts b/src/plugins/i18n/config.ts index 4103ebec1..a212098d8 100644 --- a/src/plugins/i18n/config.ts +++ b/src/plugins/i18n/config.ts @@ -3,6 +3,12 @@ import zhVxeTable from "vxe-table/lib/locale/lang/zh-CN"; import enVxeTable from "vxe-table/lib/locale/lang/en-US"; +// element-plus国际化 +import { locale } from "element-plus"; +import enLocale from "element-plus/lib/locale/lang/en"; +import zhLocale from "element-plus/lib/locale/lang/zh-cn"; +locale(zhLocale); + export const menusConfig = { zh: { message: { @@ -106,9 +112,11 @@ export const localesConfigs = { zh: { message: Object.assign({}, ...localesList.map((v) => v.zh.message)), ...zhVxeTable, + ...zhLocale, }, en: { message: Object.assign({}, ...localesList.map((v) => v.en.message)), ...enVxeTable, + ...enLocale, }, }; diff --git a/src/plugins/i18n/index.ts b/src/plugins/i18n/index.ts index d8c4a54d7..c00fc16d9 100644 --- a/src/plugins/i18n/index.ts +++ b/src/plugins/i18n/index.ts @@ -5,7 +5,7 @@ import { localesConfigs } from "./config"; export const i18n = createI18n({ locale: "zh", // set locale - fallbackLocale: "zh", // set fallback locale + fallbackLocale: "en", // set fallback locale messages: localesConfigs, }); diff --git a/src/plugins/vxe-table/index.ts b/src/plugins/vxe-table/index.ts index d7f61ffc5..ff8a8f11f 100644 --- a/src/plugins/vxe-table/index.ts +++ b/src/plugins/vxe-table/index.ts @@ -58,6 +58,9 @@ VXETable.setup({ // 鼠标移到行是否要高亮显示 highlightHoverRow: true, }, + input: { + clearable: true, + }, // 对组件内置的提示语进行国际化翻译 i18n: (key, args) => i18n.global.t(key, args), // 可选,对参数中的列头、校验提示..等进行自动翻译(只对支持国际化的有效) @@ -66,6 +69,9 @@ VXETable.setup({ if (key && key.indexOf("message.") > -1) { return i18n.global.t(key, args); } + if (key && key.indexOf("el.") > -1) { + return i18n.global.t(key, args); + } return key; }, }); diff --git a/src/router/index.ts b/src/router/index.ts index 216adb151..d712ffa8d 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -233,7 +233,9 @@ const routes: Array = [ { path: "/system/dict", component: () => - import(/* webpackChunkName: "system" */ "../views/system/dict.vue"), + import( + /* webpackChunkName: "system" */ "../views/system/dict/index.vue" + ), meta: { // icon: '', title: "message.hsDict", diff --git a/src/views/system/dict/config.vue b/src/views/system/dict/config.vue new file mode 100644 index 000000000..a3db9f288 --- /dev/null +++ b/src/views/system/dict/config.vue @@ -0,0 +1,177 @@ + + + + + diff --git a/src/views/system/dict.vue b/src/views/system/dict/index.vue similarity index 87% rename from src/views/system/dict.vue rename to src/views/system/dict/index.vue index 0458e9f69..ad1c107df 100644 --- a/src/views/system/dict.vue +++ b/src/views/system/dict/index.vue @@ -1,13 +1,9 @@ -