New language switching function on the front page (#921)

* feat: Added Internationalization(vue-i18n)

* feat: Adding an Internationalization Instance

Co-authored-by: 冯建军 <fengjj@data4truth.com>
pull/924/head
PleasePerfunctory 2 years ago committed by GitHub
parent 59cb0b28c3
commit a476d34da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -59,6 +59,7 @@
"vue": "2.6.10",
"vue-cookie": "^1.1.4",
"vue-count-to": "1.0.13",
"vue-i18n": "^6.1.3",
"vue-router": "3.0.2",
"vue-splitpane": "1.0.4",
"vue2-jsoneditor": "^1.0.6",
@ -68,7 +69,7 @@
"devDependencies": {
"@babel/core": "7.0.0",
"@babel/register": "7.0.0",
"@vue/cli-plugin-babel": "3.5.3",
"@vue/cli-plugin-babel": "~4",
"@vue/cli-plugin-eslint": "3.5.1",
"@vue/cli-plugin-unit-jest": "3.5.3",
"@vue/cli-service": "3.5.3",

@ -18,7 +18,7 @@
<!-- </el-tooltip>-->
</template>
<langChange />
<el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
<div class="avatar-wrapper">
<img src="../../../public/hippo4j.gif" class="user-avatar">
@ -32,7 +32,7 @@
<el-dropdown-item>Dashboard</el-dropdown-item>
</router-link>
<el-dropdown-item divided>
<span style="display:block;" @click="logout">Log Out</span>
<span style="display:block;" @click="logout">{{ $t('system.logOut') }}</span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
@ -45,12 +45,14 @@
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import ErrorLog from '@/components/ErrorLog'
import langChange from '@/locale/langChange'
export default {
components: {
Breadcrumb,
Hamburger,
ErrorLog
ErrorLog,
langChange
},
computed: {
...mapGetters([
@ -106,7 +108,7 @@
float: right;
height: 100%;
line-height: 50px;
display: flex;
&:focus {
outline: none;
}

@ -0,0 +1,30 @@
// 导入elementUi默认中英文语言包
import elZh from 'element-ui/lib/locale/lang/zh-CN'
import elEn from 'element-ui/lib/locale/lang/en'
import zh from './lang/zh'
import en from './lang/en'
const lang = localStorage.getItem('locale_lang')
export const i18nConfig = {
locale: lang || 'en', // 默认语种
messages: {
zh: { ...zh, ...elZh }, // 中文包
en: { ...en, ...elEn } // 英文包
}
}
export const langSelectList = () => {
return [
{
lang: 'zh',
name: '中文'
},
{
lang: 'en',
name: 'English'
}
]
}

@ -0,0 +1,10 @@
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import { i18nConfig } from './config'
Vue.use(VueI18n)
const i18n = new VueI18n(i18nConfig)
export default i18n

@ -0,0 +1,31 @@
export default {
// 系统
system: {
login: 'Login Form',
username: 'Username',
password: 'Password',
logOut: 'Log Out'
},
// 公共
common: {
search: 'Search',
addition: 'Addition',
serialNumber: 'Serial Number',
operation: 'Operation',
edit: 'Edit',
delete: 'Delete',
cancel: 'Cancel',
confirm: 'Confirm'
},
// 线程池
threadPool: {
tenant: 'Tenant',
project: 'Project',
threadPool: 'Thread Pool',
}
}

@ -0,0 +1,28 @@
export default {
// 系统
system: {
login: '登 陆',
username: '用户名',
password: '密码',
logOut: '注销'
},
// 公共
common: {
search: '搜索',
addition: '添加',
serialNumber: '序号',
operation: '操作',
edit: '编辑',
delete: '删除',
cancel: '取消',
confirm: '确认'
},
// 线程池
threadPool: {
tenant: '租户',
project: '项目',
threadPool: '线程池',
}
}

@ -0,0 +1,62 @@
<template>
<div class="lang-drop-wrap">
<el-dropdown @command="selectedLang" trigger="click">
<span class="el-dropdown-link">
{{ currentLangName }}
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item
v-for="item in langSelectList"
:key="item.lang"
:command="item.lang"
>
<span class="dropdown-item-text" :data-active="item.lang === currentLang">{{ item.name }}</span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</template>
<script>
import { langSelectList } from './config'
export default {
data() {
return {
langSelectList: langSelectList(),
currentLang: ''
}
},
mounted() {
const lang = this.$i18n.locale
this.currentLang = lang || null
},
computed: {
currentLangName() {
const langItem = this.langSelectList.find(item => item.lang === this.currentLang)
return langItem?.name || '选择语言'
}
},
methods: {
//
selectedLang(value) {
this.currentLang = value
this.$i18n.locale = value
localStorage.setItem('locale_lang', value)
}
}
}
</script>
<style lang="scss" scoped>
.lang-drop-wrap{
height: 100%;
margin-right: 15px;
.el-dropdown-link{
cursor: pointer;
}
}
.dropdown-item-text{
&[data-active=true] {
color: var(--jjext-color-dropdown-text) !important;
}
}
</style>

@ -17,6 +17,7 @@ import './icons'; // icon
import './permission'; // permission control
// import './utils/error-log' // error log
import i18n from '@/locale'
import * as filters from './filters'; // global filters
import echarts from 'echarts';
Vue.prototype.$echarts = echarts;
@ -25,6 +26,7 @@ Vue.prototype.$cookie = cookie;
Vue.use(Element, {
size: Cookies.get('size') || 'medium', // set element-ui default size
i18n: (key, value) => i18n.t(key, value)
});
// register global utility filters
@ -38,5 +40,6 @@ new Vue({
el: '#app',
router,
store,
i18n,
render: (h) => h(App),
});

@ -3,7 +3,7 @@
<div class="filter-container">
<el-select
v-model="listQuery.tenantId"
placeholder="租户"
:placeholder="$t('threadPool.tenant')"
style="width: 220px"
filterable
class="filter-item"
@ -18,7 +18,7 @@
</el-select>
<el-select
v-model="listQuery.itemId"
placeholder="项目"
:placeholder="$t('threadPool.project')"
style="width: 220px"
filterable
class="filter-item"
@ -33,7 +33,7 @@
</el-select>
<el-select
v-model="listQuery.tpId"
placeholder="线程池"
:placeholder="$t('threadPool.threadPool')"
style="width: 220px"
filterable
class="filter-item"
@ -53,7 +53,7 @@
icon="el-icon-search"
@click="fetchData"
>
搜索
{{ $t('common.search') }}
</el-button>
<el-button
class="filter-item"
@ -63,7 +63,7 @@
@click="handleCreate"
:disabled="isEditDisabled"
>
添加
{{ $t('common.addition') }}
</el-button>
</div>
<el-table
@ -74,7 +74,7 @@
fit
highlight-current-row
>
<el-table-column fixed label="序号" width="80">
<el-table-column fixed :label="$t('common.serialNumber')" width="80">
<template slot-scope="scope">{{ scope.$index + 1 }}</template>
</el-table-column>
<el-table-column label="租户" width="150">
@ -129,16 +129,16 @@
<template slot-scope="scope">{{ scope.row.gmtModified }}</template>
</el-table-column>
<el-table-column
label="操作"
:label="$t('common.operation')"
fixed="right"
width="90"
align="center"
class-name="small-padding fixed-width"
>
<template slot-scope="{ row }">
<el-button type="text" size="small" @click="handleUpdate(row)"> </el-button>
<el-button type="text" size="small" @click="handleUpdate(row)"> {{ $t('common.edit') }} </el-button>
<el-button size="small" :disabled="isEditDisabled" type="text" @click="handleDelete(row)">
删除
{{ $t('common.delete') }}
</el-button>
</template>
</el-table-column>
@ -327,9 +327,9 @@
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false"> 取消 </el-button>
<el-button @click="dialogFormVisible = false"> {{ $t('common.cancel') }} </el-button>
<el-button type="primary" @click="dialogStatus === 'create' ? createData() : updateData()">
确认
{{ $t('common.confirm') }}
</el-button>
</div>
</el-dialog>

@ -9,7 +9,7 @@
label-position="left"
>
<div class="title-container">
<h3 class="title">Login Form</h3>
<h3 class="title">{{ $t('system.login') }}</h3>
</div>
<el-form-item prop="username">
@ -19,7 +19,7 @@
<el-input
ref="username"
v-model="loginForm.username"
placeholder="Username"
:placeholder="$t('system.username')"
name="username"
type="text"
tabindex="1"
@ -37,7 +37,7 @@
ref="password"
v-model="loginForm.password"
:type="passwordType"
placeholder="Password"
:placeholder="$t('system.password')"
name="password"
tabindex="2"
autocomplete="on"

@ -35,7 +35,7 @@ module.exports = {
},
proxy: {
'/hippo4j/v1/cs': {
target: `http://127.0.0.1:6691/hippo4j/v1/cs`,
target: `http://console.hippo4j.cn:80/hippo4j/v1/cs`,
changOrigin: true,
secure: false,
pathRewrite: {

Loading…
Cancel
Save