Browse Source

i18n配置及home试用

noToken
安虹睿 1 year ago
parent
commit
d7c3b958f8
  1. 1
      PC/UI.WinIn.FasterZ.Store/src/api/wms-auth.js
  2. 5
      PC/UI.WinIn.FasterZ.Store/src/lang/en.js
  3. 49
      PC/UI.WinIn.FasterZ.Store/src/lang/index.js
  4. 5
      PC/UI.WinIn.FasterZ.Store/src/lang/zh.js
  5. 3
      PC/UI.WinIn.FasterZ.Store/src/main.js
  6. 4
      PC/UI.WinIn.FasterZ.Store/src/router/index.js

1
PC/UI.WinIn.FasterZ.Store/src/api/wms-auth.js

@ -29,7 +29,6 @@ export function logout() {
// faster-new // faster-new
// 通过用户名获取用户信息 // 通过用户名获取用户信息
export function getUsersByUserName(name) { export function getUsersByUserName(name) {
console.log(33,userApi)
let _api = userApi == 'undefined' ? authApi : userApi + '/api' let _api = userApi == 'undefined' ? authApi : userApi + '/api'
return request({ return request({
url: _api + '/identity/users/by-username/'+name, url: _api + '/identity/users/by-username/'+name,

5
PC/UI.WinIn.FasterZ.Store/src/lang/en.js

@ -0,0 +1,5 @@
export default {
common: {
home:'home'
}
}

49
PC/UI.WinIn.FasterZ.Store/src/lang/index.js

@ -0,0 +1,49 @@
// lang/index.js
import Vue from "vue"
import ElementUI from "element-ui"
import VueI18n from "vue-i18n"
// elment-ui
import locale from "element-ui/lib/locale"
import zhLocale from "element-ui/lib/locale/lang/zh-CN"
import enLocale from "element-ui/lib/locale/lang/en"
// 自己的多语言文件
import zh from "./zh"
import en from "./en"
Vue.use(VueI18n)
const messages = {
"zh-CN": {
...zh,
...zhLocale,
},
"en": {
...en,
...enLocale,
}
}
console.log(localStorage.getItem("browserLanguage"))
const i18n = new VueI18n({
messages,
fallbackLocale: "zh-CN", // 匹配不到时默认的语言
silentTranslationWarn: true, // 控制台的warning
locale: localStorage.getItem("browserLanguage") || "zh-CN", // set locale
})
locale.use(ElementUI, {
i18n: (key, value) => i18n.t(key, value),
})
// ***
// 非 vue 文件中使用这个方法
const translate = (localeKey) => {
const locale = localStorage.getItem("language") || "zh-CN"
const hasKey = i18n.te(localeKey, locale) // 使用i18n的 te 方法来检查是否能够匹配到对应键值
const translatedStr = i18n.t(localeKey)
if (hasKey) {
return translatedStr
}
return localeKey
}
export { i18n, messages, translate }

5
PC/UI.WinIn.FasterZ.Store/src/lang/zh.js

@ -0,0 +1,5 @@
export default {
common: {
home:'系统首页'
}
}

3
PC/UI.WinIn.FasterZ.Store/src/main.js

@ -6,7 +6,7 @@ import App from './App'
import store from './store' import store from './store'
import router from './router' import router from './router'
import watchLocal from '@/utils/watcLlocalstorage'//用于监听本地缓存 import watchLocal from '@/utils/watcLlocalstorage'//用于监听本地缓存
import i18n from './lang'
import "./utils/utils" import "./utils/utils"
/** /**
@ -70,5 +70,6 @@ new Vue({
el: '#app', el: '#app',
router, router,
store, store,
i18n,
render: h => h(App) render: h => h(App)
}) })

4
PC/UI.WinIn.FasterZ.Store/src/router/index.js

@ -1,6 +1,6 @@
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import { translate as $t } from "@/lang"
Vue.use(Router) Vue.use(Router)
@ -71,7 +71,7 @@ export let constantRoutes = [
name: 'Dashboard', name: 'Dashboard',
meta: { meta: {
keepAlive : true, keepAlive : true,
title: localStorage.getItem('browserLanguage') == 'zh-Hans' ? '系统首页' : 'Dashboard', title: $t('common.home'),
icon: 'svg_dashboard', icon: 'svg_dashboard',
outerFirst:true outerFirst:true
// affix: true // affix: true

Loading…
Cancel
Save