|
@@ -3,9 +3,23 @@
|
3
|
3
|
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
|
4
|
4
|
|
5
|
5
|
<div class="title-container">
|
6
|
|
- <h3 class="title">Login Form</h3>
|
|
6
|
+ <h3 class="title">{{ isLogin ? $t('login') : $t('register') }}</h3>
|
7
|
7
|
</div>
|
8
|
8
|
|
|
9
|
+ <el-form-item v-if="!isLogin" prop="email">
|
|
10
|
+ <span class="svg-container">
|
|
11
|
+ <svg-icon icon-class="email" />
|
|
12
|
+ </span>
|
|
13
|
+ <el-input
|
|
14
|
+ v-model="loginForm.email"
|
|
15
|
+ placeholder="Email"
|
|
16
|
+ name="email"
|
|
17
|
+ type="email"
|
|
18
|
+ tabindex="1"
|
|
19
|
+ auto-complete="on"
|
|
20
|
+ />
|
|
21
|
+ </el-form-item>
|
|
22
|
+
|
9
|
23
|
<el-form-item prop="username">
|
10
|
24
|
<span class="svg-container">
|
11
|
25
|
<svg-icon icon-class="user" />
|
|
@@ -16,7 +30,7 @@
|
16
|
30
|
placeholder="Username"
|
17
|
31
|
name="username"
|
18
|
32
|
type="text"
|
19
|
|
- tabindex="1"
|
|
33
|
+ tabindex="2"
|
20
|
34
|
auto-complete="on"
|
21
|
35
|
/>
|
22
|
36
|
</el-form-item>
|
|
@@ -32,20 +46,21 @@
|
32
|
46
|
:type="passwordType"
|
33
|
47
|
placeholder="Password"
|
34
|
48
|
name="password"
|
35
|
|
- tabindex="2"
|
|
49
|
+ tabindex="3"
|
36
|
50
|
auto-complete="on"
|
37
|
|
- @keyup.enter.native="handleLogin"
|
|
51
|
+ @keyup.enter.native="handleSubmit"
|
38
|
52
|
/>
|
39
|
53
|
<span class="show-pwd" @click="showPwd">
|
40
|
54
|
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
|
41
|
55
|
</span>
|
42
|
56
|
</el-form-item>
|
43
|
57
|
|
44
|
|
- <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">Login</el-button>
|
|
58
|
+ <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleSubmit">
|
|
59
|
+ {{ isLogin ? $t('login') : $t('register') }}
|
|
60
|
+ </el-button>
|
45
|
61
|
|
46
|
|
- <div class="tips">
|
47
|
|
- <span style="margin-right:20px;">username: admin</span>
|
48
|
|
- <span> password: any</span>
|
|
62
|
+ <div class="switch-mode" @click="toggleMode">
|
|
63
|
+ {{ isLogin ? $t('switchToRegister') : $t('switchToLogin') }}
|
49
|
64
|
</div>
|
50
|
65
|
|
51
|
66
|
</el-form>
|
|
@@ -72,12 +87,23 @@ export default {
|
72
|
87
|
callback()
|
73
|
88
|
}
|
74
|
89
|
}
|
|
90
|
+ const validateEmail = (rule, value, callback) => {
|
|
91
|
+ const emailPattern = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/
|
|
92
|
+ if (!emailPattern.test(value)) {
|
|
93
|
+ callback(new Error('Please enter a valid email address'))
|
|
94
|
+ } else {
|
|
95
|
+ callback()
|
|
96
|
+ }
|
|
97
|
+ }
|
75
|
98
|
return {
|
|
99
|
+ isLogin: true,
|
76
|
100
|
loginForm: {
|
|
101
|
+ email: '',
|
77
|
102
|
username: 'admin',
|
78
|
103
|
password: '111111'
|
79
|
104
|
},
|
80
|
105
|
loginRules: {
|
|
106
|
+ email: [{ required: true, trigger: 'blur', validator: validateEmail }],
|
81
|
107
|
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
|
82
|
108
|
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
|
83
|
109
|
},
|
|
@@ -86,15 +112,10 @@ export default {
|
86
|
112
|
redirect: undefined
|
87
|
113
|
}
|
88
|
114
|
},
|
89
|
|
- watch: {
|
90
|
|
- $route: {
|
91
|
|
- handler: function(route) {
|
92
|
|
- this.redirect = route.query && route.query.redirect
|
93
|
|
- },
|
94
|
|
- immediate: true
|
95
|
|
- }
|
96
|
|
- },
|
97
|
115
|
methods: {
|
|
116
|
+ toggleMode() {
|
|
117
|
+ this.isLogin = !this.isLogin
|
|
118
|
+ },
|
98
|
119
|
showPwd() {
|
99
|
120
|
if (this.passwordType === 'password') {
|
100
|
121
|
this.passwordType = ''
|
|
@@ -105,11 +126,15 @@ export default {
|
105
|
126
|
this.$refs.password.focus()
|
106
|
127
|
})
|
107
|
128
|
},
|
108
|
|
- handleLogin() {
|
|
129
|
+ handleSubmit() {
|
109
|
130
|
this.$refs.loginForm.validate(valid => {
|
110
|
131
|
if (valid) {
|
111
|
132
|
this.loading = true
|
112
|
|
- this.$store.dispatch('user/login', this.loginForm).then(() => {
|
|
133
|
+ const action = this.isLogin ? 'user/login' : 'user/register'
|
|
134
|
+ this.$store.dispatch(action, this.loginForm).then(() => {
|
|
135
|
+ if (!this.isLogin) {
|
|
136
|
+ this.toggleMode()
|
|
137
|
+ }
|
113
|
138
|
this.$router.push({ path: this.redirect || '/' })
|
114
|
139
|
this.loading = false
|
115
|
140
|
}).catch(() => {
|
|
@@ -176,6 +201,7 @@ $cursor: #fff;
|
176
|
201
|
$bg:#2d3a4b;
|
177
|
202
|
$dark_gray:#889aa4;
|
178
|
203
|
$light_gray:#eee;
|
|
204
|
+$green: #00ff00;
|
179
|
205
|
|
180
|
206
|
.login-container {
|
181
|
207
|
min-height: 100%;
|
|
@@ -233,5 +259,14 @@ $light_gray:#eee;
|
233
|
259
|
cursor: pointer;
|
234
|
260
|
user-select: none;
|
235
|
261
|
}
|
|
262
|
+
|
|
263
|
+ .switch-mode {
|
|
264
|
+ text-decoration: underline;
|
|
265
|
+ color: $green;
|
|
266
|
+ cursor: pointer;
|
|
267
|
+ user-select: none;
|
|
268
|
+ text-align: center;
|
|
269
|
+ margin-top: 20px;
|
|
270
|
+ }
|
236
|
271
|
}
|
237
|
272
|
</style>
|