chore: add i18n support for TabsView.vue; 🌟

This commit is contained in:
chenghongxing 2020-07-19 18:40:27 +08:00
parent b2e0accd97
commit 3573a51dbd
3 changed files with 37 additions and 7 deletions

View File

@ -12,7 +12,7 @@
@contextmenu="onContextmenu" @contextmenu="onContextmenu"
> >
<a-tab-pane :key="page.fullPath" v-for="page in pageList"> <a-tab-pane :key="page.fullPath" v-for="page in pageList">
<span slot="tab" :pagekey="page.fullPath">{{page.name}}</span> <span slot="tab" :pagekey="page.fullPath">{{pageName(page.path)}}</span>
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
<div class="tabs-view-content"> <div class="tabs-view-content">
@ -27,13 +27,14 @@
</template> </template>
<script> <script>
import AdminLayout from './AdminLayout' import AdminLayout from '@/layouts/AdminLayout'
import Contextmenu from '../components/menu/Contextmenu' import Contextmenu from '@/components/menu/Contextmenu'
import PageToggleTransition from '../components/transition/PageToggleTransition' import PageToggleTransition from '@/components/transition/PageToggleTransition'
import {mapState, mapMutations} from 'vuex' import {mapState, mapMutations} from 'vuex'
export default { export default {
name: 'TabsView', name: 'TabsView',
i18n: require('./i18n'),
components: { PageToggleTransition, Contextmenu, AdminLayout }, components: { PageToggleTransition, Contextmenu, AdminLayout },
data () { data () {
return { return {
@ -48,12 +49,16 @@ export default {
} }
}, },
computed: { computed: {
...mapState('setting', ['multiPage', 'animate', 'layout', 'dustbins']) ...mapState('setting', ['multiPage', 'animate', 'layout', 'dustbins', 'routesI18n'])
}, },
created () { created () {
const route = this.$route const route = this.$route
this.pageList.push(route) this.pageList.push(route)
this.activePage = route.fullPath this.activePage = route.fullPath
let i18n = this.routesI18n
Object.keys(i18n).forEach(key => {
this.$i18n.mergeLocaleMessage(key, i18n[key])
})
}, },
watch: { watch: {
'$route': function (newRoute) { '$route': function (newRoute) {
@ -81,7 +86,7 @@ export default {
}, },
remove (key) { remove (key) {
if (this.pageList.length === 1) { if (this.pageList.length === 1) {
return this.$message.warning('这是最后一页,不能再关闭了啦') return this.$message.warning(this.$t('warn'))
} }
let index = this.pageList.findIndex(item => item.fullPath === key) let index = this.pageList.findIndex(item => item.fullPath === key)
let pageRoute = this.pageList[index] let pageRoute = this.pageList[index]
@ -161,6 +166,9 @@ export default {
this.setDustbins(this.dustbins.filter(item => item !== componentName)) this.setDustbins(this.dustbins.filter(item => item !== componentName))
} }
}, },
pageName(path) {
return this.$t(path.substring(1).replace(new RegExp('/', 'g'), '.') + '.name')
},
...mapMutations('setting', ['setDustbins']) ...mapMutations('setting', ['setDustbins'])
} }
} }

22
src/layouts/tabs/i18n.js Normal file
View File

@ -0,0 +1,22 @@
module.exports = {
messages: {
CN: {
closeLeft: '关闭左侧',
closeRight: '关闭右侧',
closeOthers: '关闭其它',
warn: '这是最后一页,不能再关闭了',
},
HK: {
closeLeft: '關閉左側',
closeRight: '關閉右側',
closeOthers: '關閉其它',
warn: '這是最後一頁,不能再關閉了',
},
US: {
closeLeft: 'close left',
closeRight: 'close right',
closeOthers: 'close others',
warn: 'This is the last page, you can\'t close it',
},
}
}

View File

@ -2,7 +2,7 @@ import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import PageView from '@/layouts/PageView' import PageView from '@/layouts/PageView'
import BlankView from '@/layouts/BlankView' import BlankView from '@/layouts/BlankView'
import TabsView from '@/layouts/TabsView' import TabsView from '@/layouts/tabs/TabsView'
import Login from '@/pages/login/Login' import Login from '@/pages/login/Login'
Vue.use(Router) Vue.use(Router)