-
- {{title}}
+ {{ title }}
-
+
-
+
-
+
-
- 记住我
-
+
+
+
+ {{ $t('common.login_rm') }}
+
+
+
+
+
+ {{ language }}
+
+
+
+ 简体中文
+ English
+ Vietnamese
+
+
+
+
- 登 录
- 登 录 中...
+ {{ $t('common.login') }}
+ {{ $t('common.login_ing') }}
@@ -47,27 +63,29 @@ import Config from '@/settings'
import { getCodeImg } from '@/api/login'
import Cookies from 'js-cookie'
import Background from '@/assets/images/background.jpg'
-import Logo from '@/assets/images/hailaing2.png'
+import i18n from '@/i18n'
+import { fetchMessages } from '@/api/i18n'
export default {
name: 'Login',
data() {
return {
- title: '印尼海亮铜箔LMS',
+ language: '简体中文',
+ title: i18n.t('platform.title'),
+ title_param: 'platform',
Background: Background,
- logo: Logo,
codeUrl: '',
cookiePass: '',
loginForm: {
username: 'admin',
- password: '',
+ password: '123456',
rememberMe: false,
code: '',
uuid: ''
},
loginRules: {
- username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
- password: [{ required: true, trigger: 'blur', message: '密码不能为空' }],
- code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
+ username: [{ required: true, trigger: 'blur', message: i18n.t('platform.tip1') }],
+ password: [{ required: true, trigger: 'blur', message: i18n.t('platform.tip2') }],
+ code: [{ required: true, trigger: 'change', message: i18n.t('platform.tip3') }]
},
loading: false,
redirect: undefined
@@ -82,6 +100,7 @@ export default {
}
},
created() {
+ this.setLang(localStorage.getItem('lang'))
// 获取验证码
this.getCode()
// 获取用户名密码等Cookie
@@ -90,6 +109,36 @@ export default {
this.point()
},
methods: {
+ // 中英文切换
+ // 语言切换-x
+ async changeLanguage(locale) {
+ // 如果已经加载过该语言,可以直接设置,避免重复请求
+ if (!this.$i18n.getLocaleMessage(locale)) {
+ const messages = await fetchMessages(locale)
+ this.$i18n.setLocaleMessage(locale, messages.content)
+ }
+ this.$i18n.locale = locale
+ // 可以将当前语言保存到本地存储,以便下次使用
+ localStorage.setItem('lang', locale)
+ this.setLang(locale)
+ location.reload()
+ },
+ langChange(command) {
+ this.$i18n.locale = command
+ localStorage.setItem('lang', command)
+ this.setLang(command)
+ location.reload()
+ },
+ // 国际化开发:2.设置
+ setLang(command) {
+ if (command === 'en') {
+ this.language = 'English'
+ } else if (command === 'zh') {
+ this.language = '简体中文'
+ } else if (command === 'iv') {
+ this.language = 'Vietnamese'
+ }
+ },
getCode() {
getCodeImg().then(res => {
this.codeUrl = res.img
@@ -133,7 +182,11 @@ export default {
}
this.$store.dispatch('Login', user).then(() => {
this.loading = false
- this.$router.push({ path: this.redirect || '/' })
+ window.location.href = this.redirect
+ // if (this.redirect === 'http://localhost:8013/dashboard'){
+ // window.location.href = this.redirect
+ // }
+ // this.$router.push({ path: this.redirect || '/' })
}).catch(() => {
this.loading = false
this.getCode()
@@ -149,8 +202,8 @@ export default {
console.log(point)
if (point) {
this.$notify({
- title: '提示',
- message: '当前登录状态已过期,请重新登录!',
+ title: i18n.t('common.Tips'),
+ message: i18n.t('common.Tip20'),
type: 'warning',
duration: 5000
})
@@ -162,53 +215,47 @@ export default {