国际化修改

This commit is contained in:
caoyang
2022-01-17 10:09:01 +08:00
parent 24ee90f38f
commit d95c9bb7b4
25 changed files with 602 additions and 332 deletions
+33 -22
View File
@@ -1,17 +1,13 @@
<template>
<a-config-provider :locale="locale">
<div id="app">
<div>
<a-button @click="changeLocale('en-us')" v-show="localeval=='zh-cn'">English</a-button >
<a-button @click="changeLocale('zh-cn')" v-show="localeval=='en-us'">中文</a-button >
</div>
<router-view/>
<router-view v-if="isRouterAlive" />
</div>
</a-config-provider>
</template>
<script>
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
// import en from 'ant-design-vue/lib/locale-provider/en_US'
import enUS from 'ant-design-vue/lib/locale-provider/en_US'
import enquireScreen from '@/utils/device'
import moment from 'moment'
import 'moment/locale/zh-cn'
@@ -23,7 +19,7 @@
data () {
return {
locale: zhCN,
localeval: 'zh-cn'
isRouterAlive:true
}
},
created () {
@@ -44,30 +40,45 @@
that.$store.dispatch('setSidebar', true)
}
})
// 默认中文
localStorage.lang == undefined ? localStorage.setItem("language", "zh-cn") : "";
// 自己配置多语言适配
this.$root.Bus.$on("switchLanguage", value => {
let router_path = this.$route.path;
switch (value) {
case "zh-cn":
localStorage.setItem("language", "zh-cn");
break;
case "en-us":
localStorage.setItem("language", "en-us");
break;
}
// 刷新页面
this.isRouterAlive = false; //先关闭,
this.$nextTick(function() {
this.isRouterAlive = true; //再打开
});
// 系统组件适配
let lang = localStorage.language;
if (lang == "zh-cn") {
this.locale = zhCN;
moment.locale("zh-cn");
} else if (lang == "en-us") {
this.locale = enUS;
moment.locale("en-us");
}
});
},
mounted() {
},
watch:{
},
computed:{
},
methods:{
moment,
changeLocale (localeval) {
this.localeval = localeval
if (localeval === EN) {
moment.locale(EN)
this.$i18n.locale = EN
this.locale = null
} else {
moment.locale(ZH)
this.$i18n.locale = ZH
this.locale = zhCN
}
}
}
}
</script>