Skip to content

Commit f3bfaa0

Browse files
committed
feat[login]:add 18n to login form
1 parent e261fbc commit f3bfaa0

File tree

5 files changed

+132
-82
lines changed

5 files changed

+132
-82
lines changed

src/lang/en.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,14 @@ export default {
4444
theme: 'Theme',
4545
clipboardDemo: 'Clipboard',
4646
i18n: 'I18n'
47+
},
48+
login: {
49+
title: 'Login Form',
50+
logIn: 'Log in',
51+
username: 'Username',
52+
password: 'Password',
53+
any: 'any',
54+
thirdparty: 'Or connect with',
55+
thirdpartyTips: 'Local can not be simulated, please combine their own business simulation! ! !'
4756
}
4857
}

src/lang/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const messages = {
2020
}
2121

2222
const i18n = new VueI18n({
23-
locale: Cookies.get('language') || 'zh', // set locale
23+
locale: Cookies.get('language') || 'en', // set locale
2424
messages // set locale messages
2525
})
2626

src/lang/zh.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,14 @@ export default {
4444
theme: '换肤',
4545
clipboardDemo: 'clipboard',
4646
i18n: '国际化'
47+
},
48+
login: {
49+
title: '系统登录',
50+
logIn: '登录',
51+
username: '账号',
52+
password: '密码',
53+
any: '随便填',
54+
thirdparty: '第三方登录',
55+
thirdpartyTips: '本地不能模拟,请结合自己业务进行模拟!!!'
4756
}
4857
}

src/utils/i18n.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// translate router.meta.title , be used in breadcrumb sidebar tagsview
12
export function generateTitle(title) {
23
return this.$t('route.' + title) // $t :this method from vue-i18n ,inject in @/lang/index.js
34
}

src/views/login/index.vue

Lines changed: 112 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
<template>
22
<div class="login-container">
3-
<el-form class="card-box login-form" autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left">
4-
<h3 class="title">系统登录</h3>
5-
<el-dropdown trigger="click" class='international' @command="handleSetLanguage">
6-
<div>
7-
<svg-icon class-name='right-menu-item international-icon' icon-class="language" />
8-
</div>
9-
<el-dropdown-menu slot="dropdown">
10-
<el-dropdown-item command="zh" :disabled="language==='zh'">中文</el-dropdown-item>
11-
<el-dropdown-item command="en" :disabled="language==='en'">English</el-dropdown-item>
12-
</el-dropdown-menu>
13-
</el-dropdown>
14-
3+
<el-form class="login-form" autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left">
4+
<div class="title-container">
5+
<h3 class="title">{{ translateKey('title')}}</h3>
6+
<lang-select class="set-language"></lang-select>
7+
</div>
158
<el-form-item prop="username">
169
<span class="svg-container svg-container_login">
1710
<svg-icon icon-class="user" />
1811
</span>
19-
<el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="邮箱" />
12+
<el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="username" />
2013
</el-form-item>
2114

2215
<el-form-item prop="password">
2316
<span class="svg-container">
2417
<svg-icon icon-class="password" />
2518
</span>
2619
<el-input name="password" :type="pwdType" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on"
27-
placeholder="密码" />
28-
<span class="show-pwd" @click="showPwd"><svg-icon icon-class="eye" /></span>
20+
placeholder="password" />
21+
<span class="show-pwd" @click="showPwd">
22+
<svg-icon icon-class="eye" />
23+
</span>
2924
</el-form-item>
3025

31-
<el-button type="primary" style="width:100%;margin-bottom:30px;" :loading="loading" @click.native.prevent="handleLogin">登录</el-button>
26+
<el-button type="primary" style="width:100%;margin-bottom:30px;" :loading="loading" @click.native.prevent="handleLogin">{{translateKey('logIn')}}</el-button>
3227

33-
<div class="tips">账号:admin 密码随便填</div>
34-
<div class="tips">账号:editor 密码随便填</div>
28+
<div class="tips">
29+
<span>{{translateKey('username')}} : admin</span>
30+
<span>{{translateKey('password')}} : {{translateKey('any')}}</span>
31+
</div>
32+
<div class="tips">
33+
<span>{{translateKey('username')}} : editor </span>
34+
<span>{{translateKey('password')}} : {{translateKey('any')}}</span>
35+
</div>
3536

36-
<el-button class="thirdparty-button" type="primary" @click="showDialog=true">打开第三方登录</el-button>
37+
<el-button class="thirdparty-button" type="primary" @click="showDialog=true">{{translateKey('thirdparty')}}</el-button>
3738
</el-form>
3839

39-
<el-dialog title="第三方验证" :visible.sync="showDialog">
40-
本地不能模拟,请结合自己业务进行模拟!!!<br/><br/><br/>
41-
邮箱登录成功,请选择第三方验证<br/>
40+
<el-dialog :title="translateKey('thirdparty')" :visible.sync="showDialog">
41+
{{translateKey('thirdpartyTips')}}
42+
<br/>
43+
<br/>
44+
<br/>
4245
<social-sign />
4346
</el-dialog>
4447

@@ -47,22 +50,23 @@
4750

4851
<script>
4952
import { isvalidUsername } from '@/utils/validate'
53+
import LangSelect from '@/components/LangSelect'
5054
import socialSign from './socialsignin'
5155
5256
export default {
53-
components: { socialSign },
57+
components: { LangSelect, socialSign },
5458
name: 'login',
5559
data() {
5660
const validateUsername = (rule, value, callback) => {
5761
if (!isvalidUsername(value)) {
58-
callback(new Error('请输入正确的用户名'))
62+
callback(new Error('Please enter the correct user name'))
5963
} else {
6064
callback()
6165
}
6266
}
6367
const validatePassword = (rule, value, callback) => {
6468
if (value.length < 6) {
65-
callback(new Error('密码不能小于6位'))
69+
callback(new Error('The password can not be less than 6 digits'))
6670
} else {
6771
callback()
6872
}
@@ -82,6 +86,9 @@ export default {
8286
}
8387
},
8488
methods: {
89+
translateKey(key) {
90+
return this.$t('login.' + key)
91+
},
8592
showPwd() {
8693
if (this.pwdType === 'password') {
8794
this.pwdType = ''
@@ -135,19 +142,15 @@ export default {
135142
</script>
136143

137144
<style rel="stylesheet/scss" lang="scss">
138-
@import "src/styles/mixin.scss";
139-
$bg:#2d3a4b;
140-
$dark_gray:#889aa4;
141-
$light_gray:#eee;
145+
$bg:#2d3a4b;
146+
$light_gray:#eee;
142147
143-
.login-container {
144-
@include relative;
145-
height: 100vh;
146-
background-color: $bg;
147-
input:-webkit-autofill {
148-
-webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
149-
-webkit-text-fill-color: #fff !important;
150-
}
148+
/* reset element-ui css */
149+
.login-container {
150+
.el-input {
151+
display: inline-block;
152+
height: 47px;
153+
width: 85%;
151154
input {
152155
background: transparent;
153156
border: 0px;
@@ -156,27 +159,62 @@ export default {
156159
padding: 12px 5px 12px 15px;
157160
color: $light_gray;
158161
height: 47px;
162+
&:-webkit-autofill {
163+
-webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
164+
-webkit-text-fill-color: #fff !important;
165+
}
159166
}
160-
.el-input {
161-
display: inline-block;
162-
height: 47px;
163-
width: 85%;
164-
}
165-
.tips {
166-
font-size: 14px;
167-
color: #fff;
168-
margin-bottom: 10px;
169-
}
170-
.svg-container {
171-
padding: 6px 5px 6px 15px;
172-
color: $dark_gray;
173-
vertical-align: middle;
174-
width: 30px;
175-
display: inline-block;
176-
&_login {
177-
font-size: 20px;
167+
}
168+
.el-form-item {
169+
border: 1px solid rgba(255, 255, 255, 0.1);
170+
background: rgba(0, 0, 0, 0.1);
171+
border-radius: 5px;
172+
color: #454545;
173+
}
174+
}
175+
176+
</style>
177+
178+
<style rel="stylesheet/scss" lang="scss" scoped>
179+
@import "src/styles/mixin.scss";
180+
$bg:#2d3a4b;
181+
$dark_gray:#889aa4;
182+
$light_gray:#eee;
183+
184+
.login-container {
185+
@include relative;
186+
height: 100vh;
187+
background-color: $bg;
188+
.login-form {
189+
position: absolute;
190+
left: 0;
191+
right: 0;
192+
width: 520px;
193+
padding: 35px 35px 15px 35px;
194+
margin: 120px auto;
195+
}
196+
.tips {
197+
font-size: 14px;
198+
color: #fff;
199+
margin-bottom: 10px;
200+
span {
201+
&:first-of-type {
202+
margin-right: 16px;
178203
}
179204
}
205+
}
206+
.svg-container {
207+
padding: 6px 5px 6px 15px;
208+
color: $dark_gray;
209+
vertical-align: middle;
210+
width: 30px;
211+
display: inline-block;
212+
&_login {
213+
font-size: 20px;
214+
}
215+
}
216+
.title-container {
217+
position: relative;
180218
.title {
181219
font-size: 26px;
182220
font-weight: 400;
@@ -185,33 +223,26 @@ export default {
185223
text-align: center;
186224
font-weight: bold;
187225
}
188-
.login-form {
189-
position: absolute;
190-
left: 0;
191-
right: 0;
192-
width: 400px;
193-
padding: 35px 35px 15px 35px;
194-
margin: 120px auto;
195-
}
196-
.el-form-item {
197-
border: 1px solid rgba(255, 255, 255, 0.1);
198-
background: rgba(0, 0, 0, 0.1);
199-
border-radius: 5px;
200-
color: #454545;
201-
}
202-
.show-pwd {
203-
position: absolute;
204-
right: 10px;
205-
top: 7px;
206-
font-size: 16px;
207-
color: $dark_gray;
208-
cursor: pointer;
209-
user-select:none;
210-
}
211-
.thirdparty-button{
226+
.set-language {
227+
color: #fff;
212228
position: absolute;
213-
right: 35px;
214-
bottom: 28px;
229+
top: 5px;
230+
right: 0px;
215231
}
216232
}
233+
.show-pwd {
234+
position: absolute;
235+
right: 10px;
236+
top: 7px;
237+
font-size: 16px;
238+
color: $dark_gray;
239+
cursor: pointer;
240+
user-select: none;
241+
}
242+
.thirdparty-button {
243+
position: absolute;
244+
right: 35px;
245+
bottom: 28px;
246+
}
247+
}
217248
</style>

0 commit comments

Comments
 (0)