index.vue
9.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<template>
<div id="login">
<div class="login-content-wrap">
<div class="login-logo"><img src="./images/logo-login.svg" /></div>
<div class="login-con">
<div class="login-img">
<div class="content"></div>
</div>
<div class="login-wrap">
<p>账号登录</p>
<div class="login-user" :class="{ 'select-border': change.user }">
<img class="user-icon" src="./images/user.svg" />
<input
type="text"
class="user-input"
placeholder="请输入账号"
v-model="userInfo.username"
@focus="reduceBorder('user')"
@blur="addBorder('user')"
/>
<span class="warning" v-show="warning.user">账号不能为空</span>
</div>
<div
class="login-user user-mt"
:class="{ 'select-border': change.pass }"
>
<img class="user-icon" src="./images/password.svg" />
<input
type="password"
class="user-input"
placeholder="请输入密码"
v-model="userInfo.password"
v-show="!selectEye"
@focus="reduceBorder('pass')"
@blur="addBorder('pass')"
/>
<input
type="text"
class="user-input"
placeholder="请输入密码"
v-model="userInfo.password"
v-show="selectEye"
@focus="reduceBorder('pass')"
@blur="addBorder('pass')"
/>
<img
class="password-eye"
src="./images/open.svg"
@click="selectEyes"
v-show="selectEye"
/>
<img
class="password-eye"
src="./images/close.svg"
@click="selectEyes"
v-show="!selectEye"
/>
<span class="warning" v-show="warning.pass">密码不能为空</span>
</div>
<div
class="login-user login-valid"
:class="{ 'select-border': change.valid }"
>
<img class="user-icon" src="./images/valid.svg" />
<input
type="text"
class="user-input"
placeholder="请输入验证码"
v-model="userInfo.captchaCode"
@focus="reduceBorder('valid')"
@blur="addBorder('valid')"
/>
<img
class="valid-img"
:src="codeSrc"
alt="暂无验证码"
@click="reloadCaptcha"
/>
<span class="warning" v-show="warning.valid">验证码不能为空</span>
</div>
<div id="loginBtn" class="login-btn" @click="goHome">登录</div>
</div>
</div>
</div>
</div>
</template>
<script>
import axios from "axios";
export default {
data() {
return {
// 用户名
selectIcon: true,
// 用户名
selectEye: false,
userInfo: {
// 用户名
username: "",
// 密码
password: "",
// 重定向地址
redirectUrl: "",
// 验证码key
captchaKey: "",
// 验证码值
captchaCode: "",
},
//边框
change: {
user: false,
pass: false,
valid:false
},
// 提示语
warning: {
user: false,
pass: false,
valid: false,
},
// 验证码图片地址
codeSrc:""
};
},
mounted() {
this.initPage();
this.userInfo.redirectUrl = localStorage.getItem("dj-location");
this.reloadCaptcha()
let self = this;
document.onkeydown = function (e) {
//按下回车提交
let key = window.event.keyCode;
//事件中keycode=13为回车事件
if (key == 13) {
self.goHome();
}
};
},
methods: {
// 更新验证码
reloadCaptcha(){
axios.get(window._config.services.management + "/management/captcha?format=json").then(res => {
if (res.data.status === 1) {
this.userInfo.captchaKey = res.data.content['dubhe.captcha']
this.codeSrc = res.data.content.image
}
})
},
// 初始化
initPage() {
let userInfo =
localStorage.getItem("userInfo") &&
JSON.parse(localStorage.getItem("userInfo"));
if (userInfo) {
this.userInfo.username = userInfo.username;
this.userInfo.password = userInfo.password;
}
},
goHome() {
if (this.userInfo.username && this.userInfo.password) {
axios
.post(
window._config.services.management + "/management/cas/login",
this.userInfo
)
.then((response) => {
if (response.data.status === 1) {
if (response.data.content.location) {
window.location.href = response.data.content.location;
}
} else {
this.$message.error(response.data.message);
}
})
.catch((error) => {
console.log(error);
this.$message.error(error.message);
});
} else {
return
}
},
selectEyes() {
this.selectEye = !this.selectEye;
},
//获取焦点
reduceBorder(type) {
this.change[type] = true
},
addBorder(type) {
//失去焦点
switch (type) {
case "user":
this.change.user = false;
if (!this.userInfo.username) {
this.warning.user = true;
} else {
this.warning.user = false;
}
break;
case "pass":
this.change.pass = false;
if (!this.userInfo.password) {
this.warning.pass = true;
} else {
this.warning.pass = false;
}
break;
case "valid":
this.change.valid = false;
if (!this.userInfo.captchaCode) {
this.warning.valid = true;
} else {
this.warning.valid = false;
}
break;
default:
break;
}
}
},
};
</script>
<style lang="scss" scoped>
input::placeholder{
color: #878787;
font-size: 14px;
font-family:Arial, Helvetica, sans-serif
}
#login {
width: 100vw;
height: 100vh;
background: url("./images/login-bg.png") no-repeat;
background-size: 100%;
overflow: hidden;
position: relative;
.login-content-wrap{
position: absolute;
left: 50%;
top: calc(50% + 10px);
transform: translate(-50%, -50%);
}
.login-logo {
height: 70px;
width: 100%;
text-align: center;
position: absolute;
top: -140px;
}
.login-logo img {
height: 100%;
}
.login-con {
margin: 0 auto;
width: 936px;
height: 450px;
.login-img{
width: 456px;
height: 450px;
float: left;
box-sizing: border-box;
padding: 126px 86px;
background-color: #fff;
position: relative;
&:after{
content: "";
display: inline-block;
width: 1px;
height: calc(100% - 96px);
background-image: linear-gradient(#fff,#9AA4C8,#fff);
position: absolute;
right: 0;
top: 48px;
}
.content{
width: 100%;
height: 100%;
background: url("./images/login-img.svg") no-repeat;
}
}
.login-wrap{
width: 480px;
height: 450px;
float: left;
box-sizing: border-box;
padding: 48px 56px;
background: #FFFFFF;
p{
width: 80px;
font-size: 20px;
font-weight: 500;
color: #333333;
line-height: 26px;
position: relative;
&:after{
content: "";
display: inline-block;
height: 2px;
width: 74px;
background-color: #CF8933;
position: absolute;
bottom: -4px;
left: 2px;
}
}
}
}
.login-user {
width: 100%;
height: 40px;
border: 1px solid #E5E5E5;
box-sizing: border-box;
margin-top: 34px;
border-radius: 2px;
position: relative;
.user-icon {
float: left;
margin: 10px auto auto 10px;
width: 28px;
height: 18px;
}
.user-input {
width: 80%;
float: left;
font-size: 16px;
outline: 0;
border: none;
color: #4a4a4a;
height: 38px;
line-height: 40px;
}
.password-eye {
float: right;
width: 16px;
height: 16px;
margin-right: 12px;
margin-top: 13px;
cursor: pointer;
}
.warning {
font-size: 12px;
color: red;
position: absolute;
left: 0;
bottom: -18px;
}
}
.login-valid{
width: 60%;
.valid-img{
width: 50%;
position: absolute;
right: -66%;
top: 2px;
cursor: pointer;
}
}
.user-mt {
margin-top: 26px;
}
.select-border {
border: 1px solid rgba(0, 113, 255, 1);
}
.login-btn {
width: 100%;
height: 48px;
background: #74A3F5;
border-radius: 2px;
margin: 0 auto;
margin-top: 40px;
font-size: 20px;
font-weight: 500;
line-height: 48px;
text-align: center;
color: #fff;
cursor: pointer;
}
.reserved-con {
position: absolute;
bottom: 0;
width: 100%;
height: 18px;
background-color: #4971ca;
}
}
</style>